kone

package module
v0.0.0-...-9c896fd Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 23 Imported by: 0

README

github workflow codecov

KONE

The project aims to improve the experience of accessing internet in home/enterprise network.

The name "KONE" comes from k1, a chronometer made by Larcum Kendall and played a important role in Captain Cook's voyage.

By now, it supports:

Use

go build ./cmd/kone
sudo ./kone -debug -config cmd/kone/test.ini

For more information, please read test.ini.

Web Status

The default web status port is 9200 , just visit http://localhost:9200/ to check the kone status.

Documents

License

The MIT License (MIT) Copyright (c) 2016 xjdrew

Documentation

Index

Constants

View Source
const (
	HTTP_PROXY  = "http_proxy"
	HTTPS_PROXY = "https_proxy"
	SOCKS_PROXY = "socks_proxy"
)
View Source
const (
	DnsDefaultPort         = 53
	DnsDefaultTtl          = 600
	DnsDefaultPacketSize   = 4096
	DnsDefaultReadTimeout  = 5
	DnsDefaultWriteTimeout = 5
)
View Source
const (
	NatSessionLifeSeconds   = 600
	NatSessionCheckInterval = 300
)
View Source
const DnsIPPoolMaxSpace = 0x3ffff // 4*65535

Variables

View Source
var ErrResolve = errors.New("resolve timeout")
View Source
var MTU = 1500

Functions

This section is empty.

Types

type ConnData

type ConnData struct {
	Src      string
	Dst      string
	Proxy    string
	Upload   int64
	Download int64
}

statistical data of every connection

type CoreConfig

type CoreConfig struct {
	Tun             string   `ini:"tun"`     // tun name
	Network         string   `ini:"network"` // tun network
	TcpListenPort   uint16   `ini:"tcp-listen-port"`
	TcpNatPortStart uint16   `ini:"tcp-nat-port-start"`
	TcpNatPortEnd   uint16   `ini:"tcp-nat-port-end"`
	UdpListenPort   uint16   `ini:"udp-listen-port"`
	UdpNatPortStart uint16   `ini:"udp-nat-port-start"`
	UdpNatPortEnd   uint16   `ini:"udp-nat-port-end"`
	DnsListenPort   uint16   `ini:"dns-listen-port"`
	DnsTtl          uint     `ini:"dns-ttl"`
	DnsPacketSize   uint16   `ini:"dns-packet-size"`
	DnsReadTimeout  uint     `ini:"dns-read-timeout"`
	DnsWriteTimeout uint     `ini:"dns-write-timeout"`
	DnsServer       []string `ini:"dns-server" delim:","`
}

type Dns

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

func NewDns

func NewDns(one *One, cfg CoreConfig) (*Dns, error)

func (*Dns) Resolve

func (d *Dns) Resolve(domain string) (*dns.Msg, error)

query synchronously

func (*Dns) Serve

func (d *Dns) Serve() error

func (*Dns) ServeDNS

func (d *Dns) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

type DnsIPPool

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

func NewDnsIPPool

func NewDnsIPPool(ip net.IP, subnet *net.IPNet) *DnsIPPool

func (*DnsIPPool) Alloc

func (pool *DnsIPPool) Alloc(tips string) net.IP

use tips as a hint to find a stable index

func (*DnsIPPool) Capacity

func (pool *DnsIPPool) Capacity() int

func (*DnsIPPool) Contains

func (pool *DnsIPPool) Contains(ip net.IP) bool

func (*DnsIPPool) Release

func (pool *DnsIPPool) Release(ip net.IP)

type DnsTable

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

func NewDnsTable

func NewDnsTable(ip net.IP, subnet *net.IPNet) *DnsTable

func (*DnsTable) ClearNonProxyDomain

func (c *DnsTable) ClearNonProxyDomain()

func (*DnsTable) Contains

func (c *DnsTable) Contains(ip net.IP) bool

func (*DnsTable) Get

func (c *DnsTable) Get(domain string) *DomainRecord

func (*DnsTable) GetByIP

