Sign inSign up

kirari04/p2phttp

By kirari04

•Updated about 1 year ago

Image
0

288

kirari04/p2phttp repository overview

⁠p2phttp

This project provides a peer-to-peer HTTP client and server, acting as a proof-of-concept for a peer-to-peer HTTP proxy. It aims to be a simple alternative to solutions like Pangolin or Cloudflare Tunnel.

⁠Features

  • Peer-to-Peer HTTP Proxy: Establishes a direct connection between a client and a server to proxy HTTP requests.
  • Docker Support: Easy deployment using Docker containers and Docker Compose.
  • Configurable: Environment variables for server and client settings.
  • Local Development: Streamlined development workflow with air for live reloading.

⁠Deployment

This application can be deployed using Docker containers.

⁠Building Docker Images (Optional)

If you want to build the Docker images locally instead of using the pre-built images from Docker Hub, you can use the provided Makefile targets:

make build-server
make build-client
⁠Running Docker Containers
⁠Docker Compose

For easier deployment, you can use Docker Compose. This will set up both the p2phttp-server (which acts as the entry point for client connections) and the p2phttp-client (which proxies requests to a remote URL).

Create a docker-compose.yml file with the following content:

version: '3.8'
services:
  p2phttp-server:
    image: kirari04/p2phttp:server # Or use your locally built image: p2phttp:server
    ports:
      - "8677:8677"
    command: ["s"]
  p2phttp-client:
    image: kirari04/p2phttp:client # Or use your locally built image: p2phttp:client
    command: ["c"]

Then, run:

docker-compose up -d

This will start both the server and client containers in detached mode. You can verify they are running using docker-compose ps.

⁠Server (Manual Docker Run)

The p2phttp-server listens on port 8677 by default. To run the server container manually:

sudo docker run -p 8677:8677 kirari04/p2phttp:server # Or your locally built image
⁠Client (Manual Docker Run)

The p2phttp-client connects to the server and proxies requests to a remote URL. To run the client container manually:

sudo docker run kirari04/p2phttp:client # Or your locally built image
⁠Configuration

You can configure the server and client using environment variables. These can be set directly in your shell, in a .env file (for local development), or within your docker-compose.yml.

⁠Server Environment Variables
  • P2PHTTP_SERVER_LISTEN_ADDR: The address and port the server will listen on (default: 0.0.0.0:8677) Example for Docker Compose:
    services:
      p2phttp-server:
        environment:
          - P2PHTTP_SERVER_LISTEN_ADDR=0.0.0.0:8080
    
  • P2PHTTP_SERVER_TIMEOUT: Server timeout in seconds (default: 15) Example for Docker Compose:
    services:
      p2phttp-server:
        environment:
          - P2PHTTP_SERVER_TIMEOUT=30
    
⁠Client Environment Variables
  • P2PHTTP_CLIENT_WEBSOCKET_URL: The WebSocket URL for the client to connect to the server (default: ws://0.0.0.0:8677/p2phttp_internal/ws) Example for Docker Compose:
    services:
      p2phttp-client:
        environment:
          - P2PHTTP_CLIENT_WEBSOCKET_URL=ws://your-server-ip:8677/p2phttp_internal/ws
    
  • P2PHTTP_CLIENT_REMOTE_PROXY_URL: The URL of the remote proxy the client will connect to (default: https://github.com) Example for Docker Compose:
    services:
      p2phttp-client:
        environment:
          - P2PHTTP_CLIENT_REMOTE_PROXY_URL=https://www.google.com
    
  • P2PHTTP_CLIENT_TIMEOUT: Client timeout in seconds (default: 15) Example for Docker Compose:
    services:
      p2phttp-client:
        environment:
          - P2PHTTP_CLIENT_TIMEOUT=30
    
⁠Local Development

For local development and testing without Docker, you can run the server and client directly using Go.

First, ensure you have Go installed (version 1.24.3 or higher is recommended) and download the project dependencies:

make configure

This command installs air (a live-reloading tool for Go applications) and fetches all Go modules.

air provides live reloading, which is convenient for development.

# Run the server locally with live reloading
air s

# Run the client locally with live reloading
air c
⁠Running without air

You can also run the server and client directly using go run:

# Run the server locally
go run main.go s

# Run the client locally
go run main.go c

Environment variables for local development can be set in a .env file in the project root, or directly in your shell.

⁠Usage

Once the p2phttp-server and p2phttp-client are running (either via Docker Compose or locally), you can use the p2phttp-server as your proxy entry point.

The server will forward incoming HTTP requests to the connected client, which will then proxy the request to the P2PHTTP_CLIENT_REMOTE_PROXY_URL configured for the client.

For example, if your p2phttp-client is configured with P2PHTTP_CLIENT_REMOTE_PROXY_URL=https://github.com and your p2phttp-server is listening on 0.0.0.0:8677 (default), you can make a request to the server, and it will be proxied to GitHub:

curl -v http://localhost:8677/

This curl command will send a request to your p2phttp-server, which will then instruct the p2phttp-client to fetch content from https://github.com and return it to your curl client.

⁠Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

Tag summary

Content type

Image

Digest

sha256:bfca35a5c…

Size

12.1 MB

Last updated

about 1 year ago

docker pull kirari04/p2phttp:client