github.com/ergo-services/ergo@v1.999.224/apps/cloud/types.go (about) 1 package cloud 2 3 import ( 4 "hash" 5 6 "github.com/ergo-services/ergo/etf" 7 "github.com/ergo-services/ergo/gen" 8 "github.com/ergo-services/ergo/lib" 9 "github.com/ergo-services/ergo/node" 10 ) 11 12 const ( 13 EventCloud gen.Event = "cloud" 14 15 ProtoHandshakeV1 = 41 16 ProtoHandshakeV1Auth = 100 17 ProtoHandshakeV1AuthReply = 101 18 ProtoHandshakeV1Challenge = 102 19 ProtoHandshakeV1ChallengeAccept = 103 20 ProtoHandshakeV1Error = 200 21 ) 22 23 type MessageEventCloud struct { 24 Cluster string 25 Online bool 26 Proxy string 27 } 28 29 func RegisterTypes() error { 30 types := []interface{}{ 31 node.CloudFlags{}, 32 MessageHandshakeV1Auth{}, 33 MessageHandshakeV1AuthReply{}, 34 MessageHandshakeV1Challenge{}, 35 MessageHandshakeV1ChallengeAccept{}, 36 MessageHandshakeV1Error{}, 37 } 38 rtOpts := etf.RegisterTypeOptions{Strict: true} 39 40 for _, t := range types { 41 if _, err := etf.RegisterType(t, rtOpts); err != nil && err != lib.ErrTaken { 42 return err 43 } 44 } 45 return nil 46 } 47 48 func GenDigest(h hash.Hash, items ...[]byte) []byte { 49 x := []byte{} 50 for _, i := range items { 51 x = append(x, i...) 52 } 53 return h.Sum(x) 54 } 55 56 // client -> cloud 57 type MessageHandshakeV1Auth struct { 58 Node string 59 Cluster string 60 Creation uint32 61 Flags node.CloudFlags 62 } 63 64 // cloud -> client 65 type MessageHandshakeV1AuthReply struct { 66 Node string 67 Creation uint32 68 Digest []byte 69 } 70 71 // client -> cloud 72 type MessageHandshakeV1Challenge struct { 73 Digest []byte 74 } 75 76 // cloud -> client 77 type MessageHandshakeV1ChallengeAccept struct { 78 Node string // mapped node name 79 } 80 81 // cloud -> client 82 type MessageHandshakeV1Error struct { 83 Reason string 84 }