E-Goat

module
v0.0.0-...-d0249f0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2025 License: MIT

README ΒΆ

E-Goat

E-Goat is a lightweight P2P messaging application built in Go that supports multiple connection types with automatic fallback. It combines WebRTC peer-to-peer connections, WebSocket communication, and HTTP polling to ensure reliable connectivity across different network environments.

e_goat

✨ Features

  • πŸ”— Layered Connection Architecture - Automatic fallback between multiple connection types
  • 🌐 WebRTC P2P Mesh - Direct peer-to-peer connections with minimal latency
  • ⚑ Real-time WebSocket - Bidirectional communication for instant messaging
  • πŸ”„ HTTP Polling Fallback - Universal compatibility across all network environments
  • πŸ’Ύ Local SQLite Storage - All messages stored locally with easy backup/migration
  • πŸ“± Single Binary - No dependencies beyond a web browser
  • πŸ§ͺ Comprehensive Testing - Full test suite for build verification and E2E communication

πŸš€ Quick Start

Build and Run
# Build the application
make build

# Run all verification tests
make test

# Start E-Goat
make run

# Or manually:
go build -o e-goat ./cmd/messanger
./e-goat -http-port=8080 -ws-port=9000 -db="$HOME/tmp/e-goat/chat.db"
Access the Application

Open http://localhost:8080 in your browser, create or join a room, and start chatting!

πŸ§ͺ Testing & Verification

E-Goat includes a comprehensive testing suite to ensure reliability and functionality:

Make Targets
# Run all tests (recommended)
make test

# Build verification only  
make verify

# Quick functionality test
make quick-test

# End-to-end communication test
make e2e-test

# Run complete verification
make all

# Clean up test artifacts
make clean
Test Scripts
  • ./scripts/build-verify.sh - Verifies build process and basic functionality
  • ./scripts/quick-test.sh - Fast single-instance functionality test
  • ./scripts/test-e2e.sh - Comprehensive two-instance communication test with network scenarios
  • ./scripts/run-tests.sh - Main test orchestrator with configurable options
  • ./scripts/cleanup.sh - Cleans up test artifacts and processes
Unit Tests
# Run unit tests for transport layer
go test -v ./tests/...

# Run with coverage
go test -cover ./tests/...
Script Options
./scripts/run-tests.sh --quick           # Quick tests only
./scripts/run-tests.sh --skip-e2e        # Skip end-to-end tests  
./scripts/run-tests.sh --interactive     # Interactive mode with prompts
Manual Testing

After running the E2E test, manually verify communication by opening:

Send messages between instances to verify real-time communication.

πŸ—οΈ Architecture Overview

E-Goat implements a layered connection architecture that automatically selects the best available connection method and gracefully falls back when connections fail.

Connection Priority System

E-Goat tries connection types in order of preference and performance:

  1. πŸš€ WebRTC STUN (Priority 100) - Direct P2P connections

    • Best performance, lowest latency
    • Works through most NATs
    • No server relay needed
  2. πŸ”„ WebRTC TURN (Priority 80) - Relayed P2P connections

    • Works through symmetric NATs
    • Uses TURN server relay
    • Maintains P2P encryption
  3. ⚑ WebSocket Direct (Priority 60) - Real-time TCP connections

    • Bidirectional real-time communication
    • Works in most corporate networks
    • Lower overhead than HTTP polling
  4. 🌐 HTTP Polling (Priority 40) - REST API fallback

    • Works everywhere HTTP works
    • Highest compatibility
    • Higher latency due to polling
  5. πŸ“‘ LAN Broadcast (Priority 20) - Local network discovery

    • Direct local network communication
    • No internet required
    • Perfect for local setups
Network Adaptation

The system automatically adapts to different network conditions:

  • 🟒 Perfect LAN: Uses WebRTC STUN for optimal performance
  • 🏒 Corporate Network: Falls back to WebSocket/HTTP
  • πŸ”’ Symmetric NAT: Automatically uses TURN relay
  • 🚫 Highly Restricted: HTTP polling ensures connectivity
Component Architecture
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ E-Goat Application                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚   HTTP Server   β”‚  β”‚ WebSocket Serverβ”‚  β”‚ Signaling Hub β”‚ β”‚
β”‚ β”‚   (Port 8080)   β”‚  β”‚   (Port 9000)   β”‚  β”‚   (WebRTC)    β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚            Layered Transport Manager                    β”‚ β”‚
β”‚ β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚ β”‚
β”‚ β”‚  β”‚WebRTC P2Pβ”‚ β”‚WebSocketβ”‚ β”‚HTTP Pollβ”‚ β”‚LAN Broadcastβ”‚   β”‚ β”‚
β”‚ β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ SQLite Storage  β”‚  β”‚        Web Interface               β”‚ β”‚
β”‚ β”‚ ($HOME/tmp/     β”‚  β”‚ (HTML/CSS/JavaScript)              β”‚ β”‚
β”‚ β”‚  e-goat/chat.db)β”‚  β”‚                                     β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Message Flow
  1. Connection Establishment: Client connects using the highest priority available method
  2. Automatic Failover: If connection fails, automatically tries next priority method
  3. Quality Monitoring: Continuously monitors connection quality and switches if needed
  4. Message Delivery: All connection types use the same message interface
  5. Persistent Storage: Messages stored locally in SQLite regardless of connection type

