|
|
@ -17,6 +17,7 @@ import (
|
|
|
|
type SignalDirection int
|
|
|
|
type SignalDirection int
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
StopSignalType SignalType = "STOP"
|
|
|
|
StopSignalType SignalType = "STOP"
|
|
|
|
|
|
|
|
ErrorSignalType = "ERROR"
|
|
|
|
StatusSignalType = "STATUS"
|
|
|
|
StatusSignalType = "STATUS"
|
|
|
|
LinkSignalType = "LINK"
|
|
|
|
LinkSignalType = "LINK"
|
|
|
|
LockSignalType = "LOCK"
|
|
|
|
LockSignalType = "LOCK"
|
|
|
@ -126,6 +127,18 @@ func NewDirectSignal(signal_type SignalType) BaseSignal {
|
|
|
|
|
|
|
|
|
|
|
|
var StopSignal = NewDownSignal(StopSignalType)
|
|
|
|
var StopSignal = NewDownSignal(StopSignalType)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ErrorSignal struct {
|
|
|
|
|
|
|
|
BaseSignal
|
|
|
|
|
|
|
|
Error error `json:"error"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewErrorSignal(err error) ErrorSignal {
|
|
|
|
|
|
|
|
return ErrorSignal{
|
|
|
|
|
|
|
|
BaseSignal: NewDirectSignal(ErrorSignalType),
|
|
|
|
|
|
|
|
Error: err,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type IDSignal struct {
|
|
|
|
type IDSignal struct {
|
|
|
|
BaseSignal
|
|
|
|
BaseSignal
|
|
|
|
ID NodeID `json:"id"`
|
|
|
|
ID NodeID `json:"id"`
|
|
|
@ -150,26 +163,26 @@ func NewIDSignal(signal_type SignalType, direction SignalDirection, id NodeID) I
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type StateSignal struct {
|
|
|
|
type StringSignal struct {
|
|
|
|
BaseSignal
|
|
|
|
BaseSignal
|
|
|
|
State string `json:"state"`
|
|
|
|
Str string `json:"state"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (signal StateSignal) Serialize() ([]byte, error) {
|
|
|
|
func (signal StringSignal) Serialize() ([]byte, error) {
|
|
|
|
return json.Marshal(&signal)
|
|
|
|
return json.Marshal(&signal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type IDStateSignal struct {
|
|
|
|
type IDStringSignal struct {
|
|
|
|
BaseSignal
|
|
|
|
BaseSignal
|
|
|
|
ID NodeID `json:"id"`
|
|
|
|
ID NodeID `json:"id"`
|
|
|
|
State string `json:"state"`
|
|
|
|
Str string `json:"state"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (signal IDStateSignal) Serialize() ([]byte, error) {
|
|
|
|
func (signal IDStringSignal) Serialize() ([]byte, error) {
|
|
|
|
return json.Marshal(&signal)
|
|
|
|
return json.Marshal(&signal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (signal IDStateSignal) String() string {
|
|
|
|
func (signal IDStringSignal) String() string {
|
|
|
|
ser, err := json.Marshal(signal)
|
|
|
|
ser, err := json.Marshal(signal)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "STATE_SER_ERR"
|
|
|
|
return "STATE_SER_ERR"
|
|
|
@ -177,42 +190,42 @@ func (signal IDStateSignal) String() string {
|
|
|
|
return string(ser)
|
|
|
|
return string(ser)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewStatusSignal(status string, source NodeID) IDStateSignal {
|
|
|
|
func NewStatusSignal(status string, source NodeID) IDStringSignal {
|
|
|
|
return IDStateSignal{
|
|
|
|
return IDStringSignal{
|
|
|
|
BaseSignal: NewUpSignal(StatusSignalType),
|
|
|
|
BaseSignal: NewUpSignal(StatusSignalType),
|
|
|
|
ID: source,
|
|
|
|
ID: source,
|
|
|
|
State: status,
|
|
|
|
Str: status,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewLinkSignal(state string) StateSignal {
|
|
|
|
func NewLinkSignal(state string) StringSignal {
|
|
|
|
return StateSignal{
|
|
|
|
return StringSignal{
|
|
|
|
BaseSignal: NewDirectSignal(LinkSignalType),
|
|
|
|
BaseSignal: NewDirectSignal(LinkSignalType),
|
|
|
|
State: state,
|
|
|
|
Str: state,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewIDStateSignal(signal_type SignalType, direction SignalDirection, state string, id NodeID) IDStateSignal {
|
|
|
|
func NewIDStringSignal(signal_type SignalType, direction SignalDirection, state string, id NodeID) IDStringSignal {
|
|
|
|
return IDStateSignal{
|
|
|
|
return IDStringSignal{
|
|
|
|
BaseSignal: NewBaseSignal(signal_type, direction),
|
|
|
|
BaseSignal: NewBaseSignal(signal_type, direction),
|
|
|
|
ID: id,
|
|
|
|
ID: id,
|
|
|
|
State: state,
|
|
|
|
Str: state,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewLinkStartSignal(link_type string, target NodeID) IDStateSignal {
|
|
|
|
func NewLinkStartSignal(link_type string, target NodeID) IDStringSignal {
|
|
|
|
return NewIDStateSignal(LinkStartSignalType, Direct, link_type, target)
|
|
|
|
return NewIDStringSignal(LinkStartSignalType, Direct, link_type, target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewLockSignal(state string) StateSignal {
|
|
|
|
func NewLockSignal(state string) StringSignal {
|
|
|
|
return StateSignal{
|
|
|
|
return StringSignal{
|
|
|
|
BaseSignal: NewDirectSignal(LockSignalType),
|
|
|
|
BaseSignal: NewDirectSignal(LockSignalType),
|
|
|
|
State: state,
|
|
|
|
Str: state,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (signal StateSignal) Permission() Action {
|
|
|
|
func (signal StringSignal) Permission() Action {
|
|
|
|
return MakeAction(signal.Type(), signal.State)
|
|
|
|
return MakeAction(signal.Type(), signal.Str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ReadSignal struct {
|
|
|
|
type ReadSignal struct {
|
|
|
@ -250,7 +263,7 @@ func NewReadResultSignal(req_id uuid.UUID, node_type NodeType, exts map[ExtType]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ECDHSignal struct {
|
|
|
|
type ECDHSignal struct {
|
|
|
|
StateSignal
|
|
|
|
StringSignal
|
|
|
|
Time time.Time
|
|
|
|
Time time.Time
|
|
|
|
ECDSA *ecdsa.PublicKey
|
|
|
|
ECDSA *ecdsa.PublicKey
|
|
|
|
ECDH *ecdh.PublicKey
|
|
|
|
ECDH *ecdh.PublicKey
|
|
|
@ -258,7 +271,7 @@ type ECDHSignal struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type ECDHSignalJSON struct {
|
|
|
|
type ECDHSignalJSON struct {
|
|
|
|
StateSignal
|
|
|
|
StringSignal
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
Time time.Time `json:"time"`
|
|
|
|
ECDSA []byte `json:"ecdsa_pubkey"`
|
|
|
|
ECDSA []byte `json:"ecdsa_pubkey"`
|
|
|
|
ECDH []byte `json:"ecdh_pubkey"`
|
|
|
|
ECDH []byte `json:"ecdh_pubkey"`
|
|
|
@ -267,7 +280,7 @@ type ECDHSignalJSON struct {
|
|
|
|
|
|
|
|
|
|
|
|
func (signal *ECDHSignal) MarshalJSON() ([]byte, error) {
|
|
|
|
func (signal *ECDHSignal) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&ECDHSignalJSON{
|
|
|
|
return json.Marshal(&ECDHSignalJSON{
|
|
|
|
StateSignal: signal.StateSignal,
|
|
|
|
StringSignal: signal.StringSignal,
|
|
|
|
Time: signal.Time,
|
|
|
|
Time: signal.Time,
|
|
|
|
ECDH: signal.ECDH.Bytes(),
|
|
|
|
ECDH: signal.ECDH.Bytes(),
|
|
|
|
ECDSA: signal.ECDH.Bytes(),
|
|
|
|
ECDSA: signal.ECDH.Bytes(),
|
|
|
@ -310,9 +323,9 @@ func NewECDHReqSignal(ctx *Context, node *Node) (ECDHSignal, *ecdh.PrivateKey, e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ECDHSignal{
|
|
|
|
return ECDHSignal{
|
|
|
|
StateSignal: StateSignal{
|
|
|
|
StringSignal: StringSignal{
|
|
|
|
BaseSignal: NewDirectSignal(ECDHSignalType),
|
|
|
|
BaseSignal: NewDirectSignal(ECDHSignalType),
|
|
|
|
State: "req",
|
|
|
|
Str: "req",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Time: now,
|
|
|
|
Time: now,
|
|
|
|
ECDSA: &node.Key.PublicKey,
|
|
|
|
ECDSA: &node.Key.PublicKey,
|
|
|
@ -352,9 +365,9 @@ func NewECDHRespSignal(ctx *Context, node *Node, req ECDHSignal) (ECDHSignal, []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ECDHSignal{
|
|
|
|
return ECDHSignal{
|
|
|
|
StateSignal: StateSignal{
|
|
|
|
StringSignal: StringSignal{
|
|
|
|
BaseSignal: NewDirectSignal(ECDHSignalType),
|
|
|
|
BaseSignal: NewDirectSignal(ECDHSignalType),
|
|
|
|
State: "resp",
|
|
|
|
Str: "resp",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Time: now,
|
|
|
|
Time: now,
|
|
|
|
ECDSA: &node.Key.PublicKey,
|
|
|
|
ECDSA: &node.Key.PublicKey,
|
|
|
|