core

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package core holds the transport-agnostic heart of a shadowgate server: the tun device and the routing table that maps a tunnel address to the transport peer that owns it. Transports (TCP, UDP) plug into a Router by registering a Sink per peer and calling Inbound for frames they receive; the Router moves frames between the tun device and those sinks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

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

Router owns the tun device and the routing table shared by all transports.

func NewRouter

func NewRouter(device tun.TUN, ip net.IP, network *net.IPNet) *Router

func (*Router) EnsureRoute

func (self *Router) EnsureRoute(ip net.IP, sink Sink)

EnsureRoute associates a tunnel address with a sink only if no route exists yet. Transports call this for keepalives so a route stays available (over whichever transport is still alive) without a keepalive on one transport stealing the return path from the transport actually carrying data.

func (*Router) IP

func (self *Router) IP() net.IP

IP returns the server's own tunnel address.

func (*Router) Inbound

func (self *Router) Inbound(frame ipv4.Frame)

Inbound routes a frame received from a transport peer (a client). Frames for the server's own tunnel address, and frames for destinations outside the tunnel subnet, are handed to the local tun so the server host forwards them per its own routing table (server acting as a gateway). Frames for another connected client are relayed to that client; frames for an unconnected in-subnet address are dropped.

func (*Router) Interface

func (self *Router) Interface() string

Interface returns the name of the underlying tun interface.

func (*Router) Network

func (self *Router) Network() *net.IPNet

Network returns the tunnel subnet.

func (*Router) Register

func (self *Router) Register(ip net.IP, sink Sink)

Register associates a tunnel address with the sink that reaches it, replacing any existing route. Transports call this for every data frame received from a client so the return path follows whichever transport the client is actively using. Because a client's frames may carry arbitrary (even spoofed) source addresses, the number of routes is bounded per sink and overall so one client cannot exhaust memory; excess routes are dropped.

func (*Router) Start

func (self *Router) Start()

Start launches the tun read and write loops.

func (*Router) Stop

func (self *Router) Stop()

Stop signals shutdown, closes the tun device, and waits for the loops to end.

func (*Router) Unregister

func (self *Router) Unregister(sink Sink)

Unregister removes every route pointing at the given sink. It is O(routes for this sink), not a full-table scan, so a disconnecting client cannot stall the router while holding the lock.

type Sink

type Sink interface {
	Send(frame ipv4.Frame)
}

Sink delivers a frame toward a single peer. Implementations must not block (drop the frame instead) so one slow or dead peer cannot stall routing.

Jump to

Keyboard shortcuts

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