diff --git a/examples/multipro/echo.go b/examples/multipro/echo.go index 5392e8e9fe29acdd4db83f6d7b825915fcade3b8..60e83c50e13f4f6e7f11926ea3c1afe76fa36c63 100644 --- a/examples/multipro/echo.go +++ b/examples/multipro/echo.go @@ -45,8 +45,9 @@ func (e *EchoProtocol) onEchoRequest(s inet.Stream) { log.Printf("%s: Received echo request from %s. Message: %s", s.Conn().LocalPeer(), s.Conn().RemotePeer(), data.Message) - // send response to sender log.Printf("%s: Sending echo response to %s. Message id: %s...", s.Conn().LocalPeer(), s.Conn().RemotePeer(), data.MessageData.Id) + + // send response to request send using the message string he provided resp := &p2p.EchoResponse{ MessageData: NewMessageData(e.host.ID().String(), data.MessageData.Id, false), Message: data.Message} @@ -85,7 +86,7 @@ func (e *EchoProtocol) onEchoResponse(s inet.Stream) { assert.True(req.Message == data.Message, nil, "Expected echo to respond with request message") - log.Printf("%s: Received Echo response from %s. Message id:%s. Message: %s.", s.Conn().LocalPeer(), s.Conn().RemotePeer(), data.MessageData.Id, data.Message) + log.Printf("%s: Received echo response from %s. Message id:%s. Message: %s.", s.Conn().LocalPeer(), s.Conn().RemotePeer(), data.MessageData.Id, data.Message) e.done <- true } diff --git a/examples/multipro/main.go b/examples/multipro/main.go index 53efce6cbf674720d037106f7e228edab6e66628..97218255da00eb9bd02760a7e3f88178ac3aa4dd 100644 --- a/examples/multipro/main.go +++ b/examples/multipro/main.go @@ -18,7 +18,7 @@ import ( func makeRandomNode(port int, done chan bool) *Node { // Ignoring most errors for brevity // See echo example for more details and better implementation - priv, pub, _ := crypto.GenerateKeyPair(crypto.RSA, 2048) + priv, pub, _ := crypto.GenerateKeyPair(crypto.Secp256k1, 256) pid, _ := peer.IDFromPublicKey(pub) listen, _ := ma.NewMultiaddr(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", port)) peerStore := ps.NewPeerstore() @@ -47,10 +47,10 @@ func main() { log.Printf("This is a conversation between %s and %s\n", h1.host.ID(), h2.host.ID()) // send messages using the protocols - h1.pingProtocol.Ping(h2) - h2.pingProtocol.Ping(h1) - h1.echoProtocol.Echo(h2) - h2.echoProtocol.Echo(h1) + h1.Ping(h2) + h2.Ping(h1) + h1.Echo(h2) + h2.Echo(h1) // block until all responses have been processed for i := 0; i < 4; i++ { diff --git a/examples/multipro/node.go b/examples/multipro/node.go index 7892bfbb8b88061d8efd0bcd67c8fe295a081f5c..e490b5cb718ee451fa4705e24167fa3cfd14a6b0 100644 --- a/examples/multipro/node.go +++ b/examples/multipro/node.go @@ -44,14 +44,14 @@ func NewMessageData(nodeId string, messageId string, gossip bool) *p2p.MessageDa // Node type - implements one or more p2p protocols type Node struct { - host host.Host // lib-p2p host - pingProtocol *PingProtocol // ping protocol impl - echoProtocol *EchoProtocol // echo protocol impl + host host.Host // lib-p2p host + *PingProtocol // ping protocol impl + *EchoProtocol // echo protocol impl } // create a new node with its implemented protocols func NewNode(host host.Host, done chan bool) *Node { return &Node{host: host, - pingProtocol: NewPingProtocol(host, done), - echoProtocol: NewEchoProtocol(host, done)} + PingProtocol: NewPingProtocol(host, done), + EchoProtocol: NewEchoProtocol(host, done)} } diff --git a/examples/multipro/pb/p2p.proto b/examples/multipro/pb/p2p.proto index 62df22d29583104f3ab6c73d5e7e25bb090c4fdf..13d312546a7f04a4362d743055bd36e7ae01decb 100644 --- a/examples/multipro/pb/p2p.proto +++ b/examples/multipro/pb/p2p.proto @@ -10,7 +10,7 @@ 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) - string sign = 6; // signature of message data + method specific data by message authoring node + bytes sign = 6; // signature of message data + method specific data by message authoring node } //// ping protocol diff --git a/examples/protocol-multiplexing-with-multicodecs/README.md b/examples/protocol-multiplexing-with-multicodecs/README.md index 217933876d5784ce974a23b003373e2a9b5eabc4..0001f60bee31908560712d1c47cf676990c5094e 100644 --- a/examples/protocol-multiplexing-with-multicodecs/README.md +++ b/examples/protocol-multiplexing-with-multicodecs/README.md @@ -1,3 +1,4 @@ + # Protocol Multiplexing using multicodecs with libp2p This examples shows how to use multicodecs (i.e. json) to encode and transmit information between LibP2P hosts using LibP2P Streams.