From 8fa257cdf01d32d89485f008cee1a7aedf5dccd0 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 13 Apr 2019 12:56:29 +0300 Subject: [PATCH] track context given in identify constructor and use it to gate identify push --- p2p/protocol/identify/id.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index acf0aa90..d53c99ea 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -47,6 +47,8 @@ const transientTTL = 10 * time.Second type IDService struct { Host host.Host + ctx context.Context + // connections undergoing identification // for wait purposes currid map[inet.Conn]chan struct{} @@ -64,6 +66,7 @@ type IDService struct { func NewIDService(ctx context.Context, h host.Host) *IDService { s := &IDService{ Host: h, + ctx: ctx, currid: make(map[inet.Conn]chan struct{}), observedAddrs: NewObservedAddrSet(ctx), } @@ -162,7 +165,7 @@ func (ids *IDService) Push() { // stream over an existing connection. This would avoid the need for the // supervisory goroutine below, but timeout-less contexts in network operations // make me nervous. - ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + ctx, cancel := context.WithTimeout(ids.ctx, 15*time.Second) ctx = inet.WithNoDial(ctx, "identify push") for _, p := range ids.Host.Network().Peers() {