| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.NAT.Relay.Transport
Description
Circuit Relay v2 client transport (specsrelaycircuit-v2).
Turns a p2p-circuit multiaddr into a first-class Transport so that
relayed peers become ordinary Connections in the Switch's pool.
The spec states that once the hop CONNECT (dialer side) or stop
CONNECT (target side) exchange succeeds, "the original stream becomes
the relayed connection", which clients then upgrade "with a security
protocol and a multiplexer, just like they would e.g. upgrade a TCP
connection". This module produces the RawConnection for that stream;
the existing upgrade pipeline in LibP2P.Switch.Upgrade does the rest.
Outbound: dial the relay, negotiate hop, send CONNECT, hand the
stream to the Switch as a raw connection.
Inbound: transportListen reserves on a relay and registers a queue
keyed by that relay's peer id. The stop protocol handler calls
acceptStopStream, which enqueues the relayed stream; the Switch's
accept loop then drives it through the normal inbound path (gating,
upgrade, resource limits, pool, notifiers, teardown).
Synopsis
- data CircuitState
- newCircuitState :: IO CircuitState
- data ReservationRefreshConfig = ReservationRefreshConfig {
- rrcMargin :: !POSIXTime
- rrcPollInterval :: !Int
- defaultReservationRefreshConfig :: ReservationRefreshConfig
- circuitTransport :: Switch -> CircuitState -> ReservationRefreshConfig -> Transport
- acceptStopStream :: CircuitState -> Connection -> PeerId -> StreamIO -> IO ()
- data CircuitAddr = CircuitAddr {}
- parseCircuitAddr :: Multiaddr -> Either String CircuitAddr
- circuitAddrOf :: Multiaddr -> PeerId -> Maybe PeerId -> Multiaddr
Shared state
data CircuitState Source #
Per-Switch state shared between the circuit transport and the stop
protocol handler: one inbound queue per relay we hold a reservation on.
newCircuitState :: IO CircuitState Source #
Create empty circuit state.
Reservation refresh
data ReservationRefreshConfig Source #
Tuning for client-side reservation refresh (specsrelaycircuit-v2: "the reservation becomes invalid after this time and it's the responsibility of the client to refresh").
Values follow go-libp2p's autorelay relay finder
(rsvpExpirationSlack / rsvpRefreshInterval): refresh once the
reservation is within rrcMargin of its expiry, checked every
rrcPollInterval.
Constructors
| ReservationRefreshConfig | |
Fields
| |
Instances
| Show ReservationRefreshConfig Source # | |
Defined in LibP2P.NAT.Relay.Transport Methods showsPrec :: Int -> ReservationRefreshConfig -> ShowS # show :: ReservationRefreshConfig -> String # showList :: [ReservationRefreshConfig] -> ShowS # | |
| Eq ReservationRefreshConfig Source # | |
Defined in LibP2P.NAT.Relay.Transport Methods (==) :: ReservationRefreshConfig -> ReservationRefreshConfig -> Bool # (/=) :: ReservationRefreshConfig -> ReservationRefreshConfig -> Bool # | |
defaultReservationRefreshConfig :: ReservationRefreshConfig Source #
Default refresh tuning: a 2 minute margin, checked every minute.
Transport
circuitTransport :: Switch -> CircuitState -> ReservationRefreshConfig -> Transport Source #
The Circuit Relay v2 client transport.
Captures the Switch so it can dial the relay; register it after
newSwitch with addTransport.
Inbound relayed streams
acceptStopStream :: CircuitState -> Connection -> PeerId -> StreamIO -> IO () Source #
Hand a relayed stream that arrived via the stop protocol to the
listener for the relay it came over.
The stream is closed when no listener is registered for that relay: without a reservation we have nothing to accept the circuit into.
Address handling (exported for testing)
data CircuitAddr Source #
A parsed circuit multiaddr.
Wire form: <relayTransportAddr>/p2p/<relay>/p2p-circuit[/p2p/<target>].
The target component is present when dialling and absent when listening.
Constructors
| CircuitAddr | |
Instances
| Show CircuitAddr Source # | |
Defined in LibP2P.NAT.Relay.Transport Methods showsPrec :: Int -> CircuitAddr -> ShowS # show :: CircuitAddr -> String # showList :: [CircuitAddr] -> ShowS # | |
| Eq CircuitAddr Source # | |
Defined in LibP2P.NAT.Relay.Transport | |
parseCircuitAddr :: Multiaddr -> Either String CircuitAddr Source #
Parse a circuit multiaddr into its relay and target parts.