Expand description
Client SDK for a deployed pb-mapper relay.
A Client holds a relay address and a credential. register publishes a
local TCP or UDP service under a key, and connect makes that service
reachable on a local port. Every connection tries a direct QUIC path first
and falls back to the relay before any byte is sent; reconnection and
recovery are handled inside the returned handles.
ⓘ
use std::time::Duration;
use pb_mapper::{Client, ClientConfig, ConnectRequest, RegisterRequest, Transport};
let client = Client::new(ClientConfig {
server: "relay.example.com:7666".into(),
credential: std::env::var("MSG_HEADER_KEY").expect("MSG_HEADER_KEY"),
keep_alive: true,
namespace: None,
})?;
let registration = client
.register(RegisterRequest {
key: "echo".into(),
local_addr: "127.0.0.1:8080".into(),
transport: Transport::Tcp,
codec: false,
force_namespace: false,
})
.await?;
registration.wait_ready().await?;
let connection = client
.connect(ConnectRequest {
key: "echo".into(),
local_addr: "127.0.0.1:9090".into(),
transport: Transport::Tcp,
})
.await?;
connection.wait_ready().await?;
// Status changes as they happen, and what recovery did.
let mut status = connection.subscribe();
status.changed().await.ok();
println!("{:?} {:?}", *status.borrow(), connection.diagnostics().events);
// With the administrator key: a scoped, expiring credential for a workload.
let issued = client
.admin()?
.issue_key(Duration::from_secs(3600), Some("agent".into()))
.await?;
client.admin()?.revoke_key(issued.key_id).await?;
connection.stop().await?;
registration.stop().await?;Runnable examples for every capability are in examples/; start with
cargo run -p pb-mapper --example quickstart, which needs no relay of your
own. The CLI and relay binary are the pb-mapper-cli package
(cargo install pb-mapper-cli).
Structs§
- Admin
- Administrator RPCs. Constructed via
super::Client::admin. - Auth
Status Info - Relay-side snapshot of the credential subsystem.
- Client
- Session against one deployed relay.
- Client
Config - Configuration for a
Clientsession. - Connect
Options - Connect
Request - Subscribe to a registered service and listen locally.
- Connection
- A live
connecttunnel: a local listener forwarding to a registered service. - Connection
Info - One control connection the relay holds for a registered service.
- Connection
Page - One page of live service connections.
- Direct
Attempt - The direct attempt a tunnel is making right now.
- Events
Lagged - A
TunnelEventssubscriber fell behind and missedskippedevents. - Issued
Key - A temporary credential, with the secret the relay just minted.
- KeyList
Page - One page of temporary credentials.
- KeyMetadata
- A temporary credential without its secret.
- Observed
Report - Path
Diagnostics - Port
Mapping Diagnostics - A tunnel’s port mapping: where it stands, and what it took to get there.
- Port
Mapping Status - A gateway mapping as it stands after its latest change. Credential-free; what the gateway said about a failure is cut to 256 characters.
- Quic
Connection Diagnostics - Cumulative Quinn counters for one live connection; sampled only on request.
- Register
Options - Register
Request - Register a local TCP/UDP service with the relay.
- Registration
- A live
registertunnel: a local service published on the relay. - Relay
Diagnostics - The relay carrier as this client’s pool sees it, sampled on request.
- Remote
Id - Relay mapping dump from
status remote-id. - Service
Connection - One control connection the relay is holding for a service key.
- Service
Info - A registered service as the relay sees it.
- Service
Page - One page of registered services.
- Session
Observation - Tunnel
Diagnostics - A point-in-time view of this tunnel and its process-shared relay budget. Non-exhaustive: fields are added as the SDK observes more.
- Tunnel
Event - One event of a tunnel. In
TunnelDiagnostics::events, oldest first, consecutive repeats fold into one entry, so a long outage cannot push out what came before it;TunnelEventsdelivers every occurrence. - Tunnel
Events - A tunnel’s events as they happen, after the history it has kept: from
subscribe_eventson aRegistrationor aConnection.
Enums§
- Direct
Stage - Where a direct attempt stands. Every stage before
Self::Committingcan still fall back to the relay; a fallback names the stage it left. - Error
- Errors returned by the client SDK.
- Legacy
Protocol - Legacy framing policy, matching
pb-mapper admin legacy-protocol. - Path
Policy - Per-connect path policy.
- Port
Mapping - Whether a tunnel asks this network’s router (PCP, NAT-PMP or UPnP) to map
its direct endpoint’s UDP port, so that a peer’s first packet gets in
where the NAT drops what it has not seen. A mapping never holds up a
session, is renewed while the tunnel runs and released when it stops,
and is ignored while the tunnel keeps to the relay;
TunnelDiagnostics::port_mappingsays where it stands. - Port
Mapping Protocol - How a gateway is asked for a mapping.
- Port
Mapping Stage - Where a gateway mapping stands. A lease outlives some stages: whether one
is usable right now is
PortMappingStatus::active. - Recovery
Failure - Why a recovery attempt failed, without credentials or application data.
- Recovery
Phase - The phase most recently entered by a tunnel worker.
- Relay
Transport - Session
Path - Session
State - Transport
- Transport used by a registered service or a local subscriber.
- Tunnel
Event Kind - What happened, in a
TunnelEvent. - Tunnel
Status - Observed lifecycle of a
super::Registrationorsuper::Connection.
Constants§
- QUIC_
UNAVAILABLE - The refusal code for a relay that offers no QUIC: one started without a QUIC listener, or one from before QUIC, which cannot read the question. Final, since retrying the same relay cannot change it, and so a tunnel asked to use QUIC there fails rather than retrying forever.
- SDK_
VERSION - The SDK version compiled into this process.