hs-libp2p-0.2.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.DHT.Maintenance

Description

DHT provider republishing and value-record expiry maintenance.

Synopsis

Documentation

data DHTMaintenanceConfig Source #

Scheduling, expiry, and per-tick work limits for DHT maintenance.

Constructors

DHTMaintenanceConfig 

Fields

defaultDHTMaintenanceConfig :: DHTMaintenanceConfig Source #

go-libp2p Amino DHT defaults: providers republish every 22 hours, value records expire after 48 hours, and value GC runs every 24 hours.

data DHTMaintenanceState Source #

Mutable worker state owned by one DHT node.

startValueGCWorker :: DHTMaintenanceState -> TVar Bool -> TVar (Map ByteString DHTRecord) -> IO () Source #

Start the bounded value-record GC loop. Non-positive age or interval disables the worker, matching go-libp2p's configuration semantics.

runValueGCTick :: DHTMaintenanceState -> TVar (Map ByteString DHTRecord) -> IO () Source #

Delete at most one configured batch of expired records.

ensureProviderWorker :: DHTMaintenanceState -> TVar Bool -> IO Int -> IO () Source #

Start the provider worker once. After each configured interval it walks every locally provided key in bounded batches, yielding between batches.

stopDHTMaintenance :: DHTMaintenanceState -> IO () Source #

Cancel every maintenance worker and clear their handles.

storeReceivedRecord :: DHTMaintenanceState -> TVar (Map ByteString DHTRecord) -> DHTRecord -> IO () Source #

Store a value record with a receiver-controlled timestamp.

lookupLiveRecord :: DHTMaintenanceState -> TVar (Map ByteString DHTRecord) -> ByteString -> IO (Maybe DHTRecord) Source #

Read a live record, deleting malformed, misfiled, or expired data.

recordIsExpired :: DHTMaintenanceState -> UTCTime -> DHTRecord -> Bool Source #

Whether a record is older than the configured maximum age. Missing or malformed receive times are expired when age checking is enabled.

rememberLocalProvider :: DHTMaintenanceState -> ByteString -> [Multiaddr] -> IO () Source #

Track a key that this node still provides.

nextLocalProviderBatch :: DHTMaintenanceState -> IO [(ByteString, [Multiaddr])] Source #

Select the next bounded provider batch, rotating through the keyspace so a large provider set cannot starve keys beyond the first batch.