Expand description
§fastn-net
Network utilities and P2P communication between fastn entities.
This crate provides P2P networking capabilities for fastn entities using Iroh. Each fastn instance is called an “entity” in the P2P network, identified by its unique ID52 (a 52-character encoded Ed25519 public key).
§Example
use fastn_net::{global_iroh_endpoint, ping, PONG};
// Get the global Iroh endpoint for this entity
let endpoint = global_iroh_endpoint().await;
// Connect to another entity
let entity_id = "entity_id52_here".parse()?;
let connection = endpoint.connect(entity_id, "").await?;
// Open a bidirectional stream between entities
let (mut send, mut recv) = connection.open_bi().await?;
// Send ping and receive pong
ping(&mut send).await?;
let response = fastn_net::next_string(&mut recv).await?;
assert_eq!(response, PONG);§Supported Protocols
- Protocol::Ping- Test connectivity between entities
- Protocol::Http- Proxy HTTP requests through entities
- Protocol::Tcp- Tunnel TCP connections between entities
- Protocol::Socks5- SOCKS5 proxy support
Re-exports§
- pub use get_endpoint::get_endpoint;
- pub use http::ProxyResult;
- pub use protocol::APNS_IDENTITY;
- pub use protocol::Protocol;
- pub use protocol::ProtocolHeader;
Modules§
- dot_fastn 
- The fastn folder
- get_endpoint 
- http
- protocol
- Protocol multiplexing over P2P connections.
Macros§
Structs§
- Graceful
- Manages graceful shutdown of async tasks.
- HttpConnection Manager 
- Manages HTTP/1.1 connections for connection pooling.
Constants§
- ACK
- Acknowledgment message used in protocol handshakes.
- PONG
- Response message sent back after receiving a ping.
- SECRET_KEY_ FILE 
- Default file name for storing secret key.
Functions§
- accept_bi 
- Accepts an incoming bidirectional stream with the expected protocol.
- accept_bi_ with 
- Accepts an incoming bidirectional stream and reads additional data.
- generate_and_ save_ key 
- Generates a new secret key and saves it to the system keyring.
- generate_secret_ key 
- Generates a new Ed25519 secret key and returns its ID52.
- get_remote_ id52 
- Gets the ID52 string of the remote peer from a connection.
- get_secret_ key 
- Gets a secret key for a given ID52 and path.
- get_stream 
- Gets or creates a bidirectional stream to a remote peer.
- global_iroh_ endpoint 
- Returns a global singleton Iroh endpoint.
- http_to_ peer 
- Proxies an HTTP request to a remote peer over P2P.
- http_to_ peer_ non_ streaming 
- Use http_to_peer unless you have a clear reason Proxies an HTTP request to a remote peer (non-streaming version).
- id52_to_ public_ key 
- mkdir
- next_json 
- Reads a newline-terminated JSON message from a stream.
- next_string 
- Reads a newline-terminated string from a stream.
- peer_to_ http 
- Handles an incoming P2P request and proxies it to an HTTP server.
- peer_to_ tcp 
- this is the tcp proxy.
- ping
- Sends a ping message to test connectivity with a peer.
- pipe_tcp_ stream_ over_ iroh 
- public_key_ to_ id52 
- read_or_ create_ key 
- Reads an existing secret key or creates a new one if none exists.
- tcp_to_ peer 
Type Aliases§
- HttpConnection Pool 
- Connection pool for HTTP/1.1 connections.
- HttpConnection Pools 
- Collection of connection pools indexed by server address.
- IDMap
- Map of entity IDs to their port and endpoint.
- PeerStream Senders 
- Connection pool for P2P stream management.