-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: document and expose Amino DHT defaults #990
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Package amino provides protocol parameters and suggested default values for the [Amino DHT]. | ||
// | ||
// [Amino DHT] is an implementation of the Kademlia distributed hash table (DHT) algorithm, | ||
// originally designed for use in IPFS (InterPlanetary File System) network. | ||
// This package defines key constants and protocol identifiers used in the Amino DHT implementation. | ||
// | ||
// [Amino DHT]: https://probelab.io/ipfs/amino/ | ||
package amino | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p/core/protocol" | ||
) | ||
|
||
const ( | ||
// ProtocolPrefix is the base prefix for Amono DHT protocols. | ||
ProtocolPrefix protocol.ID = "/ipfs" | ||
|
||
// ProtocolID is the latest protocol identifier for the Amino DHT. | ||
ProtocolID protocol.ID = "/ipfs/kad/1.0.0" | ||
|
||
// DefaultBucketSize is the Amino DHT bucket size (k in the Kademlia paper). | ||
// It represents the maximum number of peers stored in each | ||
// k-bucket of the routing table. | ||
DefaultBucketSize = 20 | ||
|
||
// DefaultConcurrency is the suggested number of concurrent requests (alpha | ||
// in the Kademlia paper) for a given query path in Amino DHT. It | ||
// determines how many parallel lookups are performed during network | ||
// traversal. | ||
DefaultConcurrency = 10 | ||
|
||
// DefaultResiliency is the suggested number of peers closest to a target | ||
// that must have responded in order for a given query path to complete in | ||
// Amino DHT. This helps ensure reliable results by requiring multiple | ||
// confirmations. | ||
DefaultResiliency = 3 | ||
|
||
// DefaultProvideValidity is the default time that a Provider Record should | ||
// last on Amino DHT before it needs to be refreshed or removed. This value | ||
// is also known as Provider Record Expiration Interval. | ||
DefaultProvideValidity = 48 * time.Hour | ||
|
||
// DefaultProviderAddrTTL is the TTL to keep the multi addresses of | ||
// provider peers around. Those addresses are returned alongside provider. | ||
// After it expires, the returned records will require an extra lookup, to | ||
// find the multiaddress associated with the returned peer id. | ||
DefaultProviderAddrTTL = 24 * time.Hour | ||
) | ||
|
||
var ( | ||
// Protocols is a slice containing all supported protocol IDs for Amino DHT. | ||
// Currently, it only includes the main ProtocolID, but it's defined as a slice | ||
// to allow for potential future protocol versions or variants. | ||
Protocols = []protocol.ID{ProtocolID} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"github.com/ipfs/boxo/ipns" | ||
ds "github.com/ipfs/go-datastore" | ||
dssync "github.com/ipfs/go-datastore/sync" | ||
"github.com/libp2p/go-libp2p-kad-dht/amino" | ||
"github.com/libp2p/go-libp2p-kad-dht/internal/net" | ||
pb "github.com/libp2p/go-libp2p-kad-dht/pb" | ||
"github.com/libp2p/go-libp2p-kad-dht/providers" | ||
|
@@ -19,9 +20,7 @@ | |
) | ||
|
||
// DefaultPrefix is the application specific prefix attached to all DHT protocols by default. | ||
const DefaultPrefix protocol.ID = "/ipfs" | ||
|
||
const defaultBucketSize = 20 | ||
const DefaultPrefix protocol.ID = amino.ProtocolPrefix | ||
|
||
// ModeOpt describes what mode the dht should operate in | ||
type ModeOpt int | ||
|
@@ -127,9 +126,9 @@ | |
|
||
o.MaxRecordAge = providers.ProvideValidity | ||
|
||
o.BucketSize = defaultBucketSize | ||
o.Concurrency = 10 | ||
o.Resiliency = 3 | ||
o.BucketSize = amino.DefaultBucketSize | ||
o.Concurrency = amino.DefaultConcurrency | ||
o.Resiliency = amino.DefaultResiliency | ||
o.LookupCheckConcurrency = 256 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another candidate for defaults? Also, wish there was some explanation why 256 is the chosen value for concurrency. |
||
|
||
// MAGIC: It makes sense to set it to a multiple of OptProvReturnRatio * BucketSize. We chose a multiple of 4. | ||
|
@@ -139,11 +138,12 @@ | |
} | ||
|
||
func (c *Config) Validate() error { | ||
// Configuration is validated and enforced only if prefix matches Amino DHT | ||
if c.ProtocolPrefix != DefaultPrefix { | ||
return nil | ||
} | ||
if c.BucketSize != defaultBucketSize { | ||
return fmt.Errorf("protocol prefix %s must use bucket size %d", DefaultPrefix, defaultBucketSize) | ||
if c.BucketSize != amino.DefaultBucketSize { | ||
return fmt.Errorf("protocol prefix %s must use bucket size %d", DefaultPrefix, amino.DefaultBucketSize) | ||
} | ||
if !c.EnableProviders { | ||
return fmt.Errorf("protocol prefix %s must have providers enabled", DefaultPrefix) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package dht | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p-kad-dht/amino" | ||
"github.com/libp2p/go-libp2p/core/protocol" | ||
) | ||
|
||
var ( | ||
// ProtocolDHT is the default DHT protocol. | ||
ProtocolDHT protocol.ID = "/ipfs/kad/1.0.0" | ||
ProtocolDHT protocol.ID = amino.ProtocolID | ||
// DefaultProtocols spoken by the DHT. | ||
DefaultProtocols = []protocol.ID{ProtocolDHT} | ||
DefaultProtocols = amino.Protocols | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be defined in
defaults.go
as well, even if not exported?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem to be specific to crawler and really part of "Amino DHT contract", so could
I'm going to merge thus PR as-is, we can figure out what to do remaining magic numbers in follow-up PR.