Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
23cf9d6f
Commit
23cf9d6f
authored
Jan 12, 2015
by
Juan Batiz-Benet
Browse files
p2p/net/swarm: dial - filter out own addrs
parent
5c3adb60
Changes
1
Hide whitespace changes
Inline
Side-by-side
net/swarm/swarm_dial.go
View file @
23cf9d6f
...
...
@@ -39,16 +39,22 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
log
.
Warning
(
"Dial not given PrivateKey, so WILL NOT SECURE conn."
)
}
// get our own addrs
localAddrs
:=
s
.
peers
.
Addresses
(
s
.
local
)
if
len
(
localAddrs
)
==
0
{
log
.
Debug
(
"Dialing out with no local addresses."
)
}
// get remote peer addrs
remoteAddrs
:=
s
.
peers
.
Addresses
(
p
)
// make sure we can use the addresses.
remoteAddrs
=
addrutil
.
FilterUsableAddrs
(
remoteAddrs
)
// drop out any addrs that would just dial ourselves. use ListenAddresses
// as that is a more authoritative view than localAddrs.
remoteAddrs
=
addrutil
.
Subtract
(
remoteAddrs
,
s
.
ListenAddresses
())
if
len
(
remoteAddrs
)
==
0
{
return
nil
,
errors
.
New
(
"peer has no addresses"
)
}
localAddrs
:=
s
.
peers
.
Addresses
(
s
.
local
)
if
len
(
localAddrs
)
==
0
{
log
.
Debug
(
"Dialing out with no local addresses."
)
}
// open connection to peer
d
:=
&
conn
.
Dialer
{
...
...
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