|
|
@ -169,11 +169,11 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
switch state {
|
|
|
|
switch state {
|
|
|
|
case "unlock":
|
|
|
|
case "unlock":
|
|
|
|
if ext.Owner == nil {
|
|
|
|
if ext.Owner == nil {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_unlocked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_unlocked")))
|
|
|
|
} else if source != *ext.Owner {
|
|
|
|
} else if source != *ext.Owner {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_owner")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_owner")))
|
|
|
|
} else if ext.PendingOwner == nil {
|
|
|
|
} else if ext.PendingOwner == nil {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_unlocking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_unlocking")))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if len(ext.Requirements) == 0 {
|
|
|
|
if len(ext.Requirements) == 0 {
|
|
|
|
ext.Owner = nil
|
|
|
|
ext.Owner = nil
|
|
|
@ -199,11 +199,11 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
case "unlocking":
|
|
|
|
case "unlocking":
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_requirement")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_requirement")))
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("node_not_linked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("node_not_linked")))
|
|
|
|
} else if state.Lock != "unlocking" {
|
|
|
|
} else if state.Lock != "unlocking" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_unlocking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_unlocking")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "unlocked":
|
|
|
|
case "unlocked":
|
|
|
@ -213,11 +213,11 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
|
|
|
|
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_requirement")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_requirement")))
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_linked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_linked")))
|
|
|
|
} else if state.Lock != "unlocking" {
|
|
|
|
} else if state.Lock != "unlocking" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_unlocking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_unlocking")))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
state.Lock = "unlocked"
|
|
|
|
state.Lock = "unlocked"
|
|
|
|
ext.Requirements[source] = state
|
|
|
|
ext.Requirements[source] = state
|
|
|
@ -248,11 +248,11 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
|
|
|
|
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_requirement")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_requirement")))
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_linked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_linked")))
|
|
|
|
} else if state.Lock != "locking" {
|
|
|
|
} else if state.Lock != "locking" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_locking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_locking")))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
state.Lock = "locked"
|
|
|
|
state.Lock = "locked"
|
|
|
|
ext.Requirements[source] = state
|
|
|
|
ext.Requirements[source] = state
|
|
|
@ -278,18 +278,18 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
case "locking":
|
|
|
|
case "locking":
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
state, exists := ext.Requirements[source]
|
|
|
|
if exists == false {
|
|
|
|
if exists == false {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_requirement")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_requirement")))
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
} else if state.Link != "linked" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("node_not_linked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("node_not_linked")))
|
|
|
|
} else if state.Lock != "locking" {
|
|
|
|
} else if state.Lock != "locking" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("not_locking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("not_locking")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "lock":
|
|
|
|
case "lock":
|
|
|
|
if ext.Owner != nil {
|
|
|
|
if ext.Owner != nil {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_locked")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_locked")))
|
|
|
|
} else if ext.PendingOwner != nil {
|
|
|
|
} else if ext.PendingOwner != nil {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_locking")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_locking")))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
owner := source
|
|
|
|
owner := source
|
|
|
|
if len(ext.Requirements) == 0 {
|
|
|
|
if len(ext.Requirements) == 0 {
|
|
|
@ -321,7 +321,7 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node
|
|
|
|
func (ext *LockableExt) HandleLinkStartSignal(ctx *Context, source NodeID, node *Node, signal IDStringSignal) {
|
|
|
|
func (ext *LockableExt) HandleLinkStartSignal(ctx *Context, source NodeID, node *Node, signal IDStringSignal) {
|
|
|
|
ctx.Log.Logf("lockable", "LINK__START_SIGNAL: %s->%s %+v", source, node.ID, signal)
|
|
|
|
ctx.Log.Logf("lockable", "LINK__START_SIGNAL: %s->%s %+v", source, node.ID, signal)
|
|
|
|
link_type := signal.Str
|
|
|
|
link_type := signal.Str
|
|
|
|
target := signal.ID
|
|
|
|
target := signal.NodeID
|
|
|
|
switch link_type {
|
|
|
|
switch link_type {
|
|
|
|
case "req":
|
|
|
|
case "req":
|
|
|
|
state, exists := ext.Requirements[target]
|
|
|
|
state, exists := ext.Requirements[target]
|
|
|
@ -336,9 +336,9 @@ func (ext *LockableExt) HandleLinkStartSignal(ctx *Context, source NodeID, node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if exists == true {
|
|
|
|
} else if exists == true {
|
|
|
|
if state.Link == "linking" {
|
|
|
|
if state.Link == "linking" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_linking_req")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_linking_req")))
|
|
|
|
} else if state.Link == "linked" {
|
|
|
|
} else if state.Link == "linked" {
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(fmt.Errorf("already_req")))
|
|
|
|
ctx.Send(node.ID, source, NewErrorSignal(signal.ID(), fmt.Errorf("already_req")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if dep_exists == true {
|
|
|
|
} else if dep_exists == true {
|
|
|
|
ctx.Send(node.ID, source, NewLinkStartSignal("already_dep", target))
|
|
|
|
ctx.Send(node.ID, source, NewLinkStartSignal("already_dep", target))
|
|
|
|