TLS Examples package

Submodules

examples.tls.example_tls_client module

TLS-Enabled Py-libp2p Bidirectional Chat Client Example

This example demonstrates how to connect to a TLS-enabled py-libp2p host and engage in true bidirectional chat sessions where both client and server can send and receive messages simultaneously.

Features:

  • TLS 1.3 encryption for secure client-server communication

  • Three communication modes: - single message echo, - full-duplex bidirectional chat, and - ping latency testing

  • Automatic certificate verification and peer identity validation

  • Graceful error handling and connection management

  • Concurrent send/receive operations for real-time chat experience

Usage:

tls-client-demo --server MULTIADDR [--mode MODE] [--message MESSAGE] [--count COUNT]

Modes:

  • echo: Send a single message and receive the echo response (default)

  • chat: Both client and server can send/receive simultaneously

  • ping: Send ping requests and measure round-trip time

Examples:

# Echo mode (default)
tls-client-demo --server /ip4/127.0.0.1/tcp/8000/p2p/12D3Koo....

# Bidirectional chat mode - real-time conversation
tls-client-demo --server /ip4/127.0.0.1/tcp/8000/p2p/12D3Koo....
--mode chat

# Custom message in echo mode
tls-client-demo --server /ip4/127.0.0.1/tcp/8000/p2p/12D3Koo....
--message "Hello TLS!"

# Ping mode - test latency
tls-client-demo --server /ip4/127.0.0.1/tcp/8000/p2p/12D3Koo....
--mode ping --count 10
async examples.tls.example_tls_client.chat_mode(host, server_maddr: str) None

Bidirectional chat with server.

async examples.tls.example_tls_client.echo_mode(host, server_maddr: str, message: str) None

Send a single message and receive echo response.

examples.tls.example_tls_client.main() None
async examples.tls.example_tls_client.ping_mode(host, server_maddr: str, count: int) None

Send ping requests and measure round-trip time.

async examples.tls.example_tls_client.run(server: str, mode: str, message: str, count: int, seed: int | None = None) None

examples.tls.example_tls_server module

TLS-Enabled Py-libp2p Bidirectional Chat Server Example

This example demonstrates how to create a TLS-enabled py-libp2p host that acts as a bidirectional chat server. The server listens for incoming TLS connections and engages in full-duplex chat sessions where both server and client can send messages simultaneously.

Features: - TLS 1.3 encryption for secure peer-to-peer communication - Self-signed certificates with embedded peer identities - True bidirectional chat with concurrent send/receive - Automatic peer ID verification during TLS handshake - Graceful handling of chat session lifecycle - Server can initiate messages to clients

Usage:

tls-demo [–port PORT] [–seed SEED]

The server will print its listening addresses with peer ID. Use these addresses to connect clients for interactive bidirectional chat sessions.

Example:

tls-demo -p 8000

examples.tls.example_tls_server.main() None
async examples.tls.example_tls_server.run(port: int, seed: int | None = None) None

Module contents