libol

package
v0.0.0-...-04092ee Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PRINT = 01
	LOG   = 05
	STACK = 06
	DEBUG = 10
	FLOW  = 11
	CMD   = 15
	EVENT = 16
	INFO  = 20
	WARN  = 30
	ERROR = 40
	FATAL = 99
)
View Source
const (
	MaxFrame = 1600
	MaxBuf   = 4096
	HlMI     = 0x02
	HlLI     = 0x04
	HlSize   = 0x04
	EthDI    = 0x06
	MaxMsg   = 1600 * 8
)
View Source
const (
	LoginReq     = "logi= "
	LoginResp    = "logi: "
	NeighborReq  = "neig= "
	NeighborResp = "neig: "
	IpAddrReq    = "ipad= "
	IpAddrResp   = "ipad: "
	LeftReq      = "left= "
	SignReq      = "sign= "
	PingReq      = "ping= "
	PongResp     = "pong: "
	NegoReq      = "nego= "
	NegoResp     = "nego: "
)
View Source
const (
	EthArp  = 0x0806
	EthIp4  = 0x0800
	EthIp6  = 0x86DD
	EthVlan = 0x8100
)
View Source
const (
	EtherLen = 14
	VlanLen  = 4
	TcpLen   = 20
	Ipv4Len  = 20
	UdpLen   = 8
)
View Source
const (
	ArpRequest = 1
	ArpReply   = 2
)
View Source
const (
	ArpHrdNetrom = 0
	ArpHrdEther  = 1
)
View Source
const (
	Ipv4Ver = 0x04
	Ipv6Ver = 0x06
)
View Source
const (
	IpIcmp = 0x01
	IpIgmp = 0x02
	IpIpIp = 0x04
	IpTcp  = 0x06
	IpUdp  = 0x11
	IpEsp  = 0x32
	IpAh   = 0x33
	IpOspf = 0x59
	IpPim  = 0x67
	IpVrrp = 0x70
	IpIsis = 0x7c
)
View Source
const (
	TcpUrg = 0x20
	TcpAck = 0x10
	TcpPsh = 0x08
	TcpRst = 0x04
	TcpSyn = 0x02
	TcpFin = 0x01
)
View Source
const (
	ClInit        = 0x00
	ClConnected   = 0x01
	ClUnAuth      = 0x02
	ClAuth        = 0x03
	ClConnecting  = 0x04
	ClTerminal    = 0x05
	ClClosed      = 0x06
	ClNegotiating = 0x07
	ClNegotiated  = 0x08
)
View Source
const (
	CsSendOkay  = "send"
	CsRecvOkay  = "recv"
	CsSendError = "error"
	CsDropped   = "dropped"
)
View Source
const (
	SsRecv   = "recv"
	SsDeny   = "deny"
	SsAlive  = "alive"
	SsSend   = "send"
	SsDrop   = "dropped"
	SsAccept = "accept"
	SsClose  = "closed"
)
View Source
const LeaseTime = "2006-01-02T15"
View Source
const MacBase = 0x00
View Source
const SimpleTime = "2006-01-02 15:04:05"

Variables

View Source
var (
	EthZero = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
	EthAll  = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)
View Source
var (
	Date    string
	Version string
	Commit  string
)
View Source
var Gos = gos{}
View Source
var Letters = []byte("0123456789abcdefghijklmnopqrstuvwxyz")
View Source
var Logger = &logger{
	Level:    INFO,
	FileName: ".log.error",
	Errors:   list.New(),
}
View Source
var MAGIC = []byte{0xff, 0xff}

Functions

func Base64Decode

func Base64Decode(value string) ([]byte, error)

func Base64Encode

func Base64Encode(value []byte) string

func BasicAuth

func BasicAuth(username, password string) string

func Catch

func Catch(name string)

func Cmd

func Cmd(format string, v ...interface{})

func CreateFile

func CreateFile(path string) (*os.File, error)

func Debug

func Debug(format string, v ...interface{})

func Error

func Error(format string, v ...interface{})

func Exec

func Exec(bin string, args ...string) (string, error)

func Fatal

func Fatal(format string, v ...interface{})

func FileExist

func FileExist(file string) error

func FunName

func FunName(i interface{}) string

func GenEthAddr

func GenEthAddr(n int) []byte

func GenInt32

func GenInt32() int

func GenLetters

func GenLetters(n int) []byte

func GenString

func GenString(n int) string

func GenUint32

func GenUint32() uint32

func GetHostPort

func GetHostPort(addr string) (string, string)

func GetIPAddr

func GetIPAddr(addr string) string

func GetKcpBlock