🌐 Network Configuration

Automatic Connection Selection

E-Goat automatically handles network configuration challenges:

  • No Configuration Needed: Works out-of-the-box on most networks
  • Smart Fallbacks: Automatically tries different connection methods
  • Quality Monitoring: Continuously optimizes connection performance
  • Universal Compatibility: HTTP polling ensures connectivity in any environment
NAT Traversal & Port Forwarding

By default the HTTP server (:8080) and signaling WS (:9000) listen on all interfaces, but most home networks sit behind NAT. To allow external peers to reach you without WebRTC STUN/TURN:

Quick Linux Setup (Firewall + Checks)
./scripts/setup-network.sh
sudo ./scripts/setup-network.sh --apply
./scripts/setup-network.sh --port-map
Router Port-Forwarding
# Forward these ports on your router:
# HTTP: 8080 β†’ your-machine:8080
# WebSocket: 9000 β†’ your-machine:9000

# External access URL format:
# http://YOUR_WAN_IP:8080/?room=myroom&peer_id=XYZ
Public Invite Base (Optional)

If you're running locally but want invite links to use a public IP or domain:

./e-goat -public-base="http://YOUR_WAN_IP:8080"
# or set EGOAT_PUBLIC_BASE=http://YOUR_WAN_IP:8080
Firewall Configuration
# UFW (Ubuntu/Debian)
sudo ufw allow 8080/tcp
sudo ufw allow 9000/tcp
sudo ufw reload

# firewalld (RHEL/CentOS)  
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --add-port=9000/tcp --permanent
sudo firewall-cmd --reload

# iptables
sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
sudo apt install iptables-persistent
sudo netfilter-persistent save
STUN/TURN Server Configuration

For WebRTC connections in complex network environments:

# Built-in STUN servers (Google)
# stun:stun.l.google.com:19302
# stun:stun1.l.google.com:19302

# Custom TURN server (optional)
# turn:your-turn-server.com:3478

πŸ”Œ API Reference

