| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Network.LibP2P.NAT.Relay.Relay
Description
Circuit Relay v2 server: manage reservations and bridge streams.
Protocols: libp2pcircuitrelay0.2.0/hop (client ↔ relay)
Provides: - Reservation management (with expiration and limits) - Stream bridging between source and target - Resource limits (max reservations, max circuits, data/duration limits)
Synopsis
- data RelayConfig = RelayConfig {}
- data RelayState = RelayState {
- rsConfig :: !RelayConfig
- rsReservations :: !(TVar (Map PeerId ActiveReservation))
- rsCircuitCount :: !(TVar Int)
- data ActiveReservation = ActiveReservation {
- arPeerId :: !PeerId
- arExpiration :: !Word64
- defaultRelayConfig :: RelayConfig
- newRelayState :: RelayConfig -> IO RelayState
- handleReserve :: RelayState -> StreamIO -> PeerId -> IO ()
- handleConnect :: RelayState -> StreamIO -> PeerId -> HopMessage -> (PeerId -> IO (Maybe StreamIO)) -> IO ()
- bridgeStreams :: Maybe RelayLimit -> StreamIO -> StreamIO -> IO ()
- buildRelayAddrBytes :: ByteString -> ByteString -> ByteString -> ByteString
- isRelayedConnection :: ByteString -> Bool
Types
data RelayConfig Source #
Relay server configuration.
Constructors
| RelayConfig | |
Fields
| |
Instances
| Show RelayConfig Source # | |
Defined in Network.LibP2P.NAT.Relay.Relay Methods showsPrec :: Int -> RelayConfig -> ShowS # show :: RelayConfig -> String # showList :: [RelayConfig] -> ShowS # | |
| Eq RelayConfig Source # | |
Defined in Network.LibP2P.NAT.Relay.Relay | |
data RelayState Source #
Mutable relay server state.
Constructors
| RelayState | |
Fields
| |
data ActiveReservation Source #
An active reservation for a peer.
Constructors
| ActiveReservation | |
Fields
| |
Instances
| Show ActiveReservation Source # | |
Defined in Network.LibP2P.NAT.Relay.Relay Methods showsPrec :: Int -> ActiveReservation -> ShowS # show :: ActiveReservation -> String # showList :: [ActiveReservation] -> ShowS # | |
| Eq ActiveReservation Source # | |
Defined in Network.LibP2P.NAT.Relay.Relay Methods (==) :: ActiveReservation -> ActiveReservation -> Bool # (/=) :: ActiveReservation -> ActiveReservation -> Bool # | |
Configuration
defaultRelayConfig :: RelayConfig Source #
Default relay configuration.
State management
newRelayState :: RelayConfig -> IO RelayState Source #
Create new relay state from configuration.
Handlers
handleReserve :: RelayState -> StreamIO -> PeerId -> IO () Source #
Handle a RESERVE request from a peer.
handleConnect :: RelayState -> StreamIO -> PeerId -> HopMessage -> (PeerId -> IO (Maybe StreamIO)) -> IO () Source #
Handle a CONNECT request from a peer. The openStopStream callback is used to open a stop stream to the target.
Stream bridging
bridgeStreams :: Maybe RelayLimit -> StreamIO -> StreamIO -> IO () Source #
Bridge two streams bidirectionally with optional data/duration limits. Terminates when either direction closes or limits are exceeded.
Relay address helpers
buildRelayAddrBytes :: ByteString -> ByteString -> ByteString -> ByteString Source #
isRelayedConnection :: ByteString -> Bool Source #
Check if raw multiaddr bytes contain P2PCircuit (code 290). Simple heuristic: look for the varint encoding of 290.