This project implements a simple STUN (Session Traversal Utilities for NAT) and TURN (Traversal Using Relays around NAT) server using Go. It's designed to facilitate NAT traversal for peer-to-peer communications, making it easier for applications to establish direct connections between clients behind NATs.
- Combined STUN and TURN functionality
- Support for both IPv4 and IPv6
- Configurable via command-line flags and config file
- Customizable authentication endpoint
- Logging with adjustable log levels
- Go 1.16 or higher
- Make (for using the provided Makefile)
-
Clone the repository:
git clone https://github.com/yourusername/simple-turn.git cd simple-turn
-
Install dependencies:
make deps
-
Build the project:
make build
Run the server using the following command:
./simple-turn [flags]
Available flags:
-config
: Path to configuration file (default "config.json")-realm
: Realm for the TURN/STUN server (default "example.stunserver.com")-ipv4
: IPv4 address and port to bind to (default "0.0.0.0:3478")-ipv6
: IPv6 address and port to bind to (default "[::]:3478")-loglevel
: Log level (debug, info, warn, error) (default "info")-auth-endpoint
: URL to the authentication endpoint-v
or-version
: Print version and exit
Example:
./simple-turn -realm myserver.com -ipv4 0.0.0.0:3478 -loglevel debug -auth-endpoint https://myauth.com/validate
You can configure the server using a JSON configuration file. Create a config.json
file with the following structure:
{
"realm": "example.stunserver.com",
"ipv4_bind": "0.0.0.0:3478",
"ipv6_bind": "[::]:3478",
"log_level": "info",
"auth_endpoint": "https://myauth.com/validate"
}
The server supports external authentication. Set up your authentication endpoint and provide its URL using the -auth-endpoint
flag or in the configuration file. The endpoint should accept GET requests with a token
query parameter and return a 200 OK status for valid tokens.
- Run tests:
make test
- Clean build artifacts:
make clean
- Cross-compile:
- For Linux:
make build-linux
- For Windows:
make build-windows
- For macOS:
make build-mac
- For Linux:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.