core

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 22 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// the timeout of a socks5 requester shake with an AhriSocks5Server.
	Socks5ShakeTimeoutMillisec = 400
	// the timeout of an AhriClient registers itself with an AhriServer.
	AhriShakeTimeoutSec = 3

	// the maximum number of proxy frames that an AhriClientPartner can save in a special golang channel.
	AhriClientPartnerProxyFrameMaxSize = 10240
	// the maximum number of proxy frames that an AhriServer can save in a special golang channel.
	AhriServerProxyFrameMaxSize = AhriClientPartnerProxyFrameMaxSize * 20

	// Addr Type
	Socks5AddrTypeIPv4   = 0x01
	Socks5AddrTypeDomain = 0x03
	Socks5AddrTypeIPv6   = 0x04

	// Client Mode: 'Take': Serviced, 'Give': Service provider, 'Trader': Both
	AhriClientModeTake  = 0
	AhriClientModeGive  = 1
	AhriClientModeTrade = 2

	// Special Addr Name
	AhriAddrNameLocal      = "L"
	AhriAddrNameAhriServer = "S"
	AhriAddrNameForbidden  = "-"
	AhriAddrNameIntercept  = "|"

	// ARP ACK
	ArpAckOk                            = 0x00
	ArpAckWrongPassword                 = 0x01
	ArpAckClientNameIsAlreadyRegistered = 0x02
	ArpAckUnknownMode                   = 0x03
	ArpAckIllegalAesPassword            = 0x04

	// AFP
	AfpFlag          = 0x24
	AfpHeaderLen     = 16
	AfpFrameMaxLen   = 4096
	AfpPayloadMaxLen = AfpFrameMaxLen - AfpHeaderLen

	// AFP Frame type
	AfpFrameTypeHeartbeat    = 0x00
	AfpFrameTypeDirect       = 0x01
	AfpFrameTypeProxy        = 0x02
	AfpFrameTypeDial         = 0x03
	AfpFrameTypeDialAck      = 0x04
	AfpFrameTypeDialProxy    = 0x05
	AfpFrameTypeDialProxyAck = 0x06

	// AFP ACK
	AfpAckOk  = 0x00
	AfpAckErr = 0x01

	// ignore errors
	IgnoreErrorSendOnClosedChannel  = "send on closed channel"
	IgnoreErrorInvalidMemoryAddress = "runtime error: invalid memory address or nil pointer dereference"
)
View Source
const Version = "0.9.3"

Variables

View Source
var (
	Log         Logger
	Debug       Logger
	ByteArrPool = NewByteArrPool(AfpFrameMaxLen)

	// the timeout of one-way communication time interval between an AhriClient and an AhriServer;
	// AhriClient.Dial().timeout = 3 * AhriTimeoutSec
	// heartbeat timeout = 2 * AhriTimeoutSec
	AhriTimeoutSec int

	NoDeadline = time.Time{}

	// Socks5 ACK
	Socks5NoAcceptableMethods           []byte
	Socks5SecretFree                    []byte
	Socks5ConnectionNotAllowedByRuleset []byte
	Socks5UnsupportedCommand            []byte
	Socks5UnsupportedAddressType        []byte
	Socks5Success                       []byte
)

Functions

func BytesToUint16

func BytesToUint16(bs []byte) uint16

func BytesToUint64

func BytesToUint64(bs []byte) uint64

func DecryptAesCfb256

func DecryptAesCfb256(encrypted []byte, aesCipher cipher.Block) (decrypted []byte)

