2 #ifndef GRAMODS_NETWORK_PROTOCOL
3 #define GRAMODS_NETWORK_PROTOCOL
5 #include <gmNetwork/config.hh>
13 BEGIN_NAMESPACE_GMNETWORK;
21 :
public std::enable_shared_from_this<Protocol> {
25 static const size_t HEADER_LENGTH;
59 Message(
char protocol, std::vector<char> data);
65 std::vector<char> getHeader();
71 size_t from_peer_idx = std::numeric_limits<size_t>::max();
77 size_t to_peer_idx = std::numeric_limits<size_t>::max();
105 virtual void processMessage(
Message m);
111 virtual void lostPeer(
size_t idx);
113 void setSyncNode(
SyncNode *sync_node);
121 void sendMessage(std::vector<char> data);
129 size_t getLocalPeerIdx();
135 std::set<size_t> getConnectedPeers();
150 END_NAMESPACE_GMNETWORK;
TODO: write this.
Definition: Protocol.hh:21
SyncNode * sync_node
The SyncNode instance this protocol communicates through or nullptr if it has gone out of scope.
Definition: Protocol.hh:142
virtual char getProtocolFlag()
Returns the byte sent in the message to indicate which protocol instance to call for interpretation a...
Definition: Protocol.hh:37
std::mutex sync_node_lock
Lock for synchronizing the sync_node pointer.
Definition: Protocol.hh:147
A handler of network communication with multiple peers.
Definition: SyncNode.hh:34
Data entity communicated by the connection to the designated protocol.
Definition: Protocol.hh:43
Message()
Create an empty message.
Definition: Protocol.hh:48
std::vector< char > data
The complete set of data sent by the peer.
Definition: Protocol.hh:94