Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.go 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package event
  2. // Type captures the definition of many common Cwtch application events
  3. type Type string
  4. // Defining Common Event Types
  5. const (
  6. StatusRequest = Type("StatusRequest")
  7. ProtocolEngineStatus = Type("ProtocolEngineStatus")
  8. // Attempt to outbound peer with a given remote peer
  9. // attributes:
  10. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
  11. PeerRequest = Type("PeerRequest")
  12. // RetryPeerRequest
  13. // Identical to PeerRequest, but allows Engine to make decisions regarding blocked peers
  14. // attributes:
  15. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
  16. RetryPeerRequest = Type("RetryPeerRequest")
  17. // Blocking Events both Block and Unblock have the same structure
  18. // attributes:
  19. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
  20. BlockPeer = Type("BlockPeer")
  21. UnblockPeer = Type("UnblockPeer")
  22. // Turn on/off blocking of unknown peers (if peers aren't in the contact list then they will be autoblocked
  23. BlockUnknownPeers = Type("BlockUnknownPeers")
  24. AllowUnknownPeers = Type("AllowUnknownPeers")
  25. // GroupServer
  26. JoinServer = Type("JoinServer")
  27. ProtocolEngineStartListen = Type("ProtocolEngineStartListen")
  28. ProtocolEngineStopped = Type("ProtocolEngineStopped")
  29. InvitePeerToGroup = Type("InvitePeerToGroup")
  30. // a group invite has been received from a remote peer
  31. // attributes:
  32. // TimestampReceived [eg time.Now().Format(time.RFC3339Nano)]
  33. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"]
  34. // GroupInvite: [eg "torv3....."]
  35. NewGroupInvite = Type("NewGroupInvite")
  36. // GroupID
  37. AcceptGroupInvite = Type("AcceptGroupInvite")
  38. SendMessageToGroup = Type("SendMessagetoGroup")
  39. //Ciphertext, Signature:
  40. EncryptedGroupMessage = Type("EncryptedGroupMessage")
  41. //TimestampReceived, TimestampSent, Data(Message), GroupID, Signature, PreviousSignature, RemotePeer
  42. NewMessageFromGroup = Type("NewMessageFromGroup")
  43. // an error was encountered trying to send a particular Message to a group
  44. // attributes:
  45. // GroupServer: The server the Message was sent to
  46. // Signature: The signature of the Message that failed to send
  47. // Error: string describing the error
  48. SendMessageToGroupError = Type("SendMessageToGroupError")
  49. SendMessageToPeer = Type("SendMessageToPeer")
  50. NewMessageFromPeer = Type("NewMessageFromPeer")
  51. // Peer acknowledges a previously sent message
  52. // attributes
  53. // EventID: The original event id that the peer is responding too.
  54. // RemotePeer: The peer associated with the acknowledgement
  55. PeerAcknowledgement = Type("PeerAcknowledgement")
  56. // attributes:
  57. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"]
  58. // Error: string describing the error
  59. SendMessageToPeerError = Type("SendMessageToPeerError")
  60. // REQUESTS TO STORAGE ENGINE
  61. // a peer contact has been added
  62. // attributes:
  63. // RemotePeer [eg ""]
  64. PeerCreated = Type("PeerCreated")
  65. // Password, NewPassword
  66. ChangePassword = Type("ChangePassword")
  67. // Error(err), EventID
  68. ChangePasswordError = Type("ChangePasswordError")
  69. // EventID
  70. ChangePasswordSuccess = Type("ChangePasswordSuccess")
  71. // a group has been successfully added or newly created
  72. // attributes:
  73. // Data [serialized *model.Group]
  74. GroupCreated = Type("GroupCreated")
  75. // RemotePeer
  76. DeleteContact = Type("DeleteContact")
  77. // GroupID
  78. DeleteGroup = Type("DeleteGroup")
  79. // change the .Name attribute of a profile (careful - this is not a custom attribute. it is used in the underlying protocol during handshakes!)
  80. // attributes:
  81. // ProfileName [eg "erinn"]
  82. SetProfileName = Type("SetProfileName")
  83. // request to store a profile-wide attribute (good for e.g. per-profile settings like theme prefs)
  84. // attributes:
  85. // Key [eg "fontcolor"]
  86. // Data [eg "red"]
  87. SetAttribute = Type("SetAttribute")
  88. // request to store a per-contact attribute (e.g. display names for a peer)
  89. // attributes:
  90. // RemotePeer [eg ""]
  91. // Key [eg "nick"]
  92. // Data [eg "erinn"]
  93. SetPeerAttribute = Type("SetPeerAttribute")
  94. // request to store a per-cwtch-group attribute (e.g. display name for a group)
  95. // attributes:
  96. // GroupID [eg ""]
  97. // Key [eg "nick"]
  98. // Data [eg "open privacy board"]
  99. SetGroupAttribute = Type("SetGroupAttribute")
  100. // PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
  101. // RemotePeer
  102. // ConnectionState
  103. PeerStateChange = Type("PeerStateChange")
  104. // GroupServer
  105. // ConnectionState
  106. ServerStateChange = Type("ServerStateChange")
  107. /***** Application client / service messages *****/
  108. // ProfileName, Password, Data(tag)
  109. CreatePeer = Type("CreatePeer")
  110. // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')]
  111. // app -> Key, Salt
  112. NewPeer = Type("NewPeer")
  113. // Identity(onion)
  114. DeletePeer = Type("DeletePeer")
  115. // Identity(onion), Data(pluginID)
  116. AddPeerPlugin = Type("AddPeerPlugin")
  117. // Password
  118. LoadProfiles = Type("LoadProfiles")
  119. // Client has reloaded, triggers NewPeer s then ReloadDone
  120. ReloadClient = Type("ReloadClient")
  121. ReloadDone = Type("ReloadDone")
  122. // Identity - Ask service to resend all connection states
  123. ReloadPeer = Type("ReloadPeer")
  124. // Identity(onion)
  125. ShutdownPeer = Type("ShutdownPeer")
  126. Shutdown = Type("Shutdown")
  127. // Error(err)
  128. // Error creating peer
  129. PeerError = Type("PeerError")
  130. // Error(err)
  131. AppError = Type("AppError")
  132. GetACNStatus = Type("GetACNStatus")
  133. // Progress, Status
  134. ACNStatus = Type("ACNStatus")
  135. // Network Status
  136. // Status: Success || Error
  137. // Error: Description of the Error
  138. // Onion: the local onion we attempt to check
  139. NetworkStatus = Type("NetworkError")
  140. // For debugging. Allows test to emit a Syn and get a response Ack(eventID) when the subsystem is done processing a queue
  141. Syn = Type("Syn")
  142. Ack = Type("Ack")
  143. )
  144. // Field defines common event attributes
  145. type Field string
  146. // Defining Common Field Types
  147. const (
  148. // A peers local onion address
  149. Onion = Field("Onion")
  150. RemotePeer = Field("RemotePeer")
  151. Ciphertext = Field("Ciphertext")
  152. Signature = Field("Signature")
  153. PreviousSignature = Field("PreviousSignature")
  154. TimestampSent = Field("TimestampSent")
  155. TimestampReceived = Field("TimestampReceived")
  156. Identity = Field("Identity")
  157. GroupID = Field("GroupID")
  158. GroupServer = Field("GroupServer")
  159. GroupInvite = Field("GroupInvite")
  160. ProfileName = Field("ProfileName")
  161. Password = Field("Password")
  162. NewPassword = Field("NewPassword")
  163. ConnectionState = Field("ConnectionState")
  164. Key = Field("Key")
  165. Data = Field("Data")
  166. Salt = Field("Salt")
  167. Error = Field("Error")
  168. Progreess = Field("Progress")
  169. Status = Field("Status")
  170. EventID = Field("EventID")
  171. EventContext = Field("EventContext")
  172. )
  173. // Defining Common errors
  174. const (
  175. AppErrLoaded0 = "Loaded 0 profiles"
  176. )
  177. // Values to be suplied in event.NewPeer for Status
  178. const (
  179. StorageRunning = "running"
  180. StorageNew = "new"
  181. )
  182. // Defining Protocol Contexts
  183. const (
  184. ContextAck = "im.cwtch.acknowledgement"
  185. ContextInvite = "im.cwtch.invite"
  186. ContextRaw = "im.cwtch.raw"
  187. )