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 ¶
- type Router
- func (self *Router) EnsureRoute(ip net.IP, sink Sink)
- func (self *Router) IP() net.IP
- func (self *Router) Inbound(frame ipv4.Frame)
- func (self *Router) Interface() string
- func (self *Router) Network() *net.IPNet
- func (self *Router) Register(ip net.IP, sink Sink)
- func (self *Router) Start()
- func (self *Router) Stop()
- func (self *Router) Unregister(sink Sink)
- type Sink
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 (*Router) EnsureRoute ¶
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) Inbound ¶
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) Register ¶
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) Stop ¶
func (self *Router) Stop()
Stop signals shutdown, closes the tun device, and waits for the loops to end.
func (*Router) Unregister ¶
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.