package client
import "github.com/plgd-dev/go-coap/v3/udp/client"
Index ¶
- Constants
- Variables
- type Config
- type Conn
- func NewConn( session Session, createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn], inactivityMonitor InactivityMonitor, cfg *Config, ) *Conn
- func NewConnWithOpts(session Session, cfg *Config, opts ...Option) *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
- func WithBlockWise(createBlockWise func(cc *Conn) *blockwise.BlockWise[*Conn]) Option
- func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
- func WithRequestMonitor(requestMonitor RequestMonitorFunc) Option
- type RequestMonitorFunc
- type RequestsMap
- type Session
- type Transmission
- func (t *Transmission) SetTransmissionAcknowledgeTimeout(d time.Duration)
- func (t *Transmission) SetTransmissionMaxRetransmit(d uint32)
- func (t *Transmission) SetTransmissionNStart(d uint32)
- type Unlocker
Constants ¶
const DefaultMTU = 1472
https://datatracker.ietf.org/doc/html/rfc7252#section-4.8.2
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 }()
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 ¶
func (*Conn) AcquireMessage ¶
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) Close ¶
Close closes connection without waiting for the end of the Run function.
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) LocalAddr ¶
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) Process ¶
func (cc *Conn) Process(cm *coapNet.ControlMessage, datagram []byte) error
func (*Conn) ProcessReceivedMessage ¶
func (*Conn) ProcessReceivedMessageWithHandler ¶
func (cc *Conn) ProcessReceivedMessageWithHandler(req *pool.Message, handler config.HandlerFunc[*Conn])
func (*Conn) ReleaseMessage ¶
func (*Conn) RemoteAddr ¶
func (*Conn) Run ¶
Run reads and process requests from a connection, until the connection is closed.
func (*Conn) Sequence ¶
Sequence acquires sequence number.
func (*Conn) Session ¶
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 ¶
type ConnOptions struct {
// contains filtered or unexported fields
}
type CreateInactivityMonitorFunc ¶
type CreateInactivityMonitorFunc = func() InactivityMonitor
type ErrorFunc ¶
type ErrorFunc = func(error)
type EventFunc ¶
type EventFunc = func()
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.
func NewMutexMap ¶
func NewMutexMap() *MutexMap
NewMutexMap returns an initialized MutexMap.
func (*MutexMap) Lock ¶
Lock acquires a lock corresponding to this key. This method will never return nil and Unlock() must be called to release the lock when done.
type Option ¶
type Option = func(opts *ConnOptions)
func WithBlockWise ¶
WithBlockWise enables block-wise transfer for the connection.
func WithInactivityMonitor ¶
func WithInactivityMonitor(inactivityMonitor InactivityMonitor) Option
WithInactivityMonitor enables inactivity monitor for the connection.
func WithRequestMonitor ¶
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 ¶
type RequestsMap ¶
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.
type Unlocker ¶
type Unlocker interface {
Unlock()
}
Unlocker provides an Unlock method to release the lock.
Source Files ¶
- Version
- v3.3.6 (latest)
- Published
- Sep 18, 2024
- Platform
- linux/amd64
- Imports
- 26 packages
- Last checked
- 1 week ago –
Tools for package owners.