Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9680c4a
network: Cherrypick changes to kademlia for capabilities db
nolash Aug 30, 2019
b832695
network: WIP rehabilitate tests
nolash Aug 30, 2019
336efda
network, pss: Add capabilities to discovery message (WIP)
nolash Sep 2, 2019
1266df6
network: Add capabilities array to discovery messages tests
nolash Sep 3, 2019
e355d4c
network: Clean up code and enforce constructors for BzzAddr
nolash Sep 3, 2019
b30b40d
network, pot, pss: Rename RandomAddr to explicit RandomBzzAddr
nolash Sep 4, 2019
7f85493
network: Custom deserialize in BzzAddr for Capabilities
nolash Sep 8, 2019
152ec4c
network: Add serialization tests
nolash Sep 8, 2019
6de5a42
network: Temporary workaround for contingent list in BzzAddr deserialize
nolash Sep 9, 2019
633583e
network: BzzAddr deserialize fail on empty object
nolash Sep 10, 2019
a74293a
network, cmd: WIP debugging
nolash Sep 11, 2019
0dd7aab
network: Add deserialize in peersMsg to elimiate list error
nolash Sep 11, 2019
a9ef8fd
network: Re-instate serialize capabilites to bytes in BzzAddr
nolash Sep 11, 2019
31b500e
pot: Revert inadvertent rename of RandomAddress*
nolash Sep 11, 2019
d486f48
pot: Remove wrong rename for random address gen in pot test
nolash Sep 12, 2019
6af8d12
network: Remove comments, reinstate skipped hive test
nolash Sep 12, 2019
5e228bf
network: Add test for kademlia capability indices
nolash Sep 13, 2019
a94933b
network: Add test for connections capabilities index filtering
nolash Sep 13, 2019
f6be3f3
network: Add comments to capabilities index test
nolash Sep 13, 2019
a85f9e8
newtork: Add comments, stub for capabilities index removal
nolash Sep 13, 2019
42763dd
network: Complete remove from index method and corresponding test
nolash Sep 13, 2019
b09418a
network: Split up capability indices test
nolash Sep 16, 2019
07f4d86
network, pss: Implement capabilities in pss
nolash Sep 17, 2019
904b8c0
network: Rebase cleanup
nolash Sep 19, 2019
9705770
network: Revert regression of comment
nolash Sep 19, 2019
544c1a2
Re-trigger ci (unrelated stream test fail)
nolash Sep 19, 2019
6363f2c
network, pss: Use constants for capability IDs
nolash Sep 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion network/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
Expand Down
7 changes: 6 additions & 1 deletion network/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -81,6 +82,7 @@ func NewKadParams() *KadParams {
RetryInterval: 4200000000, // 4.2 sec
MaxRetries: 42,
RetryExponent: 2,
Capabilities: capability.NewCapabilities(),
}
}

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions network/networkid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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++
Expand Down
23 changes: 16 additions & 7 deletions network/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

var (
CapabilityID = capability.CapabilityID(0)
capabilitiesRetrieve = 0
capabilitiesPush = 1
capabilitiesRelayRetrieve = 4
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pss/pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Comment thread
nolash marked this conversation as resolved.
AllowForward bool
}

// Sane defaults for Pss
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down