func GetKcpBlock(algo string, key string) kcp.BlockCrypt

func GetLeaseTime

func GetLeaseTime(value string) (time.Time, error)

func GetLocalByGw

func GetLocalByGw(addr string) (net.IP, error)

func GetLocalTime

func GetLocalTime(layout, value string) (time.Time, error)

func GetPrefix

func GetPrefix(value string, index int) string

func GetPrefixLen

func GetPrefixLen(addr string) int

func GetSuffix

func GetSuffix(value string, index int) string

func Go

func Go(call func())

func HasLog

func HasLog(level int) bool

func IPNetmask

func IPNetmask(ipAddr string) (string, error)

func IPNetwork

func IPNetwork(ipAddr string) (string, error)

func IfName

func IfName(name string) string

func Info

func Info(format string, v ...interface{})

func IpAddrAdd

func IpAddrAdd(name, addr string, opts ...string) ([]byte, error)

func IpAddrDel

func IpAddrDel(name, addr string) ([]byte, error)

func IpAddrShow

func IpAddrShow(name string) []string

func IpLinkDown

func IpLinkDown(name string) ([]byte, error)

func IpLinkUp

func IpLinkUp(name string) ([]byte, error)

func IpMetricSet

func IpMetricSet(name, metric string, opts ...string) ([]byte, error)

func IpProto2Str

func IpProto2Str(proto uint8) string

func IpRouteAdd

func IpRouteAdd(name, prefix, nexthop string, opts ...string) ([]byte, error)

func IpRouteDel

func IpRouteDel(name, prefix, nexthop string, opts ...string) ([]byte, error)

func IpRouteShow

func IpRouteShow(name string) []string

func LoadWithoutAnn

func LoadWithoutAnn(file string) ([]byte, error)

func Log

func Log(format string, v ...interface{})

func LookupIP

func LookupIP(name string) string

func Marshal

func Marshal(v interface{}, pretty bool) ([]byte, error)

func MarshalSave

func MarshalSave(v interface{}, file string, pretty bool) error

func Netmask2Len

func Netmask2Len(s string) int

func NewErr

func NewErr(message string, v ...interface{}) error

func OpenRead

func OpenRead(path string) (*os.File, error)

func OpenTrunk

func OpenTrunk(path string) (*os.File, error)

func OpenWrite

func OpenWrite(path string) (*os.File, error)

func ParseAddr

func ParseAddr(addr string) net.IP

func ParseNet

func ParseNet(addr string) (*net.IPNet, error)

func PreNotify

func PreNotify()

func PrettyBytes

func PrettyBytes(b int64) string

func PrettyTime

func PrettyTime(t int64) string

func Print

func Print(format string, v ...interface{})

func ScanAnn

func ScanAnn(r io.Reader) ([]byte, error)

func SdNotify

func SdNotify()

func SetLevel

func SetLevel(level int)

func SetLogger

func SetLogger(file string, level int)

func Stack

func Stack(format string, v ...interface{})

func Sudo

func Sudo(bin string, args ...string) (string, error)

func Uint2S

func Uint2S(value uint32) string

func Unmarshal

func Unmarshal(v interface{}, contents []byte) error

func UnmarshalLoad

func UnmarshalLoad(v interface{}, file string) error

func Wait

func Wait()

func Warn

func Warn(format string, v ...interface{})

func XDPListen

func XDPListen(addr string, clients, bufSize int) (net.Listener, error)

Types

type Arp

type Arp struct {
	HrdCode uint16 // format hardware address
	ProCode uint16 // format protocol address
	HrdLen  uint8  // length of hardware address
	ProLen  uint8  // length of protocol address
	OpCode  uint16 // ARP Op(command)

	SHwAddr []byte // sender hardware address.
	SIpAddr []byte // sender IP address.
	THwAddr []byte // target hardware address.
	TIpAddr []byte // target IP address.
	Len     int
}

func NewArp

func NewArp() (a *Arp)

func NewArpFromFrame

func NewArpFromFrame(frame []byte) (a *Arp, err error)

func (*Arp) Decode

func (a *Arp) Decode(frame []byte) error

func (*Arp) Encode

func (a *Arp) Encode() []byte

func (*Arp) IsIP4

func (a *Arp) IsIP4() bool

func (*Arp) IsReply

func (a *Arp) IsReply() bool

func (*Arp) IsRequest

func (a *Arp) IsRequest() bool

type Auth

type Auth struct {
	Type     string
	Username string
	Password string
}

type BlockCrypt

type BlockCrypt struct {
	kcp.BlockCrypt
	// contains filtered or unexported fields
}

func CopyBlockCrypt

