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) typedef
void(*
This function is the higher layer callback for reporting an error during handling of an incoming TCP connection.
CallbackRemovedFunct)(void *listenerState) typedef
void(*
This function is invoked for removing a callback.
ConnectionReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveConnection *con) typedef
void(*
This function is the higher layer callback for handling an incoming TCP connection.
MessageLayerActivityChangeHandlerFunct)(bool messageLayerIsActive) typedef
void(*
This function is the application callback for reporting message layer activity change.
MessageReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveMessageInfo *msgInfo, PacketBuffer *payload) typedef
void(*
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) typedef
void(*
This function is the higher layer callback invoked upon encountering an error.
State{
  kState_NotInitialized = 0,
  kState_Initializing = 1,
  kState_Initialized = 2
}
enum
The state of the WeaveMessageLayer.
TunneledMsgReceiveFunct)(WeaveMessageLayer *msgLayer, PacketBuffer *payload) typedef
void(*
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::Weave::WeaveMessageLayer::InitContext

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
[in] msgLayer
A pointer to the WeaveMessageLayer object.
[in] err
The WEAVE_ERROR encountered when handling an incoming TCP connection.

CallbackRemovedFunct

void(* CallbackRemovedFunct)(void *listenerState)

This function is invoked for removing a callback.

Details
Parameters
[in] listenerState
A pointer to the application state object.

ConnectionReceiveFunct

void(* ConnectionReceiveFunct)(WeaveMessageLayer *msgLayer, WeaveConnection *con)

This function is the higher layer callback for handling an incoming TCP connection.

Details
Parameters
[in] msgLayer
A pointer to the WeaveMessageLayer object.
[in] con
A pointer to the WeaveConnection object.

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
[in] messageLayerIsActive
A boolean value indicating whether message layer is active or not.

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
[in] msgLayer
A pointer to the WeaveMessageLayer object.
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] payload
Pointer to PacketBuffer message containing tunneled packet received.

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
[in] msgLayer
A pointer to the WeaveMessageLayer object.
[in] err
The WEAVE_ERROR encountered when receiving data.
[in] pktInfo
A read-only pointer to the IPPacketInfo object.

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
[in] msgLayer
A pointer to the WeaveMessageLayer object.
[in] payload
Pointer to PacketBuffer message containing tunneled packet received.

Public attributes

AppState

void * AppState

A pointer to an application-specific state object.

ExchangeMgr

WeaveExchangeManager * ExchangeMgr

[READ ONLY] The associated WeaveExchangeManager object.

FabricState

WeaveFabricState * FabricState

[READ ONLY] The associated WeaveFabricState 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.

State

uint8_t State

[READ ONLY] The state of the WeaveMessageLayer 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
[out] tunPtr
A pointer to pointer of a WeaveConnectionTunnel object.
[in] conOne
A reference to the first WeaveConnection object.
[in] conTwo
A reference to the second WeaveConnection object.
[in] inactivityTimeoutMS
The maximum time in milliseconds that the Weave connection tunnel could be idle.
Return Values
WEAVE_NO_ERROR
on successful creation of the WeaveConnectionTunnel.
WEAVE_ERROR_INCORRECT_STATE
if the component WeaveConnection objects of the WeaveConnectionTunnel is not in the correct state.
WEAVE_ERROR_NO_MEMORY
if a new WeaveConnectionTunnel object cannot be created.

DecodeHeader

WEAVE_ERROR DecodeHeader(
  PacketBuffer *msgBuf,
  WeaveMessageInfo *msgInfo,
  uint8_t **payloadStart
)

Decode a Weave Message layer header from a received Weave message.

Details
Parameters
[in] msgBuf
A pointer to the PacketBuffer object holding the Weave message.
[in] msgInfo
A pointer to a WeaveMessageInfo object which will receive information about the message.
[out] payloadStart
A pointer to a pointer to the position in the message buffer after decoding is complete.
Return Values
WEAVE_NO_ERROR
On successful decoding of the message header.
WEAVE_ERROR_INVALID_MESSAGE_LENGTH
If the message buffer passed is of invalid length.
WEAVE_ERROR_UNSUPPORTED_MESSAGE_VERSION
If the Weave Message header format version is not supported.

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
[in] msgInfo
A pointer to a WeaveMessageInfo object containing information about the message to be encoded.
[in] msgBuf
A pointer to the PacketBuffer object that would hold the Weave message.
[in] con
A pointer to the WeaveConnection object.
[in] maxLen
The maximum length of the encoded Weave message.
[in] reserve
The reserved space before the payload to hold the Weave message header.
Return Values
WEAVE_NO_ERROR
on successful encoding of the message.
WEAVE_ERROR_UNSUPPORTED_MESSAGE_VERSION
if the Weave Message header format version is not supported.
WEAVE_ERROR_INVALID_MESSAGE_LENGTH
if the payload length in the message buffer is zero.
WEAVE_ERROR_UNSUPPORTED_ENCRYPTION_TYPE
if the encryption type in the message header is not supported.
WEAVE_ERROR_MESSAGE_TOO_LONG
if the encoded message would be longer than the requested maximum.
WEAVE_ERROR_BUFFER_TOO_SMALL
if there is not enough space before or after the message payload.
other
errors generated by the fabric state object when fetching the session state.

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
[in] destAddr
The destination IP Address.
[in] destPort
The destination port.
[in] sendIntId
The interface on which to send the Weave message.
[in] msgInfo
A pointer to a WeaveMessageInfo object.
[in] payload
A pointer to the PacketBuffer object that would hold the Weave message.
Return Values
WEAVE_NO_ERROR
on successful encoding of the Weave message.
WEAVE_ERROR_UNSUPPORTED_MESSAGE_VERSION
if the Weave Message version is not supported.
WEAVE_ERROR_INVALID_MESSAGE_LENGTH
if the payload length in the message buffer is zero.
WEAVE_ERROR_UNSUPPORTED_ENCRYPTION_TYPE
if the encryption type is not supported.
WEAVE_ERROR_MESSAGE_TOO_LONG
if the encoded message would be longer than the requested maximum.
WEAVE_ERROR_BUFFER_TOO_SMALL
if there is not enough space before or after the message payload.
other
errors generated by the fabric state object when fetching the session state.

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
[out] aOutInUse
Reference to size_t, in which the number of connections in use is stored.

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
[in] context
A pointer to the InitContext object.
Return Values
WEAVE_NO_ERROR
on successful initialization.
WEAVE_ERROR_INVALID_ARGUMENT
if the passed InitContext object is NULL.
WEAVE_ERROR_INCORRECT_STATE
if the state of the WeaveMessageLayer object is incorrect.
other
errors generated from the lower Inet layer during endpoint creation.

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
WEAVE_NO_ERROR
on successful refreshing of endpoints.
InetLayer
errors based on calls to create TCP/UDP endpoints.

