plugeth/p2p/simulations/examples
Felix Lange dcae0d348b
p2p/simulations: fix a deadlock and clean up adapters (#17891)
This fixes a rare deadlock with the inproc adapter:

- A node is stopped, which acquires Network.lock.
- The protocol code being simulated (swarm/network in my case)
  waits for its goroutines to shut down.
- One of those goroutines calls into the simulation to add a peer,
  which waits for Network.lock.

The fix for the deadlock is really simple, just release the lock
before stopping the simulation node.

Other changes in this PR clean up the exec adapter so it reports
node startup errors better and remove the docker adapter because
it just adds overhead.

In the exec adapter, node information is now posted to a one-shot
server. This avoids log parsing and allows reporting startup
errors to the simulation host.

A small change in package node was needed because simulation
nodes use port zero. Node.{HTTP,WS}Endpoint now return the live
endpoints after startup by checking the TCP listener.
2018-10-11 20:32:14 +02:00
..
ping-pong.go p2p/simulations: fix a deadlock and clean up adapters (#17891) 2018-10-11 20:32:14 +02:00
ping-pong.sh p2p: add network simulation framework (#14982) 2017-09-25 10:08:07 +02:00
README.md p2p: add network simulation framework (#14982) 2017-09-25 10:08:07 +02:00

devp2p simulation examples

ping-pong

ping-pong.go implements a simulation network which contains nodes running a simple "ping-pong" protocol where nodes send a ping message to all their connected peers every 10s and receive pong messages in return.

To run the simulation, run go run ping-pong.go in one terminal to start the simulation API and ./ping-pong.sh in another to start and connect the nodes:

$ go run ping-pong.go
INFO [08-15|13:53:49] using sim adapter
INFO [08-15|13:53:49] starting simulation server on 0.0.0.0:8888...
$ ./ping-pong.sh
---> 13:58:12 creating 10 nodes
Created node01
Started node01
...
Created node10
Started node10
---> 13:58:13 connecting node01 to all other nodes
Connected node01 to node02
...
Connected node01 to node10
---> 13:58:14 done

Use the --adapter flag to choose the adapter type:

$ go run ping-pong.go --adapter exec
INFO [08-15|14:01:14] using exec adapter                       tmpdir=/var/folders/k6/wpsgfg4n23ddbc6f5cnw5qg00000gn/T/p2p-example992833779
INFO [08-15|14:01:14] starting simulation server on 0.0.0.0:8888...