nl:: Weave:: WeaveMessageLayer
#include <src/lib/core/WeaveMessageLayer.h>
The definition of the WeaveMessageLayer class, which manages communication with other Weave nodes.
Summary
It employs one of several InetLayer endpoints to establish a communication channel with other Weave nodes.
Constructors and Destructors |
|
---|---|
WeaveMessageLayer(void)
The Weave Message layer constructor.
|
Public types |
|
---|---|
AcceptErrorFunct)(WeaveMessageLayer *msgLayer, WEAVE_ERROR err)
|
typedefvoid(*
This function is the higher layer callback for reporting an error during handling of an incoming TCP connection. |
CallbackRemovedFunct)(void *listenerState)
|
typedefvoid(*
This function is invoked for removing a callback. |
ConnectionReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveConnection *con)
|
typedefvoid(*
This function is the higher layer callback for handling an incoming TCP connection. |
MessageLayerActivityChangeHandlerFunct)(bool messageLayerIsActive)
|
typedefvoid(*
This function is the application callback for reporting message layer activity change. |
MessageReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveMessageInfo *msgInfo, PacketBuffer *payload)
|
typedefvoid(*
This function is the higher layer callback that is invoked upon receipt of a Weave message over UDP. |
ReceiveErrorFunct)(WeaveMessageLayer *msgLayer, WEAVE_ERROR err, const IPPacketInfo *pktInfo)
|
typedefvoid(*
This function is the higher layer callback invoked upon encountering an error. |
State{
|
enum The state of the WeaveMessageLayer. |
TunneledMsgReceiveFunct)(WeaveMessageLayer *msgLayer, PacketBuffer *payload)
|
typedefvoid(*
This function is the higher layer callback that is invoked upon receipt of a Tunneled packet over a local UDP tunnel. |
Public attributes |
|
---|---|
AppState
|
void *
A pointer to an application-specific state object.
|
ExchangeMgr
|
[READ ONLY] The associated WeaveExchangeManager object.
|
FabricState
|
[READ ONLY] The associated WeaveFabricState object.
|
IncomingConIdleTimeout
|
uint32_t
Default idle timeout (in milliseconds) for incoming connections.
|
Inet
|
InetLayer *
[READ ONLY] The associated InetLayer object.
|
IsListening
|
bool
[READ ONLY] True if listening for incoming connections/messages, false otherwise.
|
OnAcceptError
|
|
OnConnectionReceived
|
|
OnMessageReceived
|
|
OnReceiveError
|
|
OnUDPTunneledMessageReceived
|
|
SecurityMgr
|
[READ ONLY] The associated WeaveSecurityManager object.
|
State
|
uint8_t
[READ ONLY] The state of the WeaveMessageLayer object.
|
SystemLayer
|
|
mDropMessage
|
bool
Internal and for Debug Only; When set, WeaveMessageLayer drops the message and returns.
|
Public functions |
|
---|---|
ClearUnsecuredConnectionListener(ConnectionReceiveFunct oldOnUnsecuredConnectionReceived, CallbackRemovedFunct newOnUnsecuredConnectionCallbacksRemoved)
|
|
CloseEndpoints(void)
|
Close all open TCP and UDP endpoints.
|
CreateTunnel(WeaveConnectionTunnel **tunPtr, WeaveConnection & conOne, WeaveConnection & conTwo, uint32_t inactivityTimeoutMS)
|
Create a WeaveConnectionTunnel by coupling together two specified WeaveConnections.
|
DecodeHeader(PacketBuffer *msgBuf, WeaveMessageInfo *msgInfo, uint8_t **payloadStart)
|
Decode a Weave Message layer header from a received Weave message.
|
EncodeMessage(WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf, WeaveConnection *con, uint16_t maxLen, uint16_t reserve)
|
Encode a WeaveMessageLayer header into an PacketBuffer.
|
EncodeMessage(const IPAddress & destAddr, uint16_t destPort, InterfaceId sendIntId, WeaveMessageInfo *msgInfo, PacketBuffer *payload)
|
Encode a Weave Message layer header into an PacketBuffer.
|
EphemeralUDPPortEnabled(void) const
|
bool
Check if locally initiated Weave UDP exchanges should be sent from an ephemeral UDP source port.
|
GetConnectionPoolStats(nl::Weave::System::Stats::count_t & aOutInUse) const
|
void
Get the number of WeaveConnections in use and the size of the pool.
|
IPv4ListenEnabled(void) const
|
bool
Check if the WeaveMessageLayer is configured to listen for inbound communications over IPv4.
|
IPv6ListenEnabled(void) const
|
bool
Check if the WeaveMessageLayer is configured to listen for inbound communications over IPv4.
|
Init(InitContext *context)
|
Initialize the Weave Message layer object.
|
IsBoundToLocalIPv4Address(void) const
|
bool
Check if the WeaveMessageLayer is bound to a local IPv4 address.
|
IsBoundToLocalIPv6Address(void) const
|
bool
Check if the WeaveMessageLayer is bound to a local IPv6 address.
|
IsMessageLayerActive(void)
|
bool
|
NewConnection(void)
|
Create a new WeaveConnection object from a pool.
|
NewConnectionTunnel(void)
|
Create a new WeaveConnectionTunnel object from a pool.
|
ReEncodeMessage(PacketBuffer *buf)
|
|
RefreshEndpoints(void)
|
Refresh the InetLayer endpoints based on the current state of the system's network interfaces.
|
ResendMessage(WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
|
ResendMessage(const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
|
ResendMessage(const IPAddress & destAddr, uint16_t destPort, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
|
ResendMessage(const IPAddress & destAddr, uint16_t destPort, InterfaceId interfaceId, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
|
SendMessage(WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
|
SendMessage(const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
|
SendMessage(const IPAddress & destAddr, uint16_t destPort, InterfaceId sendIntfId, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
|
SendUDPTunneledMessage(const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Function to send a Tunneled packet over a local UDP tunnel.
|
SetSignalMessageLayerActivityChanged(MessageLayerActivityChangeHandlerFunct messageLayerActivityChangeHandler)
|
void
Set an application handler that will get called every time the activity of the message layer changes.
|
SetTCPListenEnabled(bool val)
|
void
Enable or disable listening for inbound TCP connections in the WeaveMessageLayer.
|
SetUDPListenEnabled(bool val)
|
void
Enable or disable listening for inbound UDP messages in the WeaveMessageLayer.
|
SetUnsecuredConnectionListener(ConnectionReceiveFunct newOnUnsecuredConnectionReceived, CallbackRemovedFunct newOnUnsecuredConnectionCallbacksRemoved, bool force, void *listenerState)
|
|
Shutdown(void)
|
Shutdown the WeaveMessageLayer.
|
TCPListenEnabled(void) const
|
bool
Check if the WeaveMessageLayer is configured to listen for inbound TCP connections.
|
UDPListenEnabled(void) const
|
bool
Check if the WeaveMessageLayer is configured to listen for inbound UDP messages.
|
UnsecuredListenEnabled(void) const
|
bool
Enable or disabled initiating Weave UDP exchanges from an ephemeral UDP source port.
|
Public static functions |
|
---|---|
GetMaxWeavePayloadSize(const PacketBuffer *msgBuf, bool isUDP, uint32_t udpMTU)
|
uint32_t
Get the max Weave payload size for a message configuration and supplied PacketBuffer.
|
GetPeerDescription(char *buf, size_t bufSize, uint64_t nodeId, const IPAddress *addr, uint16_t port, InterfaceId interfaceId, const WeaveConnection *con)
|
void
Constructs a string describing a peer node and its associated address / connection information.
|
GetPeerDescription(char *buf, size_t bufSize, const WeaveMessageInfo *msgInfo)
|
void
Constructs a string describing a peer node based on the information associated with a message received from the peer.
|
Classes |
|
---|---|
nl:: |
The definition of the InitContext class. |
Public types
AcceptErrorFunct
void(* AcceptErrorFunct)(WeaveMessageLayer *msgLayer, WEAVE_ERROR err)
This function is the higher layer callback for reporting an error during handling of an incoming TCP connection.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
CallbackRemovedFunct
void(* CallbackRemovedFunct)(void *listenerState)
This function is invoked for removing a callback.
Details | |||
---|---|---|---|
Parameters |
|
ConnectionReceiveFunct
void(* ConnectionReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveConnection *con)
This function is the higher layer callback for handling an incoming TCP connection.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
MessageLayerActivityChangeHandlerFunct
void(* MessageLayerActivityChangeHandlerFunct)(bool messageLayerIsActive)
This function is the application callback for reporting message layer activity change.
Message layer is considered active if there is at least one open exchange or pending message counter synchronization request.
Details | |||
---|---|---|---|
Parameters |
|
MessageReceiveFunct
void(* MessageReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveMessageInfo *msgInfo, PacketBuffer *payload)
This function is the higher layer callback that is invoked upon receipt of a Weave message over UDP.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
ReceiveErrorFunct
void(* ReceiveErrorFunct)(WeaveMessageLayer *msgLayer, WEAVE_ERROR err, const IPPacketInfo *pktInfo)
This function is the higher layer callback invoked upon encountering an error.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
State
State
The state of the WeaveMessageLayer.
Properties | |
---|---|
kState_Initialized
|
State when the WeaveMessageLayer is initialized. |
kState_Initializing
|
State when the WeaveMessageLayer is in the process of being initialized. |
kState_NotInitialized
|
State when the WeaveMessageLayer is not initialized. |
TunneledMsgReceiveFunct
void(* TunneledMsgReceiveFunct)(WeaveMessageLayer *msgLayer, PacketBuffer *payload)
This function is the higher layer callback that is invoked upon receipt of a Tunneled packet over a local UDP tunnel.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
Public attributes
AppState
void * AppState
A pointer to an application-specific state object.
ExchangeMgr
WeaveExchangeManager * ExchangeMgr
[READ ONLY] The associated WeaveExchangeManager object.
IncomingConIdleTimeout
uint32_t IncomingConIdleTimeout
Default idle timeout (in milliseconds) for incoming connections.
Inet
InetLayer * Inet
[READ ONLY] The associated InetLayer object.
IsListening
bool IsListening
[READ ONLY] True if listening for incoming connections/messages, false otherwise.
OnAcceptError
AcceptErrorFunct OnAcceptError
OnConnectionReceived
ConnectionReceiveFunct OnConnectionReceived
OnMessageReceived
MessageReceiveFunct OnMessageReceived
OnReceiveError
ReceiveErrorFunct OnReceiveError
OnUDPTunneledMessageReceived
TunneledMsgReceiveFunct OnUDPTunneledMessageReceived
SecurityMgr
WeaveSecurityManager * SecurityMgr
[READ ONLY] The associated WeaveSecurityManager object.
SystemLayer
System::Layer * SystemLayer
mDropMessage
bool mDropMessage
Internal and for Debug Only; When set, WeaveMessageLayer drops the message and returns.
Public functions
ClearUnsecuredConnectionListener
WEAVE_ERROR ClearUnsecuredConnectionListener( ConnectionReceiveFunct oldOnUnsecuredConnectionReceived, CallbackRemovedFunct newOnUnsecuredConnectionCallbacksRemoved )
CloseEndpoints
WEAVE_ERROR CloseEndpoints( void )
Close all open TCP and UDP endpoints.
Then abort any open WeaveConnections and shutdown any open WeaveConnectionTunnel objects.
See also:Shutdown().
CreateTunnel
WEAVE_ERROR CreateTunnel( WeaveConnectionTunnel **tunPtr, WeaveConnection & conOne, WeaveConnection & conTwo, uint32_t inactivityTimeoutMS )
Create a WeaveConnectionTunnel by coupling together two specified WeaveConnections.
On successful creation, the TCPEndPoints corresponding to the component WeaveConnection objects are handed over to the WeaveConnectionTunnel, otherwise the WeaveConnections are closed.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
DecodeHeader
WEAVE_ERROR DecodeHeader( PacketBuffer *msgBuf, WeaveMessageInfo *msgInfo, uint8_t **payloadStart )
Decode a Weave Message layer header from a received Weave message.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
EncodeMessage
WEAVE_ERROR EncodeMessage( WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf, WeaveConnection *con, uint16_t maxLen, uint16_t reserve )
Encode a WeaveMessageLayer header into an PacketBuffer.
Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||||
Return Values |
|
EncodeMessage
WEAVE_ERROR EncodeMessage( const IPAddress & destAddr, uint16_t destPort, InterfaceId sendIntId, WeaveMessageInfo *msgInfo, PacketBuffer *payload )
Encode a Weave Message layer header into an PacketBuffer.
Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||||
Return Values |
|
EphemeralUDPPortEnabled
bool EphemeralUDPPortEnabled( void ) const
Check if locally initiated Weave UDP exchanges should be sent from an ephemeral UDP source port.
GetConnectionPoolStats
void GetConnectionPoolStats( nl::Weave::System::Stats::count_t & aOutInUse ) const
Get the number of WeaveConnections in use and the size of the pool.
Details | |||
---|---|---|---|
Parameters |
|
IPv4ListenEnabled
bool IPv4ListenEnabled( void ) const
Check if the WeaveMessageLayer is configured to listen for inbound communications over IPv4.
IPv6ListenEnabled
bool IPv6ListenEnabled( void ) const
Check if the WeaveMessageLayer is configured to listen for inbound communications over IPv4.
Init
WEAVE_ERROR Init( InitContext *context )
Initialize the Weave Message layer object.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
IsBoundToLocalIPv4Address
bool IsBoundToLocalIPv4Address( void ) const
Check if the WeaveMessageLayer is bound to a local IPv4 address.
IsBoundToLocalIPv6Address
bool IsBoundToLocalIPv6Address( void ) const
Check if the WeaveMessageLayer is bound to a local IPv6 address.
IsMessageLayerActive
bool IsMessageLayerActive( void )
NewConnection
WeaveConnection * NewConnection( void )
Create a new WeaveConnection object from a pool.
Details | |
---|---|
Returns |
a pointer to the newly created WeaveConnection object if successful, otherwise NULL.
|
NewConnectionTunnel
WeaveConnectionTunnel * NewConnectionTunnel( void )
Create a new WeaveConnectionTunnel object from a pool.
Details | |
---|---|
Returns |
a pointer to the newly created WeaveConnectionTunnel object if successful, otherwise NULL.
|
ReEncodeMessage
WEAVE_ERROR ReEncodeMessage( PacketBuffer *buf )
RefreshEndpoints
WEAVE_ERROR RefreshEndpoints( void )
Refresh the InetLayer endpoints based on the current state of the system's network interfaces.
Details | |||||
---|---|---|---|---|---|
Return Values |
|
ResendMessage
WEAVE_ERROR ResendMessage( WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
ResendMessage
WEAVE_ERROR ResendMessage( const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
ResendMessage
WEAVE_ERROR ResendMessage( const IPAddress & destAddr, uint16_t destPort, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||
Return Values |
|
ResendMessage
WEAVE_ERROR ResendMessage( const IPAddress & destAddr, uint16_t destPort, InterfaceId interfaceId, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.
Note:-If the destination address has not been supplied, attempt to determine it from the node identifier in the message header. Fail if this can't be done. -If the destination address is a fabric address for the local fabric, and the caller didn't specify the destination node id, extract it from the destination address.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
SendMessage
WEAVE_ERROR SendMessage( WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
SendMessage
WEAVE_ERROR SendMessage( const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
Note:-The destination port used is WEAVE_PORT. -If the destination address has not been supplied, attempt to determine it from the node identifier in the message header. Fail if this can't be done.
-If the destination address is a fabric address for the local fabric, and the caller didn't specify the destination node id, extract it from the destination address.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
SendMessage
WEAVE_ERROR SendMessage( const IPAddress & destAddr, uint16_t destPort, InterfaceId sendIntfId, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.
Note:-If the destination address has not been supplied, attempt to determine it from the node identifier in the message header. Fail if this can't be done. -If the destination address is a fabric address for the local fabric, and the caller didn't specify the destination node id, extract it from the destination address.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
SendUDPTunneledMessage
WEAVE_ERROR SendUDPTunneledMessage( const IPAddress & destAddr, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Function to send a Tunneled packet over a local UDP tunnel.
Send a tunneled IPv6 data message over UDP.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Return Values |
|
SetSignalMessageLayerActivityChanged
void SetSignalMessageLayerActivityChanged( MessageLayerActivityChangeHandlerFunct messageLayerActivityChangeHandler )
Set an application handler that will get called every time the activity of the message layer changes.
Specifically, application will be notified every time:
- the number of opened exchanges changes.
- the number of pending message counter synchronization requests changes from zero to at least one and back to zero. The handler is served as general signal indicating whether there are any ongoing Weave conversations or pending responses. The handler must be set after the WeaveMessageLayer has been initialized; shutting down the WeaveMessageLayer will clear out the current handler.
Details | |||
---|---|---|---|
Parameters |
|
||
Return Values |
|
SetTCPListenEnabled
void SetTCPListenEnabled( bool val )
Enable or disable listening for inbound TCP connections in the WeaveMessageLayer.
NOTE: RefreshEndpoints()
must be called after the TCP listening state is changed.
SetUDPListenEnabled
void SetUDPListenEnabled( bool val )
Enable or disable listening for inbound UDP messages in the WeaveMessageLayer.
NOTE: RefreshEndpoints()
must be called after the UDP listening state is changed.
SetUnsecuredConnectionListener
WEAVE_ERROR SetUnsecuredConnectionListener( ConnectionReceiveFunct newOnUnsecuredConnectionReceived, CallbackRemovedFunct newOnUnsecuredConnectionCallbacksRemoved, bool force, void *listenerState )
Shutdown
WEAVE_ERROR Shutdown( void )
Shutdown the WeaveMessageLayer.
Close all open Inet layer endpoints, reset all higher layer callbacks, member variables and objects. A call to Shutdown() terminates the WeaveMessageLayer object.
TCPListenEnabled
bool TCPListenEnabled( void ) const
Check if the WeaveMessageLayer is configured to listen for inbound TCP connections.
UDPListenEnabled
bool UDPListenEnabled( void ) const
Check if the WeaveMessageLayer is configured to listen for inbound UDP messages.
UnsecuredListenEnabled
bool UnsecuredListenEnabled( void ) const
Enable or disabled initiating Weave UDP exchanges from an ephemeral UDP source port.
NOTE: RefreshEndpoints()
must be called after the ephemeral port state is changed. Check if unsecured listening is enabled.
WeaveMessageLayer
WeaveMessageLayer( void )
The Weave Message layer constructor.
Public static functions
GetMaxWeavePayloadSize
uint32_t GetMaxWeavePayloadSize( const PacketBuffer *msgBuf, bool isUDP, uint32_t udpMTU )
Get the max Weave payload size for a message configuration and supplied PacketBuffer.
The maximum payload size returned will not exceed the available space for a payload inside the supplied PacketBuffer.
If the message is UDP, the maximum payload size returned will not result in a Weave message that will not overflow the specified UDP MTU.
Finally, the maximum payload size returned will not result in a Weave message that will overflow the max Weave message size.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Returns |
the max Weave payload size.
|
GetPeerDescription
void GetPeerDescription( char *buf, size_t bufSize, uint64_t nodeId, const IPAddress *addr, uint16_t port, InterfaceId interfaceId, const WeaveConnection *con )
Constructs a string describing a peer node and its associated address / connection information.
The generated string has the following format:
([ ]: % , con )
Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
GetPeerDescription
void GetPeerDescription( char *buf, size_t bufSize, const WeaveMessageInfo *msgInfo )
Constructs a string describing a peer node based on the information associated with a message received from the peer.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|