Documentation ¶
Overview ¶
Package coap provides a CoAP client and server.
Package coap provides a CoAP client and server.
Index ¶
- Constants
- Variables
- func ActivateAndServe(l Listener, p net.Conn, handler Handler) error
- func CalcETag(payload []byte) []byte
- func DefaultHandle(handler Handler)
- func DefaultHandleFunc(handler func(w ResponseWriter, r *Request))
- func GenerateMessageID() uint16
- func GenerateToken() ([]byte, error)
- func Handle(pattern string, handler Handler)
- func HandleFailed(w ResponseWriter, req *Request)
- func HandleFunc(pattern string, handler func(w ResponseWriter, r *Request))
- func HandleRemove(pattern string)
- func ListenAndServe(network string, addr string, handler Handler) error
- func ListenAndServeDTLS(network string, addr string, config *dtls.Config, handler Handler) error
- func ListenAndServeTLS(network, addr string, config *tls.Config, handler Handler) error
- func MarshalBlockOption(szx BlockWiseSzx, blockNumber uint, moreBlocksFollowing bool) (uint32, error)
- type BlockWiseSzx
- type COAPType
- type Client
- type ClientCommander
- func (cc *ClientCommander) Close() error
- func (cc *ClientCommander) Delete(path string) (Message, error)
- func (cc *ClientCommander) DeleteWithContext(ctx context.Context, path string) (Message, error)
- func (cc *ClientCommander) Equal(cc1 *ClientCommander) bool
- func (cc *ClientCommander) Exchange(m Message) (Message, error)
- func (cc *ClientCommander) ExchangeWithContext(ctx context.Context, m Message) (Message, error)
- func (cc *ClientCommander) Get(path string) (Message, error)
- func (cc *ClientCommander) GetWithContext(ctx context.Context, path string) (Message, error)
- func (cc *ClientCommander) LocalAddr() net.Addr
- func (cc *ClientCommander) NewDeleteRequest(path string) (Message, error)
- func (cc *ClientCommander) NewGetRequest(path string) (Message, error)
- func (cc *ClientCommander) NewMessage(p MessageParams) Message
- func (cc *ClientCommander) NewPostRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) NewPutRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) Observe(path string, observeFunc func(req *Request)) (*Observation, error)
- func (cc *ClientCommander) ObserveWithContext(ctx context.Context, path string, observeFunc func(req *Request), ...) (*Observation, error)
- func (cc *ClientCommander) PeerCertificates() []*x509.Certificate
- func (cc *ClientCommander) Ping(timeout time.Duration) error
- func (cc *ClientCommander) PingWithContext(ctx context.Context) error
- func (cc *ClientCommander) Post(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) PostWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) Put(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) PutWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (cc *ClientCommander) RemoteAddr() net.Addr
- func (cc *ClientCommander) Sequence() uint64
- func (cc *ClientCommander) WriteMsg(m Message) error
- func (cc *ClientCommander) WriteMsgWithContext(ctx context.Context, m Message) error
- type ClientConn
- func Dial(network, address string) (*ClientConn, error)
- func DialDTLS(network, address string, config *dtls.Config) (conn *ClientConn, err error)
- func DialDTLSWithTimeout(network, address string, config *dtls.Config, timeout time.Duration) (conn *ClientConn, err error)
- func DialTLS(network, address string, tlsConfig *tls.Config) (conn *ClientConn, err error)
- func DialTLSWithTimeout(network, address string, tlsConfig *tls.Config, timeout time.Duration) (conn *ClientConn, err error)
- func DialTimeout(network, address string, timeout time.Duration) (*ClientConn, error)
- func (co *ClientConn) Close() error
- func (co *ClientConn) Delete(path string) (Message, error)
- func (co *ClientConn) DeleteWithContext(ctx context.Context, path string) (Message, error)
- func (co *ClientConn) Exchange(m Message) (Message, error)
- func (co *ClientConn) ExchangeWithContext(ctx context.Context, m Message) (Message, error)
- func (co *ClientConn) Get(path string) (Message, error)
- func (co *ClientConn) GetWithContext(ctx context.Context, path string) (Message, error)
- func (co *ClientConn) LocalAddr() net.Addr
- func (co *ClientConn) NewDeleteRequest(path string) (Message, error)
- func (co *ClientConn) NewGetRequest(path string) (Message, error)
- func (co *ClientConn) NewMessage(p MessageParams) Message
- func (co *ClientConn) NewPostRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) NewPutRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) Observe(path string, observeFunc func(req *Request)) (*Observation, error)
- func (co *ClientConn) ObserveWithContext(ctx context.Context, path string, observeFunc func(req *Request), ...) (*Observation, error)
- func (co *ClientConn) PeerCertificates() []*x509.Certificate
- func (co *ClientConn) Ping(timeout time.Duration) error
- func (co *ClientConn) PingWithContext(ctx context.Context) error
- func (co *ClientConn) Post(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) PostWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) Put(path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) PutWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
- func (co *ClientConn) RemoteAddr() net.Addr
- func (co *ClientConn) Sequence() uint64
- func (co *ClientConn) WriteMsg(m Message) error
- func (co *ClientConn) WriteMsgWithContext(ctx context.Context, m Message) error
- type DgramMessage
- type Error
- type Handler
- type HandlerFunc
- type KeepAlive
- type Listener
- type MediaType
- type Message
- type MessageBase
- func (m *MessageBase) AddOption(opID OptionID, val interface{})
- func (m *MessageBase) AllOptions() options
- func (m *MessageBase) Code() codes.Code
- func (m *MessageBase) IsConfirmable() bool
- func (m *MessageBase) Option(o OptionID) interface{}
- func (m *MessageBase) Options(o OptionID) []interface{}
- func (m *MessageBase) Path() []string
- func (m *MessageBase) PathString() string
- func (m *MessageBase) Payload() []byte
- func (m *MessageBase) Query() []string
- func (m *MessageBase) QueryString() string
- func (m *MessageBase) RemoveOption(opID OptionID)
- func (m *MessageBase) SetCode(code codes.Code)
- func (m *MessageBase) SetObserve(b uint32)
- func (m *MessageBase) SetOption(opID OptionID, val interface{})
- func (m *MessageBase) SetPath(s []string)
- func (m *MessageBase) SetPathString(s string)
- func (m *MessageBase) SetPayload(p []byte)
- func (m *MessageBase) SetQuery(s []string)
- func (m *MessageBase) SetQueryString(s string)
- func (m *MessageBase) SetToken(p []byte)
- func (m *MessageBase) SetType(typ COAPType)
- func (m *MessageBase) SetURIQuery(s string)
- func (m *MessageBase) Token() []byte
- func (m *MessageBase) Type() COAPType
- type MessageParams
- type MulticastClient
- type MulticastClientConn
- func (mconn *MulticastClientConn) Close()
- func (mconn *MulticastClientConn) LocalAddr() net.Addr
- func (mconn *MulticastClientConn) NewGetRequest(path string) (Message, error)
- func (mconn *MulticastClientConn) NewMessage(p MessageParams) Message
- func (mconn *MulticastClientConn) Publish(path string, responseHandler func(req *Request)) (*ResponseWaiter, error)
- func (mconn *MulticastClientConn) PublishMsg(req Message, responseHandler func(req *Request)) (*ResponseWaiter, error)
- func (mconn *MulticastClientConn) PublishMsgWithContext(ctx context.Context, req Message, responseHandler func(req *Request)) (*ResponseWaiter, error)
- func (mconn *MulticastClientConn) PublishWithContext(ctx context.Context, path string, responseHandler func(req *Request)) (*ResponseWaiter, error)
- func (mconn *MulticastClientConn) RemoteAddr() net.Addr
- func (mconn *MulticastClientConn) WriteMsg(m Message) error
- func (mconn *MulticastClientConn) WriteMsgWithContext(ctx context.Context, m Message) error
- type Observation
- type OptionID
- type Request
- type ResponseWaiter
- type ResponseWriter
- type RetryFunc
- type RetryFuncFactory
- type ServeMux
- func (mux *ServeMux) DefaultHandle(handler Handler)
- func (mux *ServeMux) DefaultHandleFunc(handler func(w ResponseWriter, r *Request))
- func (mux *ServeMux) Handle(pattern string, handler Handler) error
- func (mux *ServeMux) HandleFunc(pattern string, handler func(w ResponseWriter, r *Request))
- func (mux *ServeMux) HandleRemove(pattern string) error
- func (mux *ServeMux) ServeCOAP(w ResponseWriter, r *Request)
- type Server
- type TcpMessage
- type TokenHandler
Constants ¶
const ( TCP_MESSAGE_LEN13_BASE = 13 TCP_MESSAGE_LEN14_BASE = 269 TCP_MESSAGE_LEN15_BASE = 65805 TCP_MESSAGE_MAX_LEN = 0x7fff0000 // Large number that works in 32-bit builds. )
const DefaultPort = 5683
DefaultPort default unsecure port for COAP server
const DefaultSecurePort = 5684
DefaultSecurePort default secure port for COAP server
const ErrBlockInvalidSize = Error("block has invalid size")
ErrBlockInvalidSize block has invalid size
const ErrBlockNumberExceedLimit = Error("block number exceed limit 1,048,576")
ErrBlockNumberExceedLimit block number exceed limit 1,048,576
const ErrConnectionClosed = Error("connection closed")
ErrConnectionClosed Connection closed
const ErrContentFormatNotSet = Error("content format is not set")
ErrContentFormatNotSet content format is not set
const ErrInvalidBlockWiseSzx = Error("invalid block-wise transfer szx")
ErrInvalidBlockWiseSzx invalid block-wise transfer szx
const ErrInvalidMaxMesssageSizeParameter = Error("invalid .MaxMessageSize parameter")
ErrInvalidMaxMesssageSizeParameter invalid .MaxMessageSize parameter
const ErrInvalidNetParameter = Error("invalid .Net parameter")
ErrInvalidNetParameter invalid .Net parameter
const ErrInvalidOptionBlock1 = Error("message has invalid value of Block1")
ErrInvalidOptionBlock1 message has invalid value of Block1
const ErrInvalidOptionBlock2 = Error("message has invalid value of Block2")
ErrInvalidOptionBlock2 message has invalid value of Block2
const ErrInvalidPayload = Error("invalid payload")
ErrInvalidPayload invalid payload
const ErrInvalidPayloadSize = Error("invalid payload size")
ErrInvalidPayloadSize invalid payload size
const ErrInvalidReponseCode = Error("response code has invalid value")
ErrInvalidReponseCode response code has invalid value
const ErrInvalidRequest = Error("invalid request")
ErrInvalidRequest invalid requests
const ErrInvalidResponse = Error("invalid response")
ErrInvalidResponse invalid response received for certain token
const ErrInvalidServerConnParameter = Error("invalid Server.Conn parameter")
ErrInvalidServerConnParameter invalid Server.Conn parameter
const ErrInvalidServerListenerParameter = Error("invalid Server.Listener parameter")
ErrInvalidServerListenerParameter invalid Server.Listener parameter
const ErrInvalidTokenLen = Error("invalid token length")
ErrInvalidTokenLen invalid token length in Message
const ErrMaxMessageSizeLimitExceeded = Error("maximum message size limit exceeded")
ErrMaxMessageSizeLimitExceeded message size is bigger than maximum message size limit
const ErrMessageInvalidVersion = Error("invalid version of Message")
ErrMessageInvalidVersion invalid version of Message
const ErrMessageNotInterested = Error("message not to be sent due to disinterest")
ErrMessageNotInterested message is not of interest to the client
const ErrMessageTruncated = Error("message is truncated")
ErrMessageTruncated message is truncated
const ErrMsgTooLarge = Error("message it too large, for processing")
ErrMsgTooLarge message it too large, for processing
const ErrNotSupported = Error("not supported")
ErrNotSupported invalid response received for certain token
const ErrOptionGapTooLarge = Error("option gap too large")
ErrOptionGapTooLarge option gap too large in Message
const ErrOptionTooLong = Error("option is too long")
ErrOptionTooLong option is too long in Message
const ErrOptionTruncated = Error("option is truncated")
ErrOptionTruncated option is truncated
const ErrOptionUnexpectedExtendMarker = Error("unexpected extended option marker")
ErrOptionUnexpectedExtendMarker unexpected extended option marker
const ErrRequestEntityIncomplete = Error("payload comes in bad order")
ErrRequestEntityIncomplete payload comes in bad order
const ErrServerAlreadyStarted = Error("server already started")
ErrServerAlreadyStarted server already started
const ErrServerClosed = net.ErrServerClosed
ErrServerClosed Server closed
const ErrServerNotStarted = Error("server not started")
ErrServerNotStarted server not started
const ErrShortRead = Error("short read")
ErrShortRead To construct Message we need to read more data from connection
const ErrTokenAlreadyExist = Error("token is not unique for session")
ErrTokenAlreadyExist Token in request is not unique for session
const ErrTokenNotExist = Error("token is not exist")
ErrTokenNotExist Token in request is not exist
const ErrUnexpectedReponseCode = Error("unexpected response code")
ErrUnexpectedReponseCode unexpected response code occurs
const MaxTokenSize = 8
MaxTokenSize maximum of token size that can be used in message
Variables ¶
var DefaultServeMux = NewServeMux()
DefaultServeMux is the default ServeMux used by Serve.
var ErrKeepAliveDeadlineExceeded = fmt.Errorf("keepalive: %w", context.DeadlineExceeded)
ErrKeepAliveDeadlineExceeded occurs during waiting for pong response
Functions ¶
func ActivateAndServe ¶
ActivateAndServe activates a server with a listener from systemd, l and p should not both be non-nil. If both l and p are not nil only p will be used. Invoke handler for incoming queries.
func DefaultHandle ¶
func DefaultHandle(handler Handler)
DefaultHandle set the default handler in the DefaultServeMux.
func DefaultHandleFunc ¶
func DefaultHandleFunc(handler func(w ResponseWriter, r *Request))
DefaultHandleFunc set the default handler in the DefaultServeMux.
func GenerateMessageID ¶
func GenerateMessageID() uint16
GenerateMessageID generates a message id for UDP-coap
func GenerateToken ¶
GenerateToken generates a random token by a given length
func Handle ¶
Handle registers the handler with the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.
func HandleFailed ¶
func HandleFailed(w ResponseWriter, req *Request)
HandleFailed returns a HandlerFunc that returns NotFound for every request it gets.
func HandleFunc ¶
func HandleFunc(pattern string, handler func(w ResponseWriter, r *Request))
HandleFunc registers the handler function with the given pattern in the DefaultServeMux.
func HandleRemove ¶
func HandleRemove(pattern string)
HandleRemove deregisters the handle with the given pattern in the DefaultServeMux.
func ListenAndServe ¶
ListenAndServe Starts a server on address and network specified Invoke handler for incoming queries.
func ListenAndServeDTLS ¶
ListenAndServeDTLS acts like ListenAndServeTLS, more information in http://golang.org/pkg/net/http/#ListenAndServeTLS
func ListenAndServeTLS ¶
ListenAndServeTLS acts like http.ListenAndServeTLS, more information in http://golang.org/pkg/net/http/#ListenAndServeTLS
func MarshalBlockOption ¶
func MarshalBlockOption(szx BlockWiseSzx, blockNumber uint, moreBlocksFollowing bool) (uint32, error)
Types ¶
type BlockWiseSzx ¶
type BlockWiseSzx uint8
BlockWiseSzx enum representation for szx
const ( //BlockWiseSzx16 block of size 16bytes BlockWiseSzx16 BlockWiseSzx = 0 //BlockWiseSzx32 block of size 32bytes BlockWiseSzx32 BlockWiseSzx = 1 //BlockWiseSzx64 block of size 64bytes BlockWiseSzx64 BlockWiseSzx = 2 //BlockWiseSzx128 block of size 128bytes BlockWiseSzx128 BlockWiseSzx = 3 //BlockWiseSzx256 block of size 256bytes BlockWiseSzx256 BlockWiseSzx = 4 //BlockWiseSzx512 block of size 512bytes BlockWiseSzx512 BlockWiseSzx = 5 //BlockWiseSzx1024 block of size 1024bytes BlockWiseSzx1024 BlockWiseSzx = 6 //BlockWiseSzxBERT block of size n*1024bytes BlockWiseSzxBERT BlockWiseSzx = 7 //BlockWiseSzxCount count of block enums BlockWiseSzxCount BlockWiseSzx = 8 )
func UnmarshalBlockOption ¶
func UnmarshalBlockOption(blockVal uint32) (szx BlockWiseSzx, blockNumber uint, moreBlocksFollowing bool, err error)
type COAPType ¶
type COAPType uint8
COAPType represents the message type.
const ( // Confirmable messages require acknowledgements. Confirmable COAPType = 0 // NonConfirmable messages do not require acknowledgements. NonConfirmable COAPType = 1 // Acknowledgement is a message indicating a response to confirmable message. Acknowledgement COAPType = 2 // Reset indicates a permanent negative acknowledgement. Reset COAPType = 3 )
type Client ¶
type Client struct { Net string // if "tcp" or "tcp-tls" (COAP over TLS) a TCP query will be initiated, otherwise an UDP one (default is "" for UDP) or "udp-mcast" for multicast MaxMessageSize uint32 // Max message size that could be received from peer. If not set it defaults to 1152 B. TLSConfig *tls.Config // TLS connection configuration DTLSConfig *dtls.Config // TLS connection configuration DialTimeout time.Duration // set Timeout for dialer ReadTimeout time.Duration // net.ClientConn.SetReadTimeout value for connections, defaults to 1 hour - overridden by Timeout when that value is non-zero WriteTimeout time.Duration // net.ClientConn.SetWriteTimeout value for connections, defaults to 1 hour - overridden by Timeout when that value is non-zero HeartBeat time.Duration // Defines wake up interval from operations Read, Write over connection. defaults is 100ms. Handler HandlerFunc // default handler for handling messages from server NotifySessionEndFunc func(err error) // if NotifySessionEndFunc is set it is called when TCP/UDP session was ended. BlockWiseTransfer *bool // Use blockWise transfer for transfer payload (default for UDP it's enabled, for TCP it's disable) BlockWiseTransferSzx *BlockWiseSzx // Set maximal block size of payload that will be send in fragment DisableTCPSignalMessageCSM bool // Disable send tcp signal CSM message DisablePeerTCPSignalMessageCSMs bool // Disable processes Capabilities and Settings Messages from client - iotivity sends max message size without blockwise. MulticastHopLimit int //sets the hop limit field value for future outgoing multicast packets. default is 2. Errors func(err error) // Report errors // Keepalive setup KeepAlive KeepAlive }
A Client defines parameters for a COAP client.
func (*Client) DialWithContext ¶
func (c *Client) DialWithContext(ctx context.Context, address string) (clientConn *ClientConn, err error)
DialWithContext connects to the address on the named network.
type ClientCommander ¶
type ClientCommander struct {
// contains filtered or unexported fields
}
ClientCommander provides commands Get,Post,Put,Delete,Observe For compare use ClientCommander.Equal
func (*ClientCommander) Delete ¶
func (cc *ClientCommander) Delete(path string) (Message, error)
Delete deletes the resource identified by the request path
func (*ClientCommander) DeleteWithContext ¶
DeleteContext deletes with context the resource identified by the request path
func (*ClientCommander) Equal ¶
func (cc *ClientCommander) Equal(cc1 *ClientCommander) bool
Equal compare two ClientCommanders
func (*ClientCommander) Exchange ¶
func (cc *ClientCommander) Exchange(m Message) (Message, error)
Exchange same as ExchangeContext without context
func (*ClientCommander) ExchangeWithContext ¶
ExchangeContext performs a synchronous query with context. It sends the message m to the address contained in a and waits for a reply.
ExchangeContext does not retry a failed query, nor will it fall back to TCP in case of truncation.
func (*ClientCommander) Get ¶
func (cc *ClientCommander) Get(path string) (Message, error)
Get retrieves the resource identified by the request path
func (*ClientCommander) GetWithContext ¶
GetContext retrieves with context the resource identified by the request path
func (*ClientCommander) LocalAddr ¶
func (cc *ClientCommander) LocalAddr() net.Addr
LocalAddr implements the networkSession.LocalAddr method.
func (*ClientCommander) NewDeleteRequest ¶
func (cc *ClientCommander) NewDeleteRequest(path string) (Message, error)
NewDeleteRequest creates delete request
func (*ClientCommander) NewGetRequest ¶
func (cc *ClientCommander) NewGetRequest(path string) (Message, error)
NewGetRequest creates get request
func (*ClientCommander) NewMessage ¶
func (cc *ClientCommander) NewMessage(p MessageParams) Message
NewMessage creates message for request
func (*ClientCommander) NewPostRequest ¶
func (cc *ClientCommander) NewPostRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
NewPostRequest creates post request
func (*ClientCommander) NewPutRequest ¶
func (cc *ClientCommander) NewPutRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
NewPutRequest creates put request
func (*ClientCommander) Observe ¶
func (cc *ClientCommander) Observe(path string, observeFunc func(req *Request)) (*Observation, error)
func (*ClientCommander) ObserveWithContext ¶
func (cc *ClientCommander) ObserveWithContext( ctx context.Context, path string, observeFunc func(req *Request), options ...func(Message), ) (*Observation, error)
ObserveContext subscribe to severon path. After subscription and every change on path, server sends immediately response
func (*ClientCommander) PeerCertificates ¶
func (cc *ClientCommander) PeerCertificates() []*x509.Certificate
PeerCertificates implements the networkSession.PeerCertificates method.
func (*ClientCommander) Ping ¶
func (cc *ClientCommander) Ping(timeout time.Duration) error
Ping send a ping message and wait for a pong response
func (*ClientCommander) PingWithContext ¶
func (cc *ClientCommander) PingWithContext(ctx context.Context) error
PingContext send with context a ping message and wait for a pong response
func (*ClientCommander) Post ¶
func (cc *ClientCommander) Post(path string, contentFormat MediaType, body io.Reader) (Message, error)
Post updates the resource identified by the request path
func (*ClientCommander) PostWithContext ¶
func (cc *ClientCommander) PostWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
PostContext updates with context the resource identified by the request path
func (*ClientCommander) Put ¶
func (cc *ClientCommander) Put(path string, contentFormat MediaType, body io.Reader) (Message, error)
Put creates the resource identified by the request path
func (*ClientCommander) PutWithContext ¶
func (cc *ClientCommander) PutWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
PutContext creates with context the resource identified by the request path
func (*ClientCommander) RemoteAddr ¶
func (cc *ClientCommander) RemoteAddr() net.Addr
RemoteAddr implements the networkSession.RemoteAddr method.
func (*ClientCommander) Sequence ¶
func (cc *ClientCommander) Sequence() uint64
Sequence discontinuously unique growing number for connection.
func (*ClientCommander) WriteMsg ¶
func (cc *ClientCommander) WriteMsg(m Message) error
WriteMsg sends direct a message through the connection
func (*ClientCommander) WriteMsgWithContext ¶
func (cc *ClientCommander) WriteMsgWithContext(ctx context.Context, m Message) error
WriteContextMsg sends with context direct a message through the connection
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
A ClientConn represents a connection to a COAP server.
func Dial ¶
func Dial(network, address string) (*ClientConn, error)
Dial connects to the address on the named network.
func DialDTLS ¶
func DialDTLS(network, address string, config *dtls.Config) (conn *ClientConn, err error)
DialDTLS connects to the address on the named network with DTLS.
func DialDTLSWithTimeout ¶
func DialDTLSWithTimeout(network, address string, config *dtls.Config, timeout time.Duration) (conn *ClientConn, err error)
DialDTLSWithTimeout acts like DialwriteDeadlineDTLS but takes a timeout.
func DialTLS ¶
func DialTLS(network, address string, tlsConfig *tls.Config) (conn *ClientConn, err error)
DialTLS connects to the address on the named network with TLS.
func DialTLSWithTimeout ¶
func DialTLSWithTimeout(network, address string, tlsConfig *tls.Config, timeout time.Duration) (conn *ClientConn, err error)
DialTLSWithTimeout acts like DialTLS but takes a timeout.
func DialTimeout ¶
func DialTimeout(network, address string, timeout time.Duration) (*ClientConn, error)
DialTimeout acts like Dial but takes a timeout.
func (*ClientConn) DeleteWithContext ¶
Delete delete the resource identified by the request path
func (*ClientConn) ExchangeWithContext ¶
ExchangeContext performs a synchronous query. It sends the message m to the address contained in a and waits for a reply.
ExchangeContext does not retry a failed query, nor will it fall back to TCP in case of truncation. To specify a local address or a timeout, the caller has to set the `Client.Dialer` attribute appropriately
func (*ClientConn) Get ¶
func (co *ClientConn) Get(path string) (Message, error)
GetContext retrieve the resource identified by the request path
func (*ClientConn) GetWithContext ¶
func (*ClientConn) LocalAddr ¶
func (co *ClientConn) LocalAddr() net.Addr
LocalAddr implements the networkSession.LocalAddr method.
func (*ClientConn) NewDeleteRequest ¶
func (co *ClientConn) NewDeleteRequest(path string) (Message, error)
NewDeleteRequest creates delete request
func (*ClientConn) NewGetRequest ¶
func (co *ClientConn) NewGetRequest(path string) (Message, error)
NewGetRequest creates get request
func (*ClientConn) NewMessage ¶
func (co *ClientConn) NewMessage(p MessageParams) Message
NewMessage Create message for request
func (*ClientConn) NewPostRequest ¶
func (co *ClientConn) NewPostRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
NewPostRequest creates post request
func (*ClientConn) NewPutRequest ¶
func (co *ClientConn) NewPutRequest(path string, contentFormat MediaType, body io.Reader) (Message, error)
NewPutRequest creates put request
func (*ClientConn) Observe ¶
func (co *ClientConn) Observe(path string, observeFunc func(req *Request)) (*Observation, error)
func (*ClientConn) ObserveWithContext ¶
func (co *ClientConn) ObserveWithContext( ctx context.Context, path string, observeFunc func(req *Request), options ...func(Message), ) (*Observation, error)
func (*ClientConn) PeerCertificates ¶
func (co *ClientConn) PeerCertificates() []*x509.Certificate
PeerCertificates implements the networkSession.PeerCertificates method.
func (*ClientConn) Ping ¶
func (co *ClientConn) Ping(timeout time.Duration) error
Ping send a ping message and wait for a pong response
func (*ClientConn) PingWithContext ¶
func (co *ClientConn) PingWithContext(ctx context.Context) error
Ping send a ping message and wait for a pong response
func (*ClientConn) PostWithContext ¶
func (co *ClientConn) PostWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
Post update the resource identified by the request path
func (*ClientConn) PutWithContext ¶
func (co *ClientConn) PutWithContext(ctx context.Context, path string, contentFormat MediaType, body io.Reader) (Message, error)
PutContext create the resource identified by the request path
func (*ClientConn) RemoteAddr ¶
func (co *ClientConn) RemoteAddr() net.Addr
RemoteAddr implements the networkSession.RemoteAddr method.
func (*ClientConn) Sequence ¶
func (co *ClientConn) Sequence() uint64
Sequence discontinuously unique growing number for connection.
func (*ClientConn) WriteMsg ¶
func (co *ClientConn) WriteMsg(m Message) error
func (*ClientConn) WriteMsgWithContext ¶
func (co *ClientConn) WriteMsgWithContext(ctx context.Context, m Message) error
WriteContextMsg sends direct a message through the connection
type DgramMessage ¶
type DgramMessage struct { MessageBase // contains filtered or unexported fields }
DgramMessage implements Message interface.
func NewDgramMessage ¶
func NewDgramMessage(p MessageParams) *DgramMessage
func ParseDgramMessage ¶
func ParseDgramMessage(data []byte) (*DgramMessage, error)
ParseDgramMessage extracts the Message from the given input.
func (*DgramMessage) MarshalBinary ¶
func (m *DgramMessage) MarshalBinary(buf io.Writer) error
MarshalBinary produces the binary form of this DgramMessage.
func (*DgramMessage) MessageID ¶
func (m *DgramMessage) MessageID() uint16
func (*DgramMessage) SetMessageID ¶
func (m *DgramMessage) SetMessageID(messageID uint16)
SetMessageID
func (*DgramMessage) ToBytesLength ¶
func (m *DgramMessage) ToBytesLength() (int, error)
ToBytesLength gets the length of the message
func (*DgramMessage) UnmarshalBinary ¶
func (m *DgramMessage) UnmarshalBinary(data []byte) error
UnmarshalBinary parses the given binary slice as a DgramMessage.
type Handler ¶
type Handler interface {
ServeCOAP(w ResponseWriter, r *Request)
}
Handler is implemented by any value that implements ServeCOAP.
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
The HandlerFunc type is an adapter to allow the use of ordinary functions as COAP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) ServeCOAP ¶
func (f HandlerFunc) ServeCOAP(w ResponseWriter, r *Request)
ServeCOAP calls f(w, r).
type KeepAlive ¶
type KeepAlive struct { // Enable watch connection Enable bool // Interval between two success pings Interval time.Duration // WaitForPong how long it will waits for pong response. WaitForPong time.Duration // NewRetryPolicy creates retry policy for the connection when ping fails. NewRetryPolicy RetryFuncFactory }
KeepAlive config
func MakeKeepAlive ¶
MakeKeepAlive creates a policy that detects dropped connections within the connTimeout limit while attempting to make 3 pings during that period.
func MustMakeKeepAlive ¶
MustMakeKeepAlive must creates a keepalive policy.
type MediaType ¶
type MediaType uint16
MediaType specifies the content format of a message.
const ( TextPlain MediaType = 0 // text/plain;charset=utf-8 AppCoseEncrypt0 MediaType = 16 // application/cose; cose-type="cose-encrypt0" (RFC 8152) AppCoseMac0 MediaType = 17 // application/cose; cose-type="cose-mac0" (RFC 8152) AppCoseSign1 MediaType = 18 // application/cose; cose-type="cose-sign1" (RFC 8152) AppLinkFormat MediaType = 40 // application/link-format AppXML MediaType = 41 // application/xml AppOctets MediaType = 42 // application/octet-stream AppExi MediaType = 47 // application/exi AppJSON MediaType = 50 // application/json AppJsonPatch MediaType = 51 //application/json-patch+json (RFC6902) AppJsonMergePatch MediaType = 52 //application/merge-patch+json (RFC7396) AppCBOR MediaType = 60 //application/cbor (RFC 7049) AppCWT MediaType = 61 //application/cwt AppCoseEncrypt MediaType = 96 //application/cose; cose-type="cose-encrypt" (RFC 8152) AppCoseMac MediaType = 97 //application/cose; cose-type="cose-mac" (RFC 8152) AppCoseSign MediaType = 98 //application/cose; cose-type="cose-sign" (RFC 8152) AppCoseKey MediaType = 101 //application/cose-key (RFC 8152) AppCoseKeySet MediaType = 102 //application/cose-key-set (RFC 8152) AppSenmlJSON MediaType = 110 //application/senml+json AppSenmlCbor MediaType = 112 //application/senml+cbor AppCoapGroup MediaType = 256 //coap-group+json (RFC 7390) AppOcfCbor MediaType = 10000 //application/vnd.ocf+cbor AppLwm2mTLV MediaType = 11542 //application/vnd.oma.lwm2m+tlv AppLwm2mJSON MediaType = 11543 //application/vnd.oma.lwm2m+json )
Content formats.
type Message ¶
type Message interface { Type() COAPType Code() codes.Code MessageID() uint16 Token() []byte Payload() []byte AllOptions() options IsConfirmable() bool Options(o OptionID) []interface{} Option(o OptionID) interface{} Path() []string PathString() string SetPathString(s string) SetPath(s []string) SetType(typ COAPType) Query() []string QueryString() string SetQueryString(string) SetQuery([]string) SetURIQuery(s string) SetObserve(b uint32) SetPayload(p []byte) RemoveOption(opID OptionID) AddOption(opID OptionID, val interface{}) SetOption(opID OptionID, val interface{}) MarshalBinary(buf io.Writer) error UnmarshalBinary(data []byte) error SetToken(t []byte) SetMessageID(messageID uint16) ToBytesLength() (int, error) SetCode(code codes.Code) // contains filtered or unexported methods }
Message represents the COAP message
type MessageBase ¶
type MessageBase struct {
// contains filtered or unexported fields
}
MessageBase is a CoAP message.
func (*MessageBase) AddOption ¶
func (m *MessageBase) AddOption(opID OptionID, val interface{})
AddOption adds an option.
func (*MessageBase) AllOptions ¶
func (m *MessageBase) AllOptions() options
func (*MessageBase) Code ¶
func (m *MessageBase) Code() codes.Code
func (*MessageBase) IsConfirmable ¶
func (m *MessageBase) IsConfirmable() bool
IsConfirmable returns true if this message is confirmable.
func (*MessageBase) Option ¶
func (m *MessageBase) Option(o OptionID) interface{}
Option gets the first value for the given option ID.
func (*MessageBase) Options ¶
func (m *MessageBase) Options(o OptionID) []interface{}
Options gets all the values for the given option.
func (*MessageBase) Path ¶
func (m *MessageBase) Path() []string
Path gets the Path set on this message if any.
func (*MessageBase) PathString ¶
func (m *MessageBase) PathString() string
PathString gets a path as a / separated string.
func (*MessageBase) Payload ¶
func (m *MessageBase) Payload() []byte
func (*MessageBase) Query ¶
func (m *MessageBase) Query() []string
Query gets the Query set on this message if any.
func (*MessageBase) QueryString ¶
func (m *MessageBase) QueryString() string
QueryString gets a path as an ampersand separated string.
func (*MessageBase) RemoveOption ¶
func (m *MessageBase) RemoveOption(opID OptionID)
RemoveOption removes all references to an option
func (*MessageBase) SetCode ¶
func (m *MessageBase) SetCode(code codes.Code)
SetCode sets the coap code on the message
func (*MessageBase) SetObserve ¶
func (m *MessageBase) SetObserve(b uint32)
Set Observer attribute to the message
func (*MessageBase) SetOption ¶
func (m *MessageBase) SetOption(opID OptionID, val interface{})
SetOption sets an option, discarding any previous value
func (*MessageBase) SetPath ¶
func (m *MessageBase) SetPath(s []string)
SetPath updates or adds a URIPath attribute on this message.
func (*MessageBase) SetPathString ¶
func (m *MessageBase) SetPathString(s string)
SetPathString sets a path by a / separated string.
func (*MessageBase) SetQuery ¶
func (m *MessageBase) SetQuery(s []string)
SetQuery updates or adds a URIQuery attribute on this message.
func (*MessageBase) SetQueryString ¶
func (m *MessageBase) SetQueryString(s string)
SetQueryString sets a query by an ampersand separated string.
func (*MessageBase) SetType ¶
func (m *MessageBase) SetType(typ COAPType)
func (*MessageBase) SetURIQuery ¶
func (m *MessageBase) SetURIQuery(s string)
Set URIQuery attibute to the message
func (*MessageBase) Token ¶
func (m *MessageBase) Token() []byte
func (*MessageBase) Type ¶
func (m *MessageBase) Type() COAPType
type MessageParams ¶
type MessageParams struct { Type COAPType Code codes.Code MessageID uint16 Token []byte Payload []byte }
MessageParams params to create COAP message
type MulticastClient ¶
type MulticastClient struct { Net string // udp4" / "udp6" / "udp" - don't use udp on apple, because multicast ipv6->ipv4 is not supported. MaxMessageSize uint32 // Max message size that could be received from peer. If not set it defaults to 1152 B. DialTimeout time.Duration // set Timeout for dialer ReadTimeout time.Duration // net.ClientConn.SetReadTimeout value for connections, defaults to 1 hour - overridden by Timeout when that value is non-zero WriteTimeout time.Duration // net.ClientConn.SetWriteTimeout value for connections, defaults to 1 hour - overridden by Timeout when that value is non-zero HeartBeat time.Duration // The maximum of time for synchronization go-routines, defaults to 30 seconds - overridden by Timeout when that value is non-zero if it occurs, then it call log.Fatal Handler HandlerFunc // default handler for handling messages from server NotifySessionEndFunc func(err error) // if NotifySessionEndFunc is set it is called when TCP/UDP session was ended. BlockWiseTransfer *bool // Use blockWise transfer for transfer payload (default for UDP it's enabled, for TCP it's disable) BlockWiseTransferSzx *BlockWiseSzx // Set maximal block size of payload that will be send in fragment MulticastHopLimit int //sets the hop limit field value for future outgoing multicast packets. default is 2. Errors func(err error) // Report errors // contains filtered or unexported fields }
A MulticastClient defines parameters for a COAP client.
func (*MulticastClient) Dial ¶
func (c *MulticastClient) Dial(address string) (*MulticastClientConn, error)
func (*MulticastClient) DialWithContext ¶
func (c *MulticastClient) DialWithContext(ctx context.Context, address string) (*MulticastClientConn, error)
DialWithContext connects with context to the address on the named network.
type MulticastClientConn ¶
type MulticastClientConn struct {
// contains filtered or unexported fields
}
A ClientConn represents a connection to a COAP server.
func (*MulticastClientConn) Close ¶
func (mconn *MulticastClientConn) Close()
Close close connection
func (*MulticastClientConn) LocalAddr ¶
func (mconn *MulticastClientConn) LocalAddr() net.Addr
LocalAddr implements the networkSession.LocalAddr method.
func (*MulticastClientConn) NewGetRequest ¶
func (mconn *MulticastClientConn) NewGetRequest(path string) (Message, error)
NewGetRequest creates get request
func (*MulticastClientConn) NewMessage ¶
func (mconn *MulticastClientConn) NewMessage(p MessageParams) Message
NewMessage Create message for request
func (*MulticastClientConn) Publish ¶
func (mconn *MulticastClientConn) Publish(path string, responseHandler func(req *Request)) (*ResponseWaiter, error)
Publish subscribes to sever on path. After subscription and every change on path, server sends immediately response
func (*MulticastClientConn) PublishMsg ¶
func (mconn *MulticastClientConn) PublishMsg(req Message, responseHandler func(req *Request)) (*ResponseWaiter, error)
PublishMsg subscribes to sever with GET message. After subscription and every change on path, server sends immediately response
func (*MulticastClientConn) PublishMsgWithContext ¶
func (mconn *MulticastClientConn) PublishMsgWithContext(ctx context.Context, req Message, responseHandler func(req *Request)) (*ResponseWaiter, error)
PublishMsgWithContext subscribes with context to sever with GET message. After subscription and every change on path, server sends immediately response
func (*MulticastClientConn) PublishWithContext ¶
func (mconn *MulticastClientConn) PublishWithContext(ctx context.Context, path string, responseHandler func(req *Request)) (*ResponseWaiter, error)
PublishContext subscribes with context to sever on path. After subscription and every change on path, server sends immediately response
func (*MulticastClientConn) RemoteAddr ¶
func (mconn *MulticastClientConn) RemoteAddr() net.Addr
RemoteAddr implements the networkSession.RemoteAddr method.
func (*MulticastClientConn) WriteMsg ¶
func (mconn *MulticastClientConn) WriteMsg(m Message) error
WriteMsg sends a message through the connection co.
func (*MulticastClientConn) WriteMsgWithContext ¶
func (mconn *MulticastClientConn) WriteMsgWithContext(ctx context.Context, m Message) error
WriteContextMsg sends a message with context through the connection co.
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() error
func (*Observation) CancelWithContext ¶
func (o *Observation) CancelWithContext(ctx context.Context) error
CancelContext remove observation from server. For recreate observation use Observe.
type OptionID ¶
type OptionID uint16
OptionID identifies an option in a message.
const ( IfMatch OptionID = 1 URIHost OptionID = 3 ETag OptionID = 4 IfNoneMatch OptionID = 5 Observe OptionID = 6 URIPort OptionID = 7 LocationPath OptionID = 8 URIPath OptionID = 11 ContentFormat OptionID = 12 MaxAge OptionID = 14 URIQuery OptionID = 15 Accept OptionID = 17 LocationQuery OptionID = 20 Block2 OptionID = 23 Block1 OptionID = 27 Size2 OptionID = 28 ProxyURI OptionID = 35 ProxyScheme OptionID = 39 Size1 OptionID = 60 NoResponse OptionID = 258 )
Option IDs.
Signal Release Option IDs
+-----+---+---+---------------------+--------+--------+---------+ | No. | C | R | Name | Format | Length | Default | +-----+---+---+---------------------+--------+--------+---------+ | 2 | | x | Alternative-Address | string | 1-255 | (none) | | 4 | | | Hold-Off | uint3 | 0-3 | (none) | +-----+---+---+---------------------+--------+--------+---------+ C=Critical, R=Repeatable
const (
BadCSMOption OptionID = 2
)
Signal Abort Option IDs
+-----+---+---+---------------------+--------+--------+---------+ | No. | C | R | Name | Format | Length | Default | +-----+---+---+---------------------+--------+--------+---------+ | 2 | | | Bad-CSM-Option | uint | 0-2 | (none) | +-----+---+---+---------------------+--------+--------+---------+ C=Critical, R=Repeatable
const (
Custody OptionID = 2
)
type Request ¶
type Request struct { Msg Message Client *ClientConn Ctx context.Context Sequence uint64 // discontinuously growing number for every request from connection starts from 0 }
type ResponseWaiter ¶
type ResponseWaiter struct {
// contains filtered or unexported fields
}
ResponseWaiter represents subscription to resource on the server
func (*ResponseWaiter) Cancel ¶
func (r *ResponseWaiter) Cancel() error
Cancel remove observation from server. For recreate observation use Observe.
type ResponseWriter ¶
type ResponseWriter interface { Write(p []byte) (n int, err error) // WriteContext response with payload. // If p is nil it writes response without payload. // If p is non-nil then SetContentFormat must be called before Write otherwise Write fails. WriteWithContext(ctx context.Context, p []byte) (n int, err error) // SetCode for response that is send via Write call. // // If SetCode is not called explicitly, the first call to Write // will trigger an implicit SetCode(Content/Changed/Deleted/Created - depends on request). // Thus explicit calls to SetCode are mainly used to send error codes. SetCode(code codes.Code) // SetContentFormat of payload for response that is send via Write call. // // If SetContentFormat is not called and Write is called with non-nil argumet // If SetContentFormat is set but Write is called with nil argument it fails SetContentFormat(contentFormat MediaType) //NewResponse create response with code and token, messageid against request NewResponse(code codes.Code) Message WriteMsg(msg Message) error //WriteContextMsg to client. //If Option ContentFormat is set and Payload is not set then call will failed. //If Option ContentFormat is not set and Payload is set then call will failed. WriteMsgWithContext(ctx context.Context, msg Message) error // contains filtered or unexported methods }
A ResponseWriter interface is used by an CAOP handler to construct an COAP response. For Obsevation (GET+option observe) it can be stored and used in another go-routine with using calls NewResponse, WriteContextMsg
type RetryFuncFactory ¶
type RetryFuncFactory = func() RetryFunc
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is an COAP request multiplexer. It matches the path name of each incoming request against a list of registered patterns add calls the handler for the pattern with same name. ServeMux is also safe for concurrent access from multiple goroutines.
func (*ServeMux) DefaultHandle ¶
DefaultHandle set default handler to the ServeMux
func (*ServeMux) DefaultHandleFunc ¶
func (mux *ServeMux) DefaultHandleFunc(handler func(w ResponseWriter, r *Request))
DefaultHandleFunc set a default handler function to the ServeMux.
func (*ServeMux) HandleFunc ¶
func (mux *ServeMux) HandleFunc(pattern string, handler func(w ResponseWriter, r *Request))
HandleFunc adds a handler function to the ServeMux for pattern.
func (*ServeMux) HandleRemove ¶
HandleRemove deregistrars the handler specific for pattern from the ServeMux.
func (*ServeMux) ServeCOAP ¶
func (mux *ServeMux) ServeCOAP(w ResponseWriter, r *Request)
ServeCOAP dispatches the request to the handler whose pattern most closely matches the request message. If DefaultServeMux is used the correct thing for DS queries is done: a possible parent is sought. If no handler is found a standard NotFound message is returned
type Server ¶
type Server struct { // Address to listen on, ":COAP" if empty. Addr string // if "tcp" or "tcp-tls" (COAP over TLS) it will invoke a TCP listener, otherwise an UDP one Net string // TCP Listener to use, this is to aid in systemd's socket activation. Listener Listener // TLS connection configuration TLSConfig *tls.Config // DTLSConfig connection configuration DTLSConfig *dtls.Config // UDP/TCP "Listener/Connection" to use, this is to aid in systemd's socket activation. Conn net.Conn // Handler to invoke, COAP.DefaultServeMux if nil. Handler Handler // Max message size that could be received from peer. Min 16bytes. If not set // it defaults is unlimited. MaxMessageSize uint32 // The net.Conn.SetReadTimeout value for new connections, defaults to 1hour. ReadTimeout time.Duration // The net.Conn.SetWriteTimeout value for new connections, defaults to 1hour. WriteTimeout time.Duration // If NotifyStartedFunc is set it is called once the server has started listening. NotifyStartedFunc func() // Defines wake up interval from operations Read, Write over connection. defaults is 100ms. HeartBeat time.Duration // If NotifyNewSession is set it is called when new TCP/UDP session was created. NotifySessionNewFunc func(w *ClientConn) // If NotifyNewSession is set it is called when TCP/UDP session was ended. NotifySessionEndFunc func(w *ClientConn, err error) // The interfaces that will be used for udp-mcast (default uses the system assigned for multicast) UDPMcastInterfaces []net.Interface // Use blockWise transfer for transfer payload (default for UDP it's enabled, for TCP it's disable) BlockWiseTransfer *bool // Set maximal block size of payload that will be send in fragment BlockWiseTransferSzx *BlockWiseSzx // Disable send tcp signal CSM message DisableTCPSignalMessageCSM bool // Disable processes Capabilities and Settings Messages from client - iotivity sends max message size without blockwise. DisablePeerTCPSignalMessageCSMs bool // Keepalive setup KeepAlive KeepAlive // Report errors Errors func(err error) // contains filtered or unexported fields }
A Server defines parameters for running an COAP server.
func (*Server) ActivateAndServe ¶
ActivateAndServe starts a coapserver with the PacketConn or Listener configured in *Server. Its main use is to start a server from systemd.
func (*Server) ListenAndServe ¶
ListenAndServe starts a coapserver on the configured address in *Server.
type TcpMessage ¶
type TcpMessage struct {
MessageBase
}
TcpMessage is a CoAP MessageBase that can encode itself for TCP transport.
func Decode ¶
func Decode(reader io.Reader) (*TcpMessage, error)
Decode reads a single message from its input.
func NewTcpMessage ¶
func NewTcpMessage(p MessageParams) *TcpMessage
func PullTcp ¶
func PullTcp(data []byte) (*TcpMessage, []byte, error)
PullTcp extracts a complete TCP CoAP message from the front of a byte queue.
Return values:
*TcpMessage: On success, points to the extracted message; nil if a complete message could not be extracted. []byte: The unread portion of of the supplied byte buffer. If a message was not extracted, this is the unchanged buffer that was passed in. error: Non-nil if the buffer contains an invalid CoAP message.
Note: It is not an error if the supplied buffer does not contain a complete message. In such a case, nil *TclMessage and error values are returned along with the original buffer.
func (*TcpMessage) MarshalBinary ¶
func (m *TcpMessage) MarshalBinary(buf io.Writer) error
func (*TcpMessage) MessageID ¶
func (m *TcpMessage) MessageID() uint16
func (*TcpMessage) ToBytesLength ¶
func (m *TcpMessage) ToBytesLength() (int, error)
func (*TcpMessage) UnmarshalBinary ¶
func (m *TcpMessage) UnmarshalBinary(data []byte) error
type TokenHandler ¶
type TokenHandler struct {
// contains filtered or unexported fields
}
TokenHandler container for regirstration handlers by token
func (*TokenHandler) Add ¶
func (s *TokenHandler) Add(token []byte, handler func(w ResponseWriter, r *Request)) error
Add register handler for token
func (*TokenHandler) Handle ¶
func (s *TokenHandler) Handle(w ResponseWriter, r *Request, next HandlerFunc)
Handle call handler for request if exist otherwise use next
func (*TokenHandler) Remove ¶
func (s *TokenHandler) Remove(token []byte) error
Remove unregister handler for token
Source Files ¶
- blockwise.go
- client.go
- clientcommander.go
- error.go
- getresponsewriter.go
- keepalive.go
- message.go
- messagedgram.go
- messagetcp.go
- multicastClient.go
- networksession.go
- noresponsewriter.go
- request.go
- responsewriter.go
- server.go
- servermux.go
- sessionbase.go
- sessiondtls.go
- sessiontcp.go
- sessionudp.go
- shutdownContext.go
- tokenhandler.go
- utils.go