core

module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT

README

The core library

github.com/go-gost/core defines all interfaces and shared types for the GOST tunneling toolkit. It has no implementations and zero third-party dependencies — just Go's standard library. All concrete types live in the x/ module.

Interfaces

The module defines every component of the GOST proxy pipeline:

  • Service — Wraps a listener + handler into a runnable server
  • Listener — Accepts inbound connections (TCP, TLS, HTTP/2/3, QUIC, etc.)
  • Handler — Processes inbound connections: authenticates, routes, forwards
  • Dialer — Dials from one node to the next proxy hop
  • Connector — Connects from the final node to the destination
  • Chain / Route / Transporter / Node / Hop — Proxy chain routing and node selection
  • Router — Top-level router combining chain, resolver, host mapping, retries, and timeouts
  • Registry[T] — Generic typed registry for component registration
  • Selector / Strategy / Filter — Generic load balancing and node selection

Supporting types: Authenticator, Admission, Bypass, Resolver, HostMapper, Recorder, Observer, Ingress, SD (service discovery), Logger, Metrics, Limiter (conn/rate/traffic), Stats, Matcher, and Router (OS-level).

Architecture

Request Path (Forward Proxy)
 Client
   │
   ▼
┌──────────────┐
│   Listener   │  Accepts inbound connections
│              │  (tcp, tls, ws, http2/3, quic, kcp, icmp, tun, udp, ...)
└──────┬───────┘
       │  net.Conn
       ▼
┌──────────────┐
│   Handler    │  Authenticates, routes, and proxies traffic
│              │  (http, socks4/5, ss, ssh, tunnel, tun, dns, redirect, ...)
└──────┬───────┘
       │  chain.Router.Dial(ctx, network, address)
       ▼
┌──────────────────────────────────────────────────────────────┐
│                        chain.Router                          │
│                                                              │
│  Resolver ─► HostMapper ─► Recorders ─► Retries/Timeout      │
│       │                                                      │
│       ▼                                                      │
│  ┌─────────┐   ┌─────┐   ┌──────────┐                        │
│  │ Chainer │──►│ Hop │──►│  Node[]  │  (per chain hop)       │
│  └─────────┘   └──┬──┘   └────┬─────┘                        │
│                   │            │                             │
│              Selector    chain.Transporter                   │
│           (rr/random/    ┌──────────────────┐                │
│            weighted/     │    Dialer        │  dial to next  │
│            fail-filter)  │    Handshaker    │  proxy hop     │
│                          │    Connector     │  connect to    │
│                          │    Binder        │  destination   │
│                          │    Multiplexer   │                │
│                          └──────────────────┘                │
└──────────────────────────────────────────────────────────────┘
       │
       ▼
  Destination
Reverse Proxy / Tunnel
 Client ◄── Tunnel ──┐
                     │
               ┌─────▼──────┐
               │  Listener  │
               └─────┬──────┘
                     │
               ┌─────▼──────┐
               │  Handler   │
               └─────┬──────┘
                     │  chain.Router.Bind(ctx, network, address)
                     ▼
              chain.Router ─► chain.Route.Bind() ─► Transporter.Bind()
                     │                                    │
                     ▼                                    ▼
               Destination                      net.Listener (on remote node)
Service Composition
┌────────────────────────────────────────┐
│               Service                  │
│                                        │
│  ┌──────────┐          ┌───────────┐   │
│  │ Listener │─────────►│  Handler  │   │
│  │          │ net.Conn │           │   │
│  └──────────┘          └─────┬─────┘   │
│                              │         │
│                   chain.Router         │
└────────────────────────────────────────┘

Service = 1 Listener + 1 Handler + cross-cutting concerns:

  Listener.Options:          Handler.Options:
    Auth                        Auth / Auther
    Auther                      Bypass
    Admission                   Router
    ConnLimiter                 RateLimiter
    TrafficLimiter              TrafficLimiter
    Stats                       TLSConfig
    ProxyProtocol               Observer
    Router (chain.Router)       Recorders
    Logger                      Logger
