-
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
feat: allow disabling value and provider storage/messages #400
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52747fc
feat: allow disabling value and provider storage/messages
Stebalien c2b72b2
doc(options): document that disabling values/providers should only be…
Stebalien ba86f51
fix: return a closed channel from FindProvidersAsync when providers a…
Stebalien 2a39785
fix(options): make the disable providers/values options consistent
Stebalien 5a048ea
docs(options): document that DisableValues disables retrieving public…
Stebalien 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
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
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 |
---|---|---|
|
@@ -34,6 +34,10 @@ var asyncQueryBuffer = 10 | |
// PutValue adds value corresponding to given Key. | ||
// This is the top level "Store" operation of the DHT | ||
func (dht *IpfsDHT) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) (err error) { | ||
if !dht.enableValues { | ||
return routing.ErrNotSupported | ||
} | ||
|
||
eip := logger.EventBegin(ctx, "PutValue") | ||
defer func() { | ||
eip.Append(loggableKey(key)) | ||
|
@@ -110,6 +114,10 @@ type RecvdVal struct { | |
|
||
// GetValue searches for the value corresponding to given Key. | ||
func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...routing.Option) (_ []byte, err error) { | ||
if !dht.enableValues { | ||
return nil, routing.ErrNotSupported | ||
} | ||
|
||
eip := logger.EventBegin(ctx, "GetValue") | ||
defer func() { | ||
eip.Append(loggableKey(key)) | ||
|
@@ -148,6 +156,10 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...routing.Op | |
} | ||
|
||
func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error) { | ||
if !dht.enableValues { | ||
return nil, routing.ErrNotSupported | ||
} | ||
|
||
var cfg routing.Options | ||
if err := cfg.Apply(opts...); err != nil { | ||
return nil, err | ||
|
@@ -250,8 +262,11 @@ func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...routing | |
|
||
// GetValues gets nvals values corresponding to the given key. | ||
func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []RecvdVal, err error) { | ||
eip := logger.EventBegin(ctx, "GetValues") | ||
if !dht.enableValues { | ||
return nil, routing.ErrNotSupported | ||
} | ||
|
||
eip := logger.EventBegin(ctx, "GetValues") | ||
eip.Append(loggableKey(key)) | ||
defer eip.Done() | ||
|
||
|
@@ -398,6 +413,9 @@ func (dht *IpfsDHT) getValues(ctx context.Context, key string, nvals int) (<-cha | |
|
||
// Provide makes this node announce that it can provide a value for the given key | ||
func (dht *IpfsDHT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error) { | ||
if !dht.enableProviders { | ||
return routing.ErrNotSupported | ||
} | ||
eip := logger.EventBegin(ctx, "Provide", key, logging.LoggableMap{"broadcast": brdcst}) | ||
defer func() { | ||
if err != nil { | ||
|
@@ -477,6 +495,9 @@ func (dht *IpfsDHT) makeProvRecord(skey cid.Cid) (*pb.Message, error) { | |
|
||
// FindProviders searches until the context expires. | ||
func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrInfo, error) { | ||
if !dht.enableProviders { | ||
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. same here. |
||
return nil, routing.ErrNotSupported | ||
} | ||
var providers []peer.AddrInfo | ||
for p := range dht.FindProvidersAsync(ctx, c, dht.bucketSize) { | ||
providers = append(providers, p) | ||
|
@@ -488,8 +509,13 @@ func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrIn | |
// Peers will be returned on the channel as soon as they are found, even before | ||
// the search query completes. | ||
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo { | ||
logger.Event(ctx, "findProviders", key) | ||
peerOut := make(chan peer.AddrInfo, count) | ||
if !dht.enableProviders { | ||
close(peerOut) | ||
return peerOut | ||
} | ||
|
||
logger.Event(ctx, "findProviders", key) | ||
|
||
go dht.findProvidersAsyncRoutine(ctx, key, count, peerOut) | ||
return peerOut | ||
|
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.
is this correct behaviour? We might know a peer that supports
GetValue
and so on.