diff --git a/examples/multipro/echo.go b/examples/multipro/echo.go index 75f4078f2de18c054291f860331a77c43b3baf9f..13d25a65566368629cfd94aabd9a1019e90291bf 100644 --- a/examples/multipro/echo.go +++ b/examples/multipro/echo.go @@ -33,7 +33,7 @@ func NewEchoProtocol(node *Node, done chan bool) *EchoProtocol { } // remote peer requests handler -func (e EchoProtocol) onEchoRequest(s inet.Stream) { +func (e *EchoProtocol) onEchoRequest(s inet.Stream) { // get request data data := &p2p.EchoRequest{} decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s)) @@ -86,7 +86,7 @@ func (e EchoProtocol) onEchoRequest(s inet.Stream) { } // remote echo response handler -func (e EchoProtocol) onEchoResponse(s inet.Stream) { +func (e *EchoProtocol) onEchoResponse(s inet.Stream) { data := &p2p.EchoResponse{} decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s)) err := decoder.Decode(data) @@ -120,7 +120,7 @@ func (e EchoProtocol) onEchoResponse(s inet.Stream) { e.done <- true } -func (e EchoProtocol) Echo(host host.Host) bool { +func (e *EchoProtocol) Echo(host host.Host) bool { log.Printf("%s: Sending echo to: %s....", e.node.ID(), host.ID()) // create message data diff --git a/examples/multipro/node.go b/examples/multipro/node.go index e2bb07d949f319bf16356c63babdfe3b5f776079..39c9d67d2a02021cbc87da573e742584f8bf6fff 100644 --- a/examples/multipro/node.go +++ b/examples/multipro/node.go @@ -24,7 +24,7 @@ func NewNode(host host.Host, done chan bool) *Node { return node } -func (n Node) authenticateMessage(message proto.Message, data *p2p.MessageData) bool { +func (n *Node) authenticateMessage(message proto.Message, data *p2p.MessageData) bool { // store a temp ref to sig and remove it from data sign := data.Sign @@ -49,7 +49,7 @@ func (n Node) authenticateMessage(message proto.Message, data *p2p.MessageData) return n.verifyData(bin, []byte(sign), peerId, []byte(data.NodePubKey)) } -func (n Node) signProtoMessage(message proto.Message) ([]byte, error) { +func (n *Node) signProtoMessage(message proto.Message) ([]byte, error) { data, err := proto.Marshal(message) if err != nil { return nil, err @@ -57,16 +57,16 @@ func (n Node) signProtoMessage(message proto.Message) ([]byte, error) { return n.signData(data) } -func (n Node) signData(data []byte) ([]byte, error) { +func (n *Node) signData(data []byte) ([]byte, error) { key := n.Peerstore().PrivKey(n.ID()) res, err := key.Sign(data) return res, err } // precondition: we have info about the signer peer in the local peer store -func (n Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyData []byte) bool { +func (n *Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyData []byte) bool { - // todo: restore pub key from message and use it + // todo: restore pub key from message and not from the local peer store and use it key := n.Peerstore().PubKey(peerId) //todo: fix this @@ -79,7 +79,7 @@ func (n Node) verifyData(data []byte, signature []byte, peerId peer.ID, pubKeyDa res, err := key.Verify(data, signature) if err != nil { - log.Println("Error authenticating data") + log.Println ("Error authenticating data") return false } diff --git a/examples/multipro/pb/p2p.proto b/examples/multipro/pb/p2p.proto index 8f43f3fe85d2c63689fa06eef1c09cd1837bf182..365b86a419a6ca900ba2ca8e51f5f21a80c419ee 100644 --- a/examples/multipro/pb/p2p.proto +++ b/examples/multipro/pb/p2p.proto @@ -10,8 +10,8 @@ message MessageData { string id = 3; // allows requesters to use request data when processing a response bool gossip = 4; // true to have receiver peer gossip the message to neighbors string nodeId = 5; // id of node that created the message (not the peer that may have sent it). =base58(mh(sha256(nodePubKey))) - bytes nodePubKey = 6; // node's Secp256k1 public key bytes (32bytes) - string sign = 7; // signature of message data + method specific data by message authoring node + bytes nodePubKey = 6; // Authoring node Secp256k1 public key (32bytes) + string sign = 7; // signature of message data + method specific data by message authoring node } //// ping protocol diff --git a/examples/multipro/ping.go b/examples/multipro/ping.go index d2bf528849adc431d811a4ff12794ef7d1d28d90..f62610794568328f2a2bafcc297ba63f64d0a82b 100644 --- a/examples/multipro/ping.go +++ b/examples/multipro/ping.go @@ -33,7 +33,7 @@ func NewPingProtocol(node *Node, done chan bool) *PingProtocol { } // remote peer requests handler -func (p PingProtocol) onPingRequest(s inet.Stream) { +func (p *PingProtocol) onPingRequest(s inet.Stream) { // get request data data := &p2p.PingRequest{} @@ -86,7 +86,7 @@ func (p PingProtocol) onPingRequest(s inet.Stream) { } // remote ping response handler -func (p PingProtocol) onPingResponse(s inet.Stream) { +func (p *PingProtocol) onPingResponse(s inet.Stream) { data := &p2p.PingResponse{} decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s)) err := decoder.Decode(data) @@ -117,7 +117,7 @@ func (p PingProtocol) onPingResponse(s inet.Stream) { p.done <- true } -func (p PingProtocol) Ping(host host.Host) bool { +func (p *PingProtocol) Ping(host host.Host) bool { log.Printf("%s: Sending ping to: %s....", p.node.ID(), host.ID()) // create message data diff --git a/examples/multipro/protocol.go b/examples/multipro/protocol.go index 2b19e75f4b00c7d3401a14f62fb1a1c91ebc414c..0b57d89859e38b3512359e33909d55aa7fc061e7 100644 --- a/examples/multipro/protocol.go +++ b/examples/multipro/protocol.go @@ -37,7 +37,7 @@ func NewMessageData(node *Node, messageId string, gossip bool) *p2p.MessageData nodePubKey, err := node.Peerstore().PubKey(node.ID()).Bytes() if err != nil { - panic("Failed to get public key for sender node from peer store.") + panic("Failed to get public key for sender from local peer store.") } return &p2p.MessageData{ClientVersion: clientVersion,