dht

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxEntryNameLength          = 32
	MaxEntryDescLength          = 160
	MaxEntryPublicAddressLength = 253
	MaxEntrySeeds               = 100000
)
View Source
const AddressBinarySize = 20
View Source
const AddressVersion = 0
View Source
const (
	BucketSize = 20
)

Variables

This section is empty.

Functions

func ShuffleEntries

func ShuffleEntries(slice Entries)

Types

type Address

type Address struct {
	Raw     []byte
	Encoded string
}

func DecodeAddress

func DecodeAddress(value string) (Address, error)

Decodes a string address into address bytes.

func NewAddress

func NewAddress(key []byte) (addr Address)

Generates an Address from a PublicKey.

func RandomAddress

func RandomAddress() (*Address, error)

func (*Address) Bytes

func (a *Address) Bytes() ([]byte, error)

func (*Address) Encode

func (a *Address) Encode() ([]byte, error)

func (*Address) EncodeString

func (a *Address) EncodeString() (string, error)

func (*Address) Equals

func (a *Address) Equals(other *Address) bool

func (*Address) Generate

func (a *Address) Generate(key []byte) (string, error)

Generate a Zif address from a public key. This process involves one SHA3-256 iteration, followed by BLAKE2. This is similar to bitcoin, and the BLAKE2 makes the resulting address a bit shorter

func (*Address) LeadingZeroes

func (a *Address) LeadingZeroes() int

Counts the number of leading zeroes this address has. The address should be the result of an Xor. This shows the k-bucket that this address should go into.

func (*Address) Less

func (a *Address) Less(other *Address) bool

func (*Address) String

func (a *Address) String() (string, error)

Returns Address.Bytes Base58 encoded and prepended with a Z. Base58 removes ambiguous characters, reducing the chances of address confusion.

func (Address) StringOr

func (a Address) StringOr(or string) string

func (*Address) Xor

func (a *Address) Xor(other *Address) *Address

type DHT

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

func NewDHT

func NewDHT(addr Address, path string) *DHT

sets up the dht

func (*DHT) Address

func (dht *DHT) Address() Address

func (*DHT) FindClosest

func (dht *DHT) FindClosest(addr Address) (Entries, error)

func (*DHT) Insert

func (dht *DHT) Insert(entry Entry) (int64, error)

func (*DHT) LoadTable

func (dht *DHT) LoadTable(path string)

func (*DHT) Query

func (dht *DHT) Query(addr Address) (*Entry, error)

func (*DHT) SaveTable

func (dht *DHT) SaveTable(path string)

func (*DHT) SearchEntries

func (dht *DHT) SearchEntries(name, desc string, page int) ([]Address, error)

type Entries

type Entries []*Entry

func (Entries) Len

func (e Entries) Len() int

func (Entries) Less

func (e Entries) Less(i, j int) bool

func (Entries) Swap

func (e Entries) Swap(i, j int)

type Entry

type Entry struct {
	Address       Address `json:"address"`
	Name          string  `json:"name"`
	Desc          string  `json:"desc"`
	PublicAddress string  `json:"publicAddress"`
	PublicKey     []byte  `json:"publicKey"`
	PostCount     int     `json:"postCount"`
	Updated       uint64  `json:"updated"`

	// The owner of this entry should have signed it, we need to store the
	// sigature. It's actually okay as we can verify that a peer owns a public
	// key by generating an address from it - if the address is not the peers,
	// then Mallory is just using someone elses entry for their own address.
	Signature      []byte `json:"signature"`
	CollectionHash []byte `json:"collectionHash"`
	Port           int    `json:"port"`

	Seeds   [][]byte `json:"seeds"`
	Seeding [][]byte `json:"seeding"`
	Seen    int      `json:"seed"`
	// contains filtered or unexported fields
}

This is an entry into the DHT. It is used to connect to a peer given just it's Zif address.

func DecodeEntry

func DecodeEntry(data []byte, isJson bool) (*Entry, error)

true if JSON, false if msgpack

func (Entry) Bytes

func (e Entry) Bytes() ([]byte, error)

This is signed, *not* the JSON. This is needed because otherwise the order of the posts encoded is not actually guaranteed, which can lead to invalid signatures. Plus we can only sign data that is actually needed.

func (Entry) Encode

func (e Entry) Encode() ([]byte, error)

func (Entry) EncodeString

func (e Entry) EncodeString() (string, error)

Returns a JSON encoded string, not msgpack. This is because it is likely going to be seen by a human, otherwise it would be bytes.

func (*Entry) SetLocalPeer

func (e *Entry) SetLocalPeer(lp Node)

func (Entry) String

func (e Entry) String() (string, error)

func (*Entry) Verify

func (entry *Entry) Verify() error

Ensures that all the members of an entry struct fit the requirements for the Zif libzifcol. If an entry passes this, then we should be able to perform most operations on it.

type InvalidValue

type InvalidValue struct {
	Value string
}

func (*InvalidValue) Error

func (iv *InvalidValue) Error() string

type NetDB

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

func NewNetDB

func NewNetDB(addr Address, path string) (*NetDB, error)

func (*NetDB) FindClosest

func (ndb *NetDB) FindClosest(addr Address) (Entries, error)

func (*NetDB) Insert

func (ndb *NetDB) Insert(entry Entry) (int64, error)

Inserts an entry into both the routing table and the database

func (*NetDB) InsertSeed

func (ndb *NetDB) InsertSeed(entry Address, seed Address) error

func (*NetDB) Len

func (ndb *NetDB) Len() (int, error)

Get the total number of entries we have stored

func (*NetDB) LoadTable

func (ndb *NetDB) LoadTable(path string)

func (*NetDB) Query

func (ndb *NetDB) Query(addr Address) (*Entry, int, error)

Returns the KeyValue if this node has the address, nil if not, and err otherwise

func (*NetDB) QueryLatest

func (ndb *NetDB) QueryLatest() ([]Entry, error)

func (*NetDB) QuerySeeding

func (ndb *NetDB) QuerySeeding(addr Address) ([]Address, error)

func (*NetDB) QuerySeeds

func (ndb *NetDB) QuerySeeds(addr Address) ([]Address, error)

Fetch the seeds for an entry, given its address

func (*NetDB) SaveTable

func (ndb *NetDB) SaveTable(path string)

func (*NetDB) SearchPeer

func (ndb *NetDB) SearchPeer(name, desc string, page int) ([]Address, error)

func (*NetDB) TableLen

func (ndb *NetDB) TableLen() int

Get the total size of the in-memory routing table

func (*NetDB) Update

func (ndb *NetDB) Update(entry Entry) (int64, error)

type NoCapacity

type NoCapacity struct {
	Max int
}

func (*NoCapacity) Error

func (nc *NoCapacity) Error() string

type Node

type Node interface {
	Address() *Address
	PublicKey() []byte
}

Jump to

Keyboard shortcuts

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