mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/pss: style fix
This commit is contained in:
parent
b86a8ac367
commit
144e477190
1 changed files with 25 additions and 20 deletions
|
|
@ -123,18 +123,24 @@ func readSnapshot(t *testing.T, nodeCount int) simulations.Snapshot {
|
||||||
return snap
|
return snap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newTestData() *testData {
|
||||||
|
return &testData{
|
||||||
|
kademlias: make(map[enode.ID]*network.Kademlia),
|
||||||
|
nodeAddrs: make(map[enode.ID][]byte),
|
||||||
|
recipients: make(map[int][]enode.ID),
|
||||||
|
allowed: make(map[int][]enode.ID),
|
||||||
|
expectedMsgs: make(map[enode.ID][]uint64),
|
||||||
|
allowedMsgs: make(map[enode.ID][]uint64),
|
||||||
|
senders: make(map[int]enode.ID),
|
||||||
|
handlerC: make(chan handlerNotification),
|
||||||
|
doneC: make(chan struct{}),
|
||||||
|
errC: make(chan error),
|
||||||
|
msgC: make(chan handlerNotification),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *testData) init(msgCount int) {
|
func (d *testData) init(msgCount int) {
|
||||||
log.Debug("TestProxNetwork start")
|
log.Debug("TestProxNetwork start")
|
||||||
d.nodeAddrs = make(map[enode.ID][]byte)
|
|
||||||
d.recipients = make(map[int][]enode.ID)
|
|
||||||
d.allowed = make(map[int][]enode.ID)
|
|
||||||
d.expectedMsgs = make(map[enode.ID][]uint64)
|
|
||||||
d.allowedMsgs = make(map[enode.ID][]uint64)
|
|
||||||
d.senders = make(map[int]enode.ID)
|
|
||||||
d.handlerC = make(chan handlerNotification)
|
|
||||||
d.doneC = make(chan struct{})
|
|
||||||
d.errC = make(chan error)
|
|
||||||
d.msgC = make(chan handlerNotification)
|
|
||||||
|
|
||||||
for _, nodeId := range d.sim.NodeIDs() {
|
for _, nodeId := range d.sim.NodeIDs() {
|
||||||
d.nodeAddrs[nodeId] = nodeIDToAddr(nodeId)
|
d.nodeAddrs[nodeId] = nodeIDToAddr(nodeId)
|
||||||
|
|
@ -189,14 +195,14 @@ func (d *testData) init(msgCount int) {
|
||||||
|
|
||||||
// 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
|
||||||
// the handler. The tests generate a number of messages with random addresses.
|
// the handler. The tests generate a number of messages with random addresses.
|
||||||
// Then, for each message it calculates which nodes in the network the msg address
|
// Then, for each message it calculates which nodes have the msg address
|
||||||
// within its nearest neighborhood depth, and stores those nodes as possible
|
// within its nearest neighborhood depth, and stores those nodes as possible
|
||||||
// recipients. Those nodes that are the closest to the message address (nodes
|
// recipients. Those nodes that are the closest to the message address (nodes
|
||||||
// belonging to the deepest PO wrt the msg address) are stored as required
|
// belonging to the deepest PO wrt the msg address) are stored as required
|
||||||
// recipients. The difference between allowed and required recipients results
|
// recipients. The difference between allowed and required recipients results
|
||||||
// from the fact that the nearest neighbours are not necessarily reciprocal.
|
// from the fact that the nearest neighbours are not necessarily reciprocal.
|
||||||
// Upon sending the messages, the test verifies that the respective message is
|
// Upon sending the messages, the test verifies that the respective message is
|
||||||
// passed to the message handlers of these required recipients. Test will fail
|
// passed to the message handlers of these required recipients. The test fails
|
||||||
// if a message is handled by recipient which is not listed among the allowed
|
// if a message is handled by recipient which is not listed among the allowed
|
||||||
// recipients of this particular message. It also fails after timeout, if not
|
// recipients of this particular message. It also fails after timeout, if not
|
||||||
// all the required recipients have received their respective messages.
|
// all the required recipients have received their respective messages.
|
||||||
|
|
@ -222,12 +228,11 @@ func TestProxNetworkLong(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testProxNetwork(t *testing.T) {
|
func testProxNetwork(t *testing.T) {
|
||||||
var tstdata testData
|
tstdata := newTestData()
|
||||||
msgCount, nodeCount := getCmdParams(t)
|
msgCount, nodeCount := getCmdParams(t)
|
||||||
handlerContextFuncs := make(map[Topic]handlerContextFunc)
|
handlerContextFuncs := make(map[Topic]handlerContextFunc)
|
||||||
handlerContextFuncs[topic] = nodeMsgHandler
|
handlerContextFuncs[topic] = nodeMsgHandler
|
||||||
tstdata.kademlias = make(map[enode.ID]*network.Kademlia)
|
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()
|
||||||
err := tstdata.sim.UploadSnapshot(fmt.Sprintf("testdata/snapshot_%d.json", nodeCount))
|
err := tstdata.sim.UploadSnapshot(fmt.Sprintf("testdata/snapshot_%d.json", nodeCount))
|
||||||
|
|
@ -243,7 +248,7 @@ func testProxNetwork(t *testing.T) {
|
||||||
}
|
}
|
||||||
tstdata.init(msgCount) // initialize the test data
|
tstdata.init(msgCount) // initialize the test data
|
||||||
wrapper := func(c context.Context, _ *simulation.Simulation) error {
|
wrapper := func(c context.Context, _ *simulation.Simulation) error {
|
||||||
return runFunc(&tstdata, c)
|
return testRoutine(tstdata, c)
|
||||||
}
|
}
|
||||||
result := tstdata.sim.Run(ctx, wrapper) // call the main test function
|
result := tstdata.sim.Run(ctx, wrapper) // call the main test function
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
|
@ -259,7 +264,7 @@ func testProxNetwork(t *testing.T) {
|
||||||
t.Logf("completed %d", result.Duration)
|
t.Logf("completed %d", result.Duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendAllMsgs(tstdata *testData) {
|
func (tstdata *testData) sendAllMsgs() {
|
||||||
for i, msg := range tstdata.msgs {
|
for i, msg := range tstdata.msgs {
|
||||||
log.Debug("sending msg", "idx", i, "from", tstdata.senders[i])
|
log.Debug("sending msg", "idx", i, "from", tstdata.senders[i])
|
||||||
nodeClient, err := tstdata.sim.Net.GetNode(tstdata.senders[i]).Client()
|
nodeClient, err := tstdata.sim.Net.GetNode(tstdata.senders[i]).Client()
|
||||||
|
|
@ -273,10 +278,10 @@ func sendAllMsgs(tstdata *testData) {
|
||||||
log.Debug("all messages sent")
|
log.Debug("all messages sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
// runFunc is the main test function, called by Simulation.Run()
|
// testRoutine is the main test function, called by Simulation.Run()
|
||||||
func runFunc(tstdata *testData, ctx context.Context) error {
|
func testRoutine(tstdata *testData, ctx context.Context) error {
|
||||||
go handlerChannelListener(tstdata, ctx)
|
go handlerChannelListener(tstdata, ctx)
|
||||||
go sendAllMsgs(tstdata)
|
go tstdata.sendAllMsgs()
|
||||||
received := 0
|
received := 0
|
||||||
|
|
||||||
// collect incoming messages and terminate with corresponding status when message handler listener ends
|
// collect incoming messages and terminate with corresponding status when message handler listener ends
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue