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-kad-dht
Commits
fececcc8
Unverified
Commit
fececcc8
authored
Feb 17, 2020
by
Vibhav Pant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the Routing Table's latency tolerance configurable.
parent
2bceee5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
3 deletions
+11
-3
dht.go
dht.go
+3
-3
opts/options.go
opts/options.go
+8
-0
No files found.
dht.go
View file @
fececcc8
...
...
@@ -99,7 +99,7 @@ func New(ctx context.Context, h host.Host, options ...opts.Option) (*IpfsDHT, er
if
err
:=
cfg
.
Apply
(
append
([]
opts
.
Option
{
opts
.
Defaults
},
options
...
)
...
);
err
!=
nil
{
return
nil
,
err
}
dht
:=
makeDHT
(
ctx
,
h
,
cfg
.
Datastore
,
cfg
.
Protocols
,
cfg
.
BucketSize
)
dht
:=
makeDHT
(
ctx
,
h
,
cfg
.
Datastore
,
cfg
.
Protocols
,
cfg
.
BucketSize
,
cfg
.
RoutingTable
.
LatencyTolerance
)
dht
.
autoRefresh
=
cfg
.
RoutingTable
.
AutoRefresh
dht
.
rtRefreshPeriod
=
cfg
.
RoutingTable
.
RefreshPeriod
dht
.
rtRefreshQueryTimeout
=
cfg
.
RoutingTable
.
RefreshQueryTimeout
...
...
@@ -152,9 +152,9 @@ func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT
return
dht
}
func
makeDHT
(
ctx
context
.
Context
,
h
host
.
Host
,
dstore
ds
.
Batching
,
protocols
[]
protocol
.
ID
,
bucketSize
int
)
*
IpfsDHT
{
func
makeDHT
(
ctx
context
.
Context
,
h
host
.
Host
,
dstore
ds
.
Batching
,
protocols
[]
protocol
.
ID
,
bucketSize
int
,
latency
time
.
Duration
)
*
IpfsDHT
{
self
:=
kb
.
ConvertPeerID
(
h
.
ID
())
rt
:=
kb
.
NewRoutingTable
(
bucketSize
,
self
,
time
.
Minute
,
h
.
Peerstore
())
rt
:=
kb
.
NewRoutingTable
(
bucketSize
,
self
,
latency
,
h
.
Peerstore
())
cmgr
:=
h
.
ConnManager
()
rt
.
PeerAdded
=
func
(
p
peer
.
ID
)
{
...
...
opts/options.go
View file @
fececcc8
...
...
@@ -34,6 +34,7 @@ type Options struct {
RefreshQueryTimeout
time
.
Duration
RefreshPeriod
time
.
Duration
AutoRefresh
bool
LatencyTolerance
time
.
Duration
}
}
...
...
@@ -69,6 +70,13 @@ var Defaults = func(o *Options) error {
return
nil
}
func
RoutingTableLatencyTolerance
(
latency
time
.
Duration
)
Option
{
return
func
(
o
*
Options
)
error
{
o
.
RoutingTable
.
LatencyTolerance
=
latency
return
nil
}
}
// RoutingTableRefreshQueryTimeout sets the timeout for routing table refresh
// queries.
func
RoutingTableRefreshQueryTimeout
(
timeout
time
.
Duration
)
Option
{
...
...
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