blockwise

package
v3.5.8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 19 Imported by: 8 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultReceivingMessagesCacheMaxEntries = 4096
)

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

	// ErrRequestEntityIncomplete request body is missing blocks
	ErrRequestEntityIncomplete = errors.New("request entity incomplete")

	// ErrRequestEntityTooLarge request body exceeds the size limit
	ErrRequestEntityTooLarge = errors.New("request entity too large")
)

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[C Client] struct {
	// contains filtered or unexported fields
}

func New

func New[C Client](
	cc C,
	expiration time.Duration,
	errors func(error),
	getSentRequestFromOutside func(token message.Token) (*pool.Message, bool),
) *BlockWise[C]

New provides blockwise. getSentRequestFromOutside must returns a copy of request which will be released after use.

func (*BlockWise[C]) CheckExpirations

func (b *BlockWise[C]) CheckExpirations(now time.Time)

CheckExpirations iterates over caches and remove expired items.

func (*BlockWise[C]) Do

func (b *BlockWise[C]) Do(r *pool.Message, maxSzx SZX, maxMessageSize uint32, remoteAddr net.Addr, do func(req *pool.Message) (*pool.Message, error)) (*pool.Message, error)

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

func (*BlockWise[C]) Handle

func (b *BlockWise[C]) Handle(w *responsewriter.ResponseWriter[C], r *pool.Message, maxSZX SZX, maxMessageSize uint32, remoteAddr net.Addr, next func(w *responsewriter.ResponseWriter[C], r *pool.Message))

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

func (*BlockWise[C]) SetMaxReceiveBodySize added in v3.5.6

func (b *BlockWise[C]) SetMaxReceiveBodySize(size int64)

SetMaxReceiveBodySize limits the Block1 body size, 0 means unlimited.

func (*BlockWise[C]) SetReceivingMessagesCacheMaxEntries added in v3.5.7

func (b *BlockWise[C]) SetReceivingMessagesCacheMaxEntries(maxEntries int)

SetReceivingMessagesCacheMaxEntries sets max entries for in-flight incoming block-wise assemblies per connection, including concurrent transfers. Value 0 means unlimited.

func (*BlockWise[C]) SetRollingExpiration added in v3.5.6

func (b *BlockWise[C]) SetRollingExpiration(enabled bool)

SetRollingExpiration resets the Block1 transfer expiration on each new block.

func (*BlockWise[C]) WriteMessage

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

WriteMessage sends an coap message via blockwise transfer.

type Client

type Client interface {
	// create message from pool
	AcquireMessage(ctx context.Context) *pool.Message
	// return back the message to the pool for next use
	ReleaseMessage(m *pool.Message)
}

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