You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#wait for messages containing total messages used during the protocol.
62
+
init.wait_for_number_of_messages()
63
+
```
64
+
65
+
## Client
66
+
Here's an example client.py file. In this case, we want to create a node running the **Shout** protocol, which is alredy implemented in the **Protocols** package. Alternatively, you can define your custom protocol directly in the client.py file for convenience.
67
+
68
+
```python
69
+
import sys
70
+
from Nodes.Nodes.Node import Node
71
+
from Nodes.Protocols.Shout import Shout
72
+
iflen(sys.argv) !=4:
73
+
raiseValueError('Please provide HOST, initializer PORT and local PORT NUMBER.')
This is a possibile implementation of the Shout protocol, used to create a spanning tree in a undirected graph in a distributed way. As you can see, it is similar to pseudo-code.
85
+
To create your custom protocol, always override these 3 methods:
86
+
87
+
-```setup()```: setup procedure that each node executes at the beginning of the protocol. It is usefull to initialize variables or start parallel threads (see example5);
88
+
89
+
-```handle_message()```: this method should be the core of the protocol. You have to specify for each possibile combination of state and message what the node should do. Remember that you can find some useful tokens in the ```Nodes.const``` package to avoid typos in strings.
90
+
When the node has locally terminated the computation, just return ```True```.
91
+
92
+
-```cleanup()```: you can optionally override this method to send extra information or log variables at the end of the protocol. In this case, we send the total number of messages sent by the node during the computation.
0 commit comments