func CopyBlockCrypt(crypt *BlockCrypt) *BlockCrypt

func NewBlockCrypt

func NewBlockCrypt(algo string, key string) *BlockCrypt

func (*BlockCrypt) Update

func (b *BlockCrypt) Update(key string)

type CertConfig

type CertConfig struct {
	Key      string
	Crt      string
	RootCa   string
	Insecure bool
}

type ClientListener

type ClientListener struct {
	OnClose     func(client SocketClient) error
	OnConnected func(client SocketClient) error
	OnStatus    func(client SocketClient, old, new SocketStatus)
}

type ControlMessage

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

func NewControlMessage

func NewControlMessage(action, opr string, body []byte) *ControlMessage

operator: request is '= ', and response is ': ' action: login, network etc. body: json string.

func (*ControlMessage) Encode

func (c *ControlMessage) Encode() *FrameMessage

type Ether

type Ether struct {
	Dst  []byte
	Src  []byte
	Type uint16
	Len  int
}

func NewEther

func NewEther(t uint16) (e *Ether)

func NewEtherArp

func NewEtherArp() (e *Ether)

func NewEtherFromFrame

func NewEtherFromFrame(frame []byte) (e *Ether, err error)

func NewEtherIP4

func NewEtherIP4() (e *Ether)

func (*Ether) Decode

func (e *Ether) Decode(frame []byte) error

func (*Ether) Encode

func (e *Ether) Encode() []byte

func (*Ether) IsArp

func (e *Ether) IsArp() bool

func (*Ether) IsIP4

func (e *Ether) IsIP4() bool

func (*Ether) IsVlan

func (e *Ether) IsVlan() bool

type FrameMessage

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

func NewControlFrame

func NewControlFrame(action string, body []byte) *FrameMessage

func NewFrameMessage

func NewFrameMessage(maxSize int) *FrameMessage

func NewFrameMessageFromBytes

func NewFrameMessageFromBytes(buffer []byte) *FrameMessage

func (*FrameMessage) Action

func (m *FrameMessage) Action() string

func (*FrameMessage) Append

func (m *FrameMessage) Append(data []byte)

func (*FrameMessage) CmdAndParams

func (m *FrameMessage) CmdAndParams() (string, []byte)

func (*FrameMessage) Decode

func (m *FrameMessage) Decode() bool

func (*FrameMessage) Frame

func (m *FrameMessage) Frame() []byte

func (*FrameMessage) IsControl

func (m *FrameMessage) IsControl() bool

func (*FrameMessage) IsEthernet

func (m *FrameMessage) IsEthernet() bool

func (*FrameMessage) Proto

func (m *FrameMessage) Proto() (*FrameProto, error)

func (*FrameMessage) SetSize

func (m *FrameMessage) SetSize(v int)

func (*FrameMessage) Size

func (m *FrameMessage) Size() int

func (*FrameMessage) String

func (m *FrameMessage) String() string

type FrameProto

type FrameProto struct {
	// public
	Eth   *Ether
	Vlan  *Vlan
	Arp   *Arp
	Ip4   *Ipv4
	Udp   *Udp
	Tcp   *Tcp
	Err   error
	Frame []byte
}

func (*FrameProto) Decode

func (i *FrameProto) Decode() error

type HttpClient

type HttpClient struct {
	Method    string
	Url       string
	Payload   io.Reader
	Auth      Auth
	TlsConfig *tls.Config
	Client    *http.Client
}

func (*HttpClient) Close

func (cl *HttpClient) Close()

func (*HttpClient) Do

func (cl *HttpClient) Do() (*http.Response, error)

type Ipv4

type Ipv4 struct {
	Version        uint8 //4bite v4: 0100, v6: 0110
	HeaderLen      uint8 //4bit 15*4
	ToS            uint8 //Type of Service
	TotalLen       uint16
	Identifier     uint16
	Flag           uint16 //3bit Z|DF|MF
	Offset         uint16 //13bit Fragment offset
	ToL            uint8  //Time of Live
	Protocol       uint8
	HeaderChecksum uint16 //Header Checksum
	Source         []byte
	Destination    []byte
	Options        uint32 //Reserved
	Len            int
}

func NewIpv4

func NewIpv4() (i *Ipv4)

func NewIpv4FromFrame

func NewIpv4FromFrame(frame []byte) (i *Ipv4, err error)

func (*Ipv4) Decode

func (i *Ipv4) Decode(frame []byte) error

func (*Ipv4) Encode

func (i *Ipv4) Encode() []byte

func (*Ipv4) IsIP4

func (i *Ipv4) IsIP4() bool

type KcpClient

