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 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // a group has been successfully added or newly created
  66. // attributes:
  67. // Data [serialized *model.Group]
  68. GroupCreated = Type("GroupCreated")
  69. // RemotePeer
  70. DeleteContact = Type("DeleteContact")
  71. // GroupID
  72. DeleteGroup = Type("DeleteGroup")
  73. // change the .Name attribute of a profile (careful - this is not a custom attribute. it is used in the underlying protocol during handshakes!)
  74. // attributes:
  75. // ProfileName [eg "erinn"]
  76. SetProfileName = Type("SetProfileName")
  77. // request to store a profile-wide attribute (good for e.g. per-profile settings like theme prefs)
  78. // attributes:
  79. // Key [eg "fontcolor"]
  80. // Data [eg "red"]
  81. SetAttribute = Type("SetAttribute")
  82. // request to store a per-contact attribute (e.g. display names for a peer)
  83. // attributes:
  84. // RemotePeer [eg ""]
  85. // Key [eg "nick"]
  86. // Data [eg "erinn"]
  87. SetPeerAttribute = Type("SetPeerAttribute")
  88. // request to store a per-cwtch-group attribute (e.g. display name for a group)
  89. // attributes:
  90. // GroupID [eg ""]
  91. // Key [eg "nick"]
  92. // Data [eg "open privacy board"]
  93. SetGroupAttribute = Type("SetGroupAttribute")
  94. // PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
  95. // RemotePeer
  96. // ConnectionState
  97. PeerStateChange = Type("PeerStateChange")
  98. // GroupServer
  99. // ConnectionState
  100. ServerStateChange = Type("ServerStateChange")
  101. /***** Application client / service messages *****/
  102. // ProfileName, Password
  103. CreatePeer = Type("CreatePeer")
  104. // service -> client: Identity(localId), Password, [Status(new/default=blank || from reload='running')]
  105. // app -> Identity(onion)
  106. NewPeer = Type("NewPeer")
  107. // Identity(onion), Data(pluginID)
  108. AddPeerPlugin = Type("AddPeerPlugin")
  109. // Password
  110. LoadProfiles = Type("LoadProfiles")
  111. // Client has reloaded, triggers NewPeer s then ReloadDone
  112. ReloadClient = Type("ReloadClient")
  113. ReloadDone = Type("ReloadDone")
  114. // Identity - Ask service to resend all connection states
  115. ReloadPeer = Type("ReloadPeer")
  116. // Identity(onion)
  117. ShutdownPeer = Type("ShutdownPeer")
  118. Shutdown = Type("Shutdown")
  119. // Error(err)
  120. PeerError = Type("PeerError")
  121. // Error(err)
  122. AppError = Type("AppError")
  123. GetACNStatus = Type("GetACNStatus")
  124. // Progress, Status
  125. ACNStatus = Type("ACNStatus")
  126. // Network Status
  127. // Status: Success || Error
  128. // Error: Description of the Error
  129. // Onion: the local onion we attempt to check
  130. NetworkStatus = Type("NetworkError")
  131. )
  132. // Field defines common event attributes
  133. type Field string
  134. // Defining Common Field Types
  135. const (
  136. // A peers local onion address
  137. Onion = Field("Onion")
  138. RemotePeer = Field("RemotePeer")
  139. Ciphertext = Field("Ciphertext")
  140. Signature = Field("Signature")
  141. PreviousSignature = Field("PreviousSignature")
  142. TimestampSent = Field("TimestampSent")
  143. TimestampReceived = Field("TimestampReceived")
  144. Identity = Field("Identity")
  145. GroupID = Field("GroupID")
  146. GroupServer = Field("GroupServer")
  147. GroupInvite = Field("GroupInvite")
  148. ProfileName = Field("ProfileName")
  149. Password = Field("Password")
  150. ConnectionState = Field("ConnectionState")
  151. Key = Field("Key")
  152. Data = Field("Data")
  153. Error = Field("Error")
  154. Progreess = Field("Progress")
  155. Status = Field("Status")
  156. EventID = Field("EventID")
  157. EventContext = Field("EventContext")
  158. )
  159. // Defining Common errors
  160. const (
  161. AppErrLoaded0 = "Loaded 0 profiles"
  162. )
  163. // Defining Protocol Contexts
  164. const (
  165. ContextAck = "im.cwtch.acknowledgement"
  166. ContextInvite = "im.cwtch.invite"
  167. ContextRaw = "im.cwtch.raw"
  168. )