Skip to content

Setup a websocket libp2p relay with letsencrypt and nginx

License

Notifications You must be signed in to change notification settings

silkroadnomad/libp2p-relay

Repository files navigation

libp2p-relay

Test Status Coverage Status License Last Commit Open Issues Forks Stars

Overview

libp2p-relay is a project designed to facilitate peer-to-peer communication using the libp2p protocol. It includes a Dockerized setup for easy deployment, a pubsub protocol for message broadcasting, an HTTP server for web interactions, and a pinning service to ensure data persistence. For more details on the pinning service, see the Pinning Service Documentation.

Features

  • Docker Compose Setup: Simplifies deployment and management of the application.
  • Pubsub Protocol: Enables efficient message broadcasting between peers.
  • HTTP Server: Provides a web interface for interaction and management.
  • Pinning Service: Ensures data is persistently stored and accessible.
  • Circuit Relay: Facilitates connections between peers that are behind NATs or firewalls.
  • Auto-NAT: Automatically detects network address translation to optimize peer connections.
  • DCUTR (Direct Connection Upgrade Through Relay): Enables hole punching to establish direct connections between peers.
  • Secure WebSocket: Ensures secure communication over WebSocket connections.

Prerequisites

  • Docker and Docker Compose installed on your system.
  • Node.js and npm for local development and testing.

Installation

  1. Clone the Repository:

    git clone https://github.com/silkroadnomad/libp2p-relay.git
    cd libp2p-relay/relay
  2. Environment Configuration:

    • Copy .env.example to .env and configure the environment variables as needed.
  3. Modify Docker Compose:

    • Ensure the docker-compose.yml file is correctly set up for your environment.

Usage

Running with Docker

  1. Initialize Let's Encrypt:

    • Modify init-letsencrypt.sh to set up your domain.
    • Run the script to generate SSL certificates:
      ./init-letsencrypt.sh
  2. Start the Services:

    • Use Docker Compose to start the services:
      docker-compose up -d
  3. Check Logs:

    • View logs to find the libp2p address:
      docker-compose logs

Running Locally

  1. Install Dependencies:

    npm install
  2. Start the Relay:

    node relay/src/relay.js
  3. Debug Mode:

    • Run with debug mode enabled:
      DEBUG=libp2p:* node relay/src/relay.js

Pubsub Protocol

The pubsub protocol is used for broadcasting messages between peers. Ensure your topics and subscriptions are correctly configured in the .env file.

HTTP Server

The HTTP server provides a web interface for managing the relay and viewing status information. Access it via the configured domain or IP address.

Pinning Service

The IPFS pinning service ensures that data is persistently stored. It interacts with the blockchain to verify and pin content based on transactions.

Running Tests

To ensure the reliability and correctness of the libp2p-relay project, tests are provided in the relay/tests directory. Follow these steps to run the tests:

  1. Start Test Services:

    • Use Docker Compose to start the test services:
      docker compose -f docker-compose-test.yml up -d
  2. Run Tests:

    • Execute the tests using npm:
      npm test

Ensure that your environment is correctly configured before running the tests. The test services should be running to provide the necessary infrastructure for the tests.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or support, please open an issue on the GitHub repository.