Interface Dependencies
                    ┌──────────┐
                    │ Registry │  Generic[T]: Register / Get / GetAll
                    └──────────┘
                         │
                         │ registers
                         ▼
  ┌─────────┐     ┌───────────┐     ┌────────────┐
  │ Service │────►│ Listener  │     │  Handler   │
  └─────────┘     └─────┬─────┘     └──────┬─────┘
                        │                  │
                        │  chain.Router    │
                        └────────┬─────────┘
                                 │
                    ┌────────────┴────────────┐
                    │      chain.Router       │
                    │  .Chainer               │
                    │  .Resolver              │
                    │  .HostMapper            │
                    │  .Recorders             │
                    └────────────┬────────────┘
                                 │
                    ┌────────────┴───────────┐
                    │     chain.Chainer      │
                    │     Route(ctx, ...)    │
                    └────────────┬───────────┘
                                 │
                    ┌────────────┴───────────┐
                    │     chain.Route        │
                    │     Dial() / Bind()    │
                    │     Nodes()            │
                    └────────────┬───────────┘
                                 │
                    ┌────────────┴───────────┐
                    │       hop.Hop          │
                    │  Select(ctx, opts)     │
                    │  uses selector.Selector│
                    └────────────┬───────────┘
                                 │
                    ┌────────────┴───────────┐
                    │      chain.Node        │
                    │  .Transport            │
                    │  .Bypass               │
                    │  .Resolver / .HostMapper│
                    │  .TLS / .HTTP settings │
                    │  .Marker (fail count)  │
                    └────────────┬───────────┘
                                 │
                    ┌────────────┴───────────┐
                    │  chain.Transporter     │
                    │  ┌──────────────────┐  │
                    │  │ dialer.Dialer    │  │
                    │  │ connector.Con..  │  │
                    │  │ Handshaker       │  │
                    │  │ Multiplexer      │  │
                    │  │ Binder           │  │
                    │  └──────────────────┘  │
                    └────────────────────────┘
Cross-cutting Interfaces
┌──────────┐ ┌──────────┐ ┌───────────┐ ┌──────────┐ ┌──────────────┐
│   Auth   │ │ Admission│ │   Bypass  │ │ Recorder │ │   Observer   │
├──────────┤ ├──────────┤ ├───────────┤ ├──────────┤ ├──────────────┤
│Authen... │ │Admit()   │ │Contains() │ │Record()  │ │Observe()     │
│(user,pw) │ │(addr)    │ │IsWhite... │ │(bytes)   │ │(events)      │
└──────────┘ └──────────┘ └───────────┘ └──────────┘ └──────────────┘

┌──────────┐ ┌──────────┐ ┌───────────┐ ┌──────────┐ ┌──────────────┐
│ Resolver │ │HostMapper│ │  Logger   │ │ Metrics  │ │   Router     │
├──────────┤ ├──────────┤ ├───────────┤ ├──────────┤ ├──────────────┤
│Resolve() │ │Lookup()  │ │Tracef()   │ │Counter() │ │GetRoute()    │
│(host→IP) │ │(host→IP) │ │Debugf()   │ │Gauge()   │ │(dst→gateway) │
│          │ │          │ │Infof()... │ │Observer()│ │              │
└──────────┘ └──────────┘ └───────────┘ └──────────┘ └──────────────┘

┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│   conn.Limiter   │ │   rate.Limiter   │ │ traffic.Limiter  │
├──────────────────┤ ├──────────────────┤ ├──────────────────┤
│ Allow(n) bool    │ │ Allow(n) bool    │ │ Wait(ctx,n) int  │
│ Limit() int      │ │ Limit() float64  │ │ Limit() / Set()  │
│ (max conn count) │ │ (rate limiter)   │ │ (bandwidth)      │
└──────────────────┘ └──────────────────┘ └──────────────────┘

┌──────────┐ ┌──────────┐ ┌───────────┐ ┌──────────┐ ┌──────────────┐
│   SD     │ │ Ingress  │ │  Matcher  │ │  Stats   │ │   BufPool    │
├──────────┤ ├──────────┤ ├───────────┤ ├──────────┤ ├──────────────┤
│Register()│ │SetRule() │ │Match()    │ │Add/Get() │ │Get() / Put() │
│Get()     │ │GetRule() │ │(*Request) │ │conn/bytes│ │(tiered sync. │
│          │ │          │ │           │ │          │ │ Pool)        │
└──────────┘ └──────────┘ └───────────┘ └──────────┘ └──────────────┘

Usage

import (
    "github.com/go-gost/core/chain"
    "github.com/go-gost/core/connector"
    "github.com/go-gost/core/dialer"
    "github.com/go-gost/core/handler"
    "github.com/go-gost/core/listener"
    "github.com/go-gost/core/registry"
    "github.com/go-gost/core/service"
)

All interfaces follow the functional options pattern. See x/ for implementations.

Directories

