protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultFlag             = 0x6562 // eb
	DefaultVersion          = 0x1
	DefaultHeaderLength     = 12
	DefaultHashHeaderLength = 20
	MaxHeaderLength         = 60
	MaskVersion             = 0xF0
	MaskHeaderLength        = 0x0F
)
View Source
const (
	SignallingCommand       uint8 = 0x0F
	SignallingAssign        uint8 = 0x00
	SignallingEvent         uint8 = 0x10
	SignallingControl       uint8 = 0x20
	SignallingHeart         uint8 = 0x00
	SignallingRegisterEvent uint8 = 0x01
	SignallingHash          uint8 = 0x02
	SignallingEventHash           = SignallingEvent | SignallingHash
)

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 (
	ProtoEventBus = 170
	ProtoEvent    = 171
)
View Source
const (
	OptionHeartTime = "HEART_TIME"
	OptionReconnect = "RECONNECT"
)
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 IsEventID

func IsEventID(v uint32) bool

func PipeEvent

func PipeEvent(p mangos.Pipe) uint32

func PutHashHeader

func PutHashHeader(header []byte, src uint32, dest uint32, hash uint64) []byte

func PutHeader

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

func StringHeader

func StringHeader(header []byte) string

Types

type Header struct {
	Data []byte
}

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) Hash

func (h *Header) Hash() uint64

func (*Header) HeaderLength

func (h *Header) HeaderLength() uint8

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) SetDest

func (h *Header) SetDest(v uint32)

func (*Header) SetFlag

func (h *Header) SetFlag(v uint16)

func (*Header) SetHash

func (h *Header) SetHash(v uint64)

func (*Header) SetHeaderLength

func (h *Header) SetHeaderLength(v uint8)

func (*Header) SetSignalling

func (h *Header) SetSignalling(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) 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)
	WaitAllPipe()
}

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