diff --git a/network/default.go b/network/default.go index 36bcd628..ab8905c7 100644 --- a/network/default.go +++ b/network/default.go @@ -276,10 +276,7 @@ func (n *network) processNetChan(client transport.Client, listener tunnel.Listen } n.Unlock() // get all the node peers down to MaxDepth encoded in protobuf - msg, err := n.node.getProtoTopology(MaxDepth) - if err != nil { - log.Debugf("Network unable to retrieve node topology: %s", err) - } + msg := n.node.getProtoTopology(MaxDepth) // advertise yourself to the network if err := n.sendMsg("peer", msg, NetworkChannel); err != nil { log.Debugf("Network failed to advertise peers: %v", err) @@ -396,12 +393,7 @@ func (n *network) announce(client transport.Client) { case <-n.closed: return case <-announce.C: - msg, err := n.node.getProtoTopology(MaxDepth) - if err != nil { - log.Debugf("Network unable to retrieve node topology: %s", err) - continue - } - n.node.RUnlock() + msg := n.node.getProtoTopology(MaxDepth) // advertise yourself to the network if err := n.sendMsg("peer", msg, NetworkChannel); err != nil { log.Debugf("Network failed to advertise peers: %v", err) diff --git a/network/node.go b/network/node.go index c4c49f1c..dad609e5 100644 --- a/network/node.go +++ b/network/node.go @@ -129,7 +129,7 @@ func (n *node) Peers() []Node { } // getProtoTopology returns node topology down to the given depth encoded in protobuf -func (n *node) getProtoTopology(depth uint) (*pb.Peer, error) { +func (n *node) getProtoTopology(depth uint) *pb.Peer { n.RLock() defer n.RUnlock() @@ -145,7 +145,7 @@ func (n *node) getProtoTopology(depth uint) (*pb.Peer, error) { // return if have either reached the depth or have no more peers if depth == 0 || len(n.peers) == 0 { - return pbPeers, nil + return pbPeers } // decrement the depth @@ -155,10 +155,7 @@ func (n *node) getProtoTopology(depth uint) (*pb.Peer, error) { for _, peer := range n.peers { // get peers of the node peers // NOTE: this is [not] a recursive call - pbPeerPeer, err := peer.getProtoTopology(depth) - if err != nil { - return nil, err - } + pbPeerPeer := peer.getProtoTopology(depth) // add current peer to explored peers peers = append(peers, pbPeerPeer) } @@ -166,7 +163,7 @@ func (n *node) getProtoTopology(depth uint) (*pb.Peer, error) { // add peers to the parent topology pbPeers.Peers = peers - return pbPeers, nil + return pbPeers } // unpackPeer unpacks pb.Peer into node topology of given depth diff --git a/network/node_test.go b/network/node_test.go index 774d78ec..2a49be11 100644 --- a/network/node_test.go +++ b/network/node_test.go @@ -266,10 +266,8 @@ func TestGetProtoTopology(t *testing.T) { } topCount := 0 - protoTop, err := single.getProtoTopology(10) - if err != nil { - t.Errorf("Error getting proto topology: %s", err) - } + protoTop := single.getProtoTopology(10) + if len(protoTop.Peers) != topCount { t.Errorf("Expected to find %d nodes, found: %d", topCount, len(protoTop.Peers)) } @@ -284,10 +282,8 @@ func TestGetProtoTopology(t *testing.T) { peerIds[id] = true } // depth 1 should give us immmediate neighbours only - protoTop, err = node.getProtoTopology(1) - if err != nil { - t.Errorf("Error getting proto topology: %s", err) - } + protoTop = node.getProtoTopology(1) + if len(protoTop.Peers) != topCount { t.Errorf("Expected to find %d nodes, found: %d", topCount, len(protoTop.Peers)) }