Skip to main content

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

swarmnet-0.0.7.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

swarmnet-0.0.7-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file swarmnet-0.0.7.tar.gz.

File metadata

  • Download URL: swarmnet-0.0.7.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for swarmnet-0.0.7.tar.gz
Algorithm Hash digest
SHA256 1d17d8cb996914f44167fe52ae4630a47839c22ab73738591832de87b7d05160
MD5 f83a19f1b4a82f80b10696958f7b6760
BLAKE2b-256 1f836e95c1e6f02baef372199993ba5bebc027da119d3517678760aa65dd1fa7

See more details on using hashes here.

File details

Details for the file swarmnet-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: swarmnet-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for swarmnet-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac378dad0f28bd62ed8dbe9c95a8920c54d15c00cc79a27276166cda7ff5d52
MD5 d8b2d451cdc937845ecde0e7c0d6cea8
BLAKE2b-256 1f0fde26b81fffe0539531390c6757d4d1d9c6a7971d6c970f096a4d5ae27a54

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page