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
0ef8622d
Commit
0ef8622d
authored
May 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address CR feedback
parent
b1df8043
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
6 deletions
+10
-6
addr/addr.go
addr/addr.go
+2
-2
addr/filter.go
addr/filter.go
+4
-0
swarm_dial.go
swarm_dial.go
+4
-4
No files found.
addr/addr.go
View file @
0ef8622d
...
@@ -40,8 +40,8 @@ func init() {
...
@@ -40,8 +40,8 @@ func init() {
SupportedTransportProtocols
=
transports
SupportedTransportProtocols
=
transports
}
}
// FilterAddrs is a filter that removes certain addresses, according t
o
filter.
// FilterAddrs is a filter that removes certain addresses, according t
he given
filter
s
.
// if filter return
s
true, the address is kept.
// if
all
filter
s
return true, the address is kept.
func
FilterAddrs
(
a
[]
ma
.
Multiaddr
,
filters
...
func
(
ma
.
Multiaddr
)
bool
)
[]
ma
.
Multiaddr
{
func
FilterAddrs
(
a
[]
ma
.
Multiaddr
,
filters
...
func
(
ma
.
Multiaddr
)
bool
)
[]
ma
.
Multiaddr
{
b
:=
make
([]
ma
.
Multiaddr
,
0
,
len
(
a
))
b
:=
make
([]
ma
.
Multiaddr
,
0
,
len
(
a
))
for
_
,
addr
:=
range
a
{
for
_
,
addr
:=
range
a
{
...
...
addr/filter.go
View file @
0ef8622d
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
mafmt
"github.com/whyrusleeping/mafmt"
mafmt
"github.com/whyrusleeping/mafmt"
)
)
// SubtractFilter returns a filter func that filters all of the given addresses
func
SubtractFilter
(
addrs
...
ma
.
Multiaddr
)
func
(
ma
.
Multiaddr
)
bool
{
func
SubtractFilter
(
addrs
...
ma
.
Multiaddr
)
func
(
ma
.
Multiaddr
)
bool
{
addrmap
:=
make
(
map
[
string
]
bool
)
addrmap
:=
make
(
map
[
string
]
bool
)
for
_
,
a
:=
range
addrs
{
for
_
,
a
:=
range
addrs
{
...
@@ -16,10 +17,13 @@ func SubtractFilter(addrs ...ma.Multiaddr) func(ma.Multiaddr) bool {
...
@@ -16,10 +17,13 @@ func SubtractFilter(addrs ...ma.Multiaddr) func(ma.Multiaddr) bool {
}
}
}
}
// IsFDCostlyTransport returns true for transports that require a new file
// descriptor per connection created
func
IsFDCostlyTransport
(
a
ma
.
Multiaddr
)
bool
{
func
IsFDCostlyTransport
(
a
ma
.
Multiaddr
)
bool
{
return
mafmt
.
TCP
.
Matches
(
a
)
return
mafmt
.
TCP
.
Matches
(
a
)
}
}
// FilterNeg returns a negated version of the passed in filter
func
FilterNeg
(
f
func
(
ma
.
Multiaddr
)
bool
)
func
(
ma
.
Multiaddr
)
bool
{
func
FilterNeg
(
f
func
(
ma
.
Multiaddr
)
bool
)
func
(
ma
.
Multiaddr
)
bool
{
return
func
(
a
ma
.
Multiaddr
)
bool
{
return
func
(
a
ma
.
Multiaddr
)
bool
{
return
!
f
(
a
)
return
!
f
(
a
)
...
...
swarm_dial.go
View file @
0ef8622d
...
@@ -390,9 +390,6 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
...
@@ -390,9 +390,6 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
continue
continue
}
}
// limitedDial will start a dial to the given peer when
// it is able, respecting the various different types of rate
// limiting that occur without using extra goroutines per addr
s
.
limitedDial
(
ctx
,
p
,
addr
,
respch
)
s
.
limitedDial
(
ctx
,
p
,
addr
,
respch
)
active
++
active
++
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
...
@@ -403,7 +400,7 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
...
@@ -403,7 +400,7 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
case
resp
:=
<-
respch
:
case
resp
:=
<-
respch
:
active
--
active
--
if
resp
.
Err
!=
nil
{
if
resp
.
Err
!=
nil
{
log
.
Error
(
"got error on dial: "
,
resp
.
Err
)
log
.
Info
(
"got error on dial: "
,
resp
.
Err
)
// Errors are normal, lots of dials will fail
// Errors are normal, lots of dials will fail
exitErr
=
resp
.
Err
exitErr
=
resp
.
Err
...
@@ -417,6 +414,9 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
...
@@ -417,6 +414,9 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma.
}
}
}
}
// limitedDial will start a dial to the given peer when
// it is able, respecting the various different types of rate
// limiting that occur without using extra goroutines per addr
func
(
s
*
Swarm
)
limitedDial
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
,
resp
chan
dialResult
)
{
func
(
s
*
Swarm
)
limitedDial
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
,
resp
chan
dialResult
)
{
s
.
limiter
.
AddDialJob
(
&
dialJob
{
s
.
limiter
.
AddDialJob
(
&
dialJob
{
addr
:
a
,
addr
:
a
,
...
...
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