nets

package
v0.0.0-...-9ae062e Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	None string = "none"
	WS   string = "ws"
	TCP  string = "tcp"
	KCP  string = "kcp"
	HTTP string = "http"
)
View Source
const (
	PCK_MIN_SIZE int   = 6          // |--- header 4bytes ---|--- length 2 bytes ---|--- other datas --- ....
	PCK_HEADER   int32 = 0x2123676f // !#go
)

Variables

This section is empty.

Functions

func AddConnInfo

func AddConnInfo(id string, proto string, conn net.Conn, netWorker INetWorker) error

func AllNodes

func AllNodes() []string

func AllNodesAndPeers

func AllNodesAndPeers() []string

func AllPeers

func AllPeers() []string

func AutoPing

func AutoPing()

func CombineOriginInfo

func CombineOriginInfo(id string, url string, sig string) string

func EOF

func EOF(err error) bool

func GetInfoIdByConn

func GetInfoIdByConn(conn net.Conn) (string, bool)

func IsLocalIPv4

func IsLocalIPv4(ip string) error

func IsPeer

func IsPeer(id string) bool

func Label

func Label(id string) string

func LocalIPv4s

func LocalIPv4s() ([]string, error)

func NodeConned

func NodeConned(id string) bool

func Nodes

func Nodes(label string) []string

func ParserOriginInfo

func ParserOriginInfo(origin string) (string, string, string, error)

func RanPeerId

func RanPeerId() string

func RemoveConnInfo

func RemoveConnInfo(id string)

func ResetConnState

func ResetConnState(id string, msg []byte) bool

Types

type ConnInfos

type ConnInfos struct {
	LOCK sync.RWMutex
	// contains filtered or unexported fields
}

type ConnState

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

type INetEventListener

type INetEventListener interface {
	OnConn(string)
	OnMsg(string, []byte)
	OnClose(string, error)
	OnError(string, error)
	OnCheckNode(string) (string, bool)
}

type INetWorker

type INetWorker interface {
	Listen(url string) error
	Connect(id string, url string, origin string) error
	Send(conn net.Conn, msg []byte) error
	SendText(conn net.Conn, str string) error
	Close(id string, conn net.Conn) error
	BindEventListener(eventListener INetEventListener) error
}

func GetInfoConnById

func GetInfoConnById(id string) (net.Conn, string, INetWorker, bool)

type KcpNetWorker

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

func NewKcpNetWorker

func NewKcpNetWorker() *KcpNetWorker

func (*KcpNetWorker) BindEventListener

func (k *KcpNetWorker) BindEventListener(eventListener INetEventListener) error

func (*KcpNetWorker) Close

func (k *KcpNetWorker) Close(id string, conn net.Conn) error

func (*KcpNetWorker) Connect

func (k *KcpNetWorker) Connect(id string, url string, origin string) error

func (*KcpNetWorker) Listen

func (k *KcpNetWorker) Listen(url string) error

func (*KcpNetWorker) Send

func (k *KcpNetWorker) Send(conn net.Conn, msg []byte) error

func (*KcpNetWorker) SendText

func (k *KcpNetWorker) SendText(conn net.Conn, str string) error

type TcpBuffer

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

func NewTcpBuffer

func NewTcpBuffer(buf []byte) *TcpBuffer

func (*TcpBuffer) AddDataLen

func (t *TcpBuffer) AddDataLen(count int)

func (*TcpBuffer) Buffer

func (t *TcpBuffer) Buffer() []byte

func (*TcpBuffer) Capcity

func (t *TcpBuffer) Capcity() int

func (*TcpBuffer) Clear

func (t *TcpBuffer) Clear()

func (*TcpBuffer) Count

func (t *TcpBuffer) Count() int

func (*TcpBuffer) DeleteData

func (t *TcpBuffer) DeleteData(count int)

func (*TcpBuffer) Dispose

func (t *TcpBuffer) Dispose()

func (*TcpBuffer) Offset

func (t *TcpBuffer) Offset() int

func (*TcpBuffer) Reset

func (t *TcpBuffer) Reset()

func (*TcpBuffer) Slice

func (t *TcpBuffer) Slice() []byte

type TcpNetWorker

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

func NewTcpNetWorker

func NewTcpNetWorker() *TcpNetWorker

func (*TcpNetWorker) BindEventListener

func (t *TcpNetWorker) BindEventListener(eventListener INetEventListener) error

func (*TcpNetWorker) Close

func (t *TcpNetWorker) Close(id string, conn net.Conn) error

func (*TcpNetWorker) Connect

func (t *TcpNetWorker) Connect(id string, url string, origin string) error

func (*TcpNetWorker) Listen

func (t *TcpNetWorker) Listen(url string) error

func (*TcpNetWorker) Send

func (t *TcpNetWorker) Send(conn net.Conn, msg []byte) error

func (*TcpNetWorker) SendText

func (t *TcpNetWorker) SendText(conn net.Conn, str string) error

type WSNetWorker

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

func NewWSNetWorker

func NewWSNetWorker() *WSNetWorker

func (*WSNetWorker) BindEventListener

func (w *WSNetWorker) BindEventListener(eventListener INetEventListener) error

func (*WSNetWorker) Close

func (w *WSNetWorker) Close(id string, conn net.Conn) error

func (*WSNetWorker) Connect

func (w *WSNetWorker) Connect(id string, url string, origin string) error

func (*WSNetWorker) Listen

func (w *WSNetWorker) Listen(url string) error

func (*WSNetWorker) Send

func (w *WSNetWorker) Send(conn net.Conn, msg []byte) error

func (*WSNetWorker) SendText

func (w *WSNetWorker) SendText(conn net.Conn, str string) error

Jump to

Keyboard shortcuts

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