protocol

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFlag                     = 0x6562 // eb
	DefaultVersion                  = 0x1
	DefaultHeaderLength             = 12
	DefaultEventHeaderLength        = 20
	MaxHeaderLength                 = 60
	MaskVersion                     = 0xF0
	MaskHeaderLength                = 0x0F
	MaskEventID              uint32 = 0x80000000 // 事件ID掩码
	MaskInterIP              uint32 = 0x7FFFFFFF // 内部IP掩码
)
View Source
const (
	SignallingCommand uint8 = 0x0F // Command mask
	SignallingType    uint8 = 0xF0 // Type Mask
	SignallingAssign  uint8 = 0x00 // Assign flag
	SignallingEvent   uint8 = 0x10 // Event flag
	SignallingControl uint8 = 0x20 // Control flag
)

Signalling Format (UINT8):

 7   6   5   4   3   2   1   0
 *   *   *   *   *   *   *   *
 │   │   │   │   │           │
 └─┬─┘   │   │   └─────┬─────┘
Reserve  │   │         └> Command - 0x00 ~ 0x0F
         │   └> Event - 0x10
         └> Control - 0x20
0    0   0   0 -> Assign - 0x00
View Source
const (
	SignallingHeart         uint8 = 0x00 // Heart
	SignallingRegisterEvent uint8 = 0x01 // Register event
	SignallingDhc           uint8 = 0x02 // Dynamic host configuration
)

Control Command

View Source
const (
	SignallingRandom uint8 = 0x00 // random
	SignallingHash   uint8 = 0x01 // Hash
	SignallingRound  uint8 = 0x02 // round

	SignallingEventHash = SignallingEvent | SignallingHash // Hash event command mask
)

Event Command

View Source
const (
	ProtoEventBus = 170
	ProtoEvent    = 171
)
View Source
const (
	OptionHeartTime    = "HEART_TIME"
	OptionReconnect    = "RECONNECT"
	OptionTraceMessage = "TRACE_MESSAGE"
)
View Source
const (
	PipeEventRegistered = iota + mangos.PipeEventDetached + 1
	PipeEventHeartBeat
)
View Source
const (
	ErrBadHeader = errors.ErrBadHeader
)
View Source
const (
	PipeEbus = 0x65627573 | 0x80000000 // ebus
)

Variables

View Source
var (
	ErrBadEventName = errors.New("invalid event name")
	ErrBadAddress   = errors.New("invalid socket address")
	ErrNoWatcher    = errors.New("no connected watcher")
	ErrNoSource     = errors.New("no connected source")
)

Functions

func EventName

func EventName(event uint32) string

func EventNameN

func EventNameN(name string) uint32

func InetAtoN

func InetAtoN(ip string) uint32

func InetNtoA

func InetNtoA(i uint32) string

func IsControl added in v0.2.0

func IsControl(v uint8) bool

func IsEvent added in v0.2.0

func IsEvent(v uint8) bool

func IsEventID

func IsEventID(v uint32) bool

func PipeEvent

func PipeEvent(p mangos.Pipe) uint32

func PutHeader

func PutHeader(header []byte, src uint32, signalling uint8, dest uint32, key uint64) []byte

func StringHeader

func StringHeader(header []byte) string

Types

type Header struct {
	Data []byte
}

func (*Header) BalanceKey added in v0.2.0

func (h *Header) BalanceKey() uint64

func (*Header) Dest

func (h *Header) Dest() uint32

func (*Header) Flag

func (h *Header) Flag() uint16

func (*Header) HasHash

func (h *Header) HasHash() bool

func (*Header) HasRound added in v0.2.0

func (h *Header) HasRound() bool

func (*Header) HeaderLength

func (h *Header) HeaderLength() uint8

func (*Header) IsControl added in v0.2.0

func (h *Header) IsControl() bool

func (*Header) IsDhc added in v0.2.0

func (h *Header) IsDhc() bool

func (*Header) IsEvent

func (h *Header) IsEvent() bool

func (*Header) IsHeart

func (h *Header) IsHeart() bool

func (*Header) IsRegisterEvent

func (h *Header) IsRegisterEvent() bool

func (*Header) SetBalanceKey added in v0.2.0

func (h *Header) SetBalanceKey(v uint64)

func (*Header) SetDest

func (h *Header) SetDest(v uint32)

func (*Header) SetFlag

func (h *Header) SetFlag(v uint16)

func (*Header) SetHeaderLength

func (h *Header) SetHeaderLength(v uint8)

func (*Header) SetSignalling

func (h *Header) SetSignalling(v uint8)

func (*Header) SetSignallingCommand added in v0.2.0

