Documentation ¶
Index ¶
- Constants
- func ShuffleEntries(slice Entries)
- type Address
- func (a *Address) Bytes() ([]byte, error)
- func (a *Address) Encode() ([]byte, error)
- func (a *Address) EncodeString() (string, error)
- func (a *Address) Equals(other *Address) bool
- func (a *Address) Generate(key []byte) (string, error)
- func (a *Address) LeadingZeroes() int
- func (a *Address) Less(other *Address) bool
- func (a *Address) String() (string, error)
- func (a Address) StringOr(or string) string
- func (a *Address) Xor(other *Address) *Address
- type DHT
- func (dht *DHT) Address() Address
- func (dht *DHT) FindClosest(addr Address) (Entries, error)
- func (dht *DHT) Insert(entry Entry) (int64, error)
- func (dht *DHT) LoadTable(path string)
- func (dht *DHT) Query(addr Address) (*Entry, error)
- func (dht *DHT) SaveTable(path string)
- func (dht *DHT) SearchEntries(name, desc string, page int) ([]Address, error)
- type Entries
- type Entry
- type InvalidValue
- type NetDB
- func (ndb *NetDB) FindClosest(addr Address) (Entries, error)
- func (ndb *NetDB) Insert(entry Entry) (int64, error)
- func (ndb *NetDB) InsertSeed(entry Address, seed Address) error
- func (ndb *NetDB) Len() (int, error)
- func (ndb *NetDB) LoadTable(path string)
- func (ndb *NetDB) Query(addr Address) (*Entry, int, error)
- func (ndb *NetDB) QueryLatest() ([]Entry, error)
- func (ndb *NetDB) QuerySeeding(addr Address) ([]Address, error)
- func (ndb *NetDB) QuerySeeds(addr Address) ([]Address, error)
- func (ndb *NetDB) SaveTable(path string)
- func (ndb *NetDB) SearchPeer(name, desc string, page int) ([]Address, error)
- func (ndb *NetDB) TableLen() int
- func (ndb *NetDB) Update(entry Entry) (int64, error)
- type NoCapacity
- type Node
Constants ¶
const ( MaxEntryNameLength = 32 MaxEntryDescLength = 160 MaxEntryPublicAddressLength = 253 MaxEntrySeeds = 100000 )
const AddressBinarySize = 20
const AddressVersion = 0
const (
BucketSize = 20
)
Variables ¶
This section is empty.
Functions ¶
func ShuffleEntries ¶
func ShuffleEntries(slice Entries)
Types ¶
type Address ¶
func DecodeAddress ¶
Decodes a string address into address bytes.
func RandomAddress ¶
func (*Address) EncodeString ¶
func (*Address) Generate ¶
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 ¶
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.
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 ¶
true if JSON, false if msgpack
func (Entry) Bytes ¶
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) EncodeString ¶
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 ¶
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 (*NetDB) Query ¶
Returns the KeyValue if this node has the address, nil if not, and err otherwise
func (*NetDB) QueryLatest ¶
func (*NetDB) QuerySeeds ¶
Fetch the seeds for an entry, given its address
func (*NetDB) SearchPeer ¶
type NoCapacity ¶
type NoCapacity struct {
Max int
}
func (*NoCapacity) Error ¶
func (nc *NoCapacity) Error() string