Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-swarm
Commits
6463230b
Commit
6463230b
authored
Apr 10, 2019
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update to use NoDial option from go-libp2p-net
parent
b3c0cdb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
16 deletions
+4
-16
swarm.go
swarm.go
+2
-14
swarm_test.go
swarm_test.go
+2
-2
No files found.
swarm.go
View file @
6463230b
...
@@ -37,18 +37,6 @@ var ErrSwarmClosed = errors.New("swarm closed")
...
@@ -37,18 +37,6 @@ var ErrSwarmClosed = errors.New("swarm closed")
// transport is misbehaving.
// transport is misbehaving.
var
ErrAddrFiltered
=
errors
.
New
(
"address filtered"
)
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
// Swarm is a connection muxer, allowing connections to other peers to
// be opened and closed, while still using the same Chan for all
// be opened and closed, while still using the same Chan for all
// communication. The Chan sends/receives Messages, which note the
// 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) {
...
@@ -307,8 +295,8 @@ func (s *Swarm) NewStream(ctx context.Context, p peer.ID) (inet.Stream, error) {
for
{
for
{
c
:=
s
.
bestConnToPeer
(
p
)
c
:=
s
.
bestConnToPeer
(
p
)
if
c
==
nil
{
if
c
==
nil
{
if
nodial
:=
ctx
.
Value
(
NoDial
);
nodial
!=
nil
{
if
nodial
,
_
:=
inet
.
Get
NoDial
(
ctx
);
nodial
{
return
nil
,
ErrNoConn
return
nil
,
inet
.
ErrNoConn
}
}
if
dials
>=
DialAttempts
{
if
dials
>=
DialAttempts
{
...
...
swarm_test.go
View file @
6463230b
...
@@ -341,8 +341,8 @@ func TestNoDial(t *testing.T) {
...
@@ -341,8 +341,8 @@ func TestNoDial(t *testing.T) {
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
swarms
:=
makeSwarms
(
ctx
,
t
,
2
)
swarms
:=
makeSwarms
(
ctx
,
t
,
2
)
_
,
err
:=
swarms
[
0
]
.
NewStream
(
context
.
WithValue
(
ctx
,
NoDial
,
"swarm
.
test"
),
swarms
[
1
]
.
LocalPeer
())
_
,
err
:=
swarms
[
0
]
.
NewStream
(
inet
.
With
NoDial
(
ctx
,
"swarm
test"
),
swarms
[
1
]
.
LocalPeer
())
if
err
!=
ErrNoConn
{
if
err
!=
inet
.
ErrNoConn
{
t
.
Fatal
(
"should have failed with ErrNoConn"
)
t
.
Fatal
(
"should have failed with ErrNoConn"
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment