Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Git
.git
.gitignore

# Build artifacts
build/
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out

# IDE files
.idea/
.vscode/

# OS files
.DS_Store
Thumbs.db

# Docker files
Dockerfile
docker-compose.yml
.dockerignore

# Documentation
README.md
docs/

# Other
*.md
!README.md
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Example environment variables for NTRIP server
# Copy this file to .env and modify as needed

# Admin API key (required for admin API authentication)
# Generate a secure random key for production use
ADMIN_API_KEY=change_this_to_a_secure_random_key

# Logging level (debug, info, warn, error)
LOG_LEVEL=info
5 changes: 2 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ '*' ]

jobs:

Expand All @@ -16,7 +15,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ^1.22

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
.env
# Go workspace file
go.work

# IDE-specific files
.idea/
.vscode/

# OS-specific files
.DS_Store
Thumbs.db

# Build directory contents except .gitkeep
/build/*
!/build/.gitkeep
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM golang:1.24-alpine AS builder

# Install build dependencies
RUN apk add --no-cache gcc musl-dev

WORKDIR /app

# Copy go.mod and go.sum first to leverage Docker cache
COPY go.mod go.sum ./
RUN go mod download

# Copy the rest of the source code
COPY . .

# Build the application
RUN CGO_ENABLED=1 go build -o /ntrip-server ./cmd/ntrip-server/main.go

# Create a minimal runtime image
FROM alpine:latest

# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata sqlite

# Create a non-root user to run the application
RUN adduser -D -h /app ntrip
USER ntrip
WORKDIR /app

# Create data directory for SQLite database
RUN mkdir -p /app/data

# Copy the binary from the builder stage
COPY --from=builder --chown=ntrip:ntrip /ntrip-server /app/ntrip-server

# Expose ports
EXPOSE 2101 554 2102 8080

# Set default command
ENTRYPOINT ["/app/ntrip-server"]
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
### NTRIP Caster / Client / Server implementation in Go
# NTRIP Caster / Client / Server implementation in Go

[![Go Report Card](https://goreportcard.com/badge/github.com/go-gnss/ntrip)](https://goreportcard.com/report/github.com/go-gnss/ntrip)

## Overview

This package provides a complete implementation of the NTRIP (Networked Transport of RTCM via Internet Protocol) protocol in Go. It supports both NTRIP version 1 and 2, as well as additional features like RTSP/RTP support, sourcetable filtering, advanced authentication mechanisms, and NTRIP v1 SOURCE request handling.

## Features

### Core NTRIP Features
- NTRIP v1 and v2 client and server support
- Sourcetable parsing and generation
- Chunked transfer encoding for v2
- Basic authentication

### Advanced Features
- **RTSP/RTP Support**: Stream GNSS data over RTSP/RTP protocol
- **Sourcetable Filtering**: Filter sourcetable entries based on various criteria
- **Advanced Authentication**: Support for Basic, Digest, and Bearer authentication methods
- **NTRIP v1 SOURCE Request Handling**: Support for NTRIP v1 SOURCE requests

## Usage Examples

### Client Examples
Examples of NTRIP client implementations in [client_test.go](/client_test.go).

### Caster Examples
An example of setting up a Caster can be found in [internal/inmemory](/internal/inmemory/service_test.go).

### Complete Server Example
A complete server example with all features can be found in [cmd/ntrip-server](/cmd/ntrip-server/main.go).

## Sourcetable Filtering

The sourcetable filtering feature allows clients to request a filtered view of the sourcetable based on various criteria. The filter query can be specified in the URL query string.

Example filter queries:
```
?STR;;;;;;DEU # Filter streams in Germany
?&Bitrate>5000 # Filter streams with bitrate > 5000
?&NavSystem~GAL # Filter streams that include Galileo
?&CountryCode=USA&NMEA=true # Filter streams in USA with NMEA support
```

## Authentication

The package supports multiple authentication methods:

- **Basic Authentication**: Standard HTTP Basic authentication
- **Digest Authentication**: More secure authentication method that doesn't transmit passwords in clear text
- **Bearer Authentication**: Token-based authentication

Authentication can be configured per mount point, allowing different authentication methods for different streams.

## RTSP/RTP Support

The RTSP/RTP support allows streaming GNSS data over the RTSP protocol, which is more suitable for some network configurations and can provide better performance in certain scenarios.

The RTSP server supports the standard RTSP methods (OPTIONS, DESCRIBE, SETUP, PLAY, PAUSE, TEARDOWN) and generates appropriate SDP descriptions for GNSS data streams.

## NTRIP v1 SOURCE Request Handling

The package includes support for NTRIP v1 SOURCE requests, which allows NTRIP v1 servers to connect to the caster and provide data streams. This is implemented as a separate server that listens on a dedicated port.
119 changes: 119 additions & 0 deletions admin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# NTRIP Caster Admin API

This package implements an admin API for the NTRIP caster, providing endpoints for managing API keys, users, and mountpoints.

## Features

- **API Key Management**: Create, list, and revoke API keys with specific permissions
- **User Management**: Manage NTRIP client users, their credentials, and mount access
- **Mountpoint Management**: Configure and monitor mountpoints
- **SQLite Storage**: Persistent storage using SQLite database
- **Secure Authentication**: API key-based authentication with permission control

## Usage

### Importing the Package

```go
import "github.com/go-gnss/ntrip/admin"
```

### Creating and Starting the Server

```go
// Create a logger
logger := logrus.New()

// Create the admin server
adminServer, err := admin.NewServer(":8080", "data/ntrip.db", logger)
if err != nil {
logger.Fatalf("Failed to create admin server: %v", err)
}

// Start the server
go func() {
logger.Infof("Starting admin API server on port 8080")
if err := adminServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logger.Fatalf("Admin API server error: %v", err)
}
}()

// Graceful shutdown
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := adminServer.Shutdown(ctx); err != nil {
logger.Errorf("Error closing admin API server: %v", err)
}

// Close the admin database
if err := adminServer.Close(); err != nil {
logger.Errorf("Error closing admin database: %v", err)
}
```

### Authentication

The admin API uses API keys for authentication. The admin API key is set via the `ADMIN_API_KEY` environment variable and has full access to all endpoints.

### Database Schema

The package uses SQLite for data storage with the following schema:

#### API Keys Table

```sql
CREATE TABLE api_keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
permissions TEXT NOT NULL,
expires DATETIME,
created DATETIME DEFAULT CURRENT_TIMESTAMP
)
```

#### Users Table

```sql
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
mounts_allowed TEXT,
max_connections INTEGER DEFAULT 1,
created DATETIME DEFAULT CURRENT_TIMESTAMP
)
```

#### Mountpoints Table

```sql
CREATE TABLE mountpoints (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
protocol TEXT DEFAULT 'NTRIP/2.0',
status TEXT CHECK(status IN ('online','offline','maintenance')) DEFAULT 'online',
last_active DATETIME
)
```

## API Endpoints

See the [Admin API Documentation](../docs/admin.md) for detailed information about the available endpoints.

## Testing

The package includes unit tests that can be run with:

```bash
go test -v ./admin
```

Note that the tests require CGO to be enabled for SQLite support.

## Dependencies

- `github.com/mattn/go-sqlite3`: SQLite driver for Go
- `golang.org/x/crypto/bcrypt`: Password hashing
- `github.com/sirupsen/logrus`: Logging
Loading