type KcpClient struct {
	*SocketClientImpl
	// contains filtered or unexported fields
}

func NewKcpClient

func NewKcpClient(addr string, cfg *KcpConfig) *KcpClient

func NewKcpClientFromConn

func NewKcpClientFromConn(conn net.Conn, cfg *KcpConfig) *KcpClient

func (*KcpClient) Close

func (c *KcpClient) Close()

func (*KcpClient) Connect

func (c *KcpClient) Connect() error

func (*KcpClient) SetStatus

func (c *KcpClient) SetStatus(v SocketStatus)

func (*KcpClient) Terminal

func (c *KcpClient) Terminal()

type KcpConfig

type KcpConfig struct {
	Block        *BlockCrypt
	WinSize      int           // default 1024
	DataShards   int           // default 10
	ParityShards int           // default 3
	Timeout      time.Duration // ns
	RdQus        int           // per frames
	WrQus        int           // per frames
}

func NewKcpConfig

func NewKcpConfig() *KcpConfig

type KcpServer

type KcpServer struct {
	*SocketServerImpl
	// contains filtered or unexported fields
}

func NewKcpServer

func NewKcpServer(listen string, cfg *KcpConfig) *KcpServer

func (*KcpServer) Accept

func (k *KcpServer) Accept()

func (*KcpServer) Close

func (k *KcpServer) Close()

func (*KcpServer) Listen

func (k *KcpServer) Listen() (err error)

type LDAPConfig

type LDAPConfig struct {
	Server    string
	BindUser  string
	BindPass  string
	BaseDN    string
	Attr      string
	Filter    string
	EnableTls bool
	Timeout   int64
}

type LDAPService

type LDAPService struct {
	Conn *ldap.Conn
	Cfg  LDAPConfig
}

func NewLDAPService

func NewLDAPService(cfg LDAPConfig) (*LDAPService, error)

func (*LDAPService) Login

func (l *LDAPService) Login(userName, password string) (bool, error)

type Message

type Message struct {
	Level   string `json:"level"`
	Date    string `json:"date"`
	Message string `json:"message"`
	Module  string `json:"module"`
}

type Messager

type Messager interface {
	Crypt() *BlockCrypt
	SetCrypt(*BlockCrypt)
	Send(conn net.Conn, frame *FrameMessage) (int, error)
	Receive(conn net.Conn, max, min int) (*FrameMessage, error)
	Flush()
}

type PProf

type PProf struct {
	File   string
	Listen string
	Error  error
}

func (*PProf) Start

func (p *PProf) Start()

func (*PProf) Stop

func (p *PProf) Stop()

type PacketMessagerImpl

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

func (*PacketMessagerImpl) Crypt

func (s *PacketMessagerImpl) Crypt() *BlockCrypt

func (*PacketMessagerImpl) Flush

func (s *PacketMessagerImpl) Flush()

func (*PacketMessagerImpl) Receive

func (s *PacketMessagerImpl) Receive(conn net.Conn, max, min int) (*FrameMessage, error)

func (*PacketMessagerImpl) Send

func (s *PacketMessagerImpl) Send(conn net.Conn, frame *FrameMessage) (int, error)

func (*PacketMessagerImpl) SetCrypt

func (s *PacketMessagerImpl) SetCrypt(block *BlockCrypt)

type Promise

type Promise struct {
	Count  int
	MaxTry int
	First  time.Duration // the delay time.
	MinInt time.Duration // the normal time.
	MaxInt time.Duration // the max delay time.
}

func NewPromise

func NewPromise(first, min, max time.Duration) *Promise

func (*Promise) Done

func (p *Promise) Done(call func() error)

func (*Promise) Go

func (p *Promise) Go(call func() error)

type ReadClient

type ReadClient func(client SocketClient, f *FrameMessage) error

type SafeStrInt64

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

func NewSafeStrInt64

func NewSafeStrInt64() *SafeStrInt64

func (*SafeStrInt64) Add

func (s *SafeStrInt64) Add(k string, v int64)

func (*SafeStrInt64) Copy

func (s *SafeStrInt64) Copy(dst map[string]int64)

func (*SafeStrInt64) Data

func (s *SafeStrInt64) Data() map[string]int64

func (*SafeStrInt64) Get

func (s *SafeStrInt64) Get(k string) int64

func (*SafeStrInt64) Set

func (s *SafeStrInt64) Set(k string, v int64)

type SafeStrMap

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

func NewSafeStrMap

func NewSafeStrMap(size int) *SafeStrMap

func (*SafeStrMap) Clear

func (sm *SafeStrMap) Clear()

func (*SafeStrMap) Del

