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.

268 lines
7.5KB

  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. // RemotePeer, scope, path
  52. NewGetValMessageFromPeer = Type("NewGetValMessageFromPeer")
  53. // RemotePeer, val, exists
  54. SendRetValMessageToPeer = Type("SendRetValMessageToPeer")
  55. // RemotePeer, scope, val
  56. SendGetValMessageToPeer = Type("SendGetValMessageToPeer")
  57. // RemotePeer, scope, path, data, exists
  58. NewRetValMessageFromPeer = Type("NewRetValMessageFromPeer")
  59. // Peer acknowledges a previously sent message
  60. // attributes
  61. // EventID: The original event id that the peer is responding too.
  62. // RemotePeer: The peer associated with the acknowledgement
  63. PeerAcknowledgement = Type("PeerAcknowledgement")
  64. // attributes:
  65. // RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"]
  66. // Error: string describing the error
  67. SendMessageToPeerError = Type("SendMessageToPeerError")
  68. // REQUESTS TO STORAGE ENGINE
  69. // a peer contact has been added
  70. // attributes:
  71. // RemotePeer [eg ""]
  72. PeerCreated = Type("PeerCreated")
  73. // Password, NewPassword
  74. ChangePassword = Type("ChangePassword")
  75. // Error(err), EventID
  76. ChangePasswordError = Type("ChangePasswordError")
  77. // EventID
  78. ChangePasswordSuccess = Type("ChangePasswordSuccess")
  79. // a group has been successfully added or newly created
  80. // attributes:
  81. // Data [serialized *model.Group]
  82. GroupCreated = Type("GroupCreated")
  83. // RemotePeer
  84. DeleteContact = Type("DeleteContact")
  85. // GroupID
  86. DeleteGroup = Type("DeleteGroup")
  87. // change the .Name attribute of a profile (careful - this is not a custom attribute. it is used in the underlying protocol during handshakes!)
  88. // attributes:
  89. // ProfileName [eg "erinn"]
  90. SetProfileName = Type("SetProfileName")
  91. // request to store a profile-wide attribute (good for e.g. per-profile settings like theme prefs)
  92. // attributes:
  93. // Key [eg "fontcolor"]
  94. // Data [eg "red"]
  95. SetAttribute = Type("SetAttribute")
  96. // request to store a per-contact attribute (e.g. display names for a peer)
  97. // attributes:
  98. // RemotePeer [eg ""]
  99. // Key [eg "nick"]
  100. // Data [eg "erinn"]
  101. SetPeerAttribute = Type("SetPeerAttribute")
  102. // request to store a per-cwtch-group attribute (e.g. display name for a group)
  103. // attributes:
  104. // GroupID [eg ""]
  105. // Key [eg "nick"]
  106. // Data [eg "open privacy board"]
  107. SetGroupAttribute = Type("SetGroupAttribute")
  108. // PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
  109. // RemotePeer
  110. // ConnectionState
  111. PeerStateChange = Type("PeerStateChange")
  112. // GroupServer
  113. // ConnectionState
  114. ServerStateChange = Type("ServerStateChange")
  115. /***** Application client / service messages *****/
  116. // ProfileName, Password, Data(tag)
  117. CreatePeer = Type("CreatePeer")
  118. // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')]
  119. // app -> Key, Salt
  120. NewPeer = Type("NewPeer")
  121. // Identity(onion)
  122. DeletePeer = Type("DeletePeer")
  123. // Identity(onion), Data(pluginID)
  124. AddPeerPlugin = Type("AddPeerPlugin")
  125. // Password
  126. LoadProfiles = Type("LoadProfiles")
  127. // Client has reloaded, triggers NewPeer s then ReloadDone
  128. ReloadClient = Type("ReloadClient")
  129. ReloadDone = Type("ReloadDone")
  130. // Identity - Ask service to resend all connection states
  131. ReloadPeer = Type("ReloadPeer")
  132. // Identity(onion)
  133. ShutdownPeer = Type("ShutdownPeer")
  134. Shutdown = Type("Shutdown")
  135. // Error(err)
  136. // Error creating peer
  137. PeerError = Type("PeerError")
  138. // Error(err)
  139. AppError = Type("AppError")
  140. GetACNStatus = Type("GetACNStatus")
  141. // Progress, Status
  142. ACNStatus = Type("ACNStatus")
  143. // Network Status
  144. // Status: Success || Error
  145. // Error: Description of the Error
  146. // Onion: the local onion we attempt to check
  147. NetworkStatus = Type("NetworkError")
  148. // For debugging. Allows test to emit a Syn and get a response Ack(eventID) when the subsystem is done processing a queue
  149. Syn = Type("Syn")
  150. Ack = Type("Ack")
  151. )
  152. // Field defines common event attributes
  153. type Field string
  154. // Defining Common Field Types
  155. const (
  156. // A peers local onion address
  157. Onion = Field("Onion")
  158. RemotePeer = Field("RemotePeer")
  159. Ciphertext = Field("Ciphertext")
  160. Signature = Field("Signature")
  161. PreviousSignature = Field("PreviousSignature")
  162. TimestampSent = Field("TimestampSent")
  163. TimestampReceived = Field("TimestampReceived")
  164. Identity = Field("Identity")
  165. GroupID = Field("GroupID")
  166. GroupServer = Field("GroupServer")
  167. GroupInvite = Field("GroupInvite")
  168. ProfileName = Field("ProfileName")
  169. Password = Field("Password")
  170. NewPassword = Field("NewPassword")
  171. ConnectionState = Field("ConnectionState")
  172. Key = Field("Key")
  173. Data = Field("Data")
  174. Scope = Field("Scope")
  175. Path = Field("Path")
  176. Exists = Field("Exists")
  177. Salt = Field("Salt")
  178. Error = Field("Error")
  179. Progreess = Field("Progress")
  180. Status = Field("Status")
  181. EventID = Field("EventID")
  182. EventContext = Field("EventContext")
  183. )
  184. // Defining Common errors
  185. const (
  186. AppErrLoaded0 = "Loaded 0 profiles"
  187. )
  188. // Values to be suplied in event.NewPeer for Status
  189. const (
  190. StorageRunning = "running"
  191. StorageNew = "new"
  192. )
  193. // Defining Protocol Contexts
  194. const (
  195. ContextAck = "im.cwtch.acknowledgement"
  196. ContextInvite = "im.cwtch.invite"
  197. ContextRaw = "im.cwtch.raw"
  198. ContextGetVal = "im.cwtch.getVal"
  199. ContextRetVal = "im.cwtch.retVal"
  200. )