diff --git a/examples/multipro/README.md b/examples/multipro/README.md index 9c5640fc..1e3352cf 100644 --- a/examples/multipro/README.md +++ b/examples/multipro/README.md @@ -47,6 +47,6 @@ The idea is to use lib-p2p protocol multiplexing on a per-message basis. 5. Full access to request data when processing a response. ## Author - @avive + diff --git a/examples/multipro/echo.go b/examples/multipro/echo.go index 409bc390..27374884 100644 --- a/examples/multipro/echo.go +++ b/examples/multipro/echo.go @@ -80,7 +80,7 @@ func (e *EchoProtocol) onEchoRequest(s inet.Stream) { return } - ok := sendProtoMessage(resp, s) + ok := e.node.sendProtoMessage(resp, s) if ok { log.Printf("%s: Echo response to %s sent.", s.Conn().LocalPeer().String(), s.Conn().RemotePeer().String()) @@ -143,7 +143,7 @@ func (e *EchoProtocol) Echo(host host.Host) bool { return false } - ok := sendProtoMessage(req, s) + ok := e.node.sendProtoMessage(req, s) if !ok { return false diff --git a/examples/multipro/node.go b/examples/multipro/node.go index 978106bd..7dfc96f7 100644 --- a/examples/multipro/node.go +++ b/examples/multipro/node.go @@ -1,16 +1,16 @@ package main import ( + "bufio" "log" "time" - "bufio" p2p "github.com/avive/go-libp2p/examples/multipro/pb" "github.com/gogo/protobuf/proto" + protobufCodec "github.com/multiformats/go-multicodec/protobuf" host "gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host" peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" - protobufCodec "github.com/multiformats/go-multicodec/protobuf" inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net" ) @@ -37,7 +37,6 @@ func NewNode(host host.Host, done chan bool) *Node { // message: a protobufs go data object // data: common p2p message data func (n *Node) authenticateMessage(message proto.Message, data *p2p.MessageData) bool { - // store a temp ref to signature and remove it from message data // sign is a string to allow easy reset to zero-value (empty string) sign := data.Sign @@ -138,7 +137,7 @@ func (n *Node) NewMessageData(messageId string, gossip bool) *p2p.MessageData { // helper method - writes a protobuf go data object to a network stream // data: reference of protobuf go data object to send (not the object itself) // s: network stream to write the data to -func sendProtoMessage(data proto.Message, s inet.Stream) bool { +func (n *Node) sendProtoMessage(data proto.Message, s inet.Stream) bool { writer := bufio.NewWriter(s) enc := protobufCodec.Multicodec(nil).Encoder(writer) err := enc.Encode(data) diff --git a/examples/multipro/ping.go b/examples/multipro/ping.go index 5960d560..a8508b33 100644 --- a/examples/multipro/ping.go +++ b/examples/multipro/ping.go @@ -6,12 +6,11 @@ import ( "fmt" "log" - inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net" - p2p "github.com/avive/go-libp2p/examples/multipro/pb" uuid "github.com/google/uuid" protobufCodec "github.com/multiformats/go-multicodec/protobuf" "gx/ipfs/QmRS46AyqtpJBsf1zmQdeizSDEzo1qkWR7rdEuPFAv8237/go-libp2p-host" + inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net" ) // pattern: /protocol-name/request-or-response-message/version @@ -76,7 +75,7 @@ func (p *PingProtocol) onPingRequest(s inet.Stream) { return } - ok := sendProtoMessage(resp, s) + ok := p.node.sendProtoMessage(resp, s) if ok { log.Printf("%s: Ping response to %s sent.", s.Conn().LocalPeer().String(), s.Conn().RemotePeer().String()) @@ -136,7 +135,7 @@ func (p *PingProtocol) Ping(host host.Host) bool { return false } - ok := sendProtoMessage(req, s) + ok := p.node.sendProtoMessage(req, s) if !ok { return false