gateway

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

README

gateway

ci codecov

Gateway plugin for the Pilot Protocol daemon. Maps virtual pilot addresses to local loopback aliases (ip addr add on Linux, ifconfig lo0 alias on macOS) so legacy TCP/UDP apps can dial pilot-addressed peers as if they were on 127.x.x.x. Ports under 1024 require root on Linux.

Install

import "github.com/pilot-protocol/gateway"

Usage

g := gateway.NewService(gateway.Config{
    Dialer: driverDialer,
    Ports:  []uint16{80, 443, 8080},
})
rt.Register(g)

Layout

File What it does
gateway.go TCP/UDP proxy that splices a local listener with a pilot connection.
mapping.go Pilot-address to loopback-IP allocation, plus alias install/remove.
service.go *Servicecoreapi.Service adapter. Build tag !no_gateway.
service_disabled.go Stub when build tag no_gateway is set.

Build tags

Tag Effect
no_gateway Compiles a stub whose Start is a no-op.

License

AGPL-3.0-or-later. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPorts = []uint16{80, 443, 1000, 1001, 1002, 7, 8080, 8443}

DefaultPorts is the default set of ports the gateway proxies.

Functions

This section is empty.

Types

type Config

type Config struct {
	Subnet string   // CIDR subnet for local IPs (default: "10.4.0.0/16")
	Ports  []uint16 // Ports to proxy (default: DefaultPorts)
}

Config configures the gateway.

type Dialer

type Dialer interface {
	DialAddr(dst protocol.Addr, port uint16) (net.Conn, error)
	Close() error
}

Dialer is satisfied by *driver.Driver. The concrete implementation lives at the L12 composition root (cmd/gateway) so plugins/gateway stays free of pkg/driver.

type Gateway

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

Gateway bridges standard IP/TCP traffic to the Pilot Protocol overlay. In proxy mode, it listens on mapped local IPs and forwards TCP connections through Pilot Protocol streams.

func New

func New(cfg Config, d Dialer) (*Gateway, error)

New creates a new Gateway bound to the given Dialer. The Dialer is typically a *driver.Driver constructed by cmd/gateway.

func (*Gateway) Map

func (gw *Gateway) Map(pilotAddr protocol.Addr, localIP string) (net.IP, error)

Map registers a Pilot address and starts proxying for it. If localIP is empty, one is auto-assigned from the subnet.

func (*Gateway) Mappings

func (gw *Gateway) Mappings() *MappingTable

Mappings returns the mapping table for external use.

func (*Gateway) Stop

func (gw *Gateway) Stop()

Stop shuts down the gateway and cleans up loopback aliases. Safe to call multiple times.

func (*Gateway) Unmap

func (gw *Gateway) Unmap(localIP string) error

Unmap removes a mapping and stops proxying.

type Mapping

type Mapping struct {
	LocalIP   net.IP
	PilotAddr protocol.Addr
}

All returns all current mappings as (localIP, pilotAddr) pairs.

type MappingTable

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

MappingTable maps local IPs to Pilot addresses and vice versa.

func NewMappingTable

func NewMappingTable(cidr string) (*MappingTable, error)

NewMappingTable creates a mapping table for the given subnet (e.g. "10.4.0.0/16").

func (*MappingTable) All

func (mt *MappingTable) All() []Mapping

func (*MappingTable) Lookup

func (mt *MappingTable) Lookup(localIP net.IP) (protocol.Addr, bool)

Lookup returns the Pilot address for a local IP.

func (*MappingTable) Map

func (mt *MappingTable) Map(pilotAddr protocol.Addr, localIP net.IP) (net.IP, error)

Map registers a mapping between a Pilot address and a local IP. If localIP is nil, the next available IP in the subnet is assigned.

func (*MappingTable) ReverseLookup

func (mt *MappingTable) ReverseLookup(addr protocol.Addr) (net.IP, bool)

ReverseLookup returns the local IP for a Pilot address.

func (*MappingTable) Unmap

func (mt *MappingTable) Unmap(localIP net.IP) error

Unmap removes a mapping by local IP.

type Service

type Service struct{}

Service is the L11 plugin lifecycle adapter for the gateway. The daemon does not register this today — cmd/gateway is a standalone binary that uses gateway.New / *Gateway.Start directly. The adapter exists so the plugin package conforms to the L10 Service contract and so the no_gateway build tag has a meaningful counterpart (see service_disabled.go).

When this plugin is eventually wired into cmd/daemon's plugin runtime, this Service will own the *Gateway lifecycle. Today its Start/Stop are no-ops; it is registered nowhere.

func NewService

func NewService() *Service

NewService returns a Service ready for daemon.RegisterPlugin (when cmd/daemon eventually starts registering it). Distinct from gateway.New, which constructs the standalone *Gateway used by cmd/gateway.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Order

func (s *Service) Order() int

func (*Service) Start

func (s *Service) Start(_ context.Context, _ coreapi.Deps) error

func (*Service) Stop

func (s *Service) Stop(_ context.Context) error

Jump to

Keyboard shortcuts

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