func (sm *SafeStrMap) Del(k string)

func (*SafeStrMap) Get

func (sm *SafeStrMap) Get(k string) interface{}

func (*SafeStrMap) GetEx

func (sm *SafeStrMap) GetEx(k string) (interface{}, bool)

func (*SafeStrMap) Iter

func (sm *SafeStrMap) Iter(proc func(k string, v interface{})) int

func (*SafeStrMap) Len

func (sm *SafeStrMap) Len() int

func (*SafeStrMap) Mod

func (sm *SafeStrMap) Mod(k string, v interface{}) error

func (*SafeStrMap) Set

func (sm *SafeStrMap) Set(k string, v interface{}) error

type SafeStrStr

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

func NewSafeStrStr

func NewSafeStrStr(size int) *SafeStrStr

func (*SafeStrStr) Del

func (sm *SafeStrStr) Del(k string)

func (*SafeStrStr) Get

func (sm *SafeStrStr) Get(k string) string

func (*SafeStrStr) GetEx

func (sm *SafeStrStr) GetEx(k string) (string, bool)

func (*SafeStrStr) Iter

func (sm *SafeStrStr) Iter(proc func(k, v string)) int

func (*SafeStrStr) Len

func (sm *SafeStrStr) Len() int

func (*SafeStrStr) Reset

func (sm *SafeStrStr) Reset(k, v string) error

func (*SafeStrStr) Set

func (sm *SafeStrStr) Set(k, v string) error

type SafeVar

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

func NewSafeVar

func NewSafeVar() *SafeVar

func (*SafeVar) Get

func (sv *SafeVar) Get() interface{}

func (*SafeVar) GetWithFunc

func (sv *SafeVar) GetWithFunc(proc func(v interface{}))

func (*SafeVar) Set

func (sv *SafeVar) Set(v interface{})

type ServerListener

type ServerListener struct {
	OnClient func(client SocketClient) error
	OnClose  func(client SocketClient) error
	ReadAt   func(client SocketClient, f *FrameMessage) error
}

type SocketClient

type SocketClient interface {
	LocalAddr() string
	RemoteAddr() string
	Connect() error
	Close()
	WriteMsg(frame *FrameMessage) error
	ReadMsg() (*FrameMessage, error)
	UpTime() int64
	AliveTime() int64
	String() string
	Terminal()
	Private() interface{}
	SetPrivate(v interface{})
	Status() SocketStatus
	SetStatus(v SocketStatus)
	MaxSize() int
	SetMaxSize(value int)
	MinSize() int
	IsOk() bool
	Have(status SocketStatus) bool
	Statistics() map[string]int64
	SetListener(listener ClientListener)
	SetTimeout(v int64)
	Out() *SubLogger
	SetKey(key string)
	Key() string
}

type SocketClientImpl

type SocketClientImpl struct {
	*StreamSocket
	// contains filtered or unexported fields
}

func NewSocketClient

func NewSocketClient(cfg SocketConfig, message Messager) *SocketClientImpl

func (*SocketClientImpl) AliveTime

func (s *SocketClientImpl) AliveTime() int64

func (*SocketClientImpl) Close

func (s *SocketClientImpl) Close()

MUST IMPLEMENT

func (*SocketClientImpl) Connect

func (s *SocketClientImpl) Connect() error

MUST IMPLEMENT

func (*SocketClientImpl) Have

func (s *SocketClientImpl) Have(state SocketStatus) bool

func (*SocketClientImpl) MaxSize

func (s *SocketClientImpl) MaxSize() int

func (*SocketClientImpl) MinSize

func (s *SocketClientImpl) MinSize() int

func (*SocketClientImpl) Out

func (s *SocketClientImpl) Out() *SubLogger

func (*SocketClientImpl) Private

func (s *SocketClientImpl) Private() interface{}

func (*SocketClientImpl) Reset

func (s *SocketClientImpl) Reset(conn net.Conn)

func (*SocketClientImpl) Retry

func (s *SocketClientImpl) Retry() bool

func (*SocketClientImpl) SetListener

func (s *SocketClientImpl) SetListener(listener ClientListener)

func (*SocketClientImpl) SetMaxSize

func (s *SocketClientImpl) SetMaxSize(value int)

func (*SocketClientImpl) SetPrivate

func (s *SocketClientImpl) SetPrivate(v interface{})

func (*SocketClientImpl) SetStatus

func (s *SocketClientImpl) SetStatus(v SocketStatus)

MUST IMPLEMENT

func (*SocketClientImpl) SetTimeout

func (s *SocketClientImpl) SetTimeout(v int64)

func (*SocketClientImpl) Statistics