Path Synopsis
Package admission defines the Admission interface for connection admission control, determining whether to allow or deny incoming connections.
Package admission defines the Admission interface for connection admission control, determining whether to allow or deny incoming connections.
Package auth defines the Authenticator interface for verifying client identities.
Package auth defines the Authenticator interface for verifying client identities.
Package bypass defines the Bypass interface for deciding whether a target address should skip the proxy chain and connect directly.
Package bypass defines the Bypass interface for deciding whether a target address should skip the proxy chain and connect directly.
Package cache defines a generic key-value cache interface used across the TNET project — HTTP response caching, and (as consumers migrate) DNS responses, routes, and other []byte-serializable data.
Package cache defines a generic key-value cache interface used across the TNET project — HTTP response caching, and (as consumers migrate) DNS responses, routes, and other []byte-serializable data.
Package chain defines the proxy chain interfaces — the core routing layer of TNET.
Package chain defines the proxy chain interfaces — the core routing layer of TNET.
common
bufpool
Package bufpool provides a tiered sync.Pool for byte buffers, ranging from 128 bytes to 65 KB.
Package bufpool provides a tiered sync.Pool for byte buffers, ranging from 128 bytes to 65 KB.
net
Package net provides a minimal shared Dialer interface used across the connector and dialer packages to avoid circular dependencies.
Package net provides a minimal shared Dialer interface used across the connector and dialer packages to avoid circular dependencies.
Package connector defines interfaces for connecting to destination addresses from the final proxy node in a chain.
Package connector defines interfaces for connecting to destination addresses from the final proxy node in a chain.
Package dialer defines the Dialer interface for establishing connections to the next-hop proxy server in a chain.
Package dialer defines the Dialer interface for establishing connections to the next-hop proxy server in a chain.
Package handler defines the Handler interface for processing inbound connections — authenticating, routing, and forwarding traffic.
Package handler defines the Handler interface for processing inbound connections — authenticating, routing, and forwarding traffic.
Package hop defines the Hop interface for selecting a node from a group of equivalent proxy nodes using load-balancing strategies.
Package hop defines the Hop interface for selecting a node from a group of equivalent proxy nodes using load-balancing strategies.
Package hosts defines the HostMapper interface for static host-to-IP mappings.
Package hosts defines the HostMapper interface for static host-to-IP mappings.
Package ingress defines the Ingress interface for hostname-based tunnel routing.
Package ingress defines the Ingress interface for hostname-based tunnel routing.
Package limiter defines shared types and constants used by all limiter sub-packages (conn, rate, traffic).
Package limiter defines shared types and constants used by all limiter sub-packages (conn, rate, traffic).
conn
Package conn defines connection-level limiter interfaces for controlling the number of active connections.
Package conn defines connection-level limiter interfaces for controlling the number of active connections.
rate
Package rate defines rate-limiting interfaces for controlling the rate of new connections or requests.
Package rate defines rate-limiting interfaces for controlling the rate of new connections or requests.
traffic
Package traffic defines bandwidth/traffic limiter interfaces for controlling data transfer rates.
Package traffic defines bandwidth/traffic limiter interfaces for controlling data transfer rates.
Package listener defines the Listener interface for accepting incoming connections, analogous to net.Listener.
Package listener defines the Listener interface for accepting incoming connections, analogous to net.Listener.
Package logger defines the structured logging interface and a global default logger that components use when no explicit logger is configured.
Package logger defines the structured logging interface and a global default logger that components use when no explicit logger is configured.
Package metadata defines a key-value metadata store attached to every component in the TNET framework.
Package metadata defines a key-value metadata store attached to every component in the TNET framework.
Package metrics defines a Prometheus-style metrics abstraction for exposing gauges, counters, and observers (histograms/summaries).
Package metrics defines a Prometheus-style metrics abstraction for exposing gauges, counters, and observers (histograms/summaries).
Package observer defines the Observer interface for collecting observability events such as connection status and traffic statistics.
Package observer defines the Observer interface for collecting observability events such as connection status and traffic statistics.
stats
Package stats defines the Stats interface for tracking connection and traffic counters (total connections, current connections, bytes, errors).
Package stats defines the Stats interface for tracking connection and traffic counters (total connections, current connections, bytes, errors).
Package recorder defines the Recorder interface for capturing traffic data — hex dumps, HTTP body recording, and directional traffic logging.
Package recorder defines the Recorder interface for capturing traffic data — hex dumps, HTTP body recording, and directional traffic logging.
Package registry defines a generic Registry interface used throughout TNET for plugin-style component registration and lookup.
Package registry defines a generic Registry interface used throughout TNET for plugin-style component registration and lookup.
Package resolver defines the Resolver interface for DNS resolution.
Package resolver defines the Resolver interface for DNS resolution.
Package router defines the Router interface for OS-level route table queries used in TUN (virtual network device) mode.
Package router defines the Router interface for OS-level route table queries used in TUN (virtual network device) mode.
Package routing defines the Matcher interface for request-based routing decisions using HTTP-level context (hostname, method, path, headers, etc.).
Package routing defines the Matcher interface for request-based routing decisions using HTTP-level context (hostname, method, path, headers, etc.).
Package sd defines the SD (Service Discovery) interface for registering and discovering services in dynamic environments.
Package sd defines the SD (Service Discovery) interface for registering and discovering services in dynamic environments.
Package selector defines generic interfaces for node selection with support for strategies, filters, and failure marking.
Package selector defines generic interfaces for node selection with support for strategies, filters, and failure marking.
Package service defines the Service interface — the top-level abstraction that combines a Listener and a Handler to form a running proxy service.
Package service defines the Service interface — the top-level abstraction that combines a Listener and a Handler to form a running proxy service.

Jump to

Keyboard shortcuts

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