core

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 24 Imported by: 1

README

polevpn_core

Documentation

Index

Constants

View Source
const (
	CH_HTTP3_WRITE_SIZE     = 100
	HTTP3_HANDSHAKE_TIMEOUT = 5
)
View Source
const (
	CMD_ALLOC_IPADDR  = 0x1
	CMD_S2C_IPDATA    = 0x2
	CMD_C2S_IPDATA    = 0x3
	CMD_HEART_BEAT    = 0x4
	CMD_CLIENT_CLOSED = 0x5
	CMD_KICK_OUT      = 0x6
	CMD_USER_AUTH     = 0x7
)
View Source
const (
	POLE_CLIENT_INIT        = 0
	POLE_CLIENT_RUNING      = 1
	POLE_CLIENT_CLOSED      = 2
	POLE_CLIENT_RECONNETING = 3
)
View Source
const (
	VERSION_IP_V4                = 4
	VERSION_IP_V6                = 6
	TUN_DEVICE_CH_WRITE_SIZE     = 200
	HEART_BEAT_INTERVAL          = 10
	RECONNECT_TIMES              = 600000000
	RECONNECT_INTERVAL           = 5
	WEBSOCKET_NO_HEARTBEAT_TIMES = 2
)
View Source
const (
	CLIENT_EVENT_ADDRESS_ALLOCED = 1
	CLIENT_EVENT_RECONNECTING    = 2
	CLIENT_EVENT_STARTED         = 3
	CLIENT_EVENT_STOPPED         = 4
	CLIENT_EVENT_ERROR           = 5
	CLIENT_EVENT_RECONNECTED     = 6
)
View Source
const (
	ERROR_LOGIN   = "login"
	ERROR_NETWORK = "network"
	ERROR_UNKNOWN = "unknown"
	ERROR_IO      = "io"
	ERROR_ALLOC   = "alloc"
)
View Source
const (
	IP4_HEADER_LEN = 20
	TCP_HEADER_LEN = 20
	UDP_HEADER_LEN = 8
	DNS_PORT       = 53
	MTU            = 1504
)
View Source
const (
	CH_WEBSOCKET_WRITE_SIZE         = 100
	WEBSOCKET_HANDSHAKE_TIMEOUT     = 5
	WEBSOCKET_READ_TIMEOUT          = 30
	WEBSOCKET_TCP_WRITE_BUFFER_SIZE = 524288
	WEBSOCKET_TCP_READ_BUFFER_SIZE  = 524288
)
View Source
const (
	POLE_PACKET_HEADER_LEN = 4
)

Variables

View Source
var AesKey = []byte{0x15, 0xfc, 0xf2, 0x66, 0x78, 0x10, 0x5a, 0x34, 0xef, 0x5e, 0xac, 0xcb, 0x6f, 0x78, 0x53, 0xdc}
View Source
var ErrConnectUnknown = errors.New("server unknown error")
View Source
var ErrIPNotExist = errors.New("reconnect ip is not exist")
View Source
var ErrLoginVerify = errors.New("login verify fail")
View Source
var ErrNetwork = errors.New("network error")

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

AES解密

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

AES加密

func ExecuteCommand

func ExecuteCommand(name string, args ...string) ([]byte, error)

func GetHostByEndpoint

func GetHostByEndpoint(endpoint string) (string, error)

func GetRemoteIPByEndpoint

func GetRemoteIPByEndpoint(endpoint string) (string, error)

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func PanicHandler

func PanicHandler()

func PanicHandlerExit

func PanicHandlerExit()

func ReadPacket

func ReadPacket(conn io.Reader) ([]byte, error)

func RunCommand

func RunCommand(name string, args ...string) error

func SetLogger

func SetLogger(elog *elog.EasyLogger)

Types

type Conn

