From d8a6d25b8cd2a521aca60e86b850be0da56e46fd Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 27 Apr 2016 12:17:08 -0700 Subject: [PATCH] add a read deadline for the multistream select on dial --- p2p/net/conn/dial.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/net/conn/dial.go b/p2p/net/conn/dial.go index 0cf37896..7654bc6d 100644 --- a/p2p/net/conn/dial.go +++ b/p2p/net/conn/dial.go @@ -4,6 +4,7 @@ import ( "fmt" "math/rand" "strings" + "time" addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr" transport "gx/ipfs/QmRHqYZs3Diy8YC3bW16zvs8VDDwS2ARKBuKwALxEMqibc/go-libp2p-transport" @@ -68,12 +69,16 @@ func (d *Dialer) Dial(ctx context.Context, raddr ma.Multiaddr, remote peer.ID) ( cryptoProtoChoice = NoEncryptionTag } + maconn.SetReadDeadline(time.Now().Add(NegotiateReadTimeout)) + err = msmux.SelectProtoOrFail(cryptoProtoChoice, maconn) if err != nil { errOut = err return } + maconn.SetReadDeadline(time.Time{}) + c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn) if err != nil { maconn.Close()