Documentation
¶
Index ¶
- func VPNGatewayClientSupported() error
- func VPNGatewayServerSupported() error
- func VPNGatewaySupported() error
- type AuthStatus
- func (s *AuthStatus) AddPeer(ctx context.Context, peerID peer.ID, name, alias string, confirmed bool, ...) error
- func (s *AuthStatus) AuthStreamHandler(stream network.Stream)
- func (s *AuthStatus) BackgroundExchangeStatusInfo(ctx context.Context)
- func (s *AuthStatus) BackgroundRetryAuthRequests(ctx context.Context)
- func (s *AuthStatus) BlockPeer(peerID peer.ID, name string)
- func (s *AuthStatus) ExchangeNewStatusInfo(ctx context.Context, remotePeerID peer.ID, knownPeer config.KnownPeer) error
- func (s *AuthStatus) ExchangeStatusInfoWithAllKnownPeers(ctx context.Context)
- func (s *AuthStatus) GetAuthRequestCounts() (ingoing, outgoing int)
- func (s *AuthStatus) GetIngoingAuthRequests() map[string]protocol.AuthPeer
- func (s *AuthStatus) SendAuthRequest(ctx context.Context, peerID peer.ID, req protocol.AuthPeer) error
- func (s *AuthStatus) StatusStreamHandler(stream network.Stream)
- type DNSReconfigurer
- type NetManager
- type P2p
- type SOCKS5
- func (s *SOCKS5) Close()
- func (s *SOCKS5) GetProxyPeerID() string
- func (s *SOCKS5) ListAvailableProxies() []entity.AvailableProxy
- func (s *SOCKS5) ProxyStreamHandler(stream network.Stream)
- func (s *SOCKS5) ServeConns(ctx context.Context)
- func (s *SOCKS5) SetProxyPeerID(peerID string)
- func (s *SOCKS5) SetProxyingLocalhostEnabled(enabled bool)
- type SocketMarker
- type Tunnel
- func (t *Tunnel) ClearVPNGatewayPeer()
- func (t *Tunnel) Close()
- func (t *Tunnel) HandleReadPackets(packets []*vpn.Packet)
- func (t *Tunnel) RefreshPeersList()
- func (t *Tunnel) SetVPNGatewayPeer(gatewayPeerID peer.ID) error
- func (t *Tunnel) SetVPNGatewayServerEnabled(enabled bool)
- func (t *Tunnel) StreamHandler(stream network.Stream)
- type VPNGateway
- func (g *VPNGateway) DisableClient()
- func (g *VPNGateway) EnableClient(gatewayPeerID peer.ID) error
- func (g *VPNGateway) IsClientActive() bool
- func (g *VPNGateway) IsServerActive() bool
- func (g *VPNGateway) ListAvailableVPNGateways() []entity.AvailableVPNGateway
- func (g *VPNGateway) SetServerEnabled(enabled bool) error
- func (g *VPNGateway) SetupAtStartup() error
- func (g *VPNGateway) TeardownAtShutdown()
- type VpnPeer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VPNGatewayClientSupported ¶ added in v0.18.0
func VPNGatewayClientSupported() error
VPNGatewayClientSupported reports whether client-side VPN gateway mode can run on this OS/build.
func VPNGatewayServerSupported ¶ added in v0.18.0
func VPNGatewayServerSupported() error
VPNGatewayServerSupported reports whether server-side VPN gateway mode can run on this OS/build. Linux (iptables NAT) and Windows (WFP + WinNAT); Android exit-node support requires root or special system config, macOS lacks NAT/route glue.
func VPNGatewaySupported ¶ added in v0.18.0
func VPNGatewaySupported() error
VPNGatewaySupported reports whether any part of the VPN gateway feature set (client or server) can run on this OS/build. Callers that need a specific side must use VPNGatewayClientSupported / VPNGatewayServerSupported — the tray menu already gates client and server entries separately.
Types ¶
type AuthStatus ¶
type AuthStatus struct {
// contains filtered or unexported fields
}
func NewAuthStatus ¶
func (*AuthStatus) AuthStreamHandler ¶
func (s *AuthStatus) AuthStreamHandler(stream network.Stream)
func (*AuthStatus) BackgroundExchangeStatusInfo ¶
func (s *AuthStatus) BackgroundExchangeStatusInfo(ctx context.Context)
func (*AuthStatus) BackgroundRetryAuthRequests ¶
func (s *AuthStatus) BackgroundRetryAuthRequests(ctx context.Context)
func (*AuthStatus) ExchangeNewStatusInfo ¶
func (*AuthStatus) ExchangeStatusInfoWithAllKnownPeers ¶
func (s *AuthStatus) ExchangeStatusInfoWithAllKnownPeers(ctx context.Context)
func (*AuthStatus) GetAuthRequestCounts ¶ added in v0.17.0
func (s *AuthStatus) GetAuthRequestCounts() (ingoing, outgoing int)
GetAuthRequestCounts returns the number of pending ingoing and outgoing auth requests.
func (*AuthStatus) GetIngoingAuthRequests ¶
func (s *AuthStatus) GetIngoingAuthRequests() map[string]protocol.AuthPeer
func (*AuthStatus) SendAuthRequest ¶
func (*AuthStatus) StatusStreamHandler ¶
func (s *AuthStatus) StatusStreamHandler(stream network.Stream)
type DNSReconfigurer ¶ added in v0.18.0
type DNSReconfigurer interface {
// ForceUpstreamDNS toggles full-capture mode where all DNS is routed
// through the tunnel to a public upstream. Idempotent; a no-op when DNS is
// not active as the system resolver.
ForceUpstreamDNS(enabled bool) error
}
DNSReconfigurer is the narrow slice of the DNS service the gateway needs to prevent DNS leaks in client mode. Implemented by awl.DNSService; injected to avoid a service -> awl import cycle. May be nil.
type NetManager ¶ added in v0.19.0
type NetManager interface {
EnableClientRoutes(tunIfName string) error
DisableClientRoutes() error
ClientRoutesActive() bool
EnableServerNAT(awlSubnet, tunIfName string) error
DisableServerNAT() error
ServerNATActive() bool
}
NetManager is the slice of *netstate.Manager the gateway service needs: the runtime apply/revert of the OS-level client routes and server NAT. All methods are idempotent. Declared consumer-side so tests can substitute a bookkeeping-only fake.
type P2p ¶
type P2p interface {
ConnectPeer(ctx context.Context, peerID peer.ID) error
IsConnected(peerID peer.ID) bool
NewStream(ctx context.Context, id peer.ID, proto libp2pProtocol.ID) (network.Stream, error)
NewStreamMulti(ctx context.Context, id peer.ID, protos ...libp2pProtocol.ID) (network.Stream, error)
NewStreamWithDedicatedConn(ctx context.Context, id peer.ID, proto libp2pProtocol.ID) (network.Stream, error)
SubscribeConnectionEvents(onConnected, onDisconnected func(network.Network, network.Conn))
RecordPeerLatency(id peer.ID, rtt time.Duration)
}
type SOCKS5 ¶ added in v0.12.0
type SOCKS5 struct {
// contains filtered or unexported fields
}
func (*SOCKS5) GetProxyPeerID ¶ added in v0.17.0
func (*SOCKS5) ListAvailableProxies ¶ added in v0.12.0
func (s *SOCKS5) ListAvailableProxies() []entity.AvailableProxy
func (*SOCKS5) ProxyStreamHandler ¶ added in v0.12.0
func (*SOCKS5) ServeConns ¶ added in v0.12.0
func (*SOCKS5) SetProxyPeerID ¶ added in v0.12.0
func (*SOCKS5) SetProxyingLocalhostEnabled ¶ added in v0.12.0
SetProxyingLocalhostEnabled is created for tests and not intended for real usage.
type SocketMarker ¶ added in v0.19.0
type SocketMarker interface {
ControlFunc() func(network, address string, c syscall.RawConn) error
}
SocketMarker is the slice of *netstate.Manager the SOCKS5 service needs: the control function that marks exit-node dial sockets to bypass our own VPN gateway routes.
type Tunnel ¶
type Tunnel struct {
// contains filtered or unexported fields
}
func (*Tunnel) ClearVPNGatewayPeer ¶ added in v0.18.0
func (t *Tunnel) ClearVPNGatewayPeer()
ClearVPNGatewayPeer disables VPN gateway client mode and persists the choice.
func (*Tunnel) HandleReadPackets ¶ added in v0.15.0
HandleReadPackets for successfully handled packets it sets packet in slice as nil
func (*Tunnel) RefreshPeersList ¶
func (t *Tunnel) RefreshPeersList()
func (*Tunnel) SetVPNGatewayPeer ¶ added in v0.18.0
SetVPNGatewayPeer enables VPN gateway client mode using the existing VpnPeer for the given gateway peer, validates the peer's permission, and persists the choice in the config.
The peer must:
- Be in KnownPeers.
- Currently allow being used as a VPN gateway (KnownPeer.CanUseAsVPNGateway, i.e. AllowedUsingAsExitNode AND RemoteVPNGatewayServerEnabled from the most recent status exchange).
func (*Tunnel) SetVPNGatewayServerEnabled ¶ added in v0.18.0
SetVPNGatewayServerEnabled enables or disables VPN gateway server mode on this tunnel and persists the choice in the config. The decision propagates to other peers on the next status exchange so their UI reflects whether this node is currently offering VPN gateway server.
func (*Tunnel) StreamHandler ¶
type VPNGateway ¶ added in v0.18.0
type VPNGateway struct {
// contains filtered or unexported fields
}
VPNGateway owns the lifecycle of VPN gateway mode (both client and server sides): the glue that ties the OS-level state (applied via the netstate manager) to the persisted VPNGatewayConfig and the Tunnel's runtime peer state.
Responsibility split:
- Tunnel owns the packet-path state (gateway peer pointer, fwmark forwarding decisions, connectivity observation via p2p events).
- The netstate manager owns the OS-level state itself (routes, NAT).
- VPNGateway orchestrates: config, tunnel binding, DNS policy and the manager calls, from the API and from Application.Init / Close.
VPNGateway calls into Tunnel for the runtime bind/unbind operations (SetVPNGatewayPeer / ClearVPNGatewayPeer / SetVPNGatewayServerEnabled). When the VPN interface is disabled, Tunnel is nil and VPNGateway writes directly to the config — the API endpoints still succeed, persistence still works, and the next start with a real TUN will pick the values up.
func NewVPNGateway ¶ added in v0.18.0
func NewVPNGateway(conf *config.Config, tunnel *Tunnel, device *vpn.Device, p2p P2p, netManager NetManager, dns DNSReconfigurer) *VPNGateway
NewVPNGateway constructs a VPNGateway service. tunnel may be nil when the VPN interface is disabled; the API methods still work but only update the persisted config.
func (*VPNGateway) DisableClient ¶ added in v0.18.0
func (g *VPNGateway) DisableClient()
DisableClient turns off VPN gateway client mode and persists the choice. Tears OS-level state down first so return traffic from the gateway peer can still flow while we still hold the tunnel binding; once routes are gone, packets fall back to the regular awl path. Idempotent. Handles tunnel==nil (VPN interface disabled) by writing the config directly.
func (*VPNGateway) EnableClient ¶ added in v0.18.0
func (g *VPNGateway) EnableClient(gatewayPeerID peer.ID) error
EnableClient turns on VPN gateway client mode using the given peer as the gateway, applying OS-level routes immediately. Atomic: rolls back the tunnel binding on apply failure.
On android the OS-level apply (the netstate manager's routes / marking) is a no-op — routing is owned by the host's VpnService.Builder. This call flips the in-memory tunnel binding and persists config; the host then re-establishes the VpnService with the new routes and hot-swaps the fresh tun fd into the running app (see cmd/gomobile-lib UpdateTunDevice and vpn.SwappableTUN), so the change takes effect without restarting the daemon.
func (*VPNGateway) IsClientActive ¶ added in v0.18.0
func (g *VPNGateway) IsClientActive() bool
IsClientActive reports whether client-side gateway routes are currently installed. Test-friendly accessor; production code should not depend on this — the canonical "is gateway on" signal is config.VPNGateway.ClientEnabled or PeerInfo.VPNGateway.
func (*VPNGateway) IsServerActive ¶ added in v0.18.0
func (g *VPNGateway) IsServerActive() bool
IsServerActive reports whether VPN gateway server NAT is currently installed. Test-friendly accessor.
func (*VPNGateway) ListAvailableVPNGateways ¶ added in v0.18.0
func (g *VPNGateway) ListAvailableVPNGateways() []entity.AvailableVPNGateway
ListAvailableVPNGateways returns peers that are currently a valid VPN gateway target — i.e. they allow being used as an exit node and have VPN gateway server enabled on their side. Peers that allow exit-node use only for SOCKS5 are not included here. Returned slice is sorted by connected first, then by display name.
func (*VPNGateway) SetServerEnabled ¶ added in v0.18.0
func (g *VPNGateway) SetServerEnabled(enabled bool) error
SetServerEnabled toggles whether this node serves as a VPN gateway for permitted peers. Persisted; the new value propagates to other peers via the next status exchange. NAT / iptables state is (re)applied at runtime — no restart required. Handles tunnel==nil (VPN interface disabled) by writing the config directly.
func (*VPNGateway) SetupAtStartup ¶ added in v0.18.0
func (g *VPNGateway) SetupAtStartup() error
SetupAtStartup is the boot-time path
func (*VPNGateway) TeardownAtShutdown ¶ added in v0.18.0
func (g *VPNGateway) TeardownAtShutdown()
TeardownAtShutdown reverses SetupAtStartup. It only restores OS-level state (routes, NAT). It does NOT touch Tunnel's gateway peer pointer or the persisted config — the daemon should resume gateway mode on next start with the same gateway peer.