add a read deadline for the multistream select on dial

This commit is contained in:
Jeromy 2016-04-27 12:17:08 -07:00
parent 0d7301a721
commit d8a6d25b8c
1 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"strings" "strings"
"time"
addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr" addrutil "github.com/ipfs/go-libp2p/p2p/net/swarm/addr"
transport "gx/ipfs/QmRHqYZs3Diy8YC3bW16zvs8VDDwS2ARKBuKwALxEMqibc/go-libp2p-transport" 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 cryptoProtoChoice = NoEncryptionTag
} }
maconn.SetReadDeadline(time.Now().Add(NegotiateReadTimeout))
err = msmux.SelectProtoOrFail(cryptoProtoChoice, maconn) err = msmux.SelectProtoOrFail(cryptoProtoChoice, maconn)
if err != nil { if err != nil {
errOut = err errOut = err
return return
} }
maconn.SetReadDeadline(time.Time{})
c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn) c, err := newSingleConn(ctx, d.LocalPeer, remote, maconn)
if err != nil { if err != nil {
maconn.Close() maconn.Close()