Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Conn
- func (cc *Conn) AcquireMessage(ctx context.Context) *pool.Message
- func (cc *Conn) AddOnClose(f EventFunc)
- func (cc *Conn) AsyncPing(receivedPong func()) (func(), error)
- func (cc *Conn) CancelObservation(token message.Token)
- func (cc *Conn) CancelQBlock(key string)
- func (cc *Conn) CheckExpirations(now time.Time)
- func (cc *Conn) Close() error
- func (cc *Conn) Context() context.Context
- func (cc *Conn) DelayQBlock(key string, deadline time.Time)
- func (cc *Conn) Done() <-chan struct{}
- func (cc *Conn) GetMessageID() int32
- func (cc *Conn) InactivityMonitor() InactivityMonitor
- func (cc *Conn) LocalAddr() net.Addr
- func (cc *Conn) NetConn() net.Conn
- func (cc *Conn) OpenQBlockExchange(ctx context.Context, token message.Token) (blockwise.QBlockExchange, error)
- func (cc *Conn) Process(cm *coapNet.ControlMessage, datagram []byte) error
- func (cc *Conn) ProcessReceivedMessage(req *pool.Message)
- func (cc *Conn) ProcessReceivedMessageWithHandler(req *pool.Message, handler config.HandlerFunc[*Conn])
- func (cc *Conn) ReleaseMessage(m *pool.Message)
- func (cc *Conn) RemoteAddr() net.Addr
- func (cc *Conn) Run() error
- func (cc *Conn) ScheduleQBlock(key string, deadline time.Time, run func() error) error
- func (cc *Conn) SendQBlock(msg *pool.Message) error
- func (cc *Conn) SendQBlockAsync(msg *pool.Message, done func(error)) error
- func (cc *Conn) Sequence() uint64
- func (cc *Conn) Session() Session
- func (cc *Conn) SetContextValue(key interface{}, val interface{})
- func (cc *Conn) Transmission() *Transmission
- func (cc *Conn) WriteMessage(req *pool.Message) error
- func (cc *Conn) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, options ...coapNet.MulticastOption) error
- type ConnOptions
- type CreateInactivityMonitorFunc
- type ErrorFunc
- type EventFunc
- type GetMIDFunc
- type HandlerFunc
- type InactivityMonitor
- type MalformedMessageError
- type MessageCache
- type MutexMap
- type Option
- type RequestMonitorFunc
- type RequestsMap
- type Session
- type Transmission
- type Unlocker
Constants ¶
const DefaultMTU = 1472
const DefaultMaxPendingMessages uint32 = 1024
const ExchangeLifetime = 247 * time.Second
Variables ¶
var DefaultConfig = func() Config { opts := Config{ Common: config.NewCommon[*Conn](), CreateInactivityMonitor: func() InactivityMonitor { return inactivity.NewNilMonitor[*Conn]() }, RequestMonitor: func(*Conn, *pool.Message) (bool, error) { return false, nil }, Dialer: &net.Dialer{Timeout: time.Second * 3}, Net: "udp", TransmissionNStart: 1, TransmissionAcknowledgeTimeout: time.Second * 2, TransmissionAcknowledgeRandomFactor: 1.5, TransmissionMaxRetransmit: 4, GetMID: message.GetMID, MTU: DefaultMTU, MaxPendingMessages: DefaultMaxPendingMessages, } opts.Handler = func(w *responsewriter.ResponseWriter[*Conn], r *pool.Message) { switch r.Code() { case codes.GET, codes.POST, codes.PUT, codes.DELETE, codes.FETCH, codes.PATCH, codes.IPATCH: if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil { opts.Errors(fmt.Errorf("udp client: cannot set response: %w", err)) } } } return opts }()
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
config.Common[*Conn]
CreateInactivityMonitor CreateInactivityMonitorFunc
RequestMonitor RequestMonitorFunc
Net string
GetMID GetMIDFunc
Handler HandlerFunc
Dialer *net.Dialer
TransmissionNStart uint32
TransmissionAcknowledgeTimeout time.Duration
TransmissionAcknowledgeRandomFactor float64
TransmissionMaxRetransmit uint32
CloseSocket bool
MTU uint16
// MaxPendingMessages limits in-flight duplicate suppression per connection.
// Zero disables in-flight tracking.
MaxPendingMessages uint32
// QBlockwiseMode is Disabled by default. QBlockwiseSecure is set by the DTLS
// client integration and must not be set for a plain UDP transport.
QBlockwiseMode blockwise.QBlockwiseMode
QBlockwiseConfig blockwise.QBlockwiseConfig
QBlockwiseSecure bool
}
type Conn ¶
Conn represents a virtual connection to a conceptual endpoint, to perform COAPs commands.
func NewConn ¶
func NewConn( session Session, createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn], inactivityMonitor InactivityMonitor, cfg *Config, ) *Conn
NewConn creates connection over session and observation.
func NewConnWithOpts ¶ added in v3.3.0
func (*Conn) AddOnClose ¶
AddOnClose calls function on close connection event.
func (*Conn) AsyncPing ¶
AsyncPing sends ping and receivedPong will be called when pong arrives. It returns cancellation of ping operation.
func (*Conn) CancelObservation ¶ added in v3.7.0
CancelObservation releases any partial notification and its recovery aliases.
func (*Conn) CancelQBlock ¶ added in v3.7.0
CancelQBlock removes a pending body deadline.
func (*Conn) CheckExpirations ¶
CheckExpirations checks and remove expired items from caches.
func (*Conn) Context ¶
Context returns the client's context.
If connections was closed context is cancelled.
func (*Conn) DelayQBlock ¶ added in v3.7.0
DelayQBlock postpones a pending body set after selective recovery.
func (*Conn) Done ¶
func (cc *Conn) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Conn) GetMessageID ¶
func (*Conn) InactivityMonitor ¶
func (cc *Conn) InactivityMonitor() InactivityMonitor
func (*Conn) NetConn ¶
NetConn returns the underlying connection that is wrapped by cc. The Conn returned is shared by all invocations of NetConn, so do not modify it.
func (*Conn) OpenQBlockExchange ¶ added in v3.7.0
func (cc *Conn) OpenQBlockExchange(ctx context.Context, token message.Token) (blockwise.QBlockExchange, error)
OpenQBlockExchange reserves a full token for the lifetime of a Q body.
func (*Conn) ProcessReceivedMessage ¶ added in v3.1.0
ProcessReceivedMessage tracks in-flight duplicates until the configured processor returns. Processors dispatching asynchronous work must either wait for completion before returning or manage subsequent deduplication themselves.
func (*Conn) ProcessReceivedMessageWithHandler ¶ added in v3.1.0
func (*Conn) ReleaseMessage ¶
ReleaseMessage returns m to the message pool. Owners must release hijacked messages when they are no longer needed; this does not affect deduplication.
func (*Conn) RemoteAddr ¶
func (*Conn) Run ¶
Run reads and process requests from a connection, until the connection is closed.
func (*Conn) ScheduleQBlock ¶ added in v3.7.0
ScheduleQBlock adds or replaces a bounded per-body deadline. One worker and one timer serve the connection, irrespective of the number of blocks.
func (*Conn) SendQBlock ¶ added in v3.7.0
SendQBlock uses normal CON retransmission and NSTART handling. NON stays NON.
func (*Conn) SendQBlockAsync ¶ added in v3.7.0
SendQBlockAsync retains a message copy and awaits its ACK outside the shared deadline worker. Pending writes, including NSTART waiters, are bounded.
func (*Conn) SetContextValue ¶
func (cc *Conn) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
func (*Conn) Transmission ¶
func (cc *Conn) Transmission() *Transmission
func (*Conn) WriteMessage ¶
WriteMessage sends an coap message.
func (*Conn) WriteMulticastMessage ¶
func (cc *Conn) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, options ...coapNet.MulticastOption) error
WriteMulticastMessage sends multicast to the remote multicast address. By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1. Via opts you can specify the network interface, source IP address, and hop limit.
type ConnOptions ¶ added in v3.3.0
type ConnOptions struct {
// contains filtered or unexported fields
}
type CreateInactivityMonitorFunc ¶
type CreateInactivityMonitorFunc = func() InactivityMonitor
type GetMIDFunc ¶
type GetMIDFunc = func() int32
type HandlerFunc ¶
type HandlerFunc = func(*responsewriter.ResponseWriter[*Conn], *pool.Message)
type InactivityMonitor ¶
func DeferInactivityWhileConfirmableMessagesPending ¶ added in v3.6.0
func DeferInactivityWhileConfirmableMessagesPending(monitor InactivityMonitor) InactivityMonitor
DeferInactivityWhileConfirmableMessagesPending postpones inactivity checks until all outstanding Confirmable messages have completed.
type MalformedMessageError ¶ added in v3.5.7
type MalformedMessageError struct {
Type message.Type
MessageID int32
HasHeader bool
InvalidVersion bool
Err error
}
MalformedMessageError contains best-effort CoAP header metadata extracted during decode failure. HasHeader indicates whether Type and MessageID are valid and can be used by callers for protocol-level decisions.
func (*MalformedMessageError) Error ¶ added in v3.5.7
func (e *MalformedMessageError) Error() string
func (*MalformedMessageError) Unwrap ¶ added in v3.5.7
func (e *MalformedMessageError) Unwrap() error
type MessageCache ¶ added in v3.4.0
type MessageCache interface {
Load(key string, msg *pool.Message) (bool, error)
Store(key string, msg *pool.Message) error
CheckExpirations(time.Time)
}
MessageCache is a cache of CoAP messages.
type MutexMap ¶
type MutexMap struct {
// contains filtered or unexported fields
}
MutexMap wraps a map of mutexes. Each key locks separately.
type Option ¶ added in v3.3.0
type Option = func(opts *ConnOptions)
func WithBlockWise ¶ added in v3.3.0
WithBlockWise enables block-wise transfer for the connection.
func WithInactivityMonitor ¶ added in v3.3.0
func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
WithInactivityMonitor enables inactivity monitor for the connection.
func WithRequestMonitor ¶ added in v3.3.0
func WithRequestMonitor(requestMonitor RequestMonitorFunc) Option
WithRequestMonitor enables request monitoring for the connection. It is called for each CoAP message received from the peer before it is processed. If it returns an error, the connection is closed. If it returns true, the message is dropped.
func WithResponseMessageCache ¶ added in v3.4.0
func WithResponseMessageCache(cache MessageCache) Option
WithResponseMessageCache sets the cache used for response messages. All response messages are submitted to the cache, but it is up to the cache implementation to determine which messages are stored and for how long. Caching responses enables sending the same Acknowledgment for retransmitted confirmable messages within an EXCHANGE_LIFETIME. It may be desirable to relax this behavior in some scenarios. https://datatracker.ietf.org/doc/html/rfc7252#section-4.5 The default response message cache stores all responses with an expiration of 247 seconds, which is EXCHANGE_LIFETIME when using default CoAP transmission parameters. https://datatracker.ietf.org/doc/html/rfc7252#section-4.8.2
type RequestMonitorFunc ¶ added in v3.3.0
type Session ¶
type Session interface {
Context() context.Context
Close() error
MaxMessageSize() uint32
RemoteAddr() net.Addr
LocalAddr() net.Addr
// NetConn returns the underlying connection that is wrapped by Session. The Conn returned is shared by all invocations of NetConn, so do not modify it.
NetConn() net.Conn
WriteMessage(req *pool.Message) error
// WriteMulticast sends multicast to the remote multicast address.
// By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1.
// Via opts you can specify the network interface, source IP address, and hop limit.
WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, opts ...coapNet.MulticastOption) error
Run(cc *Conn) error
AddOnClose(f EventFunc)
SetContextValue(key interface{}, val interface{})
Done() <-chan struct{}
}
type Transmission ¶
type Transmission struct {
// contains filtered or unexported fields
}
Transmission is a threadsafe container for transmission related parameters
func (*Transmission) SetTransmissionAcknowledgeRandomFactor ¶ added in v3.6.0
func (t *Transmission) SetTransmissionAcknowledgeRandomFactor(factor float64)
func (*Transmission) SetTransmissionAcknowledgeTimeout ¶
func (t *Transmission) SetTransmissionAcknowledgeTimeout(d time.Duration)
func (*Transmission) SetTransmissionMaxRetransmit ¶
func (t *Transmission) SetTransmissionMaxRetransmit(d uint32)
func (*Transmission) SetTransmissionNStart ¶
func (t *Transmission) SetTransmissionNStart(d uint32)
SetTransmissionNStart changing the nStart value will only effect requests queued after the change. The requests waiting here already before the change will get unblocked when enough weight has been released.