protocol

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEAD_SIZE = 4
	HEADER    = "socket-cluster"
	// The maximum length of each message (including headers), which can be set to 4G
	MAX_LENGTH = 1024 * 70
)

Variables

View Source
var ExceededErr = errors.New("The maximum length of the packet is exceeded")
View Source
var HeaderErr = errors.New("The message header is incorrect")

Functions

func GenerateTLSConfigForClient

func GenerateTLSConfigForClient() *tls.Config

GenerateTLSConfigForClient setup a bare-bones(skip verify) TLS config for client.

func GenerateTLSConfigForServer

func GenerateTLSConfigForServer() *tls.Config

GenerateTLSConfigForServer setup a bare-bones TLS config for server.

func NewTLSConfigFromFile

func NewTLSConfigFromFile(tlsCertFile, tlsKeyFile string, insecureSkipVerifyForClient ...bool) (*tls.Config, error)

NewTLSConfigFromFile creates a new TLS config.

Types

type Connection

type Connection interface {
	ReadMsg() ([]byte, error)
	WriteMsg(data []byte) error
	Close() error
	Addr() string
}

type FlowProtocol

type FlowProtocol struct {
	Proto
	// contains filtered or unexported fields
}

func NewFlowProtocol

func NewFlowProtocol(header string, bufLength int, conn io.Reader) *FlowProtocol

func (*FlowProtocol) Pack

func (this *FlowProtocol) Pack(data []byte) ([]byte, error)

Pack Package raw data

func (*FlowProtocol) ReadMsg

func (this *FlowProtocol) ReadMsg() ([]byte, error)

Read Read and parse the received message

type Proto

type Proto interface {
	// Pack writes the Message into the connection.
	// NOTE: Make sure to write only once or there will be package contamination!
	Pack([]byte) ([]byte, error)
	// Read bytes from the connection.
	ReadMsg() ([]byte, error)
}

Proto pack/read protocol scheme of socket message.

type Protocol

type Protocol interface {
	// ListenAndServe turns on the listening service.
	ListenAndServe(port int64, onConnect func(conn Connection)) error
	// Dial connects with the socket of the destination address.
	Dial(addr string) (Connection, error)
}

type Session

type Session struct {
	Conn     Connection
	ClientId string
}

func (*Session) CasClientId

func (s *Session) CasClientId(newClientId string) string

CasClientId sets the session uid and return oldClientId

func (*Session) LoadClientId

func (s *Session) LoadClientId() string

LoadClientId returns the session uid.

func (*Session) StoreClientId

func (s *Session) StoreClientId(newClientId string)

StoreClientId sets the session uid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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