From e013edc656b5fd6244c4e0c0cd4de775470da394 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Wed, 27 Sep 2023 18:28:56 -0600 Subject: [PATCH] Fixed bugs found developing tm --- lockable.go | 6 +++--- node.go | 4 ++-- policy.go | 1 + serialize.go | 1 + signal.go | 10 ++++++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lockable.go b/lockable.go index d85b8cd..caa17ff 100644 --- a/lockable.go +++ b/lockable.go @@ -100,7 +100,7 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID case "remove": _, exists := ext.Requirements[signal.NodeID] 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 { delete(ext.Requirements, signal.NodeID) 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 { case "locked": state, found := ext.Requirements[source] - if found == false { - msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "not_requirement"), source) + if found == false && source != node.ID { + msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID, "got 'locked' from non-requirement"), source) } else if state == Locking { if ext.State == Locking { ext.Requirements[source] = Locked diff --git a/node.go b/node.go index befb070..ec5b7d8 100644 --- a/node.go +++ b/node.go @@ -311,10 +311,10 @@ func nodeLoop(ctx *Context, node *Node) error { ctx.Send(msgs) continue } 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 { - 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 diff --git a/policy.go b/policy.go index 0c7e792..1b31ed8 100644 --- a/policy.go +++ b/policy.go @@ -249,4 +249,5 @@ type AllNodesPolicy struct { var DefaultPolicy = NewAllNodesPolicy(Tree{ ResultType: nil, + StatusType: nil, }) diff --git a/serialize.go b/serialize.go index e6b4ec3..94338d8 100644 --- a/serialize.go +++ b/serialize.go @@ -141,6 +141,7 @@ var ( PendingSignalType = NewSerializedType("PENDING_SIGNAL") TimeType = NewSerializedType("TIME") ResultType = NewSerializedType("RESULT") + StatusType = NewSerializedType("STATUS") TreeType = NewSerializedType("TREE") SerializedTypeSerialized = NewSerializedType("SERIALIZED_TYPE") ) diff --git a/signal.go b/signal.go index 65a67aa..98f7b2a 100644 --- a/signal.go +++ b/signal.go @@ -25,7 +25,7 @@ func (header SignalHeader) Header() SignalHeader { } 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 { @@ -164,6 +164,9 @@ type ErrorSignal struct { SignalHeader Error string } +func (signal ErrorSignal) String() string { + return fmt.Sprintf("ErrorSignal(%s, %s)", signal.SignalHeader, signal.Error) +} func (signal ErrorSignal) Permission() Tree { return Tree{ ResultType: { @@ -200,7 +203,7 @@ type StatusSignal struct { } func (signal StatusSignal) Permission() Tree { return Tree{ - SerializedType(StatusSignalType): nil, + StatusType: nil, } } func NewStatusSignal(source NodeID, status string) *StatusSignal { @@ -242,6 +245,9 @@ type LockSignal struct { SignalHeader State string } +func (signal LockSignal) String() string { + return fmt.Sprintf("LockSignal(%s, %s)", signal.SignalHeader, signal.State) +} const ( LockStateBase = "LOCK_STATE"