nl:: Weave:: WeaveConnection
#include <src/lib/core/WeaveMessageLayer.h>
The definition of the Weave Connection class.
Summary
It represents a TCP or BLE connection to another Weave node.
Public types |
|
---|---|
@58{
|
enum |
ConnectionClosedFunct)(WeaveConnection *con, WEAVE_ERROR conErr)
|
typedefvoid(*
This function is the application callback that is invoked when a connection is closed. |
ConnectionCompleteFunct)(WeaveConnection *con, WEAVE_ERROR conErr)
|
typedefvoid(*
This function is the application callback that is invoked when a connection setup is complete. |
MessageReceiveFunct)(WeaveConnection *con, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
typedefvoid(*
This function is the application callback that is invoked when a message is received over a Weave connection. |
NetworkType{
|
enum The network type of the Weave connection object. |
ReceiveErrorFunct)(WeaveConnection *con, WEAVE_ERROR err)
|
typedefvoid(*
This function is the application callback invoked upon encountering an error when receiving a Weave message. |
State{
|
enum The State of the Weave connection object. |
TunneledMsgReceiveFunct)(WeaveConnection *con, const WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
typedefvoid(*
This function is the application callback that is invoked upon receipt of a Tunneled data packet over the Weave connection. |
Public attributes |
|
---|---|
AppState
|
void *
A pointer to the application-specific state object.
|
AuthMode
|
WeaveAuthMode
[READ ONLY] The authentication mode used to establish the default encryption keys for the connection.
|
DefaultEncryptionType
|
uint8_t
The default encryption type for messages.
|
DefaultKeyId
|
uint16_t
The default encryption key to use when sending messages.
|
MessageLayer
|
[READ ONLY] The associated WeaveMessageLayer object.
|
NetworkType
|
uint8_t
[READ ONLY] The network type of the associated end point.
|
OnConnectionClosed
|
|
OnConnectionComplete
|
|
OnMessageReceived
|
|
OnReceiveError
|
|
OnTunneledMessageReceived
|
|
PeerAddr
|
IPAddress
[READ ONLY] The IP address of the peer node.
|
PeerNodeId
|
uint64_t
[READ ONLY] The node identifier of the peer.
|
PeerPort
|
uint16_t
[READ ONLY] The port number of the peer node.
|
ReceiveEnabled
|
bool
[READ ONLY] True if receiving is enabled, false otherwise.
|
SendDestNodeId
|
bool
True if all messages sent via this connection must include an explicitly encoded destination node identifier, false otherwise.
|
SendSourceNodeId
|
bool
True if all messages sent via this connection must include an explicitly encoded source node identifier, false otherwise.
|
State
|
uint8_t
[READ ONLY] The state of the WeaveConnection object.
|
Public functions |
|
---|---|
Abort(void)
|
void
Performs an un-graceful close of the TCP- or BLE-based WeaveConnection, discarding any data that might be in flight to or from the peer.
|
AddRef(void)
|
void
Reserve a reference to the WeaveConnection object.
|
Close(void)
|
Performs a non-blocking graceful close of the TCP- or BLE-based WeaveConnection, delivering any remaining outgoing data before politely informing the remote host that we have reset the connection.
|
Close(bool suppressCloseLog)
|
Performs a non-blocking graceful close of the TCP- or BLE-based WeaveConnection, delivering any remaining outgoing data before politely informing the remote host that we have reset the connection.
|
Connect(uint64_t peerNodeId)
|
Connect to a Weave node using a fabric IP address derived from the specified node identifier.
|
Connect(uint64_t peerNodeId, const IPAddress & peerAddr, uint16_t peerPort)
|
Connect to a Weave node using a node identifier and/or an IP address.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, const IPAddress & peerAddr, uint16_t peerPort, InterfaceId intf)
|
Connect to a Weave node using a node identifier and/or an IP address on a specific interface.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t defaultPort)
|
Connect to a Weave node using a node identifier and/or a string host name.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t peerAddrLen, uint16_t defaultPort)
|
Connect to a Weave node using a node identifier and/or a string peer address.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t peerAddrLen, uint8_t dnsOptions, uint16_t defaultPort)
|
Connect to a Weave node using a node identifier and/or a string peer address.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, HostPortList hostPortList, InterfaceId intf)
|
Connect to a Weave node using a node identifier and/or a list of hostname and ports.
|
Connect(uint64_t peerNodeId, WeaveAuthMode authMode, HostPortList hostPortList, uint8_t dnsOptions, InterfaceId intf)
|
Connect to a Weave node using a node identifier and/or a list of hostname and ports.
|
DisableKeepAlive(void)
|
|
DisableReceive(void)
|
void
Disable receiving over this WeaveConnection.
|
EnableKeepAlive(uint16_t interval, uint16_t timeoutCount)
|
|
EnableReceive(void)
|
void
Enable receiving over this WeaveConnection.
|
GetPeerAddressInfo(IPPacketInfo & addrInfo)
|
Get the IP address information of the peer.
|
GetPeerDescription(char *buf, size_t bufSize) const
|
void
Constructs a string describing the peer node associated with the connection.
|
GetTCPEndPoint(void) const
|
TCPEndPoint *
|
IsIncoming(void) const
|
bool
|
LogId(void) const
|
uint16_t
|
Release(void)
|
void
Decrement the reference count on the WeaveConnection object.
|
ResetUserTimeout(void)
|
|
SendMessage(WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Send a Weave message over an established connection.
|
SendTunneledMessage(WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
|
Function to send a Tunneled packet over a Weave connection.
|
SetConnectTimeout(const uint32_t connTimeoutMsecs)
|
void
Set timeout for Connect to succeed or return an error.
|
SetIdleTimeout(uint32_t timeoutMS)
|
Set the idle timeout on the underlying network layer connection.
|
SetIncoming(bool val)
|
void
|
SetUserTimeout(uint32_t userTimeoutMillis)
|
|
Shutdown(void)
|
Performs a graceful TCP send-shutdown, ensuring all outgoing data has been sent and received by the peer's TCP stack.
|
Public types
@58
@58
Properties | |
---|---|
kGetPeerDescription_MaxLength
|
Maximum length of string (including NUL character) returned by GetPeerDescription(). |
ConnectionClosedFunct
void(* ConnectionClosedFunct)(WeaveConnection *con, WEAVE_ERROR conErr)
This function is the application callback that is invoked when a connection is closed.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
ConnectionCompleteFunct
void(* ConnectionCompleteFunct)(WeaveConnection *con, WEAVE_ERROR conErr)
This function is the application callback that is invoked when a connection setup is complete.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
MessageReceiveFunct
void(* MessageReceiveFunct)(WeaveConnection *con, WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
This function is the application callback that is invoked when a message is received over a Weave connection.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
NetworkType
NetworkType
ReceiveErrorFunct
void(* ReceiveErrorFunct)(WeaveConnection *con, WEAVE_ERROR err)
This function is the application callback invoked upon encountering an error when receiving a Weave message.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
State
State
The State of the Weave connection object.
TunneledMsgReceiveFunct
void(* TunneledMsgReceiveFunct)(WeaveConnection *con, const WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf)
This function is the application callback that is invoked upon receipt of a Tunneled data packet over the Weave connection.
Details | |||||||
---|---|---|---|---|---|---|---|
Parameters |
|
Public attributes
AppState
void * AppState
A pointer to the application-specific state object.
AuthMode
WeaveAuthMode AuthMode
[READ ONLY] The authentication mode used to establish the default encryption keys for the connection.
DefaultEncryptionType
uint8_t DefaultEncryptionType
The default encryption type for messages.
DefaultKeyId
uint16_t DefaultKeyId
The default encryption key to use when sending messages.
NetworkType
uint8_t NetworkType
[READ ONLY] The network type of the associated end point.
OnConnectionClosed
ConnectionClosedFunct OnConnectionClosed
OnConnectionComplete
ConnectionCompleteFunct OnConnectionComplete
OnMessageReceived
MessageReceiveFunct OnMessageReceived
OnReceiveError
ReceiveErrorFunct OnReceiveError
OnTunneledMessageReceived
TunneledMsgReceiveFunct OnTunneledMessageReceived
PeerAddr
IPAddress PeerAddr
[READ ONLY] The IP address of the peer node.
PeerNodeId
uint64_t PeerNodeId
[READ ONLY] The node identifier of the peer.
PeerPort
uint16_t PeerPort
[READ ONLY] The port number of the peer node.
ReceiveEnabled
bool ReceiveEnabled
[READ ONLY] True if receiving is enabled, false otherwise.
SendDestNodeId
bool SendDestNodeId
True if all messages sent via this connection must include an explicitly encoded destination node identifier, false otherwise.
SendSourceNodeId
bool SendSourceNodeId
True if all messages sent via this connection must include an explicitly encoded source node identifier, false otherwise.
Public functions
Abort
void Abort( void )
Performs an un-graceful close of the TCP- or BLE-based WeaveConnection, discarding any data that might be in flight to or from the peer.
A call to Abort() immediately terminates the underlying connection. After this point, the WeaveConnection object can no longer be used for further communication.
Calling Abort() decrements the reference count associated with the WeaveConnection object, whether or not the connection is open/active at the time the method is called. If this results in the reference count reaching zero, the resources associated with the connection object are freed. When this happens, the application must have no further interactions with the object.
See also:Shutdown(), Abort(), AddRef() and Release().
AddRef
void AddRef( void )
Reserve a reference to the WeaveConnection object.
The AddRef() method increments the reference count associated with the WeaveConnection object. For every call to AddRef(), the application is responsible for making a corresponding call to either Release(), Close() or Abort().
Close
WEAVE_ERROR Close( void )
Performs a non-blocking graceful close of the TCP- or BLE-based WeaveConnection, delivering any remaining outgoing data before politely informing the remote host that we have reset the connection.
This method provides no strong guarantee that any outgoing message not acknowledged at the application protocol level has been received by the remote peer. For both TCP and BLE, the underlying protocol stack will make a best-effort to deliver any pending outgoing data before resetting the connection. For TCP, Shutdown() should be used before Close() if a transport-layer message receipt confirmation is required before closing the connection. BLE connections provide no Shutdown() equivalent.
For BLE-based connections, Close() closes the WeaveConnection and returns immediately, but may cause the underlying BLEEndPoint object to linger until all outgoing data has been sent. This is a side effect of the Weave over BLE transport protocol implementation existing within the Weave BleLayer.
Once Close() has been called, the WeaveConnection object can no longer be used for further communication.
Calling Close() decrements the reference count associated with the WeaveConnection object, whether or not the connection is open/active at the time the method is called. If this results in the reference count reaching zero, the resources associated with the connection object are freed. When this happens, the application must have no further interactions with the object.
Details | |
---|---|
Returns |
WEAVE_NO_ERROR unconditionally.
|
Shutdown(), Abort(), AddRef() and Release().
Close
WEAVE_ERROR Close( bool suppressCloseLog )
Performs a non-blocking graceful close of the TCP- or BLE-based WeaveConnection, delivering any remaining outgoing data before politely informing the remote host that we have reset the connection.
This method provides no strong guarantee that any outgoing message not acknowledged at the application protocol level has been received by the remote peer. For both TCP and BLE, the underlying protocol stack will make a best-effort to deliver any pending outgoing data before resetting the connection. For TCP, Shutdown() should be used before Close() if a transport-layer message receipt confirmation is required before closing the connection. BLE connections provide no Shutdown() equivalent.
For BLE-based connections, Close() closes the WeaveConnection and returns immediately, but may cause the underlying BLEEndPoint object to linger until all outgoing data has been sent. This is a side effect of the Weave over BLE transport protocol implementation existing within the Weave BleLayer.
Once Close() has been called, the WeaveConnection object can no longer be used for further communication.
Calling Close() decrements the reference count associated with the WeaveConnection object, whether or not the connection is open/active at the time the method is called. If this results in the reference count reaching zero, the resources associated with the connection object are freed. When this happens, the application must have no further interactions with the object.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
WEAVE_NO_ERROR unconditionally.
|
Shutdown(), Abort(), AddRef() and Release().
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId )
Connect to a Weave node using a fabric IP address derived from the specified node identifier.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, const IPAddress & peerAddr, uint16_t peerPort )
Connect to a Weave node using a node identifier and/or an IP address.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, const IPAddress & peerAddr, uint16_t peerPort, InterfaceId intf )
Connect to a Weave node using a node identifier and/or an IP address on a specific interface.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t defaultPort )
Connect to a Weave node using a node identifier and/or a string host name.
If supplied, peerAddr can be any of:
: : [ ]:
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t peerAddrLen, uint16_t defaultPort )
Connect to a Weave node using a node identifier and/or a string peer address.
If supplied, peerAddr can be any of:
: : [ ]:
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, const char *peerAddr, uint16_t peerAddrLen, uint8_t dnsOptions, uint16_t defaultPort )
Connect to a Weave node using a node identifier and/or a string peer address.
If supplied, peerAddr can be any of:
: : [ ]:
Details | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, HostPortList hostPortList, InterfaceId intf )
Connect to a Weave node using a node identifier and/or a list of hostname and ports.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
Connect
WEAVE_ERROR Connect( uint64_t peerNodeId, WeaveAuthMode authMode, HostPortList hostPortList, uint8_t dnsOptions, InterfaceId intf )
Connect to a Weave node using a node identifier and/or a list of hostname and ports.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
DisableKeepAlive
WEAVE_ERROR DisableKeepAlive( void )
WeaveConnection::DisableKeepAlive.
Disable TCP keepalive probes on the underlying TCP connection.
Note:This method can only be called on a Weave connection backed by a TCP connection. This method can only be called when the connection is in a state that allows sending.
This method does nothing if keepalives have not been enabled on the connection.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Return Values |
|
DisableReceive
void DisableReceive( void )
Disable receiving over this WeaveConnection.
This method is used by the application to indicate that it is not ready to receive any arrived data over the TCP connection. In order to re-enable receiving, the application needs to call EnableReceive() to allow WeaveConnection to hand over any received data by invoking the approrpiate callbacks.
See also:EnableReceive()
EnableKeepAlive
WEAVE_ERROR EnableKeepAlive( uint16_t interval, uint16_t timeoutCount )
WeaveConnection::EnableKeepAlive.
Enable TCP keepalive probes on the underlying TCP connection.
Note:-This method can only be called on a Weave connection backed by a TCP connection. -This method can only be called when the connection is in a state that allows sending.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
-This method can be called multiple times to adjust the keepalive interval or timeout count.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Return Values |
|
EnableReceive
void EnableReceive( void )
Enable receiving over this WeaveConnection.
This method is used by the application to indicate to the WeaveConnection object that it is ready to receive any data that arrives over the TCP connection.
See also:DisableReceive()
GetPeerAddressInfo
WEAVE_ERROR GetPeerAddressInfo( IPPacketInfo & addrInfo )
Get the IP address information of the peer.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
GetPeerDescription
void GetPeerDescription( char *buf, size_t bufSize ) const
Constructs a string describing the peer node associated with the connection.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
GetTCPEndPoint
TCPEndPoint * GetTCPEndPoint( void ) const
IsIncoming
bool IsIncoming( void ) const
LogId
uint16_t LogId( void ) const
Release
void Release( void )
Decrement the reference count on the WeaveConnection object.
The Release() method decrements the reference count associated with the WeaveConnection object. If this results in the reference count reaching zero, the connection is closed and the connection object is freed. When this happens, the application must have no further interactions with the object.
ResetUserTimeout
WEAVE_ERROR ResetUserTimeout( void )
WeaveConnection::ResetUserTimeout.
Reset the TCP user timeout socket option to the system default.
Note:-This method can only be called on a Weave connection backed by a TCP connection. -This method can only be called when the connection is in a state that allows sending.
-This method does nothing if user timeout has not been set on the connection.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Return Values |
|
SendMessage
WEAVE_ERROR SendMessage( WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Send a Weave message over an established connection.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
SendTunneledMessage
WEAVE_ERROR SendTunneledMessage( WeaveMessageInfo *msgInfo, PacketBuffer *msgBuf )
Function to send a Tunneled packet over a Weave connection.
Send a tunneled Weave message over an established connection.
Details | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
||||||||||
Return Values |
|
SetConnectTimeout
void SetConnectTimeout( const uint32_t connTimeoutMsecs )
Set timeout for Connect to succeed or return an error.
Details | |||
---|---|---|---|
Parameters |
|
SetIdleTimeout
WEAVE_ERROR SetIdleTimeout( uint32_t timeoutMS )
Set the idle timeout on the underlying network layer connection.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
||||
Return Values |
|
SetIncoming
void SetIncoming( bool val )
SetUserTimeout
WEAVE_ERROR SetUserTimeout( uint32_t userTimeoutMillis )
WeaveConnection::SetUserTimeout.
Set the TCP user timeout socket option.
When the value is greater than 0, it specifies the maximum amount of time in milliseconds that transmitted data may remain unacknowledged before TCP will forcibly close the corresponding connection. If the option value is specified as 0, TCP will use the system default. See RFC 5482, for further details.
Details | |||
---|---|---|---|
Parameters |
|
Note:-This method can only be called on a Weave connection backed by a TCP connection. -This method can only be called when the connection is in a state that allows sending.
-This method can be called multiple times to adjust the TCP user timeout.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Return Values |
|
Shutdown
WEAVE_ERROR Shutdown( void )
Performs a graceful TCP send-shutdown, ensuring all outgoing data has been sent and received by the peer's TCP stack.
With most (but not all) TCP implementations, receipt of a send-shutdown will cause the remote host to shutdown their side of the connection as well, resulting in a connection close. A subsequent call to Close() would terminate the WeaveConnection.
Details | |||||||||
---|---|---|---|---|---|---|---|---|---|
Return Values |
|
Close() and Abort().