chord

package module
v0.0.0-...-17010ac Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2018 License: MIT Imports: 13 Imported by: 2

README

Chord DHT in Go

Package chord provides library functions for the Chord DHT, as described by the original authors of the Chord protocol (https://pdos.csail.mit.edu/papers/ton:chord/paper-ton.pdf).

Features

This library provides functions for:

  • Creating a new DHT
  • Joining nodes to an existing DHT
  • Looking up DHT keys according to the Chord scalable lookup protocol
  • Building applications to run on top of the Chord DHT

See the documentation for details.

Dependencies

This package requires Protobufs. Details for installing protoc can be found here: https://github.com/google/protobuf

Documentation

For a complete description of library functions, see https://godoc.org/github.com/cbocovic/chord

Documentation

Overview

Package chord

This package is a collection of structures and functions associated with the Chord distributed lookup protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InRange

func InRange(x [sha256.Size]byte, min [sha256.Size]byte, max [sha256.Size]byte) bool

InRange is a helper function that returns true if the value x is between the values (min, max)

func Lookup

func Lookup(key [sha256.Size]byte, start string) (addr string, err error)

Lookup returns the address of the successor of key in the Chord DHT. The lookup process is iterative. Beginning with the address of a Chord node, start, this function will request the finger tables of the closest preceeding Chord node to key until the successor is found.

If the start address is unreachable, the error is of type PeerError.

func Send

func Send(msg []byte, addr string) (reply []byte, err error)

Send is a helper function for sending a message to a peer in the Chord DHT. It opens a connection to the Chord node with the IP address addr, sends the message msg, and waits for a reply

Types

type ChordApp

type ChordApp interface {

	//Notify will alert the application of changes in the ChordNode's predecessor
	Notify(id [sha256.Size]byte, me [sha256.Size]byte, addr string)

	//Message will forward a message that was received through the DHT to the application
	Message(data []byte) []byte
}

ChordApp is an interface for applications to run on top of a Chord DHT.

type ChordNode

type ChordNode struct {
	// contains filtered or unexported fields
}

ChordNode type denoting a Chord server.

func Create

func Create(myaddr string) *ChordNode

Create will start a new Chord DHT and return the original ChordNode

func Join

func Join(myaddr string, addr string) (*ChordNode, error)

Join will add a new ChordNode to an existing DHT. It looks up the successor of the new node starting at an existing Chord node specified by addr. Join returns the new ChordNode when completed.

If the start address is unreachable, the error is of type PeerError.

func (*ChordNode) Finalize

func (node *ChordNode) Finalize()

Finalize stops all communication and removes the ChordNode from the DHT.

func (*ChordNode) Register

func (node *ChordNode) Register(id byte, app ChordApp) bool

Register allows chord applications to register themselves and receive notifications and messages through the Chord DHT.

A Chord node registers an application app and forwards all messages with the identifier id by calling the interface method Message. Applications will also be notified of any changes in the underlying node's predecessor.

func (*ChordNode) ShowFingers

func (node *ChordNode) ShowFingers() string

ShowFingers returns a string representation of the ChordNode's finger table.

func (*ChordNode) ShowSucc

func (node *ChordNode) ShowSucc() string

ShowSucc returns a string representation of the ChordNode's successor list.

func (*ChordNode) String

func (node *ChordNode) String() string

String returns a string containing the node's ip address, sucessor, and predecessor.

type Finger

type Finger struct {
	// contains filtered or unexported fields
}

Finger type denoting identifying information about a ChordNode

func (Finger) String

func (f Finger) String() string

type PeerError

type PeerError struct {
	Address string
	Err     error
}

func (*PeerError) Error

func (e *PeerError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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