dht

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

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

Go to latest
Published: Apr 17, 2018 License: MIT Imports: 8 Imported by: 0

README

DHT - Distributed Hash Table

This is an implementation of a distributed hash table as outlined in this paper describing a Chord. Some of the material was taken from this assignment and modified wherever I felt it needed to be modified.

For instance, some of the code provided on the project page did not feel like idiomatic Go so I turned it into what I consider more idiotmatic code.

Command line interface

The command line interface is the same as described in the project page.

Start the interface and type help to get a list of available commands.

Available commands:

Commands
  help         this command
  quit         exit the REPL
  port <port>  set the port for this node to listen on
  create       create a new ring with this node as the first
  join <addr>  join a ring at <addr>

Node commands
  put <key> <value>  store the value at the given key
  get <key>          get the value from a given key
  delete <key>       delete a value at a given key

Debugging commands:
  dump         debugging output of this node
  ping <addr>  ping a node at address <addr>

Installation

$ go get github.com/chuckha/dht/cli

Usage

This project gives you a command line interface for creating a node and joining a ring. You can start as many nodes as you like and have them join at any other node already in the ring (or they can start thier own ring).

  1. After you install the program (and assuming $GOPATH/bin is in your $PATH), run $ cli.
  2. You'll drop into a program that takes your input and runs your commands. Type help to get a full list of commands.
  3. With this first node, all we want to do is create a ring. Type create to start an RPC server for this node. Type dump and get the value of the Address field.
  4. On another computer (on the same network) or in another terminal, run the $ cli command again and type join <addr>, but replace <addr> with the address that you copied in step 3.
  5. Repeat step 4 as many times as you like. You can join the ring at any node and the nodes will correct themselves to create a ring structure.
  6. Put data on the node with put <key> <value>. You will see the address of the node the data got stored on. To retrieve the data, use the get command: get <key>.

Misc

This project is using a linear lookup and not taking advantage of the main point of the Chord paper. That means lookups are O(n) when they should be O(log(n)).

This is a fun way to play with the RPC package and also build a REPL in Go.

As always, contributions are welcome.

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExclusiveBetween

func ExclusiveBetween(left, id, right *big.Int) bool

inclusive id ε (left, right)

func FingerEntry

func FingerEntry(start string, fingerentry int) *big.Int

func GetAddress

func GetAddress() string

func Hash

func Hash(in string) *big.Int

func InclusiveBetween

func InclusiveBetween(left, id, right *big.Int) bool

inclusive id ε (left, right]

func RPCFindSuccessor

func RPCFindSuccessor(addr string, id *big.Int) (string, error)

func RPCGetPredecessor

func RPCGetPredecessor(addr string) (string, error)

func RPCHealthCheck

func RPCHealthCheck(addr string) (bool, error)

func RPCNotify

func RPCNotify(addr, notice string) error

Types

type Node

type Node struct {
	Address     string
	Port        string
	Id          *big.Int
	Successor   string
	Predecessor string
	Data        map[string]string
	// contains filtered or unexported fields
}

func NewNode

func NewNode(port string) *Node

func (*Node) Delete

func (n *Node) Delete(key string, response *bool) error

func (*Node) FindSuccessor

func (n *Node) FindSuccessor(id *big.Int, successor *string) error

func (*Node) Get

func (n *Node) Get(key string, response *string) error

func (*Node) GetPredecessor

func (n *Node) GetPredecessor(none bool, addr *string) error

func (*Node) Notify

func (n *Node) Notify(addr string, response *bool) error

func (*Node) Ping

func (n *Node) Ping(one int, two *int) error

func (*Node) Put

func (n *Node) Put(args PutArgs, success *bool) error

type PutArgs

type PutArgs struct {
	Key, Val string
}

type Server

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

func NewServer

func NewServer(n *Node) *Server

func (*Server) Debug

func (s *Server) Debug() string

func (*Server) Join

func (s *Server) Join(addr string)

func (*Server) Listen

func (s *Server) Listen()

func (*Server) Listening

func (s *Server) Listening() bool

func (*Server) Quit

func (s *Server) Quit()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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