=================== AES-256-CFB Decrypt ====================== quote from this url(https://blog.csdn.net/u012978258/article/details/87868999)

func DecryptRsa

func DecryptRsa(ciphertext []byte, priKey []byte) ([]byte, error)

=================== RSA Encrypt ====================== quote from this url(http://www.361way.com/golang-rsa-aes/5828.html)

func EncryptAesCfb256

func EncryptAesCfb256(origData []byte, aesCipher cipher.Block) (encrypted []byte)

=================== AES-256-CFB Encrypt ====================== quote from this url(https://blog.csdn.net/u012978258/article/details/87868999)

func EncryptRsa

func EncryptRsa(origData []byte, pubKey []byte) ([]byte, error)

=================== RSA Encrypt ====================== quote from this url(http://www.361way.com/golang-rsa-aes/5828.html)

func GenerateAes256Key

func GenerateAes256Key() [32]byte

func MapperAhriAddrName

func MapperAhriAddrName(atyp byte, byteAddr []byte, mapper map[string]string) string

return a ahriAddrName.

func NetAddrString

func NetAddrString(ip, port string) string

ip + port ==> format like 127.0.0.1:80, [xx:xx::xx:xx::xx]:80

func NewByteArrPool

func NewByteArrPool(sizeLimit int) *byteArrPool

func ParseAddrCtxMapper

func ParseAddrCtxMapper(lines []string, ahriHostsPath string) map[string]string

lines: lines of the hosts config file. ahriHostsPath: path of the hosts config file.

func Uint16ToBytes

func Uint16ToBytes(n uint16) []byte

func Uint64ToBytes

func Uint64ToBytes(n uint64) []byte

func ValidIp

func ValidIp(ip string) bool

func ValidPort

func ValidPort(port string) bool

Types

type AhriAddr

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

func (*AhriAddr) ParseDstAddrIP

func (ahriAddr *AhriAddr) ParseDstAddrIP() error

func (*AhriAddr) String

func (ahriAddr *AhriAddr) String() string

type AhriClient

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

func NewAhriClient

func NewAhriClient(serverIp, serverPort, serverPassword, clientName string, mode int) *AhriClient

func (*AhriClient) Dial

func (client *AhriClient) Dial(addr *AhriAddr, connId uint64) (conn *AhriConn, e error)

func (*AhriClient) Stop

func (client *AhriClient) Stop()

type AhriConn

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

当 targetAddr == AhriAddrNameLocal, AhriConn 的行为与 *net.TCPConn 基本一致 当 targetAddr == AhriAddrNameAhriServer 或者目标名, AhriConn 就是一个虚拟连接

func NewAhriConnForVirtualization

func NewAhriConnForVirtualization(
	from string,
	to string,
	connId uint64,
	aesCipher cipher.Block,
	afpFrameType int,
	connReceiver chan AhriFrame,
	sender func(AhriFrame) error,
	willClose func(*AhriConn)) *AhriConn

func (*AhriConn) Close

func (conn *AhriConn) Close() error

func (*AhriConn) Id

func (conn *AhriConn) Id() string

仅作为标识, 其内容并不是人类可读的内容

func (*AhriConn) LocalAddr

func (conn *AhriConn) LocalAddr() net.Addr

func (*AhriConn) Read

func (conn *AhriConn) Read(b []byte) (n int, err error)

func (*AhriConn) RemoteAddr

func (conn *AhriConn) RemoteAddr() net.Addr

func (*AhriConn) SetDeadline

func (conn *AhriConn) SetDeadline(t time.Time) error

func (*AhriConn) SetLinger

func (conn *AhriConn) SetLinger(sec int) error

func (*AhriConn) SetReadDeadline

func (conn *AhriConn) SetReadDeadline(t time.Time) error

func (*AhriConn) SetWriteDeadline

func (conn *AhriConn) SetWriteDeadline(t time.Time) error

func (*AhriConn) Write

func (conn *AhriConn) Write(b []byte) (n int, err error)

type AhriFrame

type AhriFrame []byte

func NewAhriFrame

func NewAhriFrame(source []byte) AhriFrame

type AhriServer

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

func NewAhriServer

func NewAhriServer(ip, port, password, rsaPriKeyPath, rsaPubKeyPath string) *AhriServer

func (*AhriServer) Stop

func (server *AhriServer) Stop()

type AhriSocks5Server

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

func NewAhriSocks5Server

func NewAhriSocks5Server(socks5IP, socks5Port, ahriHostsPath string, ahriClient *AhriClient) *AhriSocks5Server

func (*AhriSocks5Server) Stop

func (ahriSocks5Server *AhriSocks5Server) Stop()

type Alog

type Alog struct {
	LowLevel LogLevel
}

func (*Alog) Crash

func (a *Alog) Crash(log string)

func (*Alog) Crashf

func (a *Alog) Crashf(format string, args ...interface{})

func (*Alog) Debug

func (a *Alog) Debug(log string)

func (*Alog) Debugf

func (a *Alog) Debugf(format string, args ...interface{})

func (*Alog) Deny

func (a *Alog) Deny(level LogLevel) bool

func (*Alog) Error

func (a *Alog) Error(log string)

func (*Alog) Errorf

func (a *Alog) Errorf(format string, args ...interface{})

func (*Alog) Info

func (a *Alog) Info(log string)

func (*Alog) Infof

func (a *Alog) Infof(format string, args ...interface{})

func (*Alog) NoLevel

func (a *Alog) NoLevel(log string)

func (*Alog) NoLevelf

func (a *Alog) NoLevelf(format string, args ...interface{})

func (*Alog) Warn

func (a *Alog) Warn(log string)

func (*Alog) Warnf

func (a *Alog) Warnf(format string, args ...interface{})

type LogLevel

type LogLevel int
const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelCrash
	NoLevel
)

func (LogLevel) String

func (level LogLevel) String() string

type Logger

type Logger interface {
	Deny(LogLevel) bool

	NoLevel(log string)
	NoLevelf(format string, args ...interface{})

	Debug(log string)
	Info(log string)
	Warn(log string)
	Error(log string)
	Crash(log string)

	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Crashf(format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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