Documentation ¶
Index ¶
Constants ¶
View Source
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 )
View Source
const ( // K number of nodes in a bucket K = 20 // KEY_BITS number of bits in a key KEY_BITS = 160 // KEY_BYTES number of bytes in a key KEY_BYTES = KEY_BITS / 8 )
Variables ¶
View Source
var ( // ErrRequestTimeout returned when a pending request has not recevied a response before the TTL period ErrRequestTimeout = errors.New("request timeout") )
Functions ¶
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 // 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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.