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":
_, 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

@ -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

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

@ -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")
)

@ -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"