From 7fabe39290271ea6b8a2b52db1140e20d6563a14 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 18 Oct 2018 12:00:22 +0300 Subject: [PATCH] parallel identify push --- p2p/protocol/identify/id.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index d49bdf28a..5991fe695 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -149,15 +149,17 @@ func (ids *IDService) pushHandler(s inet.Stream) { func (ids *IDService) Push() { for _, p := range ids.Host.Network().Peers() { - ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) - s, err := ids.Host.NewStream(ctx, p, IDPush) - cancel() - if err != nil { - log.Debugf("error opening push stream: %s", err.Error()) - continue - } + go func(p peer.ID) { + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + s, err := ids.Host.NewStream(ctx, p, IDPush) + if err != nil { + log.Debugf("error opening push stream: %s", err.Error()) + return + } - ids.requestHandler(s) + ids.requestHandler(s) + }(p) } }