Commit 9304f557 authored by Adin Schmahmann's avatar Adin Schmahmann

feat: add advanced V1ProtocolOverride option to be used by legacy networks

parent f1f1e3fb
......@@ -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}
......
......@@ -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.
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment