Code cleanup; Indentation.

This commit is contained in:
Milos Gajdos 2020-01-14 18:48:42 +00:00
parent 0ea56a5ffe
commit dcd925f1e5
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
4 changed files with 62 additions and 60 deletions

View File

@ -880,12 +880,7 @@ func (n *network) processNetChan(listener tunnel.Listener) {
address: pbNetPeer.Node.Address,
link: m.msg.Header["Micro-Link"],
peers: make(map[string]*node),
status: &status{
err: &nerr{
count: int(pbNetPeer.Node.Status.Error.Count),
msg: errors.New(pbNetPeer.Node.Status.Error.Msg),
},
},
status: newPeerStatus(pbNetPeer),
lastSeen: now,
}
@ -985,12 +980,7 @@ func (n *network) processNetChan(listener tunnel.Listener) {
address: pbNetSync.Peer.Node.Address,
link: m.msg.Header["Micro-Link"],
peers: make(map[string]*node),
status: &status{
err: &nerr{
count: int(pbNetSync.Peer.Node.Status.Error.Count),
msg: errors.New(pbNetSync.Peer.Node.Status.Error.Msg),
},
},
status: newPeerStatus(pbNetSync.Peer),
lastSeen: now,
}
@ -1279,7 +1269,11 @@ func (n *network) manage() {
// get a list of node peers
peers := n.Peers()
// pick a random peer from the list of peers and request full sync
if peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id()); peer != nil {
peer := n.node.GetPeerNode(peers[rnd.Intn(len(peers))].Id())
if peer != nil {
continue
}
go func() {
// get node peer graph to send back to the connecting node
node := PeersToProto(n.node, MaxDepth)
@ -1310,7 +1304,6 @@ func (n *network) manage() {
log.Debugf("Network failed to send sync message: %v", err)
}
}()
}
case <-resolve.C:
n.initNodes(false)
}

View File

@ -20,7 +20,7 @@ var (
// KeepAliveTime is the time in which we want to have sent a message to a peer
KeepAliveTime = 30 * time.Second
// SyncTime is the time a network node requests full sync from the network
SyncTime = 5 * time.Minute
SyncTime = 1 * time.Minute
// PruneTime defines time interval to periodically check nodes that need to be pruned
// due to their not announcing their presence within this time interval
PruneTime = 90 * time.Second

View File

@ -69,6 +69,15 @@ func newStatus() *status {
}
}
func newPeerStatus(peer *pb.Peer) *status {
return &status{
err: &nerr{
count: int(peer.Node.Status.Error.Count),
msg: errors.New(peer.Node.Status.Error.Msg),
},
}
}
func (s *status) Error() Error {
s.RLock()
defer s.RUnlock()