type Conn interface {
	Connect(endpoint string, user string, pwd string, ip string, sni string, skipVerifySSL bool, deviceType string, deviceId string, header http.Header) error
	Close(flag bool) error
	String() string
	IsClosed() bool
	SetHandler(cmd uint16, handler func(PolePacket, Conn))
	Send(pkt []byte)
	StartProcess()
	GetUpDownBytes() (uint64, uint64)
}

type DarwinNetworkManager

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

func NewDarwinNetworkManager

func NewDarwinNetworkManager() *DarwinNetworkManager

func (*DarwinNetworkManager) RefreshDefaultGateway

func (nm *DarwinNetworkManager) RefreshDefaultGateway() error

func (*DarwinNetworkManager) RestoreNetwork

func (nm *DarwinNetworkManager) RestoreNetwork()

func (*DarwinNetworkManager) SetNetwork

func (nm *DarwinNetworkManager) SetNetwork(device string, gateway string, remoteIp string, dns string, routes []string) error

type Http3Conn

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

func NewHttp3Conn

func NewHttp3Conn() *Http3Conn

func (*Http3Conn) Close

func (h3c *Http3Conn) Close(flag bool) error

func (*Http3Conn) Connect

func (h3c *Http3Conn) Connect(endpoint string, user string, pwd string, ip string, sni string, skipVerifySSL bool, deviceType string, deviceId string, header http.Header) error

func (*Http3Conn) GetUpDownBytes

func (h3c *Http3Conn) GetUpDownBytes() (uint64, uint64)

func (*Http3Conn) IsClosed

func (h3c *Http3Conn) IsClosed() bool

func (*Http3Conn) Send

func (h3c *Http3Conn) Send(pkt []byte)

func (*Http3Conn) SetHandler

func (h3c *Http3Conn) SetHandler(cmd uint16, handler func(PolePacket, Conn))

func (*Http3Conn) StartProcess

func (h3c *Http3Conn) StartProcess()

func (*Http3Conn) String

func (h3c *Http3Conn) String() string

type IosTunFile

type IosTunFile struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

func NewIosTunFile

func NewIosTunFile(tun *os.File) *IosTunFile

func (*IosTunFile) Close

func (itf *IosTunFile) Close() error

func (*IosTunFile) Read

func (itf *IosTunFile) Read(p []byte) (int, error)

func (*IosTunFile) Write

func (itf *IosTunFile) Write(p []byte) (int, error)

type LinuxNetworkManager

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

func NewLinuxNetworkManager

func NewLinuxNetworkManager() *LinuxNetworkManager

func (*LinuxNetworkManager) RefreshDefaultGateway

func (nm *LinuxNetworkManager) RefreshDefaultGateway() error

func (*LinuxNetworkManager) RestoreNetwork

func (nm *LinuxNetworkManager) RestoreNetwork()

func (*LinuxNetworkManager) SetNetwork

func (nm *LinuxNetworkManager) SetNetwork(device string, gateway string, remoteIp string, dns string, routes []string) error

type NetworkManager

type NetworkManager interface {
	SetNetwork(device string, gateway string, remoteIp string, dns string, routes []string) error
	RestoreNetwork()
	RefreshDefaultGateway() error
}

type PolePacket

type PolePacket []byte

func (PolePacket) Cmd

func (p PolePacket) Cmd() uint16

func (PolePacket) Len

func (p PolePacket) Len() uint16

func (PolePacket) Payload

func (p PolePacket) Payload() []byte

func (PolePacket) SetCmd

func (p PolePacket) SetCmd(cmd uint16)

func (PolePacket) SetLen

func (p PolePacket) SetLen(len uint16)

type PoleVpnClient

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

func NewPoleVpnClient

func NewPoleVpnClient() (*PoleVpnClient, error)

func (*PoleVpnClient) AskAllocIPAddress

func (pc *PoleVpnClient) AskAllocIPAddress()

func (*PoleVpnClient) AttachTunDevice

func (pc *PoleVpnClient) AttachTunDevice(device *TunDevice)

func (*PoleVpnClient) CloseConnect

