Documentation
¶
Index ¶
Constants ¶
const ( RequestJoin reqType = iota RequestPut RequestGet RequestGetFromCached )
const ( // a small K is used to reflect the fact that this is not a global service DefaultK int = 12 // a small number of bits is used to reflect the fact that the network size // is much smaller DefaultBits int = 128 )
const ( RPCPing rpcType = iota RPCJoin RPCFindNode RPCPut RPCGet )
Variables ¶
var (
ErrBufferTooSmall = errors.New("size of the buffer is too small")
)
Functions ¶
This section is empty.
Types ¶
type DHT ¶
type DHT struct {
// contains filtered or unexported fields
}
DHT implements the kademlia protocol with a key-value store interface exposed for users. Asynchronous Put() and Get() methods follow the best effort approach.
Note that this DHT is intended to be used in trusted environment, e.g. managed data centers, sybil attacks are assumed to be impossible in such settings.
func (*DHT) Get ¶
Get asynchronously queries the DHT network for values associated with the specified key. Matched values will be locally cached in current peer's local store. Caller should use a follow up GetCached() call to access the returned values.
func (*DHT) GetCached ¶
GetCached returns the values associated with the specified key by only looking at current peer's local store. It is normally invoked after a successful return of Get().
func (*DHT) Put ¶
Put asynchronously puts the specified key value pair onto the DHT network with its TTL value set to ttl seconds.
func (*DHT) ScheduleGet ¶
ScheduleGet schedules a Get() to be performed after the specified delay.
type DHTConfig ¶
type DHTConfig struct { // Secret of the DHT deployment. Note that this is not a security setting, // it is only used to prevent dht nodes from different deployments talking to // each other as a result of misconfiguration. Secret uint16 Proto string Routers []net.UDPAddr Address net.UDPAddr }
DHTConfig is the config for the DHT.