Back to godoc.org
github.com/dist-ribut-us/message

package message

v0.0.0 (99b306f)
Latest Go to latest
Published: Jun 22, 2018 | License: BSD-3-Clause | Module: github.com/dist-ribut-us/message

Overview

Package message provides a common messaging header for IPC and Network communication. The body of the message can be used to hold raw data or can hold a marshalled protobuf.

Package message is a generated protocol buffer package.

It is generated from these files:

message/message.proto

It has these top-level messages:

Header
Addrpb

Index

Constants

const (
	QueryFlag = BitFlag(1 << (iota))
	ResponseFlag
	FromNet
	ToNet
)

Flag masks Flags field

const (
	Undefined = Type(iota)
	GetPort
	GetIP
	RegisterService
	Test
	Ping
	NetSend
	NetReceive
	AddBeacon
	GetPubKey
	Die
	SessionData
	StaticKey
	RandomKey
)

Types for messages

const (
	BeaconService uint32 = 19860714
	PoolService   uint32 = 1111111111
)

Services

const ServiceTypeOffset = 1024

ServiceTypeOffset claims the first 1024 values are reserved, after that, values are specific to the service handling them.

type Addrpb

type Addrpb struct {
	Ip   []byte `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
	Port uint32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"`
	Zone string `protobuf:"bytes,3,opt,name=zone" json:"zone,omitempty"`
}

func FromAddr

func FromAddr(addr *rnet.Addr) *Addrpb

FromAddr creates and Addrpb from an rnet.Addr

func UnmarshalAddrpb

func UnmarshalAddrpb(buf []byte) *Addrpb

UnmarshalAddrpb unmarshals a buffer to an Addrpb. If there is an error it is logged and a nil value is returned.

func (*Addrpb) Descriptor

func (*Addrpb) Descriptor() ([]byte, []int)

func (*Addrpb) GetAddr

func (a *Addrpb) GetAddr() *rnet.Addr

GetAddr returns the Addrpb as an rnet.Addr

func (*Addrpb) GetIp

func (m *Addrpb) GetIp() []byte

func (*Addrpb) GetPort

func (m *Addrpb) GetPort() uint32

func (*Addrpb) GetZone

func (m *Addrpb) GetZone() string

func (*Addrpb) Marshal

func (a *Addrpb) Marshal() []byte

Marshal a header to a buffer. If there is an error it is logged and nil is returned.

func (*Addrpb) ProtoMessage

func (*Addrpb) ProtoMessage()

func (*Addrpb) Reset

func (m *Addrpb) Reset()

func (*Addrpb) String

func (m *Addrpb) String() string

type BitFlag

type BitFlag uint32

BitFlag is used to set flags on the header flag field

type Header struct {
	Type32  uint32  `protobuf:"varint,1,opt,name=type32" json:"type32,omitempty"`
	Service uint32  `protobuf:"varint,2,opt,name=service" json:"service,omitempty"`
	Flags   uint32  `protobuf:"varint,3,opt,name=flags" json:"flags,omitempty"`
	Body    []byte  `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
	Id      uint32  `protobuf:"varint,5,opt,name=id" json:"id,omitempty"`
	NodeID  []byte  `protobuf:"bytes,6,opt,name=nodeID,proto3" json:"nodeID,omitempty"`
	Addrpb  *Addrpb `protobuf:"bytes,7,opt,name=Addrpb" json:"Addrpb,omitempty"`
}

func NewHeader

func NewHeader(t Type, body interface{}) *Header

NewHeader takes a type and a body. See SetBody for valid body types

func Unmarshal

func Unmarshal(buf []byte) *Header

Unmarshal a buffer to a header. If there is an error it is logged and a nil value is returned.

func (*Header) BodyString

func (h *Header) BodyString() string

BodyString returns the body as a string

func (*Header) BodyToUint32

func (h *Header) BodyToUint32() uint32

BodyToUint32 uses dist.ribut.us/serial to Unmarshal the body.

func (*Header) CheckFlag

func (h *Header) CheckFlag(flag BitFlag) bool

CheckFlag checks if a bit flag is set

func (*Header) Descriptor

func (*Header) Descriptor() ([]byte, []int)

func (*Header) GetAddr

func (h *Header) GetAddr() *rnet.Addr

GetAddr returns the Addrpb as an rnet.Addr

func (*Header) GetAddrpb

func (m *Header) GetAddrpb() *Addrpb

func (*Header) GetBody

func (m *Header) GetBody() []byte

func (*Header) GetFlags

func (m *Header) GetFlags() uint32

func (*Header) GetId

func (m *Header) GetId() uint32

func (*Header) GetNodeID

func (m *Header) GetNodeID() []byte

func (*Header) GetService

func (m *Header) GetService() uint32

func (*Header) GetType

func (h *Header) GetType() Type

GetType returns the Type

func (*Header) GetType32

func (m *Header) GetType32() uint32

func (*Header) IsFromNet

func (h *Header) IsFromNet() bool

IsFromNet checks if the FromNet flag is set

func (*Header) IsQuery

func (h *Header) IsQuery() bool

IsQuery checks if the underlying type is a query

func (*Header) IsResponse

func (h *Header) IsResponse() bool

IsResponse checks if the underlying type is a query

func (*Header) IsToNet

func (h *Header) IsToNet() bool

IsToNet checks if the FromNet flag is set

func (*Header) Marshal

func (h *Header) Marshal() []byte

Marshal a header to a buffer. If there is an error it is logged and nil is returned.

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) SetAddr

func (h *Header) SetAddr(addr *rnet.Addr) *Header

SetAddr sets the underlying Addrpb struct in the Header

func (*Header) SetBody

func (h *Header) SetBody(body interface{}) *Header

SetBody takes various types and tries to set the Body field. If body is nil, that will set the body to nil. If body is a []byte, that will be set on the body. If it is a string, it will be cast to []byte. If the body is a proto.Message it will be marshalled and the serialized data will be used. If it is a uint32, dist.ribut.us/serial will be used to marshal the value into body.

func (*Header) SetFlag

func (h *Header) SetFlag(flag BitFlag)

SetFlag sets a bit in the flag field

func (*Header) SetType

func (h *Header) SetType(t Type)

SetType sets the Type

func (*Header) String

func (m *Header) String() string

func (*Header) Unmarshal

func (h *Header) Unmarshal(pb proto.Message) error

Unmarshal the body of the header

func (*Header) UnsetFlag

func (h *Header) UnsetFlag(flag BitFlag)

UnsetFlag removes a flag

type Type

type Type uint32

Type for message header

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier