diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 16:09:32 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 16:09:32 +0200 |
commit | 7c5a6176b27b6b0c0c3ef8a4aedbdec871391a80 (patch) | |
tree | 5ebfc9b402b8aa941ab9617b5f3842071edafedf /pkg/p2p/network.go | |
parent | 0b4fb251efdfd2fba7cd6154f5f59bd61ede15f1 (diff) |
Add type on messages between peers
Diffstat (limited to 'pkg/p2p/network.go')
-rw-r--r-- | pkg/p2p/network.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/pkg/p2p/network.go b/pkg/p2p/network.go index 0acbdfa..13c99b0 100644 --- a/pkg/p2p/network.go +++ b/pkg/p2p/network.go @@ -14,6 +14,7 @@ import ( // `Message` represents a structured message on this network. type Message struct { + Type []byte `json:"type"` Timestamp int64 `json:"timestamp"` Source NetworkID `json:"source"` Payload []byte `json:"payload"` @@ -107,7 +108,7 @@ func (n *TCPNetwork) AddPeer(remoteID NetworkID, addr string) { } // Send methods is used to send a message to a specified remote peer -func (n *TCPNetwork) Send(remoteID NetworkID, payload []byte) error { +func (n *TCPNetwork) Send(remoteID NetworkID, messageType []byte, payload []byte) error { n.Lock() peerConn, exists := n.connections[remoteID] n.Unlock() @@ -123,6 +124,7 @@ func (n *TCPNetwork) Send(remoteID NetworkID, payload []byte) error { } message := Message{ + Type: messageType, Payload: payload, Source: n.id, Timestamp: time.Now().Unix(), |