coap

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: Apache-2.0 Imports: 25 Imported by: 3 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

This section is empty.

Variables

View Source
var ExtendedKeyUsage_IDENTITY_CERTIFICATE = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 44924, 1, 6}

Functions

func EncodeETagsForIncrementalChanges added in v2.2.1

func EncodeETagsForIncrementalChanges(etags [][]byte) []string

func GetDeviceIDFromIdentityCertificate

func GetDeviceIDFromIdentityCertificate(cert *x509.Certificate) (string, error)

func NewVerifyPeerCertificate

func NewVerifyPeerCertificate(rootCAs *x509.CertPool, verifyPeerCertificate func(verifyPeerCertificate *x509.Certificate) error) func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error

func TrySetDetailedReponse added in v2.2.1

func TrySetDetailedReponse(response *pool.Message, v interface{}) (interface{}, error)

TrySetDetailedReponse checks if the output value implements DetailedResponseSetter interface and sets the response options (Code and ETag) to the value.

func VerifyCloudCertificate added in v2.3.0

func VerifyCloudCertificate(cert *x509.Certificate, cloudID uuid.UUID) error

func VerifyIdentityCertificate

func VerifyIdentityCertificate(cert *x509.Certificate) error

Types

type Client

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

func NewClient

func NewClient(conn ClientConn) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Context

func (c *Client) Context() context.Context

func (*Client) DeleteResource

func (c *Client) DeleteResource(
	ctx context.Context,
	href string,
	response interface{},
	options ...OptionFunc,
) error

func (*Client) DeleteResourceWithCodec

func (c *Client) DeleteResourceWithCodec(
	ctx context.Context,
	href string,
	codec Codec,
	response interface{},
	options ...OptionFunc,
) error

func (*Client) Done

func (c *Client) Done() <-chan struct{}

func (*Client) GetResource

func (c *Client) GetResource(
	ctx context.Context,
	href string,
	response interface{},
	options ...OptionFunc,
) error

func (*Client) GetResourceWithCodec

func (c *Client) GetResourceWithCodec(
	ctx context.Context,
	href string,
	codec Codec,
	response interface{},
	options ...OptionFunc,
) error

func (*Client) Observe

func (c *Client) Observe(
	ctx context.Context,
	href string,
	codec Codec,
	handler ObservationHandler,
	options ...OptionFunc,
) (Observation, error)

Observe makes a CoAP observation request over a connection.

func (*Client) RemoteAddr

func (c *Client) RemoteAddr() net.Addr

func (*Client) UpdateResource

func (c *Client) UpdateResource(
	ctx context.Context,
	href string,
	request interface{},
	response interface{},
	options ...OptionFunc,
) error

func (*Client) UpdateResourceWithCodec

func (c *Client) UpdateResourceWithCodec(
	ctx context.Context,
	href string,
	codec Codec,
	request interface{},
	response interface{},
	options ...OptionFunc,
) error

type ClientCloseHandler

type ClientCloseHandler struct {
	*Client
	// contains filtered or unexported fields
}

func DialTCP

func DialTCP(ctx context.Context, addr string, opts ...tcp.Option) (*ClientCloseHandler, error)

func DialTCPSecure

func DialTCPSecure(ctx context.Context, addr string, tlsCfg *tls.Config, opts ...tcp.Option) (*ClientCloseHandler, error)

func DialUDP

func DialUDP(ctx context.Context, addr string, opts ...udp.Option) (*ClientCloseHandler, error)

func DialUDPSecure

func DialUDPSecure(ctx context.Context, addr string, dtlsCfg *piondtls.Config, opts ...udp.Option) (*ClientCloseHandler, error)

func NewClientCloseHandler

func NewClientCloseHandler(conn ClientConn, onClose *OnCloseHandler) *ClientCloseHandler

func (*ClientCloseHandler) RegisterCloseHandler

func (c *ClientCloseHandler) RegisterCloseHandler(f CloseHandlerFunc) (closeHandlerID int)

func (*ClientCloseHandler) UnregisterCloseHandler

func (c *ClientCloseHandler) UnregisterCloseHandler(closeHandlerID int)

type ClientConn

type ClientConn = interface {
	Post(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)
	Get(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
	Delete(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
	Observe(ctx context.Context, path string, observeFunc func(notification *pool.Message), opts ...message.Option) (Observation, error)
	RemoteAddr() net.Addr
	Close() error
	Context() context.Context
	Done() <-chan struct{}
}

type CloseHandlerFunc

type CloseHandlerFunc = func(err error)

type Codec

type Codec interface {
	ContentFormat() message.MediaType
	Encode(v interface{}) ([]byte, error)
	Decode(m *pool.Message, v interface{}) error
}

Codec encodes/decodes according to the CoAP content format/media type.

type DecodeFunc

type DecodeFunc = func(interface{}) error

DecodeFunc can be used to pass in the data type that should be decoded.

type DetailedResponse added in v2.2.1

type DetailedResponse[T any] struct {
	Code codes.Code // content format from the response options
	ETag []byte     // ETag from the response
	Body T          // parsed response body, pointer to the variable will be send to codec.Decode
}

DetailedResponse is a response with metadata from the response options.

func (*DetailedResponse[T]) GetBody added in v2.2.1

func (dr *DetailedResponse[T]) GetBody() interface{}

func (*DetailedResponse[T]) SetCode added in v2.2.1

func (dr *DetailedResponse[T]) SetCode(code codes.Code)

func (*DetailedResponse[T]) SetETag added in v2.2.1

func (dr *DetailedResponse[T]) SetETag(etag []byte)

type DetailedResponseSetter added in v2.2.1

type DetailedResponseSetter interface {
	SetCode(code codes.Code)
	SetETag(etag []byte)
	GetBody() interface{}
}

type Observation

type Observation = interface {
	Cancel(context.Context, ...message.Option) error
	Canceled() bool
}

type ObservationHandler

type ObservationHandler interface {
	Handle(client *Client, body DecodeFunc)
	Error(err error)
	Close()
}

ObservationHandler receives notifications from the observation request.

type OnCloseHandler

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

func NewOnCloseHandler

func NewOnCloseHandler() *OnCloseHandler

func (*OnCloseHandler) Add

func (h *OnCloseHandler) Add(onClose func(err error)) int

func (*OnCloseHandler) OnClose

func (h *OnCloseHandler) OnClose(err error)

func (*OnCloseHandler) Remove

func (h *OnCloseHandler) Remove(onCloseID int)

type OptionFunc

type OptionFunc = func(message.Options) message.Options

func WithAccept

func WithAccept(contentFormat message.MediaType) OptionFunc

func WithDeviceID added in v2.0.5

func WithDeviceID(in string) OptionFunc

func WithETag added in v2.2.1

func WithETag(etag []byte) OptionFunc

func WithInterface

func WithInterface(in string) OptionFunc

func WithQuery added in v2.2.1

func WithQuery(query string) OptionFunc

func WithResourceType

func WithResourceType(in string) OptionFunc

Jump to

Keyboard shortcuts

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