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-kbucket
Commits
509e9b4c
Commit
509e9b4c
authored
Feb 27, 2020
by
Aarsh Shah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
export the Option type
parent
5e066591
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
options.go
options.go
+8
-8
table.go
table.go
+2
-2
No files found.
options.go
View file @
509e9b4c
...
...
@@ -5,8 +5,8 @@ import (
"time"
)
//
o
ption is the Routing Table functional option type.
type
o
ption
func
(
*
options
)
error
//
O
ption is the Routing Table functional option type.
type
O
ption
func
(
*
options
)
error
// options is a structure containing all the functional options that can be used when constructing a Routing Table.
type
options
struct
{
...
...
@@ -19,7 +19,7 @@ type options struct {
}
// Apply applies the given options to this option.
func
(
o
*
options
)
Apply
(
opts
...
o
ption
)
error
{
func
(
o
*
options
)
Apply
(
opts
...
O
ption
)
error
{
for
i
,
opt
:=
range
opts
{
if
err
:=
opt
(
o
);
err
!=
nil
{
return
fmt
.
Errorf
(
"routing table option %d failed: %s"
,
i
,
err
)
...
...
@@ -30,7 +30,7 @@ func (o *options) Apply(opts ...option) error {
// PeerValidationFnc configures the Peer Validation function used for RT cleanup.
// Not configuring this disables Routing Table cleanup.
func
PeerValidationFnc
(
f
PeerValidationFunc
)
o
ption
{
func
PeerValidationFnc
(
f
PeerValidationFunc
)
O
ption
{
return
func
(
o
*
options
)
error
{
o
.
tableCleanup
.
peerValidationFnc
=
f
return
nil
...
...
@@ -38,7 +38,7 @@ func PeerValidationFnc(f PeerValidationFunc) option {
}
// PeersForValidationFnc configures the function that will be used to select the peers that need to be validated during cleanup.
func
PeersForValidationFnc
(
f
PeerSelectionFunc
)
o
ption
{
func
PeersForValidationFnc
(
f
PeerSelectionFunc
)
O
ption
{
return
func
(
o
*
options
)
error
{
o
.
tableCleanup
.
peersForValidationFnc
=
f
return
nil
...
...
@@ -46,7 +46,7 @@ func PeersForValidationFnc(f PeerSelectionFunc) option {
}
// TableCleanupInterval configures the interval between two runs of the Routing Table cleanup routine.
func
TableCleanupInterval
(
i
time
.
Duration
)
o
ption
{
func
TableCleanupInterval
(
i
time
.
Duration
)
O
ption
{
return
func
(
o
*
options
)
error
{
o
.
tableCleanup
.
interval
=
i
return
nil
...
...
@@ -54,7 +54,7 @@ func TableCleanupInterval(i time.Duration) option {
}
// PeerValidationTimeout sets the timeout for a single peer validation during cleanup.
func
PeerValidationTimeout
(
timeout
time
.
Duration
)
o
ption
{
func
PeerValidationTimeout
(
timeout
time
.
Duration
)
O
ption
{
return
func
(
o
*
options
)
error
{
o
.
tableCleanup
.
peerValidationTimeout
=
timeout
return
nil
...
...
@@ -79,4 +79,4 @@ var Defaults = func(o *options) error {
}
return
nil
}
}
\ No newline at end of file
table.go
View file @
509e9b4c
...
...
@@ -87,10 +87,10 @@ type RoutingTable struct {
// NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
// Passing a nil PeerValidationFunc disables periodic table cleanup.
func
NewRoutingTable
(
bucketsize
int
,
localID
ID
,
latency
time
.
Duration
,
m
peerstore
.
Metrics
,
opts
...
o
ption
)
(
*
RoutingTable
,
error
)
{
opts
...
O
ption
)
(
*
RoutingTable
,
error
)
{
var
cfg
options
if
err
:=
cfg
.
Apply
(
append
([]
o
ption
{
Defaults
},
opts
...
)
...
);
err
!=
nil
{
if
err
:=
cfg
.
Apply
(
append
([]
O
ption
{
Defaults
},
opts
...
)
...
);
err
!=
nil
{
return
nil
,
err
}
...
...
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