dht

package
v0.0.0-...-e38b929 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2017 License: MIT Imports: 14 Imported by: 2

README

dht

Stuff you'll find here are dht implementation details. Peer information, peer lists, &c. There isn't a specific DHT algorithm which we're using, but the general workflow for how our peers communicate can be found in the network folder.

We essentially hold 3 peers as important nodes: any other peers we encounter and receive from our 3 important nodes are added to a backuplist. The three important nodes are set on a quick heartbeat, whereas each other node will have an artery clogged hearbeat every minute. Each peer operates on a FSM with multiple states. If a peer is continually not responding to queries, it will be set to a timed out state, but will continued to be beaten with our heart.

Peer lists are typically used for heartbeats and peer-wide operations: for instance, whenever a request for a key not found in the current node is made, we'll iterate through each peer in the peerlist and see if that probably has the key.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer struct {
	Status      State
	Conn        *net.Conn
	IPPort      string
	BloomFilter bloomfilter.BloomFilter
	MessageBus  *message_handler.MessageHandler
	UniqueID    string

	sync.Mutex
	// contains filtered or unexported fields
}

Peer Houses the state for remote Peers

func NewPeer

func NewPeer(conn *net.Conn, mh *message_handler.MessageHandler, config *config.Cfg) *Peer

NewPeer handles creating a new peer to be used in communicating between nodes

func NewPeerByIP

func NewPeerByIP(ipPort string, mh *message_handler.MessageHandler, config config.Cfg) *Peer

NewPeerByIP handles creating a peer by its ip, opening a connection, &c.

func (*Peer) Connect

func (p *Peer) Connect() error

Connect opens a connection to a remote peer

func (*Peer) Disconnect

func (p *Peer) Disconnect()

Disconnect closes a connection to a remote peer.

func (*Peer) GetBloomFilter

func (p *Peer) GetBloomFilter()

GetBloomFilter handles retrieving a remote node's bloom filter.

func (*Peer) GetPeerList

func (p *Peer) GetPeerList(responseChannel chan string)

GetPeerListAsync handles retrieving all known peers from a remote node.

func (*Peer) SendCommand

func (p *Peer) SendCommand(Command string) (int, error)

SendCommand Handles sending a command to a remote node. Command is like this "hash:Command"

func (*Peer) SendRequest

func (p *Peer) SendRequest(Command string, responseChannel chan string, mh *message_handler.MessageHandler)

SendRequest handles taking in a peer object and a command and sending a command which will be responded to the calling channel once the request has been fulfilled

func (*Peer) TestConnection

func (p *Peer) TestConnection()

Ping handles intelligently sending heartbeats to a remote node. After 10 successive failures to ping, the remote node is considered failed and the status is set to Timeout

type PeerList

type PeerList struct {
	Peers       []*Peer
	BackupPeers []*Peer
	PeerMap     *map[string]bool
	MessageBus  *message_handler.MessageHandler

	sync.Mutex
	// contains filtered or unexported fields
}

PeerList is a data structure which represents remote Olivia nodes.

func NewPeerList

func NewPeerList(mh *message_handler.MessageHandler, config config.Cfg) *PeerList

NewPeerList Creates a new peer list

func (*PeerList) AddPeer

func (p *PeerList) AddPeer(ipPort string)

AddPeer handles intelligently putting a peer into our peer list. Priority of insertion is towards Peers first and then BackupPeers.

func (*PeerList) ConnectAllPeers

func (p *PeerList) ConnectAllPeers() error

ConnectAllPeers connects all peers (or at least attempts to)

func (*PeerList) DisconnectAllPeers

func (p *PeerList) DisconnectAllPeers()

DisconnectAllPeers disconnects all peers

type State

type State int

State represents the state that the remote peer is in.

const (
	// Disconnected signifies that the remote node is not yet connected.
	Disconnected State = iota
	// Connected signifies that there is a working connection between the
	// remote peer and our current node.
	Connected
	// Timeout signifies that the remote node has timed out and a
	// connection couldn't be established.
	Timeout
)

Jump to

Keyboard shortcuts

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