relayserver

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relayserver implements the server side of the iroh relay protocol.

It accepts relay WebSocket clients, authenticates them with the relay challenge protocol, and forwards relay datagrams between connected endpoint ids. It is intentionally small: persistence, metrics, access control, and clustering belong above this package.

The Go API is not stable before v1 and may change in any v0 release.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.1.1

type Option func(*Server)

Option configures a Server.

func WithClientRate added in v0.1.1

func WithClientRate(bytesPerSecond int64) Option

WithClientRate sets the per-client receive rate limit in bytes per second (default 64 MiB/s); <= 0 disables it.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an iroh relay protocol HTTP handler.

func New

func New() *Server

New returns a relay server with default settings. Use NewWithOptions to configure it.

func NewWithOptions added in v0.1.1

func NewWithOptions(opts ...Option) *Server

NewWithOptions returns a relay server configured by opts.

Example
package main

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	"github.com/tmc/go-iroh/relayserver"
)

func main() {
	// Override the default per-client receive rate when hosting the relay.
	srv := httptest.NewServer(relayserver.NewWithOptions(relayserver.WithClientRate(8 << 20)))
	defer srv.Close()

	resp, err := http.Get(srv.URL + "/")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	fmt.Println(resp.StatusCode)

}
Output:
404

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles relay WebSocket requests at /relay and net-report latency probes at /ping. Rust iroh clients require a 200 from /ping before selecting a relay as their home relay (iroh-relay/src/http.rs).

func (*Server) Snapshot

func (s *Server) Snapshot() metrics.Snapshot

Snapshot returns the server's counter snapshot for metrics.Registry.

Jump to

Keyboard shortcuts

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