A gossip-based swarm communication library
Project description
SwarmNet
A robust communications library for robot swarms. This is based on gossip protocols where the message will propagate around the swarm. When an agent receives a message it has not seen before, it will broadcast it to all other members of the swarm.
Usage
A SwarmNet
object must be created that handles all of the communication. Only one instance should be created. To start the communication framework, the start()
method must be run.
All devices must use the same port number
This start()
command will broadcast a JOIN command to register with the rest of the swarm.
Message Parsers
Parsers are defined to handle incoming messages of specific types, for example, you may want to send COUNT 1
to increase a distributed counter by 1 when the COUNT
command is received. This would be defined as follows.
counter = 0
def count_recv(msg: Optional[str]) -> None:
counter += int(msg)
sn = SwarmNet({"COUNT": count_recv})
sn.start()
while(True):
pass
sn.kill()
It is important to remember that the parser functions are called from a different thread. Special care should be taken to ensure data integrity and consistency across threads.
The type of each parser is Optional[str] -> None
where the string is a string of any fields in the message. For example, if the message is CMD field1 field2
, the string will be "field1 field2
.
If a message is received with a command token for which there is no parser, an error message is produced with a list of recognised command tokens. To prevent error spam in more complex systems, you can set certain commands to be ignored by defining the parser as None
. For example, if the above code was deployed in a swarm that also had DEBUG
messages that were only important to one specific node, you could ignore them using None
.
counter = 0
def count_recv(msg: Optional[str]) -> None:
counter += int(msg)
sn = SwarmNet({"COUNT": count_recv, "DEBUG": None})
sn.start()
while(True):
pass
sn.kill()
Message Format
All messages follow the format: <CMD> <DATA1> <DATA2> ...
A dictionary that maps command tokens to functions is passed to the SwarmNet
constructor. The signature of this map is Dict[str, Optional[Callable[[Optional[str]], None]]]
where the str
passed to the parser function is the rest of the message string (if any)
Internally, every message is prefixed with an identifier that is not overwritten when the message is forwarded by receivers. This means agents will not parse their own message or parse the same message more than once.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file swarmnet-0.0.8.tar.gz
.
File metadata
- Download URL: swarmnet-0.0.8.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83729c838aa13b4dd0baa5655f6f8a64d5752e1afcfdf224e5c143ac8b70b235 |
|
MD5 | 99da0faeb92500ddc5cca40be21b381b |
|
BLAKE2b-256 | 0291e73c27760276ad77f56e5c71dcaa46639b4adf7f2b2b9a3f1d32db88d689 |
File details
Details for the file swarmnet-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: swarmnet-0.0.8-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e4acf7ccaa72bf2920ea296469aa83da1700d82e51efb4415e60d756489a1a5 |
|
MD5 | cfd287daa4507f397ba79597bf51c295 |
|
BLAKE2b-256 | b302a02143a95b3ca1fe3465d239a545d4a9920ede3560353b9fde50cdf82b3d |