Components/msgnet

From Polytech Center Barcelona
Jump to: navigation, search

Upon starting a connection, both peers join the default channel. This is for unique messages between specifically these 2 hosts. The channel is concerned with signalling for synchronization purposes.

Available methods:

  • spawn_channel(): create a new channel
  • close(): close the current channel
  • invite(): invite another host to the channel and become a relay for them.
  • send_message()
  • receive(): receive message or event (such as host joined/left channel).
  • get_status(): return number of hosts in the channel

On top of this basic design we can create 3 patterns:

  • async message passing
  • req-rep
  • pub-sub

There is no concept of connection closed, just channels and active hosts (+ their unique channel ids generated per channel). When hosts disconnect or don't respond to pings, then they are kicked from the channel until they rejoin. The system is like IRC but with a p2p network model + automatic encryption.

Request:

  • spawn_channel() (usually we call this for the default channel on opening connection)
  • send_message()
  • receive()

Response:

  • accept() handler in code is called for new channel invite
  • receive()
  • send_message()