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 entitiesProtocol::Http- Proxy HTTP requests through entitiesProtocol::Tcp- Tunnel TCP connections between entitiesProtocol::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.
- Http
Connection 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§
- Http
Connection Pool - Connection pool for HTTP/1.1 connections.
- Http
Connection Pools - Collection of connection pools indexed by server address.
- IDMap
- Map of entity IDs to their port and endpoint.
- Peer
Stream Senders - Connection pool for P2P stream management.