Currently a string, because for some reason, that's what is chosen at the protobuf level TODO: convert between RFC3339 strings and use of integers (i.e. the _correct way)
Types
CandidatePeers = ref HashSet[PeerId]
- Source Edit
DefaultEntrySelector = ref object of EntrySelector
- Source Edit
DefaultEntryValidator = ref object of EntryValidator
- Source Edit
EntryRecord = object value*: seq[byte] time*: Timestamp
- Source Edit
EntrySelector = ref object of RootObj
- Source Edit
EntryValidator = ref object of RootObj
- Source Edit
KadDHT = ref object of LPProtocol switch*: Switch rng*: Rng rtable*: RoutingTable maintenanceLoop*: Future[void] republishLoop*: Future[void] expiredLoop*: Future[void] recordExpirationLoop*: Future[void] dataTable*: LocalTable providerManager*: ProviderManager config*: KadDHTConfig rpcSem*: AsyncSemaphore ## Bounds in-flight outbound RPCs to ``config.limits.maxConcurrentRpcs``.
- Source Edit
KadDHTConfig = object validator*: EntryValidator selector*: EntrySelector timeout*: chronos.Duration bucketRefreshTime*: chronos.Duration retries*: int replication*: int alpha*: int ttl*: chronos.Duration quorum*: int providerRecordCapacity*: int providedKeyCapacity*: int republishProvidedKeysInterval*: chronos.Duration cleanupProvidersInterval*: chronos.Duration providerExpirationInterval*: chronos.Duration recordExpirationInterval*: chronos.Duration cleanupDataEntriesInterval*: chronos.Duration addressPolicy*: PeerAddressPolicy hideConnectionStatus*: bool disableBootstrapping*: bool providerRejection*: bool ## When true, ADD_PROVIDER receivers reply with accepted/rejected on ## field 11; the sender spills over to farther peers when a full batch is ## rejected. The per-key cap (``limits.maxProvidersPerKey``) is always ## enforced regardless of this flag — this only controls whether ## rejections are acknowledged on the wire. limits*: KadDHTLimits
- Source Edit
KadDHTLimits = object maxProvidersPerKey*: Opt[int] ## Maximum number of distinct providers stored per key. ## ``Opt.none`` means unlimited; when limits are derived by the ## ``KadDHTConfig`` constructor this defaults to ``replication``. maxShortlistSize*: int ## Maximum number of peers retained in an iterative-lookup shortlist. ## When exceeded, farther peers are dropped so the shortlist stays bounded. maxReceivedSize*: int ## Maximum number of per-peer entries retained in a GET_VALUE ## ``ReceivedTable``. maxValueSize*: int ## Maximum size (bytes) of an individual record value. Enforced on ## ``putValue`` and on incoming PUT_VALUE / GET_VALUE records. maxLocalRecords*: Opt[int] ## Maximum number of records retained in the local value store. ## ``Opt.none`` means unlimited; when limits are derived by the ## ``KadDHTConfig`` constructor this defaults to ``DefaultMaxLocalRecords``. maxConcurrentRpcs*: int ## Maximum number of in-flight outbound RPCs (find/get/put/provider) ## across the whole node. Excess calls wait on a shared semaphore. maxPeersPerIp*: int ## Maximum number of Kademlia routing-table peers sharing one exact IP. maxPeersPerIpv4Subnet*: int ## Maximum number of Kademlia routing-table peers sharing one IPv4 /24. maxPeersPerIpv6Subnet*: int ## Maximum number of Kademlia routing-table peers sharing one IPv6 /64.
- Source Edit
LocalTable = Table[Key, EntryRecord]
- Source Edit
ProvidedKeys = ref object provided*: Table[Key, Moment] capacity*: int
- Source Edit
ProviderManager = ref object providerRecords*: ProviderRecords providedKeys*: ProvidedKeys knownKeys*: Table[Key, HashSet[Provider]]
- Source Edit
ProviderRecord = object provider*: Provider expiresAt*: chronos.Moment key*: Key
- Source Edit
ProviderRecords = ref object records*: HeapQueue[ProviderRecord] capacity*: int
- Source Edit
ReceivedTable = TableRef[PeerId, Opt[EntryRecord]]
- Source Edit
RoutingTable = ref object selfId*: Key localNodeId*: Key buckets*: seq[Bucket] config*: RoutingTableConfig
- Source Edit
RoutingTableConfig = ref object replication*: int hasher*: Opt[XorDHasher] maxBuckets*: int selfIdPreHashed*: bool
- Source Edit
XorDHasher = proc (input: seq[byte]): array[IdLength, byte] {....raises: [], nimcall, noSideEffect, ...gcsafe.}
- Source Edit
XorDistance = array[IdLength, byte]
- Source Edit
Consts
DefaultAlpha = 10
- Source Edit
DefaultBucketRefreshTime = (value: 600000000000)
- Source Edit
DefaultBucketStaleTime = (value: 1800000000000)
- Source Edit
DefaultCleanupDataEntriesInterval = (value: 3600000000000)
- Source Edit
DefaultCleanupProvidersInterval = (value: 600000000000)
- Source Edit
DefaultMaxBuckets = 256
- Source Edit
DefaultMaxConcurrentRpcs = 100
- upper bound on in-flight outbound RPCs across find/get/put/provider Source Edit
DefaultMaxLocalRecords = 500
- upper bound on locally stored value records Source Edit
DefaultMaxPeersPerIp = 4
- upper bound on Kademlia routing-table peers sharing one exact IP Source Edit
DefaultMaxPeersPerSubnet = 10
- upper bound on Kademlia routing-table peers sharing one IP subnet Source Edit
DefaultMaxProvidersPerKey = 20
- upper bound on providers stored per key Source Edit
DefaultMaxReceivedSize = 20
- upper bound on per-query ReceivedTable Source Edit
DefaultMaxShortlistSize = 40
- upper bound on iterative-lookup shortlist Source Edit
DefaultMaxValueSize = 3072
- upper bound (bytes) on a stored record value. Kept much lower than the RPC frame cap so PUT_VALUE/GET_VALUE records stay independently bounded. Source Edit
DefaultProviderExpirationInterval = (value: 172800000000000)
- Source Edit
DefaultQuorum = 5
- Source Edit
DefaultRecordExpirationInterval = (value: 86400000000000)
- Source Edit
DefaultReplication = 20
- aka k in the spec Source Edit
DefaultRepublishInterval = (value: 600000000000)
- Source Edit
DefaultRetries = 5
- Source Edit
DefaultTimeout = (value: 5000000000)
- Source Edit
MaxMsgSize = 4194304
- Source Edit
TimestampFormat = "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'"
- Source Edit
Procs
proc `<`(a, b: XorDistance): bool {....raises: [], tags: [], forbids: [].}
- Source Edit
proc `<=`(a, b: XorDistance): bool {....raises: [], tags: [], forbids: [].}
- Source Edit
proc cmp(a, b: XorDistance): int {....raises: [], tags: [], forbids: [].}
- Source Edit
proc countLeadingZeroBits(b: byte): int {....raises: [], tags: [], forbids: [].}
- Source Edit
proc get(self: LocalTable; key: Key): Opt[EntryRecord] {....raises: [], tags: [], forbids: [].}
- Source Edit
proc hashFor(k: Key; hasher: Opt[XorDHasher]): seq[byte] {....raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc init(T: typedesc[EntryRecord]; value: Key; time: Opt[Timestamp]): EntryRecord {. ...gcsafe, raises: [].}
- Source Edit
proc leadingZeros(dist: XorDistance): int {....raises: [], tags: [], forbids: [].}
- Source Edit
proc new(K: typedesc[KadDHTConfig]; validator: EntryValidator = DefaultEntryValidator(); selector: EntrySelector = DefaultEntrySelector(); timeout: chronos.Duration = DefaultTimeout; bucketRefreshTime: chronos.Duration = DefaultBucketRefreshTime; retries: int = DefaultRetries; replication: int = DefaultReplication; alpha: int = DefaultAlpha; quorum: int = DefaultQuorum; providerRecordCapacity = DefaultProviderRecordCapacity; providedKeyCapacity = DefaultProvidedKeyCapacity; republishProvidedKeysInterval: chronos.Duration = DefaultRepublishInterval; cleanupProvidersInterval: chronos.Duration = DefaultCleanupProvidersInterval; providerExpirationInterval: chronos.Duration = DefaultProviderExpirationInterval; recordExpirationInterval: chronos.Duration = DefaultRecordExpirationInterval; cleanupDataEntriesInterval: chronos.Duration = DefaultCleanupDataEntriesInterval; addressPolicy: PeerAddressPolicy = defaultAddressPolicy; hideConnectionStatus: bool = true; disableBootstrapping: bool = false; providerRejection: bool = false; limits: Opt[KadDHTLimits] = Opt.none(KadDHTLimits)): K:type {. ...raises: [].}
- Source Edit
proc new(T: typedesc[KadDHTLimits]; replication: int; quorum: int): T:type {. ...raises: [].}
- Builds a limits object whose shortlist/received caps and providers-per-key are sized off the actual replication and quorum so the configuration stays internally consistent (e.g. maxShortlistSize >= replication, maxReceivedSize >= quorum). Source Edit
proc new(T: typedesc[ProviderManager]; providerRecordCapacity: int; providedKeyCapacity: int): T:type
- Source Edit
proc noOpHasher(input: seq[byte]): array[IdLength, byte] {....raises: [], nimcall, noSideEffect, ...gcsafe, tags: [], forbids: [].}
- Source Edit
proc nowUnixSeconds(): int64 {....gcsafe, raises: [], tags: [TimeEffect], forbids: [].}
- Source Edit
proc toUnixSeconds(time: Timestamp): Result[int64, ref CatchableError] {....gcsafe, raises: [], tags: [TimeEffect], forbids: [].}
- Source Edit
proc xorDistance(a, b: Key): XorDistance {....raises: [], tags: [], forbids: [].}
- Source Edit
proc xorDistance(a, b: Key; hasher: Opt[XorDHasher]): XorDistance {....raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc xorDistance(a, b: PeerId; hasher: Opt[XorDHasher]): XorDistance {. ...raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc xorDistance(a: Key; b: PeerId; hasher: Opt[XorDHasher]): XorDistance {. ...raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc xorDistance(a: PeerId; b: Key; hasher: Opt[XorDHasher]): XorDistance {. ...raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
Methods
method isValid(self: DefaultEntryValidator; key: Key; record: EntryRecord): bool {. ...raises: [], gcsafe, tags: [], forbids: [].}
- Source Edit
method isValid(self: EntryValidator; key: Key; record: EntryRecord): bool {. base, ...raises: [], gcsafe, tags: [], forbids: [].}
- Source Edit
method select(self: DefaultEntrySelector; key: Key; records: seq[EntryRecord]): Result[ int, string] {....raises: [], gcsafe, tags: [], forbids: [].}
- Source Edit
method select(self: EntrySelector; key: Key; records: seq[EntryRecord]): Result[ int, string] {.base, ...raises: [], gcsafe, tags: [], forbids: [].}
- Source Edit
Templates
template chroniclesFormatItIMPL(it: Key): auto
- Source Edit
template withRpcSlot(kad: KadDHT)
- Acquire one rpcSem slot until the enclosing scope exits. The slot is released whether the scope exits normally, raises, or is cancelled. Source Edit