Commit 6463230b authored by vyzo's avatar vyzo

update to use NoDial option from go-libp2p-net

parent b3c0cdb1
......@@ -37,18 +37,6 @@ var ErrSwarmClosed = errors.New("swarm closed")
// transport is misbehaving.
var ErrAddrFiltered = errors.New("address filtered")
// ErrNoConn is returned when attempting to open a stream to a peer with the NoDial
// option and no usable connection is available.
var ErrNoConn = errors.New("no usable connection to peer")
// ContextOption is the type of context options understood by the swarm
type ContextOption string
// NoDial is a context option that instructs the swarm to not attempt a new
// dial when opening a stream. The value of the key should be a string indicating
// the source of the option.
var NoDial = ContextOption("swarm.NoDial")
// Swarm is a connection muxer, allowing connections to other peers to
// be opened and closed, while still using the same Chan for all
// communication. The Chan sends/receives Messages, which note the
......@@ -307,8 +295,8 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) {
for {
c := s.bestConnToPeer(p)
if c == nil {
if nodial := ctx.Value(NoDial); nodial != nil {
return nil, ErrNoConn
if nodial, _ := inet.GetNoDial(ctx); nodial {
return nil, inet.ErrNoConn
}
if dials >= DialAttempts {
......
......@@ -341,8 +341,8 @@ func TestNoDial(t *testing.T) {
ctx := context.Background()
swarms := makeSwarms(ctx, t, 2)
_, err := swarms[0].NewStream(context.WithValue(ctx, NoDial, "swarm.test"), swarms[1].LocalPeer())
if err != ErrNoConn {
_, 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