bimodal-multicast

module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: Apache-2.0

README

Bimodal Multicast Protocol

Build GoDoc

This is an implementation of the Bimodal Multicast Protocol written in GO.

You can synchronize all types of messages: bool, string, int, complex structs, etc.


Overview

The Bimodal Multicast Protocol runs in a series of rounds.

At the beginning of each round, every node randomly chooses another node and sends it a digest of its message histories. The message is called gossip message.

The node that receive the gossip message compares the given digest with the messages in its own message buffer.

If the digest differs from its message histories, then it send a message back to the original sender to request the missing messages. This message is called solicitation.


Usage

  • Step 1: Imports
import "github.com/rstefan1/bimodal-multicast/pkg/bmmc"
  • Step 2: Configure the host

The host must implement Peer interface:

type Peer interface {
	String() string
	Send(msg []byte, route string, peerToSend string) error
}
  • Step 3: Configure the bimodal-multicast protocol
cfg := bmmc.Config{
    Host:           host,
    Callbacks:      map[string]func (interface{}, *log.Logger) error {
        "custom-callback":
        func (msg interface{}, logger *log.Logger) error {
            fmt.Println("The message is:", msg)

            return nil
        },
    },
    Beta:           float64,
    Logger:         logger,
    RoundDuration:  time.Second * 5,
    BufferSize:     2048,
}
Config Required Description
Host Yes Host of Bimodal Multicast server.
Must implement Peer interface. Check the previous step.
Callback No You can define a list of callbacks.
A callback is a function that is called every time a message on the server is synchronized.
Beta No The beta factor is used to control the ratio of unicast to multicast traffic that the protocol allows.
Logger No You can define a structured logger.
RoundDuration No The duration of a gossip round.
BufferSize Yes The size of messages buffer.
The buffer will also include internal messages (e.g. synchronization of the peer list).
When the buffer is full, the oldest message will be removed.
  • Step 4. Create a bimodal multicast server
bmmcServer, err := bmmc.New(cfg)
  • Step 5. Create the host server (e.g. a HTTP server)

The server must handle a list of predefined requests. Each of these handlers must read the message body and call a predefined function.

Handler route Function to be called
bmmc.GossipRoute bmmcServer.GossipHandler(body)
bmmc.SolicitationRoute bmmcServer.SolicitationHandler(body)
bmmc.SynchronizationRoute bmmcServer.SynchronizationHandler(body)

For more details, check the exemples.

  • Step 6. Start the host server and the bimodal multicast server
# Start the host server
hostServer.Start()

# Start the bimodal multicast server
bmmcServer.Start()

  • Step 7. Add a message to broadcast
bmmcServer.AddMessage("new-message", "my-callback")
bmmcServer.AddMessage(12345, "another-callback")
bmmcServer.AddMessage(true, bmmc.NOCALLBACK)
  • Step 8. Retrieve all messages from buffer
bmcServer.GetMessages()
  • Step 9. Add/Remove peers
bmmcServer.AddPeer(peerToAdd)
bmmcServer.RemovePeer(peerToRemove)
  • Step 10. Stop the bimodal multicast server
bmmcServer.Stop()

Examples

  1. using a http server
  2. using a maelstrom server

Contributing

I welcome all contributions in the form of new issues for feature requests, bugs or even pull requests.


License

This project is licensed under Apache 2.0 license. Read the LICENSE file in the top distribution directory for the full license text.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL