| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.DHT.DHT
Description
DHT node state, RPC handler, and record/provider stores.
The DHTNode is the top-level coordinator for Kademlia DHT operations. It owns the routing table, record store, provider store, and handles both inbound (as handler) and outbound (sendDHTRequest) RPC.
For testability, sendDHTRequest is a field of DHTNode, allowing mock injection in tests without real network connections.
Synopsis
- data DHTNode = DHTNode {
- dhtSwitch :: !Switch
- dhtRoutingTable :: !(TVar RoutingTable)
- dhtRecordStore :: !(TVar (Map ByteString DHTRecord))
- dhtProviderStore :: !(TVar (Map ByteString [ProviderEntry]))
- dhtLocalKey :: !DHTKey
- dhtLocalPeerId :: !PeerId
- dhtMode :: !DHTMode
- dhtSendRequest :: !(PeerId -> DHTMessage -> IO (Either String DHTMessage))
- data DHTMode
- data ProviderEntry = ProviderEntry {
- peProvider :: !PeerId
- peAddrs :: ![Multiaddr]
- peTimestamp :: !UTCTime
- data Validator = Validator {
- valValidate :: ByteString -> ByteString -> Either String ()
- valSelect :: ByteString -> [ByteString] -> Either String Int
- newDHTNode :: Switch -> DHTMode -> IO DHTNode
- registerDHTHandler :: DHTNode -> IO ()
- handleDHTRequest :: DHTNode -> StreamIO -> PeerId -> IO ()
- storeRecord :: DHTNode -> DHTRecord -> IO ()
- lookupRecord :: DHTNode -> ByteString -> IO (Maybe DHTRecord)
- addProvider :: DHTNode -> ByteString -> ProviderEntry -> IO ()
- getProviders :: DHTNode -> ByteString -> IO [ProviderEntry]
- dhtProtocolId :: Text
Types
Top-level DHT node state.
Constructors
| DHTNode | |
Fields
| |
Server or client mode.
Instances
data ProviderEntry Source #
A provider record for content routing.
Constructors
| ProviderEntry | |
Fields
| |
Instances
| Show ProviderEntry Source # | |
Defined in Network.LibP2P.DHT.DHT Methods showsPrec :: Int -> ProviderEntry -> ShowS # show :: ProviderEntry -> String # showList :: [ProviderEntry] -> ShowS # | |
| Eq ProviderEntry Source # | |
Defined in Network.LibP2P.DHT.DHT Methods (==) :: ProviderEntry -> ProviderEntry -> Bool # (/=) :: ProviderEntry -> ProviderEntry -> Bool # | |
Validator interface for record validation.
Constructors
| Validator | |
Fields
| |
Construction
Handler registration
registerDHTHandler :: DHTNode -> IO () Source #
Register the DHT handler on the Switch (server mode only).
Inbound RPC handler
handleDHTRequest :: DHTNode -> StreamIO -> PeerId -> IO () Source #
Handle an inbound DHT RPC request.
Store operations
lookupRecord :: DHTNode -> ByteString -> IO (Maybe DHTRecord) Source #
Look up a record by key.
addProvider :: DHTNode -> ByteString -> ProviderEntry -> IO () Source #
Add a provider entry for a content key.
getProviders :: DHTNode -> ByteString -> IO [ProviderEntry] Source #
Get providers for a content key.
Constants
dhtProtocolId :: Text Source #
DHT protocol identifier for multistream-select.