Documentation ¶
Index ¶
- Constants
- Variables
- func ChaindataDir(dataDir string) string
- func DefaultDataDir() string
- func Keccak256(data []byte) []byte
- func Key(k any) []byte
- func NewDatabase(path string) (*database, error)
- func NewLatencyRouter(dht *DHT) *latencyRouter
- type Config
- type DHT
- type FindOption
- type Storage
- type StorageType
- type Value
Constants ¶
const ( // K number of nodes in a bucket K = 20 // ALPHA number of nodes to query in parallel ALPHA = 3 // KEY_BITS number of bits in a key KEY_BITS = 256 // KEY_BYTES number of bytes in a key KEY_BYTES = KEY_BITS / 8 // VALUE_BYTES maximum bytecode size that a value can have. VALUE_BYTES = 32 * 1024 // 32KiB )
const ( // PacketHeaderSize the size of the header we use to reconstruct data PacketHeaderSize = KEY_BYTES + 4 // MaxEventSize the maximum size of an event packet size MaxEventSize = 65024 // MaxPacketSize the size of packets we will send according to MTU, // minus a 8 bytes for the UDP header MaxPacketSize = 1472 // MaxPayloadSize the maximum payload of our packet. The max packet size, // minus 24 bytes for our fragment header MaxPayloadSize = MaxPacketSize - PacketHeaderSize )
Variables ¶
var ( // ErrRequestTimeout returned when a pending request has not recevied a response before the TTL period ErrRequestTimeout = errors.New("request timeout") )
Functions ¶
func ChaindataDir ¶
ChaindataDir returns the path to the LevelDB database.
func DefaultDataDir ¶
func DefaultDataDir() string
DefaultDataDir returns the default data directory path based on the operating system.
func NewDatabase ¶
Newdatabase initializes a new database instance.
func NewLatencyRouter ¶
func NewLatencyRouter(dht *DHT) *latencyRouter
Types ¶
type Config ¶
type Config struct { // LocalID the id of this node. If not specified, a random id will be generated LocalID []byte // ListenAddress the udp ip and port to listen on ListenAddress string // BootstrapAddresses the udp ip and port of the bootstrap nodes BootstrapAddresses []string // Listeners the number of threads that will listen on the designated udp port Listeners int // Timeout the amount of time before a peer is declared unresponsive and removed Timeout time.Duration // Storage implementation to use for storing key value pairs Storage Storage // StorageBackend the type of storage to use StorageBackend StorageType // LevelDBPath the path to the LevelDB database LevelDBPath string // DataDir the path to the data directory DataDir string // SocketBufferSize sets the size of the udp sockets send and receive buffer SocketBufferSize int // SocketBatchSize the batch size of udp messages that will be written to the underlying socket SocketBatchSize int // SocketBatchInterval the period with which the current batch of udp messages will be written to the underlying socket if not full SocketBatchInterval time.Duration // Logging enables basic logging Logging bool }
Config configuration parameters for the dht
type DHT ¶
type DHT struct {
// contains filtered or unexported fields
}
DHT represents the distributed hash table
func (*DHT) Find ¶
func (d *DHT) Find(key []byte, callback func(value []byte, err error), opts ...*FindOption)
Find finds a value on the network if it exists. If the key being queried has multiple values, the callback will be invoked for each result Any returned value will not be safe to use outside of the callback, so you should copy it if its needed elsewhere
type FindOption ¶
type FindOption struct {
// contains filtered or unexported fields
}
FindOption for configuring find requests
func ValuesFrom ¶
func ValuesFrom(from time.Time) *FindOption
ValuesFrom filters results to only those that were created after a given timestmap this is useful for repeat queries where duplicates ideally should be avoided
type Storage ¶
type Storage interface { Get(key []byte, from time.Time) ([]*Value, bool) Set(key, value []byte, created time.Time, ttl time.Duration) bool Iterate(cb func(value *Value) bool) }
Storage defines the storage interface used by the DLT
func InitializeStorage ¶
InitializeStorage initializes the storage based on the configuration.
type StorageType ¶
type StorageType string
StorageType defines the type of storage to use.
const ( InMemoryStorage StorageType = "inmemory" LevelDBStorage StorageType = "leveldb" )