blockwise

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockNumberExceedLimit block number exceeded the limit 1,048,576
	ErrBlockNumberExceedLimit = errors.New("block number exceeded the limit 1,048,576")

	// ErrBlockInvalidSize block has invalid size
	ErrBlockInvalidSize = errors.New("block has invalid size")

	// ErrInvalidOptionBlock2 message has invalid value of Block2
	ErrInvalidOptionBlock2 = errors.New("message has invalid value of Block2")

	// ErrInvalidOptionBlock1 message has invalid value of Block1
	ErrInvalidOptionBlock1 = errors.New("message has invalid value of Block1")

	// ErrInvalidResponseCode response code has invalid value
	ErrInvalidResponseCode = errors.New("response code has invalid value")

	// ErrInvalidPayloadSize invalid payload size
	ErrInvalidPayloadSize = errors.New("invalid payload size")

	// ErrInvalidSZX invalid block-wise transfer szx
	ErrInvalidSZX = errors.New("invalid block-wise transfer szx")
)

Functions

func EncodeBlockOption

func EncodeBlockOption(szx SZX, blockNumber int64, moreBlocksFollowing bool) (uint32, error)

EncodeBlockOption encodes block values to coap option.

Types

type BlockWise

type BlockWise struct {
	// contains filtered or unexported fields
}

func NewBlockWise

func NewBlockWise(
	acquireMessage func(ctx context.Context) Message,
	releaseMessage func(Message),
	expiration time.Duration,
	errors func(error),
	autoCleanUpResponseCache bool,
	getSentRequestFromOutside func(token message.Token) (Message, bool),
) *BlockWise

NewBlockWise provides blockwise. getSentRequestFromOutside must returns a copy of request which will be released by function releaseMessage after use.

func (*BlockWise) CheckExpirations added in v2.5.0

func (b *BlockWise) CheckExpirations(now time.Time)

CheckExpirations iterates over caches and remove expired items.

func (*BlockWise) Do

func (b *BlockWise) Do(r Message, maxSzx SZX, maxMessageSize uint32, do func(req Message) (Message, error)) (Message, error)

Do sends an coap message and returns an coap response via blockwise transfer.

func (*BlockWise) Handle

func (b *BlockWise) Handle(w ResponseWriter, r Message, maxSZX SZX, maxMessageSize uint32, next func(w ResponseWriter, r Message))

Handle middleware which constructs COAP request from blockwise transfer and send COAP response via blockwise.

func (*BlockWise) RemoveFromResponseCache

func (b *BlockWise) RemoveFromResponseCache(token message.Token)

RemoveFromResponseCache removes response from cache. It need's tu be used for udp coap.

func (*BlockWise) WriteMessage

func (b *BlockWise) WriteMessage(remoteAddr net.Addr, request Message, maxSZX SZX, maxMessageSize uint32, writeMessage func(r Message) error) error

WriteMessage sends an coap message via blockwise transfer.

type Message

type Message interface {
	// getters
	Context() context.Context
	Code() codes.Code
	Token() message.Token
	Queries() ([]string, error)
	Path() (string, error)
	GetOptionUint32(id message.OptionID) (uint32, error)
	GetOptionBytes(id message.OptionID) ([]byte, error)
	Options() message.Options
	Body() io.ReadSeeker
	BodySize() (int64, error)
	Sequence() uint64
	// setters
	SetCode(codes.Code)
	SetToken(message.Token)
	SetOptionUint32(id message.OptionID, value uint32)
	SetOptionBytes(id message.OptionID, value []byte)

	Remove(id message.OptionID)
	ResetOptionsTo(message.Options)
	SetBody(r io.ReadSeeker)
	SetSequence(uint64)
	String() string
}

Message defines message interface for blockwise transfer.

type ResponseWriter

type ResponseWriter interface {
	Message() Message
	SetMessage(Message)
	RemoteAddr() net.Addr
}

ResponseWriter defines response interface for blockwise transfer.

type SZX

type SZX uint8

SZX enum representation for the size of the block: https://tools.ietf.org/html/rfc7959#section-2.2

const (
	//SZX16 block of size 16bytes
	SZX16 SZX = 0
	//SZX32 block of size 32bytes
	SZX32 SZX = 1
	//SZX64 block of size 64bytes
	SZX64 SZX = 2
	//SZX128 block of size 128bytes
	SZX128 SZX = 3
	//SZX256 block of size 256bytes
	SZX256 SZX = 4
	//SZX512 block of size 512bytes
	SZX512 SZX = 5
	//SZX1024 block of size 1024bytes
	SZX1024 SZX = 6
	//SZXBERT block of size n*1024bytes
	SZXBERT SZX = 7
)

func DecodeBlockOption

func DecodeBlockOption(blockVal uint32) (szx SZX, blockNumber int64, moreBlocksFollowing bool, err error)

DecodeBlockOption decodes coap block option to block values.

func (SZX) Size

func (s SZX) Size() int64

Size number of bytes.

Jump to

Keyboard shortcuts

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