func (c *DnsTable) GetByIP(ip net.IP) *DomainRecord

func (*DnsTable) IsLocalIP

func (c *DnsTable) IsLocalIP(ip net.IP) bool

func (*DnsTable) IsNonProxyDomain

func (c *DnsTable) IsNonProxyDomain(domain string) bool

func (*DnsTable) Serve

func (c *DnsTable) Serve() error

func (*DnsTable) Set

func (c *DnsTable) Set(domain string, proxy string) *DomainRecord

func (*DnsTable) SetNonProxyDomain

func (c *DnsTable) SetNonProxyDomain(domain string, ttl uint32)

type DomainKeywordPattern

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

DOMAIN-KEYWORD

func (DomainKeywordPattern) Match

func (p DomainKeywordPattern) Match(val interface{}) bool

func (DomainKeywordPattern) Proxy

func (p DomainKeywordPattern) Proxy() string

type DomainPattern

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

DOMAIN

func (DomainPattern) Match

func (p DomainPattern) Match(val interface{}) bool

func (DomainPattern) Proxy

func (p DomainPattern) Proxy() string

type DomainRecord

type DomainRecord struct {
	Hostname string // hostname
	Proxy    string // proxy

	IP      net.IP // nat ip
	RealIP  net.IP // real ip
	Hits    int
	Expires time.Time
	// contains filtered or unexported fields
}

hijacked domain

func (*DomainRecord) Answer

func (record *DomainRecord) Answer(request *dns.Msg) *dns.Msg

func (*DomainRecord) SetRealIP

func (record *DomainRecord) SetRealIP(msg *dns.Msg)

func (*DomainRecord) Touch

func (record *DomainRecord) Touch()

type DomainSuffixPattern

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

DOMAIN-SUFFIX

func (DomainSuffixPattern) Match

func (p DomainSuffixPattern) Match(val interface{}) bool

func (DomainSuffixPattern) Proxy

func (p DomainSuffixPattern) Proxy() string

type FinalPattern

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

FINAL

func NewFinalPattern

func NewFinalPattern(proxy string) FinalPattern

func (FinalPattern) Match

func (p FinalPattern) Match(val interface{}) bool

func (FinalPattern) Proxy

func (p FinalPattern) Proxy() string

type GEOIPPattern

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

GEOIP

func (GEOIPPattern) Match

func (p GEOIPPattern) Match(val interface{}) bool

func (GEOIPPattern) Proxy

func (p GEOIPPattern) Proxy() string

type GeneralConfig

type GeneralConfig struct {
	ManagerAddr string `ini:"manager-addr"`
	LogLevel    string `ini:"log-level"`
}

type IPCIDRPattern

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

IP-CIDR

func (IPCIDRPattern) Match

func (p IPCIDRPattern) Match(val interface{}) bool

func (IPCIDRPattern) Proxy

func (p IPCIDRPattern) Proxy() string

type KoneConfig

type KoneConfig struct {
	General GeneralConfig
	Core    CoreConfig
	Proxy   map[string]string
	Rule    []RuleConfig
	// contains filtered or unexported fields
}

func ParseConfig

func ParseConfig(source interface{}) (*KoneConfig, error)

func (*KoneConfig) GetSystemDnsservers

func (cfg *KoneConfig) GetSystemDnsservers() (servers []string)

type Manager

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

func NewManager

func NewManager(one *One, cfg *KoneConfig) *Manager

func (*Manager) Serve

func (m *Manager) Serve() error

type Nat

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

func NewNat

func NewNat(from, to uint16) *Nat

port range [from, to)

type NatSession

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

type NatTable

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

func (*NatTable) Count

func (tbl *NatTable) Count() int

func (*NatTable) Map

func (tbl *NatTable) Map(ip net.IP, port uint16) (uint16, bool)

return: mapped port, is new mapped

func (*NatTable) Unmap

func (tbl *NatTable) Unmap(ip net.IP, port uint16)

type One

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

func FromConfig

