Create a command to easily make network topology
Problem
Each time we want to create a new topology, we need to manually specify the connections by dialing each node (whether that is in command line or using scripts). This is time consuming and error prone which is not ideal.
Goal
Make an interface that allows the following:
- Specify the number of nodes and the connections
- Doesn't need to manually dial each node to connect them
- Doesn't need to make each node listen on its web server
Proposed solution
We use a connection matrix, which tells us which nodes are connected to which. We write a parser for this connection matrix that will connect each node in the matrix as specified. Such a matrix would look like that:
Node 0 | Node 1 | Node 2 | Node 3 | Node 4 | |
---|---|---|---|---|---|
Node 0 | X | 1 | 0 | 0 | 1 |
Node 1 | X | 1 | 0 | 0 | |
Node 2 | X | 1 | 0 | ||
Node 3 | SYM | X | 1 | ||
Node 4 | X |
The table is symmetrical. It would produce the following topology:
The actual matrix would be a vector of vector (without the node 0, node 1 annotation, since the index in the matrix represents the connection). The parser would take the matrix and perform the following steps:
-
app listen --node $SWARM.i.ip_port $SWARM.i.multiaddr
where i is between 0 and the number of nodes -1 (now written asN
) -
app dial
:- start reading the first vector between index 1 and N. If the number is 1 at index
j
, doapp dial --node $SWARM.0.ip_port $SWARM.j.multiaddr
- Start reading the second vector between index 2 and N, if the number at index
j
is 1, doapp dial --node $SWARM.1.ip_port $SWARM.j.multiaddr
Basically we read between the line number +1 and N dialing on nodeline number
to the node whose index isj
for all the lines of the matrix.
- start reading the first vector between index 1 and N. If the number is 1 at index
We start reading at line number + 1 because the matrix is symmetrical and we don't need to dial the nodes twice