Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mytai20100/tunnel-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tunnel-rust

Logo tunnel-rust

Version Language License Build Stars Forks Issues PRs Welcome

A fast and reliable mining tunnel built with Rust

FeaturesInstallationUsageAPIConfiguration


Features

  • High Performance: Built with Rust for maximum speed and safety
  • Real-time Monitoring: Live hashrate, shares, and network stats
  • TLS Support: Secure connections with TLS encryption
  • SQLite Database: Fast data storage with automatic cleanup
  • REST API: Full API for integration
  • Prometheus Metrics: Built-in metrics for monitoring
  • WebSocket Logs: Real-time log streaming
  • Multi-Pool Support: Connect to multiple mining pools

Requirements

Before you start, make sure you have:

  • Rust (latest stable version)
  • Cargo (comes with Rust)
  • Git

Installation

Step 1: Install Rust

Linux/macOS:

sudo apt update ; apt upgrade -y
sudo apt install -y build-essential clang pkg-config libc6-dev libclang-dev 
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

Windows: Download and install from rustup.rs

Step 2: Verify Installation

rustc --version
cargo --version

Step 3: Clone the Repository

git clone https://github.com/Mytai20100/tunnel-rust.git
cd tunnel-rust

Building from Source

Using the Build Script (Recommended)

Linux/macOS:

chmod +x build.sh
./build.sh

The build script will:

  1. Install Rust (if needed)
  2. Check Rust version
  3. Build the release version

Manual Build

# Development build (faster, with debug info)
cargo build

# Release build (optimized, slower to build)
cargo build --release

The compiled binary will be in:

  • Debug: target/debug/tunnel-rust
  • Release: target/release/tunnel-rust

Configuration

Create a config.yml file in the project root:

pools:
  pool1:
    host: "pool.example.com"
    port: 4444
    name: "Example Pool"
  
  pool2:
    host: "another-pool.com"
    port: 3333
    name: "Another Pool"

tunnels:
  tunnel1:
    ip: "0.0.0.0"
    port: 3333
    pool: "pool1"
  
  tunnel2:
    ip: "0.0.0.0"
    port: 3334
    pool: "pool2"

api_port: 8080

database:
  path: "tunnel.db"
  max_connections: 10

Usage

Basic Commands

# Run with default settings
./target/release/tunnel-rust

# Show help
./target/release/tunnel-rust --help

# Show version
./target/release/tunnel-rust --version

Command Options

Option Description
--nodata Disable database logging
--noapi Disable API server
--nodebug Minimal output (single line status)
--tls Enable TLS encryption
--tlscert TLS certificate file (default: cert.pem)
--tlskey TLS key file (default: key.pem)

Examples

# Run without database
./target/release/tunnel-rust --nodata

# Run with minimal output
./target/release/tunnel-rust --nodebug

# Run with TLS
./target/release/tunnel-rust --tls --tlscert=cert.pem --tlskey=key.pem

# Run without database and API
./target/release/tunnel-rust --nodata --noapi

TLS Setup (Optional)

Generate Self-Signed Certificate

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

Run with TLS

./target/release/tunnel-rust --tls --tlscert=cert.pem --tlskey=key.pem

API Endpoints

Get System Metrics

GET http://localhost:8080/api/metrics

Get Miner Info

GET http://localhost:8080/api/i/{wallet_address}

Get Network Stats

GET http://localhost:8080/api/network/stats?hours=24

Get Shares Stats

GET http://localhost:8080/api/shares/stats?wallet={address}&hours=24

Prometheus Metrics

GET http://localhost:8080/metrics

WebSocket Logs

WS ws://localhost:8080/api/logs/stream

Example API Response

GET /api/metrics:

{
  "system": {
    "cpu_model": "Intel Core i7",
    "cpu_cores": 8,
    "cpu_usage": "25.50%",
    "ram_total": 17179869184,
    "ram_used": 8589934592,
    "uptime": 3600
  },
  "network": {
    "download_gb": 1.25,
    "upload_gb": 0.85,
    "packets_sent": 150000,
    "packets_received": 145000
  },
  "miners": {
    "active": 5,
    "list": [...]
  }
}

Docker Support

Dockerfile

FROM rust:latest AS builder

WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

WORKDIR /root/
COPY --from=builder /app/target/release/tunnel-rust .
COPY config.yml .

EXPOSE 3333 8080
CMD ["./tunnel-rust"]

Build & Run

docker build -t tunnel-rust:latest .
docker run -d -p 3333:3333 -p 8080:8080 --name tunnel-rust tunnel-rust:latest

Systemd Service (Linux)

Create /etc/systemd/system/tunnel-rust.service:

[Unit]
Description=Rust Mining Tunnel
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/tunnel-rust
ExecStart=/root/tunnel-rust/target/release/tunnel-rust
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Enable & Start

sudo systemctl daemon-reload
sudo systemctl enable tunnel-rust
sudo systemctl start tunnel-rust
sudo systemctl status tunnel-rust

Development

Run Tests

cargo test

Check Code

cargo check

Format Code

cargo fmt

Run Linter

cargo clippy

Logs & Debugging

View Logs

# Application logs
tail -f /var/log/tunnel-rust.log

# Systemd logs
journalctl -u tunnel-rust -f

Contributing

Contributions are welcome! Here's how:

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

📄 License

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


Acknowledgments


Support


Made with ❤️ by mytai

Star this repo🐛Report BugRequest Feature

GitHub last commit GitHub commit activity GitHub contributors

About

tunnel coook with rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published