func (s *SocketClientImpl) Statistics() map[string]int64

func (*SocketClientImpl) Status

func (s *SocketClientImpl) Status() SocketStatus

func (*SocketClientImpl) Terminal

func (s *SocketClientImpl) Terminal()

MUST IMPLEMENT

func (*SocketClientImpl) UpTime

func (s *SocketClientImpl) UpTime() int64

type SocketConfig

type SocketConfig struct {
	Address string
	Block   *BlockCrypt
}

type SocketServer

type SocketServer interface {
	Listen() (err error)
	Close()
	Accept()
	ListClient() <-chan SocketClient
	OffClient(client SocketClient)
	TotalClient() int
	Loop(call ServerListener)
	Read(client SocketClient, ReadAt ReadClient)
	String() string
	Address() string
	Statistics() map[string]int64
	SetTimeout(v int64)
}

type SocketServerImpl

type SocketServerImpl struct {
	WrQus int // per frames.
	// contains filtered or unexported fields
}

TODO keepalive to release zombie connections.

func NewSocketServer

func NewSocketServer(listen string) *SocketServerImpl

func (*SocketServerImpl) Accept

func (t *SocketServerImpl) Accept()

MUST IMPLEMENT

func (*SocketServerImpl) Address

func (t *SocketServerImpl) Address() string

func (*SocketServerImpl) Close

func (t *SocketServerImpl) Close()

MUST IMPLEMENT

func (*SocketServerImpl) ListClient

func (t *SocketServerImpl) ListClient() <-chan SocketClient

func (*SocketServerImpl) Listen

func (t *SocketServerImpl) Listen() error

MUST IMPLEMENT

func (*SocketServerImpl) Loop

func (t *SocketServerImpl) Loop(call ServerListener)

func (*SocketServerImpl) OffClient

func (t *SocketServerImpl) OffClient(client SocketClient)

func (*SocketServerImpl) Read

func (t *SocketServerImpl) Read(client SocketClient, ReadAt ReadClient)

func (*SocketServerImpl) SetTimeout

func (t *SocketServerImpl) SetTimeout(v int64)

func (*SocketServerImpl) Statistics

func (t *SocketServerImpl) Statistics() map[string]int64

func (*SocketServerImpl) String

func (t *SocketServerImpl) String() string

func (*SocketServerImpl) TotalClient

func (t *SocketServerImpl) TotalClient() int

type SocketStatus

type SocketStatus uint8

func (SocketStatus) String

func (s SocketStatus) String() string

type StreamMessagerImpl

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

func (*StreamMessagerImpl) Crypt

func (s *StreamMessagerImpl) Crypt() *BlockCrypt

func (*StreamMessagerImpl) Flush

func (s *StreamMessagerImpl) Flush()

func (*StreamMessagerImpl) Receive

func (s *StreamMessagerImpl) Receive(conn net.Conn, max, min int) (*FrameMessage, error)

430Mib

func (*StreamMessagerImpl) Send

func (s *StreamMessagerImpl) Send(conn net.Conn, frame *FrameMessage) (int, error)

func (*StreamMessagerImpl) SetCrypt

func (s *StreamMessagerImpl) SetCrypt(block *BlockCrypt)

type StreamSocket

type StreamSocket struct {
	Block *BlockCrypt
	// contains filtered or unexported fields
}

func (*StreamSocket) IsOk

func (t *StreamSocket) IsOk() bool

func (*StreamSocket) Key

func (t *StreamSocket) Key() string

func (*StreamSocket) LocalAddr

func (t *StreamSocket) LocalAddr() string

func (*StreamSocket) ReadMsg

func (t *StreamSocket) ReadMsg() (*FrameMessage, error)

func (*StreamSocket) RemoteAddr

func (t *StreamSocket) RemoteAddr() string

func (*StreamSocket) SetKey

func (t *StreamSocket) SetKey(key string)

func (*StreamSocket) String

func (t *StreamSocket) String() string

func (*StreamSocket) WriteMsg

func (t *StreamSocket) WriteMsg(frame *FrameMessage) error

type SubLogger

type SubLogger struct {
	Prefix string
	// contains filtered or unexported fields
}

func NewSubLogger

func NewSubLogger(prefix string) *SubLogger

func (*SubLogger) Cmd

func (s *SubLogger) Cmd(format string, v ...interface{})

func (*SubLogger) Debug

func (s *SubLogger) Debug(format string, v ...interface{})

func (*SubLogger) Error

func (s *SubLogger) Error(format string, v ...interface{})

func (*SubLogger) Event

func (s *SubLogger) Event(format string, v ...interface{})

