Fixed bugs found developing tm

gql_cataclysm
noah metz 2023-09-27 18:28:56 -06:00
parent d4e0d855c7
commit e013edc656
5 changed files with 15 additions and 7 deletions

@ -100,7 +100,7 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID
case "remove": case "remove":
_, exists := ext.Requirements[signal.NodeID] _, exists := ext.Requirements[signal.NodeID]
if exists == false { if exists == false {
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "not_requirement"), source) msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "can't link: not_requirement"), source)
} else { } else {
delete(ext.Requirements, signal.NodeID) delete(ext.Requirements, signal.NodeID)
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "req_removed"), source) msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "req_removed"), source)
@ -122,8 +122,8 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
switch signal.State { switch signal.State {
case "locked": case "locked":
state, found := ext.Requirements[source] state, found := ext.Requirements[source]
if found == false { if found == false && source != node.ID {
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "not_requirement"), source) msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "got 'locked' from non-requirement"), source)
} else if state == Locking { } else if state == Locking {
if ext.State == Locking { if ext.State == Locking {
ext.Requirements[source] = Locked ext.Requirements[source] = Locked

@ -311,10 +311,10 @@ func nodeLoop(ctx *Context, node *Node) error {
ctx.Send(msgs) ctx.Send(msgs)
continue continue
} else if resp == Allow { } else if resp == Allow {
ctx.Log.Logf("policy", "SIGNAL_POLICY_ALLOW: %s->%s - %s", princ_id, node.ID, msg.Signal.Permission()) ctx.Log.Logf("policy", "SIGNAL_POLICY_ALLOW: %s->%s - %s", princ_id, node.ID, reflect.TypeOf(msg.Signal))
} }
} else { } else {
ctx.Log.Logf("policy", "SIGNAL_POLICY_SELF: %s - %s", node.ID, msg.Signal.Permission()) ctx.Log.Logf("policy", "SIGNAL_POLICY_SELF: %s - %s", node.ID, reflect.TypeOf(msg.Signal))
} }
signal = msg.Signal signal = msg.Signal

@ -249,4 +249,5 @@ type AllNodesPolicy struct {
var DefaultPolicy = NewAllNodesPolicy(Tree{ var DefaultPolicy = NewAllNodesPolicy(Tree{
ResultType: nil, ResultType: nil,
StatusType: nil,
}) })

@ -141,6 +141,7 @@ var (
PendingSignalType = NewSerializedType("PENDING_SIGNAL") PendingSignalType = NewSerializedType("PENDING_SIGNAL")
TimeType = NewSerializedType("TIME") TimeType = NewSerializedType("TIME")
ResultType = NewSerializedType("RESULT") ResultType = NewSerializedType("RESULT")
StatusType = NewSerializedType("STATUS")
TreeType = NewSerializedType("TREE") TreeType = NewSerializedType("TREE")
SerializedTypeSerialized = NewSerializedType("SERIALIZED_TYPE") SerializedTypeSerialized = NewSerializedType("SERIALIZED_TYPE")
) )

@ -25,7 +25,7 @@ func (header SignalHeader) Header() SignalHeader {
} }
func (header SignalHeader) String() string { func (header SignalHeader) String() string {
return fmt.Sprintf("Signal(%d, %s->%s)", header.Direction, header.ID, header.ReqID) return fmt.Sprintf("SignalHeader(%d, %s->%s)", header.Direction, header.ID, header.ReqID)
} }
type Signal interface { type Signal interface {
@ -164,6 +164,9 @@ type ErrorSignal struct {
SignalHeader SignalHeader
Error string Error string
} }
func (signal ErrorSignal) String() string {
return fmt.Sprintf("ErrorSignal(%s, %s)", signal.SignalHeader, signal.Error)
}
func (signal ErrorSignal) Permission() Tree { func (signal ErrorSignal) Permission() Tree {
return Tree{ return Tree{
ResultType: { ResultType: {
@ -200,7 +203,7 @@ type StatusSignal struct {
} }
func (signal StatusSignal) Permission() Tree { func (signal StatusSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(StatusSignalType): nil, StatusType: nil,
} }
} }
func NewStatusSignal(source NodeID, status string) *StatusSignal { func NewStatusSignal(source NodeID, status string) *StatusSignal {
@ -242,6 +245,9 @@ type LockSignal struct {
SignalHeader SignalHeader
State string State string
} }
func (signal LockSignal) String() string {
return fmt.Sprintf("LockSignal(%s, %s)", signal.SignalHeader, signal.State)
}
const ( const (
LockStateBase = "LOCK_STATE" LockStateBase = "LOCK_STATE"