Documentation ¶
Index ¶
- Constants
- Variables
- func NewDeleteRequest(ctx context.Context, messagePool *pool.Pool, path string, ...) (*pool.Message, error)
- func NewGetRequest(ctx context.Context, messagePool *pool.Pool, path string, ...) (*pool.Message, error)
- func NewObserveRequest(ctx context.Context, messagePool *pool.Pool, path string, ...) (*pool.Message, error)
- func NewPostRequest(ctx context.Context, messagePool *pool.Pool, path string, ...) (*pool.Message, error)
- func NewPutRequest(ctx context.Context, messagePool *pool.Pool, path string, ...) (*pool.Message, error)
- type Client
- func (c *Client) ClientConn() interface{}
- func (c *Client) Close() error
- func (c *Client) Context() context.Context
- func (c *Client) Delete(ctx context.Context, path string, opts ...message.Option) (*message.Message, error)
- func (c *Client) Do(req *message.Message) (*message.Message, error)
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Get(ctx context.Context, path string, opts ...message.Option) (*message.Message, error)
- func (c *Client) Observe(ctx context.Context, path string, ...) (mux.Observation, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Post(ctx context.Context, path string, contentFormat message.MediaType, ...) (*message.Message, error)
- func (c *Client) Put(ctx context.Context, path string, contentFormat message.MediaType, ...) (*message.Message, error)
- func (c *Client) RemoteAddr() net.Addr
- func (c *Client) Sequence() uint64
- func (c *Client) SetContextValue(key interface{}, val interface{})
- func (c *Client) WriteMessage(req *message.Message) error
- type ClientConn
- func (cc *ClientConn) AcquireMessage(ctx context.Context) *pool.Message
- func (cc *ClientConn) AddOnClose(f EventFunc)
- func (cc *ClientConn) AsyncPing(receivedPong func()) (func(), error)
- func (cc *ClientConn) CheckExpirations(now time.Time)
- func (cc *ClientConn) CheckMyMessageID(req *pool.Message)
- func (cc *ClientConn) Client() *Client
- func (cc *ClientConn) Close() error
- func (cc *ClientConn) Context() context.Context
- func (cc *ClientConn) Delete(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
- func (cc *ClientConn) Do(req *pool.Message) (*pool.Message, error)
- func (cc *ClientConn) Done() <-chan struct{}
- func (cc *ClientConn) Get(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
- func (cc *ClientConn) LocalAddr() net.Addr
- func (cc *ClientConn) Observe(ctx context.Context, path string, observeFunc func(msg *pool.Message), ...) (*Observation, error)
- func (cc *ClientConn) ObserveRequest(req *pool.Message, observeFunc func(req *pool.Message)) (*Observation, error)
- func (cc *ClientConn) Ping(ctx context.Context) error
- func (cc *ClientConn) Post(ctx context.Context, path string, contentFormat message.MediaType, ...) (*pool.Message, error)
- func (cc *ClientConn) Process(datagram []byte) error
- func (cc *ClientConn) Put(ctx context.Context, path string, contentFormat message.MediaType, ...) (*pool.Message, error)
- func (cc *ClientConn) ReleaseMessage(m *pool.Message)
- func (cc *ClientConn) RemoteAddr() net.Addr
- func (cc *ClientConn) Run() error
- func (cc *ClientConn) Sequence() uint64
- func (cc *ClientConn) Session() Session
- func (cc *ClientConn) SetContextValue(key interface{}, val interface{})
- func (cc *ClientConn) Transmission() *Transmission
- func (cc *ClientConn) WriteMessage(req *pool.Message) error
- func (cc *ClientConn) WriteMulticastMessage(req *pool.Message, address *net.UDPAddr, options ...coapNet.MulticastOption) error
- type ErrorFunc
- type EventFunc
- type GetMIDFunc
- type GoPoolFunc
- type HandlerContainer
- type HandlerFunc
- type MutexMap
- type Observation
- type ResponseWriter
- type Session
- type Transmission
- type Unlocker
Constants ¶
const ExchangeLifetime = 247 * time.Second
Variables ¶
var ( ErrKeyAlreadyExists = errors.New("key already exists") ErrKeyNotExists = errors.New("key does not exist") )
Functions ¶
func NewDeleteRequest ¶
func NewDeleteRequest(ctx context.Context, messagePool *pool.Pool, path string, opts ...message.Option) (*pool.Message, error)
NewDeleteRequest creates delete request.
Use ctx to set timeout.
func NewGetRequest ¶
func NewGetRequest(ctx context.Context, messagePool *pool.Pool, path string, opts ...message.Option) (*pool.Message, error)
NewGetRequest creates get request.
Use ctx to set timeout.
func NewObserveRequest ¶ added in v2.6.0
func NewObserveRequest(ctx context.Context, messagePool *pool.Pool, path string, opts ...message.Option) (*pool.Message, error)
NewObserveRequest creates observe request.
Use ctx to set timeout.
func NewPostRequest ¶
func NewPostRequest(ctx context.Context, messagePool *pool.Pool, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)
NewPostRequest creates post request.
Use ctx to set timeout.
An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.
If payload is nil then content format is not used.
func NewPutRequest ¶
func NewPutRequest(ctx context.Context, messagePool *pool.Pool, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)
NewPutRequest creates put request.
Use ctx to set timeout.
If payload is nil then content format is not used.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cc *ClientConn) *Client
func (*Client) ClientConn ¶
func (c *Client) ClientConn() interface{}
ClientConn get's underlaying client connection.
func (*Client) Done ¶ added in v2.5.0
func (c *Client) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*Client) RemoteAddr ¶
func (*Client) SetContextValue ¶ added in v2.1.0
func (c *Client) SetContextValue(key interface{}, val interface{})
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn represents a virtual connection to a conceptual endpoint, to perform COAPs commands.
func NewClientConn ¶
func NewClientConn( session Session, observationTokenHandler *HandlerContainer, observationRequests *kitSync.Map, transmissionNStart time.Duration, transmissionAcknowledgeTimeout time.Duration, transmissionMaxRetransmit uint32, handler HandlerFunc, blockwiseSZX blockwise.SZX, blockWise *blockwise.BlockWise, goPool GoPoolFunc, errors ErrorFunc, getMID GetMIDFunc, inactivityMonitor inactivity.Monitor, responseMsgCache *cache.Cache, messagePool *pool.Pool, ) *ClientConn
NewClientConn creates connection over session and observation.
func (*ClientConn) AcquireMessage ¶ added in v2.5.0
func (cc *ClientConn) AcquireMessage(ctx context.Context) *pool.Message
func (*ClientConn) AddOnClose ¶
func (cc *ClientConn) AddOnClose(f EventFunc)
AddOnClose calls function on close connection event.
func (*ClientConn) AsyncPing ¶ added in v2.4.0
func (cc *ClientConn) AsyncPing(receivedPong func()) (func(), error)
AsyncPing sends ping and receivedPong will be called when pong arrives. It returns cancellation of ping operation.
func (*ClientConn) CheckExpirations ¶ added in v2.5.0
func (cc *ClientConn) CheckExpirations(now time.Time)
CheckExpirations checks and remove expired items from caches.
func (*ClientConn) CheckMyMessageID ¶ added in v2.5.0
func (cc *ClientConn) CheckMyMessageID(req *pool.Message)
CheckMyMessageID compare client msgID against peer messageID and if it is near < 0xffff/4 then incrase msgID. When msgIDs met it can cause issue because cache can send message to which doesn't bellows to request.
func (*ClientConn) Client ¶
func (cc *ClientConn) Client() *Client
func (*ClientConn) Close ¶
func (cc *ClientConn) Close() error
Close closes connection without waiting for the end of the Run function.
func (*ClientConn) Context ¶
func (cc *ClientConn) Context() context.Context
Context returns the client's context.
If connections was closed context is cancelled.
func (*ClientConn) Delete ¶
func (cc *ClientConn) Delete(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
Delete deletes the resource identified by the request path.
Use ctx to set timeout.
func (*ClientConn) Do ¶
Do sends an coap message and returns an coap response.
An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.
Caller is responsible to release request and response.
func (*ClientConn) Done ¶ added in v2.5.0
func (cc *ClientConn) Done() <-chan struct{}
Done signalizes that connection is not more processed.
func (*ClientConn) Get ¶
func (cc *ClientConn) Get(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)
Get issues a GET to the specified path.
Use ctx to set timeout.
An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.
func (*ClientConn) LocalAddr ¶ added in v2.5.0
func (cc *ClientConn) LocalAddr() net.Addr
func (*ClientConn) Observe ¶
func (cc *ClientConn) Observe(ctx context.Context, path string, observeFunc func(msg *pool.Message), opts ...message.Option) (*Observation, error)
Observe subscribes for every change of resource on path. It can return canceled observation and it happens when resource doesn't support observation. This is detected when the first notification doesn't contains observe option.
func (*ClientConn) ObserveRequest ¶ added in v2.6.0
func (cc *ClientConn) ObserveRequest(req *pool.Message, observeFunc func(req *pool.Message)) (*Observation, error)
ObserveRequest subscribes for every change of resource on path. It can return canceled observation and it happens when resource doesn't support observation. This is detected when the first notification doesn't contains observe option.
func (*ClientConn) Ping ¶
func (cc *ClientConn) Ping(ctx context.Context) error
Ping issues a PING to the client and waits for PONG response.
Use ctx to set timeout.
func (*ClientConn) Post ¶
func (cc *ClientConn) Post(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)
Post issues a POST to the specified path.
Use ctx to set timeout.
An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.
If payload is nil then content format is not used.
func (*ClientConn) Process ¶
func (cc *ClientConn) Process(datagram []byte) error
func (*ClientConn) Put ¶
func (cc *ClientConn) Put(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)
Put issues a PUT to the specified path.
Use ctx to set timeout.
An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.
If payload is nil then content format is not used.
func (*ClientConn) ReleaseMessage ¶ added in v2.5.0
func (cc *ClientConn) ReleaseMessage(m *pool.Message)
func (*ClientConn) RemoteAddr ¶
func (cc *ClientConn) RemoteAddr() net.Addr
func (*ClientConn) Run ¶
func (cc *ClientConn) Run() error
Run reads and process requests from a connection, until the connection is closed.
func (*ClientConn) Sequence ¶
func (cc *ClientConn) Sequence() uint64
Sequence acquires sequence number.
func (*ClientConn) Session ¶ added in v2.1.0
func (cc *ClientConn) Session() Session
func (*ClientConn) SetContextValue ¶ added in v2.1.0
func (cc *ClientConn) SetContextValue(key interface{}, val interface{})
SetContextValue stores the value associated with key to context of connection.
func (*ClientConn) Transmission ¶ added in v2.3.0
func (cc *ClientConn) Transmission() *Transmission
func (*ClientConn) WriteMessage ¶
func (cc *ClientConn) WriteMessage(req *pool.Message) error
WriteMessage sends an coap message.
func (*ClientConn) WriteMulticastMessage ¶ added in v2.5.0
func (cc *ClientConn) 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 GetMIDFunc ¶
type GetMIDFunc = func() uint16
type GoPoolFunc ¶
type GoPoolFunc = func(func()) error
type HandlerContainer ¶
type HandlerContainer struct {
// contains filtered or unexported fields
}
HandlerContainer for regirstration handlers by key
func (*HandlerContainer) Get ¶
func (s *HandlerContainer) Get(key interface{}) (HandlerFunc, error)
Get returns handler for key
func (*HandlerContainer) Insert ¶
func (s *HandlerContainer) Insert(key interface{}, handler HandlerFunc) error
Insert handler for key.
func (*HandlerContainer) Pop ¶
func (s *HandlerContainer) Pop(key interface{}) (HandlerFunc, error)
Pop pops handler for key
type HandlerFunc ¶
type HandlerFunc = func(*ResponseWriter, *pool.Message)
func HandlerFuncToMux ¶
func HandlerFuncToMux(m mux.Handler) HandlerFunc
func NewObservationHandler ¶
func NewObservationHandler(obsertionTokenHandler *HandlerContainer, next HandlerFunc) HandlerFunc
type MutexMap ¶ added in v2.3.0
type MutexMap struct {
// contains filtered or unexported fields
}
MutexMap wraps a map of mutexes. Each key locks separately.
func NewMutexMap ¶ added in v2.3.0
func NewMutexMap() *MutexMap
NewMutexMap returns an initialized MutexMap.
type Observation ¶
type Observation struct {
// contains filtered or unexported fields
}
Observation represents subscription to resource on the server
func (*Observation) Cancel ¶
func (o *Observation) Cancel(ctx context.Context) error
Cancel remove observation from server. For recreate observation use Observe.
func (*Observation) Canceled ¶ added in v2.5.0
func (o *Observation) Canceled() bool
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
A ResponseWriter interface is used by an COAP handler to construct an COAP response.
func NewResponseWriter ¶
func NewResponseWriter(response *pool.Message, cc *ClientConn, requestOptions message.Options) *ResponseWriter
func (*ResponseWriter) ClientConn ¶
func (r *ResponseWriter) ClientConn() *ClientConn
func (*ResponseWriter) SendReset ¶
func (r *ResponseWriter) SendReset()
func (*ResponseWriter) SetResponse ¶
func (r *ResponseWriter) SetResponse(code codes.Code, contentFormat message.MediaType, d io.ReadSeeker, opts ...message.Option) error
type Session ¶
type Session interface { Context() context.Context Close() error MaxMessageSize() uint32 RemoteAddr() net.Addr LocalAddr() net.Addr 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 *ClientConn) error AddOnClose(f EventFunc) SetContextValue(key interface{}, val interface{}) Done() <-chan struct{} }
type Transmission ¶ added in v2.3.0
type Transmission struct {
// contains filtered or unexported fields
}
Transmission is a threadsafe container for transmission related parameters
func (*Transmission) SetTransmissionAcknowledgeTimeout ¶ added in v2.3.0
func (t *Transmission) SetTransmissionAcknowledgeTimeout(d time.Duration)
func (*Transmission) SetTransmissionMaxRetransmit ¶ added in v2.3.0
func (t *Transmission) SetTransmissionMaxRetransmit(d int32)
func (*Transmission) SetTransmissionNStart ¶ added in v2.3.0
func (t *Transmission) SetTransmissionNStart(d time.Duration)