func (*SubLogger) Fatal

func (s *SubLogger) Fatal(format string, v ...interface{})

func (*SubLogger) Flow

func (s *SubLogger) Flow(format string, v ...interface{})

func (*SubLogger) Fmt

func (s *SubLogger) Fmt(format string) string

func (*SubLogger) Has

func (s *SubLogger) Has(level int) bool

func (*SubLogger) Info

func (s *SubLogger) Info(format string, v ...interface{})

func (SubLogger) List

func (l SubLogger) List() <-chan *Message

func (*SubLogger) Log

func (s *SubLogger) Log(format string, v ...interface{})

func (*SubLogger) Print

func (s *SubLogger) Print(format string, v ...interface{})

func (SubLogger) Save

func (l SubLogger) Save(level string, format string, v ...interface{})

func (*SubLogger) Stack

func (s *SubLogger) Stack(format string, v ...interface{})

func (*SubLogger) Warn

func (s *SubLogger) Warn(format string, v ...interface{})

func (SubLogger) Write

func (l SubLogger) Write(level int, format string, v ...interface{})

type Tcp

type Tcp struct {
	Source         uint16
	Destination    uint16
	Sequence       uint32
	Acknowledgment uint32
	DataOffset     uint8
	ControlBits    uint8
	Window         uint16
	Checksum       uint16
	UrgentPointer  uint16
	Options        []byte
	Padding        []byte
	Len            int
}

func NewTcp

func NewTcp() (t *Tcp)

func NewTcpFromFrame

func NewTcpFromFrame(frame []byte) (t *Tcp, err error)

func (*Tcp) Decode

func (t *Tcp) Decode(frame []byte) error

func (*Tcp) Encode

func (t *Tcp) Encode() []byte

func (*Tcp) HasFlag

func (t *Tcp) HasFlag(flag uint8) bool

type TcpClient

type TcpClient struct {
	*SocketClientImpl
	// contains filtered or unexported fields
}

func NewTcpClient

func NewTcpClient(addr string, cfg *TcpConfig) *TcpClient

func NewTcpClientFromConn

func NewTcpClientFromConn(conn net.Conn, cfg *TcpConfig) *TcpClient

func (*TcpClient) Close

func (t *TcpClient) Close()

func (*TcpClient) Connect

func (t *TcpClient) Connect() error

func (*TcpClient) SetStatus

func (t *TcpClient) SetStatus(v SocketStatus)

func (*TcpClient) Terminal

func (t *TcpClient) Terminal()

type TcpConfig

type TcpConfig struct {
	Tls     *tls.Config
	Block   *BlockCrypt
	Timeout time.Duration // ns
	RdQus   int           // per frames
	WrQus   int           // per frames
}

type TcpServer

type TcpServer struct {
	*SocketServerImpl
	// contains filtered or unexported fields
}

func NewTcpServer

func NewTcpServer(listen string, cfg *TcpConfig) *TcpServer

func (*TcpServer) Accept

func (t *TcpServer) Accept()

func (*TcpServer) Close

func (t *TcpServer) Close()

func (*TcpServer) Listen

func (t *TcpServer) Listen() (err error)

type Udp

type Udp struct {
	Source      uint16
	Destination uint16
	Length      uint16
	Checksum    uint16
	Len         int
}

func NewUdp

func NewUdp() (u *Udp)

func NewUdpFromFrame

func NewUdpFromFrame(frame []byte) (u *Udp, err error)

func (*Udp) Decode

func (u *Udp) Decode(frame []byte) error

func (*Udp) Encode

func (u *Udp) Encode() []byte

type UdpClient

type UdpClient struct {
	*SocketClientImpl
	// contains filtered or unexported fields
}

func NewUdpClient

func NewUdpClient(addr string, cfg *UdpConfig) *UdpClient

func NewUdpClientFromConn

func NewUdpClientFromConn(conn net.Conn, cfg *UdpConfig) *UdpClient

func (*UdpClient) Close

func (c *UdpClient) Close()

func (*UdpClient) Connect

func (c *UdpClient) Connect() error

func (*UdpClient) SetStatus

func (c *UdpClient) SetStatus(v SocketStatus)

func (*UdpClient) Terminal

func (c *UdpClient) Terminal()

type UdpConfig

type UdpConfig struct {
	Block   *BlockCrypt
	Timeout time.Duration // ns
	Clients int
	RdQus   int // per frames
	WrQus   int // per frames
}

type UdpInConnection

type UdpInConnection struct {
	Socket     int
	RemotePort uint16
	RemoteAddr string
	Spi        uint32
	Hostname   string
}

func (*UdpInConnection) Connection