func (h *Header) SetSignallingCommand(v uint8)

func (*Header) SetSignallingType

func (h *Header) SetSignallingType(v uint8)

func (*Header) SetSrc

func (h *Header) SetSrc(v uint32)

func (*Header) SetVersion

func (h *Header) SetVersion(v uint8)

func (*Header) Signalling

func (h *Header) Signalling() uint8

func (*Header) SignallingCommand added in v0.2.0

func (h *Header) SignallingCommand() uint8

func (*Header) SignallingType

func (h *Header) SignallingType() uint8

func (*Header) Src

func (h *Header) Src() uint32

func (*Header) String

func (h *Header) String() string

func (*Header) Version

func (h *Header) Version() uint8

type Pipe

type Pipe interface {
	// Event returns event id
	Event() uint32

	// SetEvent is set event id
	SetEvent(uint32)

	// RemoteID is remote id
	RemoteID() uint32

	// LocalAddr is local address
	LocalAddr() string

	// RemoteAddr is remote address
	RemoteAddr() string

	// Pipe is mangos pipe
	Pipe() mangos.Pipe

	// ID returns a unique 31-bit value associated with this.
	// The value is unique for a given socket, at a given time.
	ID() uint32

	// Close does what you think.
	Close() error

	// Stop does with no reconnect
	Stop()

	// SendMsg sends a message.  On success, it returns nil. This is a
	// blocking call.
	SendMsg(*protocol.Message) error

	// RecvMsg receives a message.  It blocks until the message is
	// received.  On error, the pipe is closed and nil is returned.
	RecvMsg() *protocol.Message

	// SetPrivate is used to set protocol private data.
	SetPrivate(interface{})

	// GetPrivate returns the previously stored protocol private data.
	GetPrivate() interface{}
}

func LocalPipe

func LocalPipe(p mangos.Pipe) Pipe

type PipeEventHook

type PipeEventHook func(mangos.PipeEvent, Pipe) interface{}

type Protocol

type Protocol interface {
	protocol.Protocol
	SetPipeEventHook(PipeEventHook)
}

type Socket

type Socket interface {
	// Info returns information about the protocol (numbers and names)
	// and peer protocol.
	Info() mangos.ProtocolInfo

	// Close closes the open Socket.  Further operations on the socket
	// will return ErrClosed.
	Close() error

	// Send puts the message on the outbound send queue.  It blocks
	// until the message can be queued, or the send deadline expires.
	// If a queued message is later dropped for any reason,
	// there will be no notification back to the application.
	Send([]byte) error

	// Recv receives a complete message.  The entire message is received.
	Recv() ([]byte, error)

	// SendMsg puts the message on the outbound send.  It works like Send,
	// but allows the caller to supply message headers.  AGAIN, the Socket
	// ASSUMES OWNERSHIP OF THE MESSAGE.
	SendMsg(*protocol.Message) error

	// RecvMsg receives a complete message, including the message header,
	// which is useful for protocols in raw mode.
	RecvMsg() (*protocol.Message, error)

	// Dial connects a remote endpoint to the Socket.  The function
	// returns immediately, and an asynchronous goroutine is started to
	// establish and maintain the connection, reconnecting as needed.
	// If the address is invalid, then an error is returned.
	Dial(addr string) error

	DialOptions(addr string, options map[string]interface{}) error

	// NewDialer returns a Dialer object which can be used to get
	// access to the underlying configuration for dialing.
	NewDialer(addr string, options map[string]interface{}) (mangos.Dialer, error)

	// Listen connects a local endpoint to the Socket.  Remote peers
	// may connect (e.g. with Dial) and will each be "connected" to
	// the Socket.  The accepter logic is run in a separate goroutine.
	// The only error possible is if the address is invalid.
	Listen(addr string) error

	ListenOptions(addr string, options map[string]interface{}) error

	NewListener(addr string, options map[string]interface{}) (mangos.Listener, error)

	// GetOption is used to retrieve an option for a socket.
	GetOption(name string) (interface{}, error)

	// SetOption is used to set an option for a socket.
	SetOption(name string, value interface{}) error

	// OpenContext creates a new Context.  If a protocol does not
	// support separate contexts, this will return an error.
	OpenContext() (mangos.Context, error)

	// SetPipeEventHook sets a PipeEventHook function to be called when a
	// Pipe is added or removed from this socket (connect/disconnect).
	SetPipeEventHook(PipeEventHook)
}

func MakeSocket

func MakeSocket(proto Protocol, hook mangos.PipeEventHook) Socket

MakeSocket creates a Socket on top of a Protocol.

Jump to

Keyboard shortcuts

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