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
4b7d6fb8
Unverified
Commit
4b7d6fb8
authored
Nov 14, 2019
by
Steven Allen
Committed by
GitHub
Nov 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #410 from aarshkshah1992/feat/config-record-maxage
Make max record age configurable
parents
8ecf9380
7a39667d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
15 deletions
+25
-15
dht.go
dht.go
+4
-0
handlers.go
handlers.go
+1
-1
opts/options.go
opts/options.go
+20
-5
records.go
records.go
+0
-9
No files found.
dht.go
View file @
4b7d6fb8
...
...
@@ -71,6 +71,8 @@ type IpfsDHT struct {
rtRefreshQueryTimeout
time
.
Duration
rtRefreshPeriod
time
.
Duration
triggerRtRefresh
chan
struct
{}
maxRecordAge
time
.
Duration
}
// Assert that IPFS assumptions about interfaces aren't broken. These aren't a
...
...
@@ -95,6 +97,8 @@ func New(ctx context.Context, h host.Host, options ...opts.Option) (*IpfsDHT, er
dht
.
rtRefreshPeriod
=
cfg
.
RoutingTable
.
RefreshPeriod
dht
.
rtRefreshQueryTimeout
=
cfg
.
RoutingTable
.
RefreshQueryTimeout
dht
.
maxRecordAge
=
cfg
.
MaxRecordAge
// register for network notifs.
dht
.
host
.
Network
()
.
Notify
((
*
netNotifiee
)(
dht
))
...
...
handlers.go
View file @
4b7d6fb8
...
...
@@ -118,7 +118,7 @@ func (dht *IpfsDHT) checkLocalDatastore(k []byte) (*recpb.Record, error) {
recordIsBad
=
true
}
if
time
.
Since
(
recvtime
)
>
M
axRecordAge
{
if
time
.
Since
(
recvtime
)
>
dht
.
m
axRecordAge
{
logger
.
Debug
(
"old record found, tossing."
)
recordIsBad
=
true
}
...
...
opts/options.go
View file @
4b7d6fb8
...
...
@@ -21,11 +21,12 @@ var (
// Options is a structure containing all the options that can be used when constructing a DHT.
type
Options
struct
{
Datastore
ds
.
Batching
Validator
record
.
Validator
Client
bool
Protocols
[]
protocol
.
ID
BucketSize
int
Datastore
ds
.
Batching
Validator
record
.
Validator
Client
bool
Protocols
[]
protocol
.
ID
BucketSize
int
MaxRecordAge
time
.
Duration
RoutingTable
struct
{
RefreshQueryTimeout
time
.
Duration
...
...
@@ -59,6 +60,7 @@ var Defaults = func(o *Options) error {
o
.
RoutingTable
.
RefreshQueryTimeout
=
10
*
time
.
Second
o
.
RoutingTable
.
RefreshPeriod
=
1
*
time
.
Hour
o
.
RoutingTable
.
AutoRefresh
=
true
o
.
MaxRecordAge
=
time
.
Hour
*
36
return
nil
}
...
...
@@ -153,6 +155,19 @@ func BucketSize(bucketSize int) Option {
}
}
// MaxRecordAge specifies the maximum time that any node will hold onto a record ("PutValue record")
// from the time its received. This does not apply to any other forms of validity that
// the record may contain.
// For example, a record may contain an ipns entry with an EOL saying its valid
// until the year 2020 (a great time in the future). For that record to stick around
// it must be rebroadcasted more frequently than once every 'MaxRecordAge'
func
MaxRecordAge
(
maxAge
time
.
Duration
)
Option
{
return
func
(
o
*
Options
)
error
{
o
.
MaxRecordAge
=
maxAge
return
nil
}
}
// DisableAutoRefresh completely disables 'auto-refresh' on the DHT routing
// table. This means that we will neither refresh the routing table periodically
// nor when the routing table size goes below the minimum threshold.
...
...
records.go
View file @
4b7d6fb8
...
...
@@ -3,7 +3,6 @@ package dht
import
(
"context"
"fmt"
"time"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/routing"
...
...
@@ -11,14 +10,6 @@ import (
ci
"github.com/libp2p/go-libp2p-core/crypto"
)
// MaxRecordAge specifies the maximum time that any node will hold onto a record
// from the time its received. This does not apply to any other forms of validity that
// the record may contain.
// For example, a record may contain an ipns entry with an EOL saying its valid
// until the year 2020 (a great time in the future). For that record to stick around
// it must be rebroadcasted more frequently than once every 'MaxRecordAge'
const
MaxRecordAge
=
time
.
Hour
*
36
type
pubkrs
struct
{
pubk
ci
.
PubKey
err
error
...
...
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