ResendMessage

WEAVE_ERROR ResendMessage(
  WeaveMessageInfo *msgInfo,
  PacketBuffer *msgBuf
)

Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.

Details
Parameters
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

ResendMessage

WEAVE_ERROR ResendMessage(
  const IPAddress & destAddr,
  WeaveMessageInfo *msgInfo,
  PacketBuffer *msgBuf
)

Resend an encoded Weave message using the underlying Inetlayer UDP endpoint.

Details
Parameters
[in] destAddr
The destination IP Address.
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] destAddr
The destination IP Address.
[in] destPort
The destination port.
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] aDestAddr
The destination IP Address.
[in] destPort
The destination port.
[in] interfaceId
The interface on which to send the Weave message.
[in] msgInfo
A pointer to the WeaveMessageInfo object.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

SendMessage

WEAVE_ERROR SendMessage(
  WeaveMessageInfo *msgInfo,
  PacketBuffer *msgBuf
)

Send a Weave message using the underlying Inetlayer UDP endpoint after encoding it.

Details
Parameters
[in] msgInfo
A pointer to a WeaveMessageInfo object containing information about the message to be sent.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] destAddr
The destination IP Address.
[in] msgInfo
A pointer to a WeaveMessageInfo object containing information about the message to be sent.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] aDestAddr
The destination IP Address.
[in] destPort
The destination port.
[in] sendIntfId
The interface on which to send the Weave message.
[in] msgInfo
A pointer to a WeaveMessageInfo object containing information about the message to be sent.
[in] payload
A pointer to the PacketBuffer object holding the encoded Weave message.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
WEAVE_ERROR_INVALID_ADDRESS
if the destAddr is not specified or cannot be determined from destination node id.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] msgInfo
A pointer to a WeaveMessageInfo object.
[in] destAddr
IPAddress of the UDP tunnel destination.
[in] msgBuf
A pointer to the PacketBuffer object holding the packet to send.
Return Values
WEAVE_NO_ERROR
on successfully sending the message down to the network layer.
WEAVE_ERROR_INVALID_ADDRESS
if the destAddr is not specified or cannot be determined from destination node id.
errors
generated from the lower Inet layer UDP endpoint during sending.

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
[in] messageLayerActivityChangeHandler
A pointer to a function to be called whenever the message layer activity changes.
Return Values
None.

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
[in] msgBuf
A pointer to the PacketBuffer to which the message payload will be written.
[in] isUDP
True if message is a UDP message.
[in] udpMTU
The size of the UDP MTU. Ignored if isUDP is false.
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
[in] buf
A pointer to a buffer into which the string should be written. The supplied buffer should be at least as big as kWeavePeerDescription_MaxLength. If a smaller buffer is given the string will be truncated to fit. The output will include a NUL termination character in all cases.
[in] bufSize
The size of the buffer pointed at by buf.
[in] nodeId
The node id to be printed.
[in] addr
A pointer to an IP address to be printed; or NULL if no IP address should be printed.
[in] port
An IP port number to be printed. No port number will be printed if addr is NULL.
[in] interfaceId
An InterfaceId identifying the interface to be printed. The output string will contain the name of the interface as known to the underlying network stack. No interface name will be printed if interfaceId is INET_NULL_INTERFACEID or if addr is NULL.
[in] con
A pointer to a WeaveConnection object whose logging id should be printed; or NULL if no connection id should be printed.

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
[in] buf
A pointer to a buffer into which the string should be written. The supplied buffer should be at least as big as kWeavePeerDescription_MaxLength. If a smaller buffer is given the string will be truncated to fit. The output will include a NUL termination character in all cases.
[in] bufSize
The size of the buffer pointed at by buf.
[in] msgInfo
A pointer to a WeaveMessageInfo structure containing information about the message.