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
f144edfc
Unverified
Commit
f144edfc
authored
Jun 17, 2018
by
Whyrusleeping
Committed by
GitHub
Jun 17, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70 from libp2p/feat/local-timeout
feat: lower timeout for local address dials
parents
fd490032
ec696be0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
2 deletions
+56
-2
addrs.go
addrs.go
+35
-0
limiter.go
limiter.go
+14
-1
swarm.go
swarm.go
+7
-1
No files found.
addrs.go
0 → 100644
View file @
f144edfc
package
swarm
import
(
mafilter
"github.com/libp2p/go-maddr-filter"
mamask
"github.com/whyrusleeping/multiaddr-filter"
)
// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
var
lowTimeoutFilters
=
mafilter
.
NewFilters
()
func
init
()
{
for
_
,
p
:=
range
[]
string
{
"/ip4/10.0.0.0/ipcidr/8"
,
"/ip4/100.64.0.0/ipcidr/10"
,
"/ip4/169.254.0.0/ipcidr/16"
,
"/ip4/172.16.0.0/ipcidr/12"
,
"/ip4/192.0.0.0/ipcidr/24"
,
"/ip4/192.0.0.0/ipcidr/29"
,
"/ip4/192.0.0.8/ipcidr/32"
,
"/ip4/192.0.0.170/ipcidr/32"
,
"/ip4/192.0.0.171/ipcidr/32"
,
"/ip4/192.0.2.0/ipcidr/24"
,
"/ip4/192.168.0.0/ipcidr/16"
,
"/ip4/198.18.0.0/ipcidr/15"
,
"/ip4/198.51.100.0/ipcidr/24"
,
"/ip4/203.0.113.0/ipcidr/24"
,
"/ip4/240.0.0.0/ipcidr/4"
,
}
{
f
,
err
:=
mamask
.
NewMask
(
p
)
if
err
!=
nil
{
panic
(
"error in lowTimeoutFilters init: "
+
err
.
Error
())
}
lowTimeoutFilters
.
AddDialFilter
(
f
)
}
}
limiter.go
View file @
f144edfc
...
...
@@ -3,6 +3,7 @@ package swarm
import
(
"context"
"sync"
"time"
addrutil
"github.com/libp2p/go-addr-util"
peer
"github.com/libp2p/go-libp2p-peer"
...
...
@@ -33,6 +34,15 @@ func (dj *dialJob) cancelled() bool {
}
}
func
(
dj
*
dialJob
)
dialTimeout
()
time
.
Duration
{
timeout
:=
DialTimeout
if
lowTimeoutFilters
.
AddrBlocked
(
dj
.
addr
)
{
timeout
=
DialTimeoutLocal
}
return
timeout
}
type
dialLimiter
struct
{
lk
sync
.
Mutex
...
...
@@ -169,7 +179,10 @@ func (dl *dialLimiter) executeDial(j *dialJob) {
return
}
con
,
err
:=
dl
.
dialFunc
(
j
.
ctx
,
j
.
peer
,
j
.
addr
)
dctx
,
cancel
:=
context
.
WithTimeout
(
j
.
ctx
,
j
.
dialTimeout
())
defer
cancel
()
con
,
err
:=
dl
.
dialFunc
(
dctx
,
j
.
peer
,
j
.
addr
)
select
{
case
j
.
resp
<-
dialResult
{
Conn
:
con
,
Addr
:
j
.
addr
,
Err
:
err
}
:
case
<-
j
.
ctx
.
Done
()
:
...
...
swarm.go
View file @
f144edfc
...
...
@@ -22,9 +22,15 @@ import (
)
// DialTimeout is the maximum duration a Dial is allowed to take.
// This includes the time spent waiting in dial limiter, between dialing the raw
// network connection, protocol selection as well the handshake, if applicable.
var
DialTimeout
=
60
*
time
.
Second
// DialTimeoutLocal is the maximum duration a Dial to local network address
// is allowed to take.
// This includes the time between dialing the raw network connection,
// protocol selection as well the handshake, if applicable.
var
DialTimeout
=
60
*
time
.
Second
var
DialTimeout
Local
=
5
*
time
.
Second
var
log
=
logging
.
Logger
(
"swarm2"
)
...
...
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