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) CheckExpirations(now time.Time)
- func (cc *Conn) Close() error
- func (cc *Conn) Context() context.Context
- 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) 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) 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 MutexMap
- type Option
- type RequestMonitorFunc
- type RequestsMap
- type Session
- type Transmission
- type Unlocker
Constants ¶
const DefaultMTU = 1472
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, TransmissionMaxRetransmit: 4, GetMID: message.GetMID, MTU: DefaultMTU, } opts.Handler = func(w *responsewriter.ResponseWriter[*Conn], r *pool.Message) { switch r.Code() { case codes.POST, codes.PUT, codes.GET, codes.DELETE: 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 TransmissionMaxRetransmit uint32 CloseSocket bool MTU uint16 }
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) 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) 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) ProcessReceivedMessage ¶ added in v3.1.0
func (*Conn) ProcessReceivedMessageWithHandler ¶ added in v3.1.0
func (*Conn) ReleaseMessage ¶
func (*Conn) RemoteAddr ¶
func (*Conn) Run ¶
Run reads and process requests from a connection, until the connection is closed.
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 ¶
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.
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) 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.