Crate fastn_net

Source
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

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§

bad_request
not_found
server_error

Structs§

Graceful
Manages graceful shutdown of async tasks.
HttpConnectionManager
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§

HttpConnectionPool
Connection pool for HTTP/1.1 connections.
HttpConnectionPools
Collection of connection pools indexed by server address.
IDMap
Map of entity IDs to their port and endpoint.
PeerStreamSenders
Connection pool for P2P stream management.