HTTP Endpoints (Port 8080)
Web Interface
  • GET / - Serves the chat UI (index.html, styles.css, chat.js)
  • GET /static/* - Serves frontend assets
REST API
  • GET /history?room=<name>&since=<timestamp>
    Returns JSON array of messages in room since timestamp

    [
      {
        "peer_id": "user123",
        "text": "Hello everyone!",
        "timestamp": 1625097600
      }
    ]
    
  • POST /send
    Accepts JSON message and returns timestamp

    // Request
    {
      "room": "general",
      "peer_id": "user123", 
      "text": "Hello world!"
    }
    
    // Response
    {
      "timestamp": 1625097600
    }
    
WebSocket Signaling (Port 9000)
  • ws://host:9000/signal?room=<name>&peer_id=<id>
    WebRTC signaling hub for SDP offers, answers, and ICE candidates

Signal message format:

{
  "peer_id": "user123",
  "type": "offer|answer|ice",
  "payload": "<SDP_or_ICE_data>"
}

βš™οΈ Technologies & Dependencies

Backend (Go)
  • Core Language: Go 1.21+ for single-binary builds
  • WebRTC: github.com/pion/webrtc/v3 - P2P connections and DataChannels
  • WebSockets: github.com/gorilla/websocket - Real-time communication
  • Database: github.com/mattn/go-sqlite3 - Embedded local storage
  • Standard Library: net/http, database/sql, embed, flag
Frontend
  • Vanilla JavaScript: WebRTC and WebSocket APIs
  • HTML/CSS: Minimal responsive design
  • No Frameworks: Zero dependencies, works in any modern browser
Transport Layer
  • Layered Architecture: Multiple connection types with automatic fallback
  • Quality Monitoring: Continuous connection performance assessment
  • Priority-Based Selection: Intelligent connection type prioritization

πŸ’» Frontend Implementation (web/chat.js)

The frontend implements automatic connection management and fallback strategies:

Core Functions
  • joinRoom(): Hides init UI, shows chat interface, displays HTTP deep-link invite
  • pollHistory(): Fetches new messages via REST API and appends to chat view
  • sendMessage(): Posts messages to /send endpoint with optimistic rendering
Connection Strategy
  • Automatically attempts WebRTC connections first for optimal performance
  • Falls back to HTTP polling if P2P connections fail
  • Generates shareable deep-link invites: http://host:8080/?room=name&peer_id=id

πŸ“ Project Structure

E-Goat/
β”œβ”€β”€ cmd/
β”‚   └── messanger/
β”‚       β”œβ”€β”€ main.go                    # Application entry point
β”‚       β”œβ”€β”€ transport_integration.go   # Transport layer integration
β”‚       └── web/
β”‚           β”œβ”€β”€ index.html             # Chat UI
β”‚           β”œβ”€β”€ chat.js                # Frontend logic
β”‚           └── styles.css             # Styling
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ signaling/
β”‚   β”‚   └── server.go                  # WebSocket signaling hub
β”‚   β”œβ”€β”€ storage/
β”‚   β”‚   └── sqlite.go                  # SQLite database management
β”‚   β”œβ”€β”€ transport/                     # Layered connection architecture
β”‚   β”‚   β”œβ”€β”€ connection.go              # Core interfaces and manager
β”‚   β”‚   β”œβ”€β”€ webrtc_stun.go            # WebRTC STUN connections
β”‚   β”‚   β”œβ”€β”€ webrtc_turn.go            # WebRTC TURN connections
β”‚   β”‚   β”œβ”€β”€ websocket_direct.go       # Direct WebSocket connections
β”‚   β”‚   β”œβ”€β”€ http_polling.go           # HTTP polling fallback
β”‚   β”‚   β”œβ”€β”€ lan_broadcast.go          # LAN broadcast discovery
β”‚   β”‚   └── manager.go                # Transport manager wrapper
β”‚   └── webrtc/
β”‚       └── peer.go                   # WebRTC peer connection logic
β”œβ”€β”€ scripts/                          # Testing and automation scripts
β”‚   β”œβ”€β”€ build-verify.sh               # Build verification
β”‚   β”œβ”€β”€ quick-test.sh                 # Quick functionality test
β”‚   β”œβ”€β”€ test-e2e.sh                   # End-to-end communication test
β”‚   β”œβ”€β”€ run-tests.sh                  # Main test orchestrator
β”‚   β”œβ”€β”€ cleanup.sh                    # Test cleanup
β”‚   └── README.md                     # Testing documentation
β”œβ”€β”€ tests/
β”‚   └── transport_test.go             # Unit tests for transport layer
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml                    # GitHub Actions CI/CD
β”œβ”€β”€ Makefile                          # Build automation
β”œβ”€β”€ go.mod                            # Go module definition
β”œβ”€β”€ go.sum                            # Go module checksums
└── README.md                         # This file

🀝 Contributing

We welcome contributions! Please follow these guidelines:

  1. Open an Issue: For significant changes, open an issue first to discuss
  2. Fork the Repository: Create your own fork of the project
  3. Create a Branch: Use a descriptive branch name for your changes
  4. Write Tests: Ensure your changes include appropriate tests
  5. Update Documentation: Update README and comments as needed
  6. Submit a Pull Request: Include a clear description of your changes
Development Workflow
# Fork and clone the repository
git clone https://github.com/your-username/E-Goat.git
cd E-Goat

# Create a feature branch
git checkout -b feature/your-feature-name

# Make your changes and test them
make test

# Commit and push your changes
git commit -m "Add your feature description"
git push origin feature/your-feature-name

# Create a pull request on GitHub

πŸ“„ License

E-Goat is licensed under the MIT License.

🎯 Roadmap

Current Focus
  • Frontend WebRTC Integration - Complete JavaScript WebRTC implementation
  • Transport Layer Integration - Connect layered architecture to main application
Near-Term Goals
  • Mobile-Responsive UI - Improved mobile experience
  • File Sharing - Binary file transfer over DataChannels
  • End-to-End Encryption - Additional security layer
Future Vision
  • Voice/Video Chat - WebRTC media channels
  • Docker Support - Containerized deployment
  • Plugin System - Extensible architecture
  • Federation - Cross-instance communication

πŸ”— External Access & Sharing

Once port-forwarding and firewall rules are configured, you can share external links:

http://YOUR_WAN_IP:8080/?room=myroom&peer_id=XYZ

This allows external users to join your chat rooms directly through your public IP address.


Made with ❀️ in Go - E-Goat provides reliable peer-to-peer communication with automatic network adaptation, ensuring your messages get through no matter the network conditions.

Directories ΒΆ

Path Synopsis
cmd
messanger command
cmd/messanger/transport_integration.go
cmd/messanger/transport_integration.go
internal
metrics
internal/metrics/metrics.go
internal/metrics/metrics.go
middleware
internal/middleware/middleware.go
internal/middleware/middleware.go
signaling
internal/signaling/server.go
internal/signaling/server.go
storage
internal/storage/sqlite.go
internal/storage/sqlite.go
transport
internal/transport/connection.go
internal/transport/connection.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL