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
9304f557
Commit
9304f557
authored
Aug 28, 2020
by
Adin Schmahmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add advanced V1ProtocolOverride option to be used by legacy networks
parent
f1f1e3fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
13 deletions
+62
-13
dht.go
dht.go
+5
-0
dht_options.go
dht_options.go
+26
-13
dht_test.go
dht_test.go
+31
-0
No files found.
dht.go
View file @
9304f557
...
...
@@ -260,6 +260,11 @@ func makeDHT(ctx context.Context, h host.Host, cfg config) (*IpfsDHT, error) {
var
protocols
,
serverProtocols
[]
protocol
.
ID
v1proto
:=
cfg
.
protocolPrefix
+
kad1
if
cfg
.
v1ProtocolOverride
!=
""
{
v1proto
=
cfg
.
v1ProtocolOverride
}
protocols
=
[]
protocol
.
ID
{
v1proto
}
serverProtocols
=
[]
protocol
.
ID
{
v1proto
}
...
...
dht_options.go
View file @
9304f557
...
...
@@ -39,19 +39,20 @@ const DefaultPrefix protocol.ID = "/ipfs"
// Options is a structure containing all the options that can be used when constructing a DHT.
type
config
struct
{
datastore
ds
.
Batching
validator
record
.
Validator
validatorChanged
bool
// if true implies that the validator has been changed and that defaults should not be used
mode
ModeOpt
protocolPrefix
protocol
.
ID
bucketSize
int
concurrency
int
resiliency
int
maxRecordAge
time
.
Duration
enableProviders
bool
enableValues
bool
providersOptions
[]
providers
.
Option
queryPeerFilter
QueryFilterFunc
datastore
ds
.
Batching
validator
record
.
Validator
validatorChanged
bool
// if true implies that the validator has been changed and that defaults should not be used
mode
ModeOpt
protocolPrefix
protocol
.
ID
v1ProtocolOverride
protocol
.
ID
bucketSize
int
concurrency
int
resiliency
int
maxRecordAge
time
.
Duration
enableProviders
bool
enableValues
bool
providersOptions
[]
providers
.
Option
queryPeerFilter
QueryFilterFunc
routingTable
struct
{
refreshQueryTimeout
time
.
Duration
...
...
@@ -275,6 +276,18 @@ func ProtocolExtension(ext protocol.ID) Option {
}
}
// V1ProtocolOverride overrides the protocolID used for /kad/1.0.0 with another. This is an
// advanced feature, and should only be used to handle legacy networks that have not been
// using protocolIDs of the form /app/kad/1.0.0.
//
// This option will override and ignore the ProtocolPrefix and ProtocolExtension options
func
V1ProtocolOverride
(
proto
protocol
.
ID
)
Option
{
return
func
(
c
*
config
)
error
{
c
.
v1ProtocolOverride
=
proto
return
nil
}
}
// BucketSize configures the bucket size (k in the Kademlia paper) of the routing table.
//
// The default value is 20.
...
...
dht_test.go
View file @
9304f557
...
...
@@ -1867,6 +1867,37 @@ func TestInvalidKeys(t *testing.T) {
}
}
func TestV1ProtocolOverride(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
d1 := setupDHT(ctx, t, false, V1ProtocolOverride("/myproto") )
d2 := setupDHT(ctx, t, false, V1ProtocolOverride("/myproto") )
d3 := setupDHT(ctx, t, false, V1ProtocolOverride("/myproto2"))
d4 := setupDHT(ctx, t, false)
dhts := []*IpfsDHT{d1,d2,d3,d4}
for i, dout := range dhts {
for _, din := range dhts[i+1:] {
connectNoSync(t, ctx, dout, din)
}
}
wait(t, ctx, d1, d2)
wait(t, ctx, d2, d1)
time.Sleep(time.Second)
if d1.RoutingTable().Size() != 1 || d2.routingTable.Size() != 1 {
t.Fatal("should have one peer in the routing table")
}
if d3.RoutingTable().Size() > 0 || d4.RoutingTable().Size() > 0{
t.Fatal("should have an empty routing table")
}
}
func TestRoutingFilter(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
...
...
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