aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/pss
diff options
context:
space:
mode:
authorlash <nolash@users.noreply.github.com>2019-03-23 04:37:25 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2019-03-23 04:37:25 +0800
commit2f5b6cb442dd1ab20279603de938e5b60e3122fb (patch)
tree1637681558132f2b1064e7d774b9ca63047f72a4 /swarm/pss
parent876f3573647f9a62d94073b342bc678f380f0304 (diff)
downloadgo-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar.gz
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar.bz2
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar.lz
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar.xz
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.tar.zst
go-tangerine-2f5b6cb442dd1ab20279603de938e5b60e3122fb.zip
swarm/network: Use different privatekey for bzz overlay in sim (#19313)
* cmd/swarm, p2p, swarm: Enable ENR in binary/execadapter * cmd/p2p/swarm: Remove comments + config.Enode nomarshal * p2p/simulations: Remove superfluous error check * p2p/simulation: Move init enode comment * swarm, p2p/simulations, cmd/swarm: Use nodekey in binary record sign * swarm/network, swarm/pss: Dervice bzzkey * swarm/pss: Remove unused function * swarm/network: Store swarm private key in simulation bucket * swarm/pss: Shorten TextProxNetwork shortrunning test timeout * swarm/pss: Increase prox test timeout * swarm/pss: Increase timeout slightly on shortrunning proxtest * swarm/network: Simplify bucket instantiation in servicectx func * p2p/simulations: Tcpport -> udpport * swarm/network, swarm/pss: Simplify + correct lock in servicefunc sim * swarm/network: Cleanup after rebase on extract swarm enode new * p2p/simulations, swarm/network: Make exec disc test pass * swarm/network: Prune ye olde comment * swarm/pss: Correct revised bzzkey method call * swarm/network: Clarify comment about privatekey generation data * swarm/pss: Fix syntax errors after rebase * swarm/network: Rename misleadingly named method (amend commit to trigger ci - attempt 5)
Diffstat (limited to 'swarm/pss')
-rw-r--r--swarm/pss/prox_test.go81
1 files changed, 57 insertions, 24 deletions
diff --git a/swarm/pss/prox_test.go b/swarm/pss/prox_test.go
index 0b60ec39a..bc32e612d 100644
--- a/swarm/pss/prox_test.go
+++ b/swarm/pss/prox_test.go
@@ -2,6 +2,7 @@ package pss
import (
"context"
+ "crypto/ecdsa"
"encoding/binary"
"errors"
"fmt"
@@ -88,7 +89,7 @@ func (d *testData) setDone() {
d.handlerDone = true
}
-func getCmdParams(t *testing.T) (int, int) {
+func getCmdParams(t *testing.T) (int, int, time.Duration) {
args := strings.Split(t.Name(), "/")
msgCount, err := strconv.ParseInt(args[2], 10, 16)
if err != nil {
@@ -98,7 +99,12 @@ func getCmdParams(t *testing.T) (int, int) {
if err != nil {
t.Fatal(err)
}
- return int(msgCount), int(nodeCount)
+ timeoutStr := fmt.Sprintf("%ss", args[3])
+ timeoutDur, err := time.ParseDuration(timeoutStr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return int(msgCount), int(nodeCount), timeoutDur
}
func newTestData() *testData {
@@ -117,11 +123,27 @@ func newTestData() *testData {
}
}
-func (d *testData) init(msgCount int) {
+func (d *testData) getKademlia(nodeId *enode.ID) (*network.Kademlia, error) {
+ kadif, ok := d.sim.NodeItem(*nodeId, simulation.BucketKeyKademlia)
+ if !ok {
+ return nil, fmt.Errorf("no kademlia entry for %v", nodeId)
+ }
+ kad, ok := kadif.(*network.Kademlia)
+ if !ok {
+ return nil, fmt.Errorf("invalid kademlia entry for %v", nodeId)
+ }
+ return kad, nil
+}
+
+func (d *testData) init(msgCount int) error {
log.Debug("TestProxNetwork start")
for _, nodeId := range d.sim.NodeIDs() {
- d.nodeAddrs[nodeId] = nodeIDToAddr(nodeId)
+ kad, err := d.getKademlia(&nodeId)
+ if err != nil {
+ return err
+ }
+ d.nodeAddrs[nodeId] = kad.BaseAddr()
}
for i := 0; i < int(msgCount); i++ {
@@ -169,6 +191,7 @@ func (d *testData) init(msgCount int) {
log.Debug("nn for msg", "targets", len(d.recipients[i]), "msgidx", i, "msg", common.Bytes2Hex(msgAddr[:8]), "sender", d.senders[i], "senderpo", smallestPo)
}
log.Debug("msgs to receive", "count", d.requiredMessages)
+ return nil
}
// Here we test specific functionality of the pss, setting the prox property of
@@ -190,7 +213,7 @@ func (d *testData) init(msgCount int) {
// nodes Y and Z will be considered required recipients of the msg,
// whereas nodes X, Y and Z will be allowed recipients.
func TestProxNetwork(t *testing.T) {
- t.Run("16/16", testProxNetwork)
+ t.Run("16/16/15", testProxNetwork)
}
// params in run name: nodes/msgs
@@ -198,29 +221,32 @@ func TestProxNetworkLong(t *testing.T) {
if !*longrunning {
t.Skip("run with --longrunning flag to run extensive network tests")
}
- t.Run("8/100", testProxNetwork)
- t.Run("16/100", testProxNetwork)
- t.Run("32/100", testProxNetwork)
- t.Run("64/100", testProxNetwork)
- t.Run("128/100", testProxNetwork)
+ t.Run("8/100/30", testProxNetwork)
+ t.Run("16/100/30", testProxNetwork)
+ t.Run("32/100/60", testProxNetwork)
+ t.Run("64/100/60", testProxNetwork)
+ t.Run("128/100/120", testProxNetwork)
}
func testProxNetwork(t *testing.T) {
tstdata := newTestData()
- msgCount, nodeCount := getCmdParams(t)
+ msgCount, nodeCount, timeout := getCmdParams(t)
handlerContextFuncs := make(map[Topic]handlerContextFunc)
handlerContextFuncs[topic] = nodeMsgHandler
services := newProxServices(tstdata, true, handlerContextFuncs, tstdata.kademlias)
tstdata.sim = simulation.New(services)
defer tstdata.sim.Close()
- ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
filename := fmt.Sprintf("testdata/snapshot_%d.json", nodeCount)
err := tstdata.sim.UploadSnapshot(ctx, filename)
if err != nil {
t.Fatal(err)
}
- tstdata.init(msgCount) // initialize the test data
+ err = tstdata.init(msgCount) // initialize the test data
+ if err != nil {
+ t.Fatal(err)
+ }
wrapper := func(c context.Context, _ *simulation.Simulation) error {
return testRoutine(tstdata, c)
}
@@ -230,7 +256,7 @@ func testProxNetwork(t *testing.T) {
// however, it might just mean that not all possible messages are received
// now we must check if all required messages are received
cnt := tstdata.getMsgCount()
- log.Debug("TestProxNetwork finnished", "rcv", cnt)
+ log.Debug("TestProxNetwork finished", "rcv", cnt)
if cnt < tstdata.requiredMessages {
t.Fatal(result.Error)
}
@@ -354,7 +380,7 @@ func nodeMsgHandler(tstdata *testData, config *adapters.NodeConfig) *handler {
// replaces pss_test.go when those tests are rewritten to the new swarm/network/simulation package
func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[Topic]handlerContextFunc, kademlias map[enode.ID]*network.Kademlia) map[string]simulation.ServiceFunc {
stateStore := state.NewInmemoryStore()
- kademlia := func(id enode.ID) *network.Kademlia {
+ kademlia := func(id enode.ID, bzzkey []byte) *network.Kademlia {
if k, ok := kademlias[id]; ok {
return k
}
@@ -364,17 +390,24 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T
params.MaxRetries = 1000
params.RetryExponent = 2
params.RetryInterval = 1000000
- kademlias[id] = network.NewKademlia(id[:], params)
+ kademlias[id] = network.NewKademlia(bzzkey, params)
return kademlias[id]
}
return map[string]simulation.ServiceFunc{
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
+ var err error
+ var bzzPrivateKey *ecdsa.PrivateKey
// normally translation of enode id to swarm address is concealed by the network package
// however, we need to keep track of it in the test driver as well.
// if the translation in the network package changes, that can cause these tests to unpredictably fail
// therefore we keep a local copy of the translation here
addr := network.NewAddr(ctx.Config.Node())
- addr.OAddr = nodeIDToAddr(ctx.Config.Node().ID())
+ bzzPrivateKey, err = simulation.BzzPrivateKeyFromConfig(ctx.Config)
+ if err != nil {
+ return nil, nil, err
+ }
+ addr.OAddr = network.PrivateKeyToBzzKey(bzzPrivateKey)
+ b.Store(simulation.BucketKeyBzzPrivateKey, bzzPrivateKey)
hp := network.NewHiveParams()
hp.Discovery = false
config := &network.BzzConfig{
@@ -382,7 +415,7 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T
UnderlayAddr: addr.Under(),
HiveParams: hp,
}
- return network.NewBzz(config, kademlia(ctx.Config.ID), stateStore, nil, nil), nil, nil
+ return network.NewBzz(config, kademlia(ctx.Config.ID, addr.OAddr), stateStore, nil, nil), nil, nil
},
"pss": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) {
// execadapter does not exec init()
@@ -395,7 +428,12 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T
privkey, err := w.GetPrivateKey(keys)
pssp := NewPssParams().WithPrivateKey(privkey)
pssp.AllowRaw = allowRaw
- pskad := kademlia(ctx.Config.ID)
+ bzzPrivateKey, err := simulation.BzzPrivateKeyFromConfig(ctx.Config)
+ if err != nil {
+ return nil, nil, err
+ }
+ bzzKey := network.PrivateKeyToBzzKey(bzzPrivateKey)
+ pskad := kademlia(ctx.Config.ID, bzzKey)
ps, err := NewPss(pskad, pssp)
if err != nil {
return nil, nil, err
@@ -433,8 +471,3 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T
},
}
}
-
-// makes sure we create the addresses the same way in driver and service setup
-func nodeIDToAddr(id enode.ID) []byte {
- return id.Bytes()
-}