func (c *UdpInConnection) Connection() string

func (*UdpInConnection) String

func (c *UdpInConnection) String() string

type UdpInServer

type UdpInServer struct {
	Port   uint16
	Socket int

	SeqNo uint32
	// contains filtered or unexported fields
}

func (*UdpInServer) Open

func (u *UdpInServer) Open() error

func (*UdpInServer) Recv

func (u *UdpInServer) Recv() (*UdpInConnection, error)

func (*UdpInServer) Send

func (u *UdpInServer) Send(to *UdpInConnection) error

type UdpServer

type UdpServer struct {
	*SocketServerImpl
	// contains filtered or unexported fields
}

func NewUdpServer

func NewUdpServer(listen string, cfg *UdpConfig) *UdpServer

func (*UdpServer) Accept

func (k *UdpServer) Accept()

func (*UdpServer) Close

func (k *UdpServer) Close()

func (*UdpServer) Listen

func (k *UdpServer) Listen() (err error)

type Vlan

type Vlan struct {
	Tci uint16
	Vid uint16
	Pro uint16
	Len int
}

func NewVlan

func NewVlan(tci uint16, vid uint16) (n *Vlan)

func NewVlanFromFrame

func NewVlanFromFrame(frame []byte) (n *Vlan, err error)

func (*Vlan) Decode

func (n *Vlan) Decode(frame []byte) error

func (*Vlan) Encode

func (n *Vlan) Encode() []byte

type WaitOne

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

func NewWaitOne

func NewWaitOne(n int) *WaitOne

func (*WaitOne) Done

func (w *WaitOne) Done()

func (*WaitOne) Wait

func (w *WaitOne) Wait()

type WebClient

type WebClient struct {
	*SocketClientImpl

	RdBuf int // per frames
	WrBuf int // per frames
	// contains filtered or unexported fields
}

func NewWebClient

func NewWebClient(addr string, cfg *WebConfig) *WebClient

func NewWebClientFromConn

func NewWebClientFromConn(conn net.Conn, cfg *WebConfig) *WebClient

func (*WebClient) Close

func (t *WebClient) Close()

func (*WebClient) Connect

func (t *WebClient) Connect() error

func (*WebClient) GetCertPool

func (t *WebClient) GetCertPool(ca string) *x509.CertPool

func (*WebClient) SetStatus

func (t *WebClient) SetStatus(v SocketStatus)

func (*WebClient) Terminal

func (t *WebClient) Terminal()

type WebConfig

type WebConfig struct {
	Cert    *CertConfig
	Block   *BlockCrypt
	Timeout time.Duration // ns
	RdQus   int           // per frames
	WrQus   int           // per frames
}

type WebServer

type WebServer struct {
	*SocketServerImpl
	// contains filtered or unexported fields
}

func NewWebServer

func NewWebServer(listen string, cfg *WebConfig) *WebServer

func (*WebServer) Accept

func (t *WebServer) Accept()

func (*WebServer) Close

func (t *WebServer) Close()

func (*WebServer) Listen

func (t *WebServer) Listen() (err error)

type WsClient

type WsClient struct {
	Auth      Auth
	Url       string
	TlsConfig *tls.Config
	Protocol  string
}

func (*WsClient) Dial

func (w *WsClient) Dial() (ws *websocket.Conn, err error)

func (*WsClient) Initialize

func (w *WsClient) Initialize()

type XDP

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

func (*XDP) Accept

func (x *XDP) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*XDP) Addr

func (x *XDP) Addr() net.Addr

returns the listener's network address.

func (*XDP) Close

func (x *XDP) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

func (*XDP) Loop

func (x *XDP) Loop()

Loop forever

func (*XDP) Recv

func (x *XDP) Recv(udpAddr *net.UDPAddr, data []byte) error

type XDPConn

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

func (*XDPConn) Close

func (c *XDPConn) Close() error

func (*XDPConn) LocalAddr

func (c *XDPConn) LocalAddr() net.Addr

func (*XDPConn) Read

func (c *XDPConn) Read(b []byte) (n int, err error)

func (*XDPConn) RemoteAddr

func (c *XDPConn) RemoteAddr() net.Addr

func (*XDPConn) SetDeadline

func (c *XDPConn) SetDeadline(t time.Time) error

func (*XDPConn) SetReadDeadline

func (c *XDPConn) SetReadDeadline(t time.Time) error

func (*XDPConn) SetWriteDeadline

func (c *XDPConn) SetWriteDeadline(t time.Time) error

func (*XDPConn) String

func (c *XDPConn) String() string

func (*XDPConn) Write

func (c *XDPConn) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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