diff --git a/network/discovery_test.go b/network/discovery_test.go index 6e191aa56b..0bfa94b71b 100644 --- a/network/discovery_test.go +++ b/network/discovery_test.go @@ -236,7 +236,6 @@ func testSortPeers(peers []*BzzAddr) []*BzzAddr { // we need to create the discovery peer objects for the additional kademlia // nodes manually func newDiscPeer(addr pot.Address) *Peer { - // deterministically create enode id // Input to the non-random input buffer is 2xaddress since it munches 256 bits addrSeed := append(addr.Bytes(), addr.Bytes()...) diff --git a/network/kademlia.go b/network/kademlia.go index d16eac967a..72d67afc1d 100644 --- a/network/kademlia.go +++ b/network/kademlia.go @@ -68,7 +68,8 @@ type KadParams struct { RetryExponent int // exponent to multiply retry intervals with MaxRetries int // maximum number of redial attempts // function to sanction or prevent suggesting a peer - Reachable func(*BzzAddr) bool `json:"-"` + Reachable func(*BzzAddr) bool `json:"-"` + Capabilities *capability.Capabilities `json:"-"` } // NewKadParams returns a params struct with default values @@ -81,6 +82,7 @@ func NewKadParams() *KadParams { RetryInterval: 4200000000, // 4.2 sec MaxRetries: 42, RetryExponent: 2, + Capabilities: capability.NewCapabilities(), } } @@ -114,6 +116,9 @@ func NewKademlia(addr []byte, params *KadParams) *Kademlia { if params == nil { params = NewKadParams() } + if params.Capabilities == nil { + params.Capabilities = capability.NewCapabilities() + } k := &Kademlia{ base: addr, KadParams: params, diff --git a/network/networkid_test.go b/network/networkid_test.go index 95ace13f5d..614092f634 100644 --- a/network/networkid_test.go +++ b/network/networkid_test.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/p2p/simulations" "github.com/ethereum/go-ethereum/p2p/simulations/adapters" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethersphere/swarm/network/capability" "github.com/ethersphere/swarm/testutil" ) @@ -199,7 +198,7 @@ func newServices() adapters.Services { } return adapters.Services{ "bzz": func(ctx *adapters.ServiceContext) (node.Service, error) { - addr := NewBzzAddrFromEnode(ctx.Config.Node()).WithCapabilities(capability.NewCapabilities()) + addr := NewBzzAddrFromEnode(ctx.Config.Node()) hp := NewHiveParams() hp.Discovery = false cnt++ diff --git a/network/protocol.go b/network/protocol.go index 6721c6249f..863e843f1c 100644 --- a/network/protocol.go +++ b/network/protocol.go @@ -34,6 +34,7 @@ import ( ) var ( + CapabilityID = capability.CapabilityID(0) capabilitiesRetrieve = 0 capabilitiesPush = 1 capabilitiesRelayRetrieve = 4 @@ -82,7 +83,7 @@ func init() { // temporary convenience functions for legacy "LightNode" func newLightCapability() *capability.Capability { - c := capability.NewCapability(0, 16) + c := capability.NewCapability(CapabilityID, 16) c.Set(capabilitiesRetrieve) c.Set(capabilitiesPush) return c @@ -93,7 +94,7 @@ func isLightCapability(c *capability.Capability) bool { // temporary convenience functions for legacy "full node" func newFullCapability() *capability.Capability { - c := capability.NewCapability(0, 16) + c := capability.NewCapability(CapabilityID, 16) c.Set(capabilitiesRetrieve) c.Set(capabilitiesPush) c.Set(capabilitiesRelayRetrieve) @@ -153,6 +154,7 @@ func NewBzz(config *BzzConfig, kad *Kademlia, store state.Store, streamerSpec, r bzz.retrievalSpec = nil } + bzz.localAddr.Capabilities = kad.Capabilities // temporary soon-to-be-legacy light/full, as above if config.LightNode { bzz.localAddr.Capabilities.Add(newLightCapability()) @@ -229,11 +231,18 @@ func (b *Bzz) Protocols() []p2p.Protocol { // * hive // Bzz implements the node.Service interface func (b *Bzz) APIs() []rpc.API { - return []rpc.API{{ - Namespace: "hive", - Version: "3.0", - Service: b.Hive, - }} + return []rpc.API{ + { + Namespace: "hive", + Version: "3.0", + Service: b.Hive, + }, + { + Namespace: "bzz", + Version: "4.0", + Service: capability.NewAPI(b.Kademlia.Capabilities), + }, + } } // RunProtocol is a wrapper for swarm subprotocols diff --git a/pss/pss.go b/pss/pss.go index a895be495d..4c53389ebc 100644 --- a/pss/pss.go +++ b/pss/pss.go @@ -33,6 +33,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethersphere/swarm/log" "github.com/ethersphere/swarm/network" + "github.com/ethersphere/swarm/network/capability" "github.com/ethersphere/swarm/p2p/protocols" "github.com/ethersphere/swarm/pot" "github.com/ethersphere/swarm/pss/crypto" @@ -51,6 +52,12 @@ const ( defaultOutboxCapacity = 100000 protocolName = "pss" protocolVersion = 2 + CapabilityID = capability.CapabilityID(1) + capabilitiesSend = 0 // node sends pss messages + capabilitiesReceive = 1 // node processes pss messages + capabilitiesForward = 4 // node forwards pss messages on behalf of network + capabilitiesPartial = 5 // node accepts partially addressed messages + capabilitiesEmpty = 6 // node accepts messages with empty address ) var ( @@ -89,6 +96,7 @@ type Params struct { privateKey *ecdsa.PrivateKey SymKeyCacheCapacity int AllowRaw bool // If true, enables sending and receiving messages without builtin pss encryption + AllowForward bool } // Sane defaults for Pss @@ -265,6 +273,16 @@ func New(k *network.Kademlia, params *Params) (*Pss, error) { }) ps.outbox = newOutbox(defaultOutboxCapacity, ps.quitC, ps.forward) + cp := capability.NewCapability(CapabilityID, 8) + cp.Set(capabilitiesSend) + cp.Set(capabilitiesReceive) + cp.Set(capabilitiesPartial) + cp.Set(capabilitiesEmpty) + if params.AllowForward { + cp.Set(capabilitiesForward) + } + k.Capabilities.Add(cp) + return ps, nil } diff --git a/swarm.go b/swarm.go index ebc29aab0d..4a9164c4d5 100644 --- a/swarm.go +++ b/swarm.go @@ -519,14 +519,14 @@ func (s *Swarm) APIs() []rpc.API { // public APIs { Namespace: "bzz", - Version: "3.0", + Version: "4.0", Service: &Info{s.config}, Public: true, }, // admin APIs { Namespace: "bzz", - Version: "3.0", + Version: "4.0", Service: api.NewInspector(s.api, s.bzz.Hive, s.netStore, s.streamer), Public: false, },