func (pc *PoleVpnClient) CloseConnect(flag bool)

func (*PoleVpnClient) GetRemoteIP

func (pc *PoleVpnClient) GetRemoteIP() string

func (*PoleVpnClient) GetUpDownBytes

func (pc *PoleVpnClient) GetUpDownBytes() (uint64, uint64)

func (*PoleVpnClient) HeartBeat

func (pc *PoleVpnClient) HeartBeat()

func (*PoleVpnClient) IsStoped

func (pc *PoleVpnClient) IsStoped() bool

func (*PoleVpnClient) SendHeartBeat

func (pc *PoleVpnClient) SendHeartBeat()

func (*PoleVpnClient) SetEventHandler

func (pc *PoleVpnClient) SetEventHandler(handler func(int, *PoleVpnClient, *anyvalue.AnyValue))

func (*PoleVpnClient) Start

func (pc *PoleVpnClient) Start(endpoint string, user string, pwd string, sni string, skipVerifySSL bool, deviceType string, deviceId string) error

func (*PoleVpnClient) Stop

func (pc *PoleVpnClient) Stop()

func (*PoleVpnClient) WaitStop

func (pc *PoleVpnClient) WaitStop()

type TunDevice

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

func AttachTunDevice

func AttachTunDevice(fd int) *TunDevice

func AttachTunDeviceIos

func AttachTunDeviceIos(fd int) *TunDevice

func NewTunDevice

func NewTunDevice() (*TunDevice, error)

func (*TunDevice) Close

func (td *TunDevice) Close() error

func (*TunDevice) GetInterface

func (td *TunDevice) GetInterface() *water.Interface

type TunIO

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

func NewTunIO

func NewTunIO(size int) *TunIO

func (*TunIO) AttachDevice

func (t *TunIO) AttachDevice(device *TunDevice)

func (*TunIO) Close

func (t *TunIO) Close() error

func (*TunIO) Enqueue

func (t *TunIO) Enqueue(pkt []byte)

func (*TunIO) IsClosed

func (t *TunIO) IsClosed() bool

func (*TunIO) SetPacketHandler

func (t *TunIO) SetPacketHandler(handler func(pkt []byte))

func (*TunIO) StartProcess

func (t *TunIO) StartProcess()

type WebSocketConn

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

func NewWebSocketConn

func NewWebSocketConn() *WebSocketConn

func (*WebSocketConn) Close

func (wsc *WebSocketConn) Close(flag bool) error

func (*WebSocketConn) Connect

func (wsc *WebSocketConn) Connect(endpoint string, user string, pwd string, ip string, sni string, skipVerifySSL bool, deviceType string, deviceId string, header http.Header) error

func (*WebSocketConn) GetUpDownBytes

func (wsc *WebSocketConn) GetUpDownBytes() (uint64, uint64)

func (*WebSocketConn) IsClosed

func (wsc *WebSocketConn) IsClosed() bool

func (*WebSocketConn) Send

func (wsc *WebSocketConn) Send(pkt []byte)

func (*WebSocketConn) SetHandler

func (wsc *WebSocketConn) SetHandler(cmd uint16, handler func(PolePacket, Conn))

func (*WebSocketConn) StartProcess

func (wsc *WebSocketConn) StartProcess()

func (*WebSocketConn) String

func (wsc *WebSocketConn) String() string

type WindowsNetworkManager

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

func NewWindowsNetworkManager

func NewWindowsNetworkManager() *WindowsNetworkManager

func (*WindowsNetworkManager) RefreshDefaultGateway

func (nm *WindowsNetworkManager) RefreshDefaultGateway() error

func (*WindowsNetworkManager) RestoreNetwork

func (nm *WindowsNetworkManager) RestoreNetwork()

func (*WindowsNetworkManager) SetNetwork

func (nm *WindowsNetworkManager) SetNetwork(device string, ip string, remoteIp string, dns string, routes []string) error

Jump to

Keyboard shortcuts

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