mbapp

package
v0.0.0-...-d4b7e32 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 12 Imported by: 2

README

Message Based Application Platform Protocol

MBAPP (em-bee-app) is a protocol for reliable Asks on top of a SecureSwarm. It also allows passthrough of Tells.

MBAPP supports carrying deadline information, and status codes over the wire. It also performs message fragmentation and reassembly. This allows the application to send messages which exceed the MTU of the underlying transport.

Wire Format

MBAPP prepends a 24 byte header to each message.

Documentation

Index

Constants

View Source
const (
	HeaderSize = 6 * 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Addr     p2p.Addr
	Code     uint8
	Request  []byte
	Response []byte
}

func (AppError) Error

func (e AppError) Error() string

type GroupID

type GroupID struct {
	OriginTime PhaseTime32
	Counter    uint32
}
type Header []byte

Header

|<-        32 bits             ->|

0 | mode bits 24| resp code 8| 1 | origin time 32| 2 | counter 32| 3 | part size 32| 4 | part index 16| part count 16| 5 | timeout or dest time

func ParseMessage

func ParseMessage(data []byte) (Header, []byte, error)

func (Header) GetCounter

func (h Header) GetCounter() uint32

Word 2

func (Header) GetErrorCode

func (h Header) GetErrorCode() uint8

func (Header) GetOriginTime

func (h Header) GetOriginTime() PhaseTime32

Word 1

func (Header) GetPartCount

func (h Header) GetPartCount() uint16

func (Header) GetPartIndex

func (h Header) GetPartIndex() uint16

Word 4

func (Header) GetTimeout

func (h Header) GetTimeout() time.Duration

func (Header) GetTotalSize

func (h Header) GetTotalSize() uint32

Word 3

func (Header) GroupID

func (h Header) GroupID() GroupID

func (Header) IsAsk

func (h Header) IsAsk() bool

Word 0

func (Header) IsReply

func (h Header) IsReply() bool

func (Header) SetCounter

func (h Header) SetCounter(x uint32)

func (Header) SetErrorCode

func (h Header) SetErrorCode(v uint8)

func (Header) SetIsAsk

func (h Header) SetIsAsk(yes bool)

func (Header) SetIsReply

func (h Header) SetIsReply(yes bool)

func (Header) SetOriginTime

func (h Header) SetOriginTime(pt PhaseTime32)

func (Header) SetPartCount

func (h Header) SetPartCount(v uint16)

func (Header) SetPartIndex

func (h Header) SetPartIndex(v uint16)

func (Header) SetTimeout

func (h Header) SetTimeout(v uint32)

Extensions

func (Header) SetTotalSize

func (h Header) SetTotalSize(size uint32)

type Option

type Option = func(c *swarmConfig)

func WithBackground

func WithBackground(ctx context.Context) Option

func WithNumWorkers

func WithNumWorkers(n int) Option

type PhaseTime32

type PhaseTime32 uint32

PhaseTime32 represents a timestamp but relative to another timestamp with a longer memory. If a bound can be placed on the difference in clocks between two processes it can provide higher accuracy with fewer bits.

func NewPhaseTime32

func NewPhaseTime32(x time.Time, units time.Duration) PhaseTime32

func (PhaseTime32) UTC

func (pt PhaseTime32) UTC(now time.Time, units time.Duration) time.Time

type Swarm

type Swarm[A p2p.Addr, Pub any] struct {
	// contains filtered or unexported fields
}

func New

func New[A p2p.Addr, Pub any](x p2p.SecureSwarm[A, Pub], mtu int, opts ...Option) *Swarm[A, Pub]

func (*Swarm[A, Pub]) Ask

func (s *Swarm[A, Pub]) Ask(ctx context.Context, resp []byte, dst A, req p2p.IOVec) (int, error)

func (*Swarm[A, Pub]) Close

func (s *Swarm[A, Pub]) Close() error

func (*Swarm[A, Pub]) LocalAddrs

func (s *Swarm[A, Pub]) LocalAddrs() []A

func (*Swarm[A, Pub]) LookupPublicKey

func (s *Swarm[A, Pub]) LookupPublicKey(ctx context.Context, x A) (Pub, error)

func (*Swarm[A, Pub]) MTU

func (s *Swarm[A, Pub]) MTU() int

func (*Swarm[A, Pub]) ParseAddr

func (s *Swarm[A, Pub]) ParseAddr(x []byte) (A, error)

func (*Swarm[A, Pub]) PublicKey

func (s *Swarm[A, Pub]) PublicKey() Pub

func (*Swarm[A, Pub]) Receive

func (s *Swarm[A, Pub]) Receive(ctx context.Context, th func(p2p.Message[A])) error

func (*Swarm[A, Pub]) ServeAsk

func (s *Swarm[A, Pub]) ServeAsk(ctx context.Context, fn func(context.Context, []byte, p2p.Message[A]) int) error

func (*Swarm[A, Pub]) Tell

func (s *Swarm[A, Pub]) Tell(ctx context.Context, dst A, msg p2p.IOVec) error

Jump to

Keyboard shortcuts

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