Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

network: Add API for Capabilities #1675

Merged
merged 6 commits into from
Aug 30, 2019

Conversation

nolash
Copy link
Contributor

@nolash nolash commented Aug 16, 2019

This PR follows the initial introduction of Capabilities in the network package generally and the Bzz object in particular. It implements some of the API methods outlined in the Adaptive Capabilities SWIP

  • RegisterCapability
  • IsRegisteredCapability
  • MatchCapability

c := a.get(id)
if c == nil {
return false, fmt.Errorf("Capability %d not registered", id)
} else if idx > len(c.Cap)-1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else, as the previous if block is returning always.

@@ -0,0 +1,45 @@
package network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about creating a package for capabilities, then we could get rid of all these long names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so merge this then I move it to separate package please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this such a big overhead to do now @nolash? we're talking 102 lines delta....

Copy link
Member

@acud acud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nolash i think some renaming is in need and I think @zelig's request to move to another pkg is reasonable at this stage. not sure why it is necessary to daisy chain every tiny chain with a PR

@@ -0,0 +1,45 @@
package network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this such a big overhead to do now @nolash? we're talking 102 lines delta....

// RegisterCapability adds the given capability object to the Capabilities collection
// If the Capability is already registered an error will be returned
func (a *CapabilitiesAPI) RegisterCapability(cp *Capability) error {
log.Debug("Registering capability", "cp", cp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace

}

// IsRegisteredCapability returns true if a Capability with the given id is registered
func (a *CapabilitiesAPI) IsRegisteredCapability(id CapabilityID) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just Has?

Copy link
Contributor Author

@nolash nolash Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember this is in the namespace of bzz from the perspective of RPC callers. Wouldn't it make sense to have the names explicity to avoid potential ambiguity?


// MatchCapability returns true if the Capability flag at the given index is set
// Fails with error if the Capability is not registered, or if the index is out of bounds
func (a *CapabilitiesAPI) MatchCapability(id CapabilityID, idx int) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Match?

@nolash
Copy link
Contributor Author

nolash commented Aug 26, 2019

@zelig @acud I have second thoughts about the separate package approach. I understand the reason is to keep method names short. But the idea here was to expose this API under the bzz namespace. Not having Capabilities in the API method names could make the RPC ambiguous and more difficult to reason about.

Would there be other reasons to keep it in a separate package?

@zelig
Copy link
Member

zelig commented Aug 27, 2019

@zelig @acud I have second thoughts about the separate package approach. I understand the reason is to keep method names short. But the idea here was to expose this API under the bzz namespace. Not having Capabilities in the API method names could make the RPC ambiguous and more difficult to reason about.

Would there be other reasons to keep it in a separate package?

why not have its own RPC namespace too?

@nolash
Copy link
Contributor Author

nolash commented Aug 28, 2019

To me it seems to belong with bzz. The kademlia/hive is where the capabilities are handled and exchanged.

@acud
Copy link
Member

acud commented Aug 29, 2019

@nolash separating capabilities into a separate package to me is orthogonal of its API namespace. You can still have an exported API type from the package and just hook it up to the API as we do with every other RPC API in Swarm. To me it seems like a compact and isolated enough piece of code that can be isolated into its own package

@nolash nolash merged commit dec28cd into ethersphere:master Aug 30, 2019
@nolash nolash deleted the adaptive-capabilities-api-cherries branch August 30, 2019 10:49
@skylenet skylenet added this to the 0.5.0 milestone Sep 17, 2019
chadsr added a commit to chadsr/swarm that referenced this pull request Sep 23, 2019
* 'master' of github.com:ethersphere/swarm:
  pss: Modularize crypto and remove Whisper. Step 1 - isolate whisper code (ethersphere#1698)
  pss: Improve pressure backstop queue handling - no mutex (ethersphere#1695)
  cmd/swarm-snapshot: if 2 nodes to create snapshot use connectChain (ethersphere#1709)
  network: Add API for Capabilities (ethersphere#1675)
  pss: fixed flaky test that was using a global variable instead of a local one (ethersphere#1702)
  pss: Port tests to `network/simulation` (ethersphere#1682)
  storage: fix hasherstore seen check to happen when error is nil (ethersphere#1700)
  vendor: upgrade go-ethereum to 1.9.2 (ethersphere#1689)
  bzzeth: initial support for bzz-eth protocol (ethersphere#1571)
  network/stream: terminate runUpdateSyncing on peer quit (ethersphere#1696)
  all: first working SWAP version (ethersphere#1554)
  version: update to v0.5.0 unstable (ethersphere#1694)
  chunk, storage: storage with multi chunk Set method (ethersphere#1684)
  chunk, storage: add HasMulti to chunk.Store (ethersphere#1686)
  chunk, shed, storage: chunk.Store GetMulti method (ethersphere#1691)
  api, chunk: progress bar support (ethersphere#1649)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants