Unverified Commit 51da4b6c authored by vyzo's avatar vyzo Committed by GitHub

Merge pull request #116 from libp2p/feat/no-dial-option

Add context option to disable dialing when opening a new stream
parents 87b9a9c7 62924673
......@@ -295,6 +295,10 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) {
for {
c := s.bestConnToPeer(p)
if c == nil {
if nodial, _ := inet.GetNoDial(ctx); nodial {
return nil, inet.ErrNoConn
}
if dials >= DialAttempts {
return nil, errors.New("max dial attempts exceeded")
}
......
......@@ -335,3 +335,13 @@ func TestFilterBounds(t *testing.T) {
t.Log("got connect")
}
}
func TestNoDial(t *testing.T) {
ctx := context.Background()
swarms := makeSwarms(ctx, t, 2)
_, err := swarms[0].NewStream(inet.WithNoDial(ctx, "swarm test"), swarms[1].LocalPeer())
if err != inet.ErrNoConn {
t.Fatal("should have failed with ErrNoConn")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment