dht

package module
v0.0.0-...-80327fb Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: AGPL-3.0 Imports: 21 Imported by: 0

README

DHT is a distributed hash table based on the Kademlia paper:
https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf.

It also uses the S/Kademlia extension "crypto puzzles" to impede Eclipse and
Sybil attacks (see the PROTOCOL, section 14 "Node ID Generation" for details).
S/Kademlia paper: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.68.4986&rep=rep1&type=pdf

DHT also includes many other security measures:
	- Node IDs are Ed25519 keypairs.
	- All messages are signed by the node's private key.
	- All messages are encrypted with the recipient's public key.
	- Fixed-size (UDP) messages are padded to avoid leaking message type.

The network is completely decentralized. For more details read the PROTOCOL.

To operate a node:

1. Install golang: golang.org/dl

On Linux distributions like Ubuntu, Fedora, etc. you should be able to install a
"golang" package through your package manager.

2. Download dht with:

	go get -u github.com/esote/dht/cmd/dht

This will create a "dht" executable in your go/bin folder. Add ~/go/bin to PATH.

3. Create a working directory, for example

	mkdir /tmp/dht

3. Start a node

	dht /tmp/dht start PORT

The program will ask for a password to encrypt the node's private key.

4. Stop a node

	dht /tmp/dht stop

5. Bootstrap another node

	dht /tmp/dht bootstrap ID IP:PORT

		Bootstrap a node, ID must be full base64 code, IP must be an
		IPv4 or IPv6 address (hostnames not allowed).

6. Store a file on the network

	dht /tmp/dht store /PATH/TO/FILE

7. Load a file from the network

	dht /tmp/dht load KEY /PATH/TO/OUTPUT

		KEY must be full base64 code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DHT

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

func NewDHT

func NewDHT(config *DHTConfig) (*DHT, error)

func (*DHT) Bootstrap

func (dht *DHT) Bootstrap(id []byte, ip net.IP, port uint16) (err error)

func (*DHT) Close

func (dht *DHT) Close() error

func (*DHT) Load

func (dht *DHT) Load(key []byte) (io.ReadCloser, uint64, error)

func (*DHT) Store

func (dht *DHT) Store(key []byte, length uint64, value Rereader) error

type DHTConfig

type DHTConfig struct {
	NetworkID     []byte
	Dir           string
	Password      []byte
	Storer        storer.Storer
	Logger        Logger
	IP            net.IP
	Port          uint16
	FixedTimeout  time.Duration // Timeout for fixed-length messages
	StreamTimeout time.Duration // Timeout for stream messages
	// contains filtered or unexported fields
}

type LogLevel

type LogLevel int

LogLevel is the priority of an event

const (
	//LogCrit    LogLevel = iota // Critical error, requiring DHT to exit
	LogErr     LogLevel = iota // Error with DHT
	LogWarning                 // Error from external request
	LogInfo                    // DHT operation information
	LogDebug                   // Debug details
)

TODO: ensure all logging follows these categories Log levels

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Log(level LogLevel, a ...interface{})
	Logf(level LogLevel, format string, a ...interface{})
}

Logger records events of varying importance.

func NewConsoleLogger

func NewConsoleLogger(min LogLevel) Logger

NewConsoleLogger records logs to the console: stdout if level >= LogInfo, otherwise stderr.

type Rereader

type Rereader interface {
	Next() (io.ReadCloser, error)
}

Rereader returns a new reader for the same source, allowing its stream to be "reread".

Directories

Path Synopsis
cmd
dht
crypto
Package crypto provides tools for encrypting and decrypting data in fixed and stream formats, and for converting Ed25519 keys to X25519 keys.
Package crypto provides tools for encrypting and decrypting data in fixed and stream formats, and for converting Ed25519 keys to X25519 keys.
Package storer implements an abstract key-value storage interface.
Package storer implements an abstract key-value storage interface.

Jump to

Keyboard shortcuts

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