From 3f926c52ebd4af48adf4ed361c325ac4d8f5b5a1 Mon Sep 17 00:00:00 2001 From: Aviv Eyal Date: Mon, 27 Nov 2017 20:34:52 +0200 Subject: [PATCH] Apply go formatting --- examples/multipro/echo.go | 5 ++--- examples/multipro/main.go | 2 +- examples/multipro/node.go | 19 +++++++++---------- examples/multipro/ping.go | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/examples/multipro/echo.go b/examples/multipro/echo.go index 95b2d98d..5392e8e9 100644 --- a/examples/multipro/echo.go +++ b/examples/multipro/echo.go @@ -10,9 +10,9 @@ import ( inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net" uuid "github.com/google/uuid" + "github.com/ipfs/go-ipfs/thirdparty/assert" p2p "github.com/libp2p/go-libp2p/examples/multipro/pb" protobufCodec "github.com/multiformats/go-multicodec/protobuf" - "github.com/ipfs/go-ipfs/thirdparty/assert" ) // pattern: /protocol-name/request-or-response-message/version @@ -21,7 +21,7 @@ const echoResponse = "/echo/echoresp/0.0.1" type EchoProtocol struct { host host.Host // local host - requests map[string] *p2p.EchoRequest // used to access request data from response handlers + requests map[string]*p2p.EchoRequest // used to access request data from response handlers done chan bool // only for demo purposes to hold main from terminating } @@ -34,7 +34,6 @@ func NewEchoProtocol(host host.Host, done chan bool) *EchoProtocol { // remote peer requests handler func (e *EchoProtocol) onEchoRequest(s inet.Stream) { - // get request data data := &p2p.EchoRequest{} decoder := protobufCodec.Multicodec(nil).Decoder(bufio.NewReader(s)) diff --git a/examples/multipro/main.go b/examples/multipro/main.go index b729c204..d3ded936 100644 --- a/examples/multipro/main.go +++ b/examples/multipro/main.go @@ -55,4 +55,4 @@ func main() { for i := 0; i < 4; i++ { <-done } -} \ No newline at end of file +} diff --git a/examples/multipro/node.go b/examples/multipro/node.go index 0f0d48ff..c35e30d6 100644 --- a/examples/multipro/node.go +++ b/examples/multipro/node.go @@ -17,7 +17,7 @@ import ( const clientVersion = "go-p2p-node/0.0.1" // helper method - writes a protobuf go data object to a network stream -// data - address of protobuf go data object to send +// data - reference of protobuf go data object to send (not the object itself) // s - network stream to write the data to func sendDataObject(data interface{}, s inet.Stream) bool { writer := bufio.NewWriter(s) @@ -35,12 +35,11 @@ func sendDataObject(data interface{}, s inet.Stream) bool { // nodeId - message author id // messageId - unique for requests, copied from request for responses func NewMessageData(nodeId string, messageId string, gossip bool) *p2p.MessageData { - return &p2p.MessageData{ - ClientVersion: clientVersion, - NodeId: nodeId, - Timestamp: time.Now().Unix(), - Id: messageId, - Gossip: gossip} + return &p2p.MessageData{ClientVersion: clientVersion, + NodeId: nodeId, + Timestamp: time.Now().Unix(), + Id: messageId, + Gossip: gossip} } // Node type - implements one or more p2p protocols @@ -50,9 +49,9 @@ type Node struct { echoProtocol *EchoProtocol // echp protocl imp } -// create a new node with its supported protocols +// 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/ping.go b/examples/multipro/ping.go index ca0020e9..357873b9 100644 --- a/examples/multipro/ping.go +++ b/examples/multipro/ping.go @@ -22,7 +22,7 @@ const pingResponse = "/ping/pingresp/0.0.1" type PingProtocol struct { host host.Host // local host requests map[string]*p2p.PingRequest // used to access request data from response handlers - done chan bool // only for demo purposes to hold main from terminating + done chan bool // only for demo purposes to stop main from terminating } func NewPingProtocol(host host.Host, done chan bool) *PingProtocol { @@ -106,7 +106,7 @@ func (p *PingProtocol) Ping(node *Node) bool { return false } - // store request so response handler has access to it + // store ref request so response handler has access to it p.requests[req.MessageData.Id] = req log.Printf("%s: Ping to: %s was sent. Message Id: %s, Message: %s", p.host.ID(), node.host.ID(), req.MessageData.Id, req.Message) return true