From c4f33d4ea5f87a4227fc1727b45b10c83286a1a0 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 26 Jun 2017 09:15:07 +0200 Subject: [PATCH] swarm/network: kad fixes * handleGetPeersMsg Send call async * RequestOrder send outside mutex lock scope --- swarm/network/discovery.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/swarm/network/discovery.go b/swarm/network/discovery.go index 8b8c83a9cb9e..56b86f77fc1d 100644 --- a/swarm/network/discovery.go +++ b/swarm/network/discovery.go @@ -201,7 +201,8 @@ func (d *discPeer) handleGetPeersMsg(msg *getPeersMsg) error { resp := &peersMsg{ Peers: peers, } - return d.Send(resp) + go d.Send(resp) + return nil } // RequestOrder broadcasts to trageted peers a request for peers of a particular @@ -212,17 +213,22 @@ func RequestOrder(k Overlay, order, broadcastSize, maxPeers uint8) { Max: maxPeers, } var i uint8 - //var err error + var peers []Conn k.EachConn(nil, 255, func(p OverlayConn, po int, isproxbin bool) bool { - if err := p.(Conn).Send(req); err == nil { - i++ - if i >= broadcastSize { - return false - } + peers = append(peers, p.(Conn)) + if len(peers) >= int(broadcastSize) { + return false } return true }) - log.Info(fmt.Sprintf("requesting bees of PO%03d from %v/%v (each max %v)", order, i, broadcastSize, maxPeers)) + go func() { + for _, c := range peers { + if err := c.Send(req); err != nil { + break + } + } + log.Info(fmt.Sprintf("requesting bees of PO%03d from %v/%v (each max %v)", order, i, broadcastSize, maxPeers)) + }() } func (d *discPeer) seen(p OverlayPeer) bool {