gossipProtocol

package module
v0.0.0-...-d05ac7c Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 17 Imported by: 0

README

Gossip protocol

Gossip based communication with partial network views & peer-sampling

Various strategies for maintaining a partial view of the network.
  • View-selection
  • View-propagation
  • Peer-selection

These strategies allow for the construction and maintenance of various dynamic unstructured overlays through gossiping membership information (https://web.archive.org/web/20170809095111/http://lpdwww.epfl.ch/upload/documents/publications/neg--1184036295all.pdf)

Partial ordering of events
  • Each Peer maintains a vector clock relative to its partial view
  • Data gossipped to the network encapsulates the vector clocks of participating Peers
  • Allows for data sent to the network to be partially ordered based on this.
Gossip Listener
package gossipProtocol

type Gossip interface {
	// Join with some initial peers
	Join(...Peer)
	// Add peers
	Add(...Peer)
	// CurrentView returned as a String
	CurrentView() string
	// SendGossip  to the network
	SendGossip(data string)
}

Example
package main

import (
	"fmt"

	"github.com/Ishan27gOrg/gossipProtocol"
)



func main() {
	// self
	g, receive := gossipProtocol.Config("localhost", "8001", "p1")
	
	// other peers
	var peers []gossipProtocol.Peer
	peers = append(peers, gossipProtocol.Peer{UdpAddress: "localhost:8002", ProcessIdentifier: "p2"})
	peers = append(peers, gossipProtocol.Peer{UdpAddress: "localhost:8003", ProcessIdentifier: "p3"})
	
	// join and send some data
	g.Join(peers...)
	
	g.SendGossip("some data")
	for{
		gossipPacket := <-receive
		fmt.Println("data - ", gossipPacket.GossipMessage.Data)
		fmt.Println("event clock for this packet - ", gossipPacket.VectorClock)
	}
}

Documentation

Index

Constants

View Source
const (
	ViewExchangeDelay = 200 * time.Millisecond // timeout after which a View  is exchanged with a peer
	MaxNodesInView    = 6                      // max peers kept in local View TODO MaxNodesInView=6
)
View Source
const (
	Random   = iota // *selection strategies
	Head            // *selection strategies
	Tail            // *selection strategies
	Push            // *propagation strategies
	Pull            // *propagation strategies
	PushPull        // *propagation strategies
)

Variables

This section is empty.

Functions

func ByteToPacket

func ByteToPacket(b []byte) (Packet, Peer)

func BytesToView

func BytesToView(bytes []byte) (View, Peer, error)

func Listen

func Listen(ctx context.Context, port string, gossipCb func(Packet, Peer) []byte, viewCb func(View, Peer) []byte)

Listen starts the udp server that listens for an incoming view or startRounds from peers. Responds with the current view / startRounds as per strategy.

func PrintView

func PrintView(view View) string

func ViewToBytes

func ViewToBytes(view View, from Peer) []byte

Types

type Gossip

type Gossip interface {
	// Join with some initial peers
	Join(...Peer)
	// Add peers
	Add(...Peer)
	// SendGossip  to the network
	SendGossip(data string)
	// CurrentView returned as a String
	CurrentView() map[string]Peer
}

func Config

func Config(hostname string, port string, id string) (Gossip, <-chan Packet)

type Packet

type Packet struct {
	AvailableAt   []string          `json:"AvailableAt"` // at which addresses the data is available
	GossipMessage gossipMessage     `json:"GossipMessage"`
	VectorClock   vClock.EventClock `json:"VectorClock"`
}

Packet exchanged between peers

func NewGossipMessage

func NewGossipMessage(data string, from string, clock vClock.EventClock) Packet

NewGossipMessage creates a Gossip message with current timestamp, creating a unique hash for every message

func (*Packet) GetData

func (p *Packet) GetData() string

func (*Packet) GetId

func (p *Packet) GetId() string

func (*Packet) GetVersion

func (p *Packet) GetVersion() int

func (*Packet) UpdateGossipAt

func (p *Packet) UpdateGossipAt()

type Peer

type Peer struct {
	UdpAddress        string
	ProcessIdentifier string
	Hop               int
}

type PeerSamplingStrategy

type PeerSamplingStrategy struct {
	PeerSelectionStrategy   int
	ViewPropagationStrategy int
	ViewSelectionStrategy   int
}

func With

func With(ps, vp, vs int) PeerSamplingStrategy

type View

type View struct {
	Nodes *sll.List
}

View of at max MaxNodesInView nodes in the network updated during selectView()

func MergeView

func MergeView(view1, view2 View) View

func (*View) RandomView

func (v *View) RandomView()

RandomView sets the current View as a random subset of current View

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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