|
|
@ -2,6 +2,7 @@ package pss |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
|
|
|
|
"crypto/ecdsa" |
|
|
|
"encoding/binary" |
|
|
|
"encoding/binary" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
@ -88,7 +89,7 @@ func (d *testData) setDone() { |
|
|
|
d.handlerDone = true |
|
|
|
d.handlerDone = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getCmdParams(t *testing.T) (int, int) { |
|
|
|
func getCmdParams(t *testing.T) (int, int, time.Duration) { |
|
|
|
args := strings.Split(t.Name(), "/") |
|
|
|
args := strings.Split(t.Name(), "/") |
|
|
|
msgCount, err := strconv.ParseInt(args[2], 10, 16) |
|
|
|
msgCount, err := strconv.ParseInt(args[2], 10, 16) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -98,7 +99,12 @@ func getCmdParams(t *testing.T) (int, int) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
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 { |
|
|
|
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") |
|
|
|
log.Debug("TestProxNetwork start") |
|
|
|
|
|
|
|
|
|
|
|
for _, nodeId := range d.sim.NodeIDs() { |
|
|
|
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++ { |
|
|
|
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("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) |
|
|
|
log.Debug("msgs to receive", "count", d.requiredMessages) |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Here we test specific functionality of the pss, setting the prox property of
|
|
|
|
// 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,
|
|
|
|
// nodes Y and Z will be considered required recipients of the msg,
|
|
|
|
// whereas nodes X, Y and Z will be allowed recipients.
|
|
|
|
// whereas nodes X, Y and Z will be allowed recipients.
|
|
|
|
func TestProxNetwork(t *testing.T) { |
|
|
|
func TestProxNetwork(t *testing.T) { |
|
|
|
t.Run("16/16", testProxNetwork) |
|
|
|
t.Run("16/16/15", testProxNetwork) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// params in run name: nodes/msgs
|
|
|
|
// params in run name: nodes/msgs
|
|
|
@ -198,29 +221,32 @@ func TestProxNetworkLong(t *testing.T) { |
|
|
|
if !*longrunning { |
|
|
|
if !*longrunning { |
|
|
|
t.Skip("run with --longrunning flag to run extensive network tests") |
|
|
|
t.Skip("run with --longrunning flag to run extensive network tests") |
|
|
|
} |
|
|
|
} |
|
|
|
t.Run("8/100", testProxNetwork) |
|
|
|
t.Run("8/100/30", testProxNetwork) |
|
|
|
t.Run("16/100", testProxNetwork) |
|
|
|
t.Run("16/100/30", testProxNetwork) |
|
|
|
t.Run("32/100", testProxNetwork) |
|
|
|
t.Run("32/100/60", testProxNetwork) |
|
|
|
t.Run("64/100", testProxNetwork) |
|
|
|
t.Run("64/100/60", testProxNetwork) |
|
|
|
t.Run("128/100", testProxNetwork) |
|
|
|
t.Run("128/100/120", testProxNetwork) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testProxNetwork(t *testing.T) { |
|
|
|
func testProxNetwork(t *testing.T) { |
|
|
|
tstdata := newTestData() |
|
|
|
tstdata := newTestData() |
|
|
|
msgCount, nodeCount := getCmdParams(t) |
|
|
|
msgCount, nodeCount, timeout := getCmdParams(t) |
|
|
|
handlerContextFuncs := make(map[Topic]handlerContextFunc) |
|
|
|
handlerContextFuncs := make(map[Topic]handlerContextFunc) |
|
|
|
handlerContextFuncs[topic] = nodeMsgHandler |
|
|
|
handlerContextFuncs[topic] = nodeMsgHandler |
|
|
|
services := newProxServices(tstdata, true, handlerContextFuncs, tstdata.kademlias) |
|
|
|
services := newProxServices(tstdata, true, handlerContextFuncs, tstdata.kademlias) |
|
|
|
tstdata.sim = simulation.New(services) |
|
|
|
tstdata.sim = simulation.New(services) |
|
|
|
defer tstdata.sim.Close() |
|
|
|
defer tstdata.sim.Close() |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second) |
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout) |
|
|
|
defer cancel() |
|
|
|
defer cancel() |
|
|
|
filename := fmt.Sprintf("testdata/snapshot_%d.json", nodeCount) |
|
|
|
filename := fmt.Sprintf("testdata/snapshot_%d.json", nodeCount) |
|
|
|
err := tstdata.sim.UploadSnapshot(ctx, filename) |
|
|
|
err := tstdata.sim.UploadSnapshot(ctx, filename) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
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 { |
|
|
|
wrapper := func(c context.Context, _ *simulation.Simulation) error { |
|
|
|
return testRoutine(tstdata, c) |
|
|
|
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
|
|
|
|
// however, it might just mean that not all possible messages are received
|
|
|
|
// now we must check if all required messages are received
|
|
|
|
// now we must check if all required messages are received
|
|
|
|
cnt := tstdata.getMsgCount() |
|
|
|
cnt := tstdata.getMsgCount() |
|
|
|
log.Debug("TestProxNetwork finnished", "rcv", cnt) |
|
|
|
log.Debug("TestProxNetwork finished", "rcv", cnt) |
|
|
|
if cnt < tstdata.requiredMessages { |
|
|
|
if cnt < tstdata.requiredMessages { |
|
|
|
t.Fatal(result.Error) |
|
|
|
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
|
|
|
|
// 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 { |
|
|
|
func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[Topic]handlerContextFunc, kademlias map[enode.ID]*network.Kademlia) map[string]simulation.ServiceFunc { |
|
|
|
stateStore := state.NewInmemoryStore() |
|
|
|
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 { |
|
|
|
if k, ok := kademlias[id]; ok { |
|
|
|
return k |
|
|
|
return k |
|
|
|
} |
|
|
|
} |
|
|
@ -364,17 +390,24 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T |
|
|
|
params.MaxRetries = 1000 |
|
|
|
params.MaxRetries = 1000 |
|
|
|
params.RetryExponent = 2 |
|
|
|
params.RetryExponent = 2 |
|
|
|
params.RetryInterval = 1000000 |
|
|
|
params.RetryInterval = 1000000 |
|
|
|
kademlias[id] = network.NewKademlia(id[:], params) |
|
|
|
kademlias[id] = network.NewKademlia(bzzkey, params) |
|
|
|
return kademlias[id] |
|
|
|
return kademlias[id] |
|
|
|
} |
|
|
|
} |
|
|
|
return map[string]simulation.ServiceFunc{ |
|
|
|
return map[string]simulation.ServiceFunc{ |
|
|
|
"bzz": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) { |
|
|
|
"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
|
|
|
|
// 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.
|
|
|
|
// 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
|
|
|
|
// 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
|
|
|
|
// therefore we keep a local copy of the translation here
|
|
|
|
addr := network.NewAddr(ctx.Config.Node()) |
|
|
|
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 := network.NewHiveParams() |
|
|
|
hp.Discovery = false |
|
|
|
hp.Discovery = false |
|
|
|
config := &network.BzzConfig{ |
|
|
|
config := &network.BzzConfig{ |
|
|
@ -382,7 +415,7 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T |
|
|
|
UnderlayAddr: addr.Under(), |
|
|
|
UnderlayAddr: addr.Under(), |
|
|
|
HiveParams: hp, |
|
|
|
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) { |
|
|
|
"pss": func(ctx *adapters.ServiceContext, b *sync.Map) (node.Service, func(), error) { |
|
|
|
// execadapter does not exec init()
|
|
|
|
// execadapter does not exec init()
|
|
|
@ -395,7 +428,12 @@ func newProxServices(tstdata *testData, allowRaw bool, handlerContextFuncs map[T |
|
|
|
privkey, err := w.GetPrivateKey(keys) |
|
|
|
privkey, err := w.GetPrivateKey(keys) |
|
|
|
pssp := NewPssParams().WithPrivateKey(privkey) |
|
|
|
pssp := NewPssParams().WithPrivateKey(privkey) |
|
|
|
pssp.AllowRaw = allowRaw |
|
|
|
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) |
|
|
|
ps, err := NewPss(pskad, pssp) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, nil, err |
|
|
|
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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|