func FromConfig(cfg *KoneConfig) (*One, error)

func (*One) Reload

func (one *One) Reload(cfg *KoneConfig) error

func (*One) Serve

func (one *One) Serve()

type PacketFilter

type PacketFilter interface {
	Filter(wr io.Writer, p tcpip.IPv4Packet)
}

type PacketFilterFunc

type PacketFilterFunc func(wr io.Writer, p tcpip.IPv4Packet)

func (PacketFilterFunc) Filter

func (f PacketFilterFunc) Filter(wr io.Writer, p tcpip.IPv4Packet)

type Pattern

type Pattern interface {
	Proxy() string
	Match(val interface{}) bool
}

func CreatePattern

func CreatePattern(rc RuleConfig) Pattern

func NewDomainKeywordPattern

func NewDomainKeywordPattern(proxy string, key string) Pattern

func NewDomainPattern

func NewDomainPattern(proxy, domain string) Pattern

func NewDomainSuffixPattern

func NewDomainSuffixPattern(proxy, suffix string) Pattern

func NewGEOIPPattern

func NewGEOIPPattern(proxy string, country string) Pattern

func NewIPCIDRPattern

func NewIPCIDRPattern(proxy string, ipNet *net.IPNet) Pattern

type Proxies

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

func NewProxies

func NewProxies(one *One, config map[string]string) (*Proxies, error)

func (*Proxies) Dial

func (p *Proxies) Dial(pname string, addr string) (net.Conn, error)

type Rule

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

func NewRule

func NewRule(rcs []RuleConfig) *Rule

func (*Rule) DirectDomain

func (rule *Rule) DirectDomain(domain string)

func (*Rule) Proxy

func (rule *Rule) Proxy(val interface{}) string

match a proxy for target `val`

type RuleConfig

type RuleConfig struct {
	Schema  string
	Pattern string
	Proxy   string
}

type TCPRelay

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

func NewTCPRelay

func NewTCPRelay(one *One, cfg CoreConfig) *TCPRelay

func (*TCPRelay) Filter

func (r *TCPRelay) Filter(wr io.Writer, ipPacket tcpip.IPv4Packet)

redirect tcp packet to relay

func (*TCPRelay) Serve

func (r *TCPRelay) Serve() error

type TrafficRecord

type TrafficRecord struct {
	Name     string
	Upload   int64
	Download int64
	Touch    time.Time
	Details  map[string]*TrafficRecordDetail
}

type TrafficRecordDetail

type TrafficRecordDetail struct {
	EndPoint string
	Upload   int64
	Download int64
	Touch    time.Time
}

statistical data of every host/website/proxy

type TunDriver

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

func NewTunDriver

func NewTunDriver(ip net.IP, subnet *net.IPNet, filters map[tcpip.IPProtocol]PacketFilter) (*TunDriver, error)

func (*TunDriver) AddRoute

func (tun *TunDriver) AddRoute(ipNet *net.IPNet) bool

func (*TunDriver) AddRouteString

func (tun *TunDriver) AddRouteString(val string) bool

func (*TunDriver) Serve

func (tun *TunDriver) Serve() error

type UDPRelay

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

func NewUDPRelay

func NewUDPRelay(one *One, cfg CoreConfig) *UDPRelay

func (*UDPRelay) Filter

func (r *UDPRelay) Filter(wr io.Writer, ipPacket tcpip.IPv4Packet)

redirect udp packet to relay

func (*UDPRelay) Serve

func (r *UDPRelay) Serve() error

type UDPTunnel

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

func (*UDPTunnel) Pump

func (tunnel *UDPTunnel) Pump() error

func (*UDPTunnel) SetDeadline

func (tunnel *UDPTunnel) SetDeadline(duration time.Duration) error

func (*UDPTunnel) Write

func (tunnel *UDPTunnel) Write(b []byte) (int, error)

Directories

Path Synopsis
cmd
date : 2016-02-18 author: xjdrew
date : 2016-02-18 author: xjdrew

Jump to

Keyboard shortcuts

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