From 7c5a6176b27b6b0c0c3ef8a4aedbdec871391a80 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 18 Apr 2025 16:09:32 +0200 Subject: Add type on messages between peers --- pkg/p2p/network.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pkg/p2p/network.go') 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(), -- cgit v1.2.3-18-g5258