|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Central owner of all channels, listeners and connections in a process. More...
#include <NetworkManager.h>
Public Member Functions | |
| THREAD_RET THREAD_FUNCTION_CALL | NetworkManagerRun (THREAD_ARG arg) |
| Thread entry point of the manager's supervision loop (do not call directly). | |
| NetworkManager () | |
| virtual | ~NetworkManager () |
| bool | setSSLCertificate (const char *sslCertPath, const char *sslKeyPath) |
| Set the certificate/key used by SSL listeners created via this manager. | |
| bool | setSSLAllowSelfSigned (bool allow) |
| bool | setSSLCALocation (const char *caFile, const char *caPath) |
| NetworkChannel * | createListener (uint16 port, uint8 encryption, uint8 protocol, bool isAsync, uint32 protocolTimeout, bool isDefaultProtocol, uint32 channelID, NetworkReceiver *recv) |
| Open a listening port for one or more protocols. | |
| NetworkChannel * | createTCPConnection (const char *addr, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint32 channelID, NetworkReceiver *recv, uint64 &conid, uint64 &location, uint32 timeoutMS=5000) |
| Connect to a remote host by name/IP and start the protocol thread. | |
| NetworkChannel * | createTCPConnection (uint64 location, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint32 channelID, NetworkReceiver *recv, uint64 &conid, uint32 timeoutMS=5000) |
| Connect to a packed uint64 endpoint. | |
| NetworkChannel * | createTCPConnection (const uint32 *addresses, uint16 addressCount, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, bool autoreconnect, uint32 channelID, NetworkReceiver *recv, uint64 &conid, uint64 &location, uint32 timeoutMS=5000) |
| Connect trying several candidate IPv4 addresses for one host. | |
| NetworkChannel * | createUDPConnection (uint16 port, uint8 protocol, bool isAsync, bool autoreconnect, uint32 channelID, NetworkReceiver *recv, uint64 &conid) |
| Bind a UDP port for datagram traffic. | |
| NetworkChannel * | addTCPConnection (const char *addr, uint16 port, uint8 encryption, uint8 protocol, bool isAsync, uint32 channelID, NetworkReceiver *recv, uint64 &conid, uint64 &location, uint32 timeoutMS=5000, const char *greetingData=NULL, uint32 greetingSize=0) |
| Like createTCPConnection() but sends optional greeting bytes right after connecting (peer identification / protocol selection) and never auto-reconnects. | |
| NetworkChannel * | addTCPConnection (uint64 location, uint8 encryption, uint8 protocol, bool isAsync, uint32 channelID, NetworkReceiver *recv, uint64 &conid, uint32 timeoutMS=5000, const char *greetingData=NULL, uint32 greetingSize=0) |
| Packed-endpoint variant of addTCPConnection(). | |
| NetworkChannel * | createWebsocketConnection (const char *url, uint32 channelID, NetworkReceiver *recv, uint64 &conid, const char *protocolName=NULL, const char *origin=NULL, uint32 timeoutMS=5000) |
| Open a client WebSocket connection from a full URL (ws:// or wss://). | |
| NetworkChannel * | createWebsocketConnection (const char *uri, const char *addr, uint16 port, uint8 encryption, uint32 channelID, NetworkReceiver *recv, uint64 &conid, const char *protocolName=NULL, const char *origin=NULL, uint32 timeoutMS=5000) |
| Open a client WebSocket connection from explicit components. | |
| bool | stopListener (uint16 port, uint8 protocol) |
| Stop a listener previously opened with createListener(). | |
| bool | endConnection (uint64 conid) |
| Gracefully close a connection (thread is asked to finish; entry kept for reuse). | |
| bool | endUDPConnection (uint16 port) |
Close the UDP connection bound to port. | |
| bool | removeConnection (uint64 conid) |
| Close a connection and remove it from the manager's maps entirely. | |
| uint8 | getConnectionType (uint64 conid) |
| uint64 | getRemoteAddress (uint64 conid) |
| NetworkChannel * | getConnection (uint64 conid) |
| NetworkChannel * | getTCPConnectionByPort (uint16 port) |
| NetworkChannel * | getUDPConnectionByPort (uint16 port) |
| uint64 | addConnection (NetworkChannel *channel) |
| Register an externally created channel with the manager. | |
| bool | sendUDPMessage (DataMessage *msg, uint64 destination) |
| Send a DataMessage as a UDP datagram via the shared output socket. | |
| HTTPReply * | makeHTTPRequest (const char *url, uint32 timeout, const char *content=NULL, uint32 contentSize=0) |
Blocking HTTP(S) exchange from a URL string (GET, or POST when content given). | |
| HTTPReply * | makeHTTPRequest (HTTPRequest *req, const char *addr, uint16 port, uint8 encryption, uint32 timeout) |
| Blocking exchange sending a pre-built request to an explicit endpoint. | |
| HTTPReply * | makeHTTPRequest (uint8 ops, std::string addr, uint32 timeout, std::map< std::string, std::string > &headerEntries, const char *content, const char *contentType, uint32 contentSize, bool keepAlive=false, uint64 ifModifiedSince=0) |
| Blocking exchange with custom headers and typed raw body. | |
| HTTPReply * | makeHTTPRequest (uint8 ops, std::string addr, uint32 timeout, std::map< std::string, std::string > &headerEntries, std::map< std::string, HTTPPostEntry * > &bodyEntries, bool keepAlive=false, uint64 ifModifiedSince=0) |
| Blocking multipart/form-data exchange (file uploads, form posts). | |
| Public Member Functions inherited from cmlabs::Runnable | |
| Runnable () | |
| Initialise flags: not running, allowed to continue. | |
| virtual | ~Runnable () |
| Destructor requests a stop (with the default timeout) before destruction proceeds. | |
| virtual bool | stop (uint32 timeout=200) |
| Ask the worker loop to finish and wait for it to do so. | |
Static Public Member Functions | |
| static bool | UnitTest () |
| Basic TCP/message-protocol round-trip self-test. | |
| static bool | UnitTestDelayedConnect () |
| Self-test of non-blocking (delayed) connect handling. | |
| static bool | UnitTestHTTP () |
| Self-test of the built-in HTTP server and client. | |
| static bool | TestHTTP (const char *host, uint32 port, std::vector< std::string > &urls) |
| Fetch a list of URLs from a host and report results (manual test helper). | |
| static bool | WebsocketTest () |
| WebSocket upgrade + echo self-test. | |
Public Attributes | |
| int8 | sslAllowSelfSigned |
| std::string | sslCAFile |
| std::string | sslCAPath |
| bool | sslCASet |
Protected Member Functions | |
| bool | run () |
| Supervision loop body (delayed connects, reconnection). | |
Protected Attributes | |
| std::map< uint32, NetworkChannel * > | channels |
| All channels by channel id (owned). | |
| std::map< uint64, NetworkChannel * > | channelsByConnection |
| Channel lookup by connection id. | |
| std::map< uint16, NetworkChannel * > | listeners |
| TCP listeners by port. | |
| std::map< uint16, NetworkChannel * > | udpListeners |
| UDP listeners by port. | |
| std::string | sslCertPath |
| PEM certificate path for SSL listeners. | |
| std::string | sslKeyPath |
| PEM private key path for SSL listeners. | |
| UDPConnection * | udpOutputCon |
| Shared output-only UDP socket for sendUDPMessage(). | |
| utils::Mutex | udpOutputConMutex |
| Serialises use of ::udpOutputCon. | |
| uint32 | lastChannelID |
| Last channel id issued. | |
| uint64 | lastConnectionID |
| Last connection id issued. | |
| Protected Attributes inherited from cmlabs::Runnable | |
| uint32 | threadID |
| ThreadManager slot ID of the worker thread (0 until known). | |
| bool | shouldContinue |
| Loop-continuation flag; cleared by stop(). | |
| bool | isRunning |
| Set by the worker while its loop is active. | |
Friends | |
| class | NetworkChannel |
Central owner of all channels, listeners and connections in a process.
Create one NetworkManager, then use the create*() factories to open listeners and outgoing connections. Each factory associates the new listener/connection with a NetworkChannel (identified by channelID; a new channel is created when needed) and an optional NetworkReceiver for push-mode dispatch. The manager's own thread supervises delayed connects and reconnection.
It is also a complete embedded HTTP(S)/WebSocket server — e.g. the PsyProbe web monitoring UI is served by a NetworkManager HTTP listener. Ports are always caller-chosen; there is no built-in default port.
timeoutMS unless a delayed/async variant is used. Definition at line 161 of file NetworkManager.h.
| cmlabs::NetworkManager::NetworkManager | ( | ) |
Definition at line 68 of file NetworkManager.cpp.
References lastChannelID, lastConnectionID, sslAllowSelfSigned, sslCASet, and udpOutputCon.
Referenced by TestHTTP(), UnitTest(), UnitTestDelayedConnect(), UnitTestHTTP(), and WebsocketTest().
|
virtual |
Definition at line 76 of file NetworkManager.cpp.
References channels, channelsByConnection, listeners, and udpOutputCon.
| uint64 cmlabs::NetworkManager::addConnection | ( | NetworkChannel * | channel | ) |
Register an externally created channel with the manager.
| channel | Channel to adopt (ownership transfers). |
Definition at line 448 of file NetworkManager.cpp.
References channelsByConnection, lastConnectionID, and NetworkChannel.
| NetworkChannel * cmlabs::NetworkManager::addTCPConnection | ( | const char * | addr, |
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000, | ||
| const char * | greetingData = NULL, | ||
| uint32 | greetingSize = 0 ) |
Like createTCPConnection() but sends optional greeting bytes right after connecting (peer identification / protocol selection) and never auto-reconnects.
| addr | Host address. |
| port | TCP port. |
| location | Out: resolved endpoint (packed uint64). |
| encryption | NOENC or SSLENC. |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push mode when true. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for async dispatch. |
| conid | Out: new connection id. |
| timeoutMS | Connect timeout in ms. |
| greetingData | Bytes sent immediately after connect (copied). |
| greetingSize | Byte count. |
Definition at line 328 of file NetworkManager.cpp.
References cmlabs::NetworkChannel::addTCPConnection(), channels, channelsByConnection, cmlabs::NetworkChannel::cid, getConnection(), lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
Referenced by UnitTestDelayedConnect().
| NetworkChannel * cmlabs::NetworkManager::addTCPConnection | ( | uint64 | location, |
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| uint32 | timeoutMS = 5000, | ||
| const char * | greetingData = NULL, | ||
| uint32 | greetingSize = 0 ) |
Packed-endpoint variant of addTCPConnection().
| location | Packed endpoint. |
| encryption | NOENC or SSLENC. |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push mode when true. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for async dispatch. |
| conid | Out: new connection id. |
| timeoutMS | Connect timeout in ms. |
| greetingData | Bytes sent immediately after connect (copied). |
| greetingSize | Byte count. |
Definition at line 362 of file NetworkManager.cpp.
References cmlabs::NetworkChannel::addTCPConnection(), channels, channelsByConnection, cmlabs::NetworkChannel::cid, getConnection(), GETIPADDRESSQUADPORT, lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
| NetworkChannel * cmlabs::NetworkManager::createListener | ( | uint16 | port, |
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| uint32 | protocolTimeout, | ||
| bool | isDefaultProtocol, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv ) |
Open a listening port for one or more protocols.
| port | TCP port to bind (caller-chosen; no default). |
| encryption | NOENC or SSLENC (certificate must be set first). |
| protocol | PROTOCOL_* bit flags; several may be OR'ed for auto-detection. |
| isAsync | Push items to recv when true; queue for waitFor*() when false. |
| protocolTimeout | Milliseconds allowed to sniff/auto-detect a new connection's protocol. |
| isDefaultProtocol | Treat the first protocol flag as fallback when detection is inconclusive. |
| channelID | Channel to attach to (0 = allocate a new channel). |
| recv | Receiver for async dispatch (may be NULL for sync mode). |
Definition at line 103 of file NetworkManager.cpp.
References channels, cmlabs::NetworkChannel::cid, getConnection(), lastChannelID, listeners, NetworkChannel, cmlabs::NetworkChannel::setNewReceiver(), and cmlabs::NetworkChannel::startListener().
Referenced by cmlabs::Test_RequestClient(), UnitTest(), UnitTestDelayedConnect(), UnitTestHTTP(), and WebsocketTest().
| NetworkChannel * cmlabs::NetworkManager::createTCPConnection | ( | const char * | addr, |
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000 ) |
Connect to a remote host by name/IP and start the protocol thread.
| addr | Host name or IPv4 string. |
| port | Remote port. |
| encryption | NOENC or SSLENC. |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push mode when true. |
| autoreconnect | Re-establish automatically on failure. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for async dispatch. |
| conid | Out: new connection id. |
| location | Out: resolved endpoint (packed uint64). |
| timeoutMS | Connect timeout in ms. |
timeoutMS. Definition at line 148 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::NetworkChannel::createTCPConnection(), getConnection(), lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
Referenced by cmlabs::HTTPServerTest(), makeHTTPRequest(), makeHTTPRequest(), makeHTTPRequest(), TestHTTP(), UnitTest(), UnitTestHTTP(), and WebsocketTest().
| NetworkChannel * cmlabs::NetworkManager::createTCPConnection | ( | const uint32 * | addresses, |
| uint16 | addressCount, | ||
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| uint64 & | location, | ||
| uint32 | timeoutMS = 5000 ) |
Connect trying several candidate IPv4 addresses for one host.
| addresses | Candidate addresses. |
| addressCount | Number of candidates. |
| port | TCP port. |
| location | Out: resolved endpoint (packed uint64). |
| encryption | NOENC or SSLENC. |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push mode when true. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for async dispatch. |
| conid | Out: new connection id. |
| timeoutMS | Connect timeout in ms. |
| autoreconnect | Re-establish automatically on failure. |
Definition at line 227 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::NetworkChannel::createTCPConnection(), getConnection(), GETIPADDRESSQUADPORT, lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
| NetworkChannel * cmlabs::NetworkManager::createTCPConnection | ( | uint64 | location, |
| uint8 | encryption, | ||
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| uint32 | timeoutMS = 5000 ) |
Connect to a packed uint64 endpoint.
See the string-address overload for details.
| location | Packed endpoint (address+port). |
| encryption | NOENC or SSLENC. |
| protocol | Single PROTOCOL_* flag. |
| isAsync | Push mode when true. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for async dispatch. |
| conid | Out: new connection id. |
| timeoutMS | Connect timeout in ms. |
| autoreconnect | Re-establish automatically on failure. |
Definition at line 182 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::TCPConnection::connect(), cmlabs::NetworkChannel::createTCPConnection(), getConnection(), GETIPADDRESSQUADPORT, lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, cmlabs::NetworkChannel::setNewReceiver(), and cmlabs::NetworkChannel::startConnection().
| NetworkChannel * cmlabs::NetworkManager::createUDPConnection | ( | uint16 | port, |
| uint8 | protocol, | ||
| bool | isAsync, | ||
| bool | autoreconnect, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid ) |
Bind a UDP port for datagram traffic.
| port | Local UDP port. |
| protocol | PROTOCOL_* flag (typically PROTOCOL_MESSAGE). |
| isAsync | Push mode when true. |
| autoreconnect | Rebind on failure. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver. |
| conid | Out: new connection id. |
Definition at line 398 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::NetworkChannel::createUDPConnection(), getConnection(), lastChannelID, NetworkChannel, cmlabs::NetworkChannel::setNewReceiver(), and udpListeners.
Referenced by UnitTest().
| NetworkChannel * cmlabs::NetworkManager::createWebsocketConnection | ( | const char * | uri, |
| const char * | addr, | ||
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| const char * | protocolName = NULL, | ||
| const char * | origin = NULL, | ||
| uint32 | timeoutMS = 5000 ) |
Open a client WebSocket connection from explicit components.
| uri | Request path. |
| addr | Host. |
| port | Port. |
| encryption | NOENC or SSLENC. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for frames. |
| conid | Out: new connection id. |
| protocolName | Optional Sec-WebSocket-Protocol. |
| origin | Optional Origin header. |
| timeoutMS | Connect+handshake timeout in ms. |
Definition at line 294 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::NetworkChannel::createWebsocketConnection(), getConnection(), lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
| NetworkChannel * cmlabs::NetworkManager::createWebsocketConnection | ( | const char * | url, |
| uint32 | channelID, | ||
| NetworkReceiver * | recv, | ||
| uint64 & | conid, | ||
| const char * | protocolName = NULL, | ||
| const char * | origin = NULL, | ||
| uint32 | timeoutMS = 5000 ) |
Open a client WebSocket connection from a full URL (ws:// or wss://).
| url | Full URL including host, port and path. |
| channelID | Channel to attach to (0 = new). |
| recv | Receiver for frames. |
| conid | Out: new connection id. |
| protocolName | Optional Sec-WebSocket-Protocol. |
| origin | Optional Origin header. |
| timeoutMS | Connect+handshake timeout in ms. |
timeoutMS. Definition at line 261 of file NetworkManager.cpp.
References channels, channelsByConnection, cmlabs::NetworkChannel::cid, cmlabs::NetworkChannel::createWebsocketConnection(), getConnection(), lastChannelID, LOG_NETWORK, LogPrint, NetworkChannel, and cmlabs::NetworkChannel::setNewReceiver().
Referenced by cmlabs::TestWebSocketRequestClient::run().
| bool cmlabs::NetworkManager::endConnection | ( | uint64 | conid | ) |
Gracefully close a connection (thread is asked to finish; entry kept for reuse).
| conid | Connection id. |
Definition at line 434 of file NetworkManager.cpp.
References channelsByConnection, cmlabs::NetworkChannel::endConnection(), and NetworkChannel.
| bool cmlabs::NetworkManager::endUDPConnection | ( | uint16 | port | ) |
Close the UDP connection bound to port.
Definition at line 441 of file NetworkManager.cpp.
References cmlabs::NetworkChannel::endUDPConnection(), NetworkChannel, and udpListeners.
| NetworkChannel * cmlabs::NetworkManager::getConnection | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 468 of file NetworkManager.cpp.
References channelsByConnection, and NetworkChannel.
Referenced by addTCPConnection(), addTCPConnection(), createListener(), createTCPConnection(), createTCPConnection(), createTCPConnection(), createUDPConnection(), createWebsocketConnection(), and createWebsocketConnection().
| uint8 cmlabs::NetworkManager::getConnectionType | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 454 of file NetworkManager.cpp.
References channelsByConnection, cmlabs::NetworkChannel::getConnectionType(), and NetworkChannel.
| uint64 cmlabs::NetworkManager::getRemoteAddress | ( | uint64 | conid | ) |
| conid | Connection id. |
Definition at line 461 of file NetworkManager.cpp.
References channelsByConnection, cmlabs::NetworkChannel::getRemoteAddress(), and NetworkChannel.
| NetworkChannel * cmlabs::NetworkManager::getTCPConnectionByPort | ( | uint16 | port | ) |
| port | Listener port. |
Definition at line 472 of file NetworkManager.cpp.
References listeners, and NetworkChannel.
| NetworkChannel * cmlabs::NetworkManager::getUDPConnectionByPort | ( | uint16 | port | ) |
| port | UDP port. |
Definition at line 476 of file NetworkManager.cpp.
References NetworkChannel, and udpListeners.
| HTTPReply * cmlabs::NetworkManager::makeHTTPRequest | ( | const char * | url, |
| uint32 | timeout, | ||
| const char * | content = NULL, | ||
| uint32 | contentSize = 0 ) |
Blocking HTTP(S) exchange from a URL string (GET, or POST when content given).
| url | Full URL (http:// or https://, may embed basic-auth credentials). |
| timeout | Total timeout in ms. |
| content | Optional request body (POST). |
| contentSize | Body size. |
Definition at line 500 of file NetworkManager.cpp.
References cmlabs::HTTPReply::CreateErrorReply(), cmlabs::HTTPRequest::createRequest(), cmlabs::html::GetHostFromURL(), cmlabs::html::GetPortFromURL(), cmlabs::html::GetProtocolFromURL(), cmlabs::html::GetURIFromURL(), HTTP_GET, HTTP_MALFORMED_URL, HTTP_NOT_IMPLEMENTED, HTTP_POST, makeHTTPRequest(), NOENC, and SSLENC.
Referenced by makeHTTPRequest(), and cmlabs::TestWebRequestClient::run().
| HTTPReply * cmlabs::NetworkManager::makeHTTPRequest | ( | HTTPRequest * | req, |
| const char * | addr, | ||
| uint16 | port, | ||
| uint8 | encryption, | ||
| uint32 | timeout ) |
Blocking exchange sending a pre-built request to an explicit endpoint.
| req | Request to send (caller keeps ownership). |
| addr | Host. |
| port | Port. |
| encryption | NOENC or SSLENC. |
| timeout | Total timeout in ms. |
Definition at line 537 of file NetworkManager.cpp.
References cmlabs::HTTPReply::CreateErrorReply(), createTCPConnection(), cmlabs::NetworkChannel::endConnection(), HTTP_SERVER_UNAVAILABLE, NetworkChannel, NOENC, PROTOCOL_HTTP_CLIENT, cmlabs::NetworkChannel::sendReceiveHTTPRequest(), and SSLENC.
| HTTPReply * cmlabs::NetworkManager::makeHTTPRequest | ( | uint8 | ops, |
| std::string | addr, | ||
| uint32 | timeout, | ||
| std::map< std::string, std::string > & | headerEntries, | ||
| const char * | content, | ||
| const char * | contentType, | ||
| uint32 | contentSize, | ||
| bool | keepAlive = false, | ||
| uint64 | ifModifiedSince = 0 ) |
Blocking exchange with custom headers and typed raw body.
| ops | HTTP_* method id. |
| addr | Full URL or host address. |
| timeout | ms. |
| headerEntries | Extra header name/value pairs. |
| content | Body bytes. |
| contentType | Body MIME type. |
| contentSize | Body size. |
| keepAlive | Request a persistent connection. |
| ifModifiedSince | ms epoch or 0. |
Definition at line 560 of file NetworkManager.cpp.
References cmlabs::HTTPReply::CreateErrorReply(), cmlabs::HTTPRequest::createRequest(), createTCPConnection(), cmlabs::NetworkChannel::endConnection(), cmlabs::html::GetHostFromURL(), cmlabs::html::GetPortFromURL(), cmlabs::html::GetProtocolFromURL(), cmlabs::html::GetURIFromURL(), HTTP_MALFORMED_URL, HTTP_SERVER_UNAVAILABLE, NetworkChannel, NOENC, PROTOCOL_HTTP_CLIENT, cmlabs::NetworkChannel::sendReceiveHTTPRequest(), SSLENC, and stricmp.
| HTTPReply * cmlabs::NetworkManager::makeHTTPRequest | ( | uint8 | ops, |
| std::string | addr, | ||
| uint32 | timeout, | ||
| std::map< std::string, std::string > & | headerEntries, | ||
| std::map< std::string, HTTPPostEntry * > & | bodyEntries, | ||
| bool | keepAlive = false, | ||
| uint64 | ifModifiedSince = 0 ) |
Blocking multipart/form-data exchange (file uploads, form posts).
| ops | HTTP_* method id. |
| addr | Full URL or host address. |
| timeout | ms. |
| headerEntries | Extra headers. |
| bodyEntries | Named body parts (not owned). |
| keepAlive | Persistent connection flag. |
| ifModifiedSince | ms epoch or 0. |
Definition at line 613 of file NetworkManager.cpp.
References cmlabs::HTTPReply::CreateErrorReply(), cmlabs::HTTPRequest::createMultipartRequest(), cmlabs::HTTPRequest::createRequest(), createTCPConnection(), cmlabs::NetworkChannel::endConnection(), cmlabs::html::GetHostFromURL(), cmlabs::html::GetPortFromURL(), cmlabs::html::GetProtocolFromURL(), cmlabs::html::GetURIFromURL(), HTTP_MALFORMED_URL, HTTP_SERVER_UNAVAILABLE, NetworkChannel, NOENC, PROTOCOL_HTTP_CLIENT, cmlabs::NetworkChannel::sendReceiveHTTPRequest(), SSLENC, and stricmp.
| THREAD_RET THREAD_FUNCTION_CALL cmlabs::NetworkManager::NetworkManagerRun | ( | THREAD_ARG | arg | ) |
Thread entry point of the manager's supervision loop (do not call directly).
Definition at line 64 of file NetworkManager.cpp.
References THREAD_ARG, THREAD_FUNCTION_CALL, THREAD_RET, and thread_ret_val.
| bool cmlabs::NetworkManager::removeConnection | ( | uint64 | conid | ) |
Close a connection and remove it from the manager's maps entirely.
| conid | Connection id. |
Definition at line 429 of file NetworkManager.cpp.
References channelsByConnection.
|
protected |
Supervision loop body (delayed connects, reconnection).
| bool cmlabs::NetworkManager::sendUDPMessage | ( | DataMessage * | msg, |
| uint64 | destination ) |
Send a DataMessage as a UDP datagram via the shared output socket.
| msg | Message (caller keeps ownership). |
| destination | Packed uint64 endpoint. |
Definition at line 480 of file NetworkManager.cpp.
References cmlabs::MessageProtocol::SendMessage(), udpOutputCon, and udpOutputConMutex.
Referenced by UnitTest().
|
inline |
Definition at line 199 of file NetworkManager.h.
References sslAllowSelfSigned.
|
inline |
Definition at line 203 of file NetworkManager.h.
| bool cmlabs::NetworkManager::setSSLCertificate | ( | const char * | sslCertPath, |
| const char * | sslKeyPath ) |
Set the certificate/key used by SSL listeners created via this manager.
| sslCertPath | PEM certificate path. |
| sslKeyPath | PEM private key path. |
Definition at line 96 of file NetworkManager.cpp.
References sslCertPath, and sslKeyPath.
| bool cmlabs::NetworkManager::stopListener | ( | uint16 | port, |
| uint8 | protocol ) |
Stop a listener previously opened with createListener().
| port | Listener port. |
| protocol | PROTOCOL_* flags it was created with. |
Definition at line 139 of file NetworkManager.cpp.
References listeners, NetworkChannel, and cmlabs::NetworkChannel::stopListener().
|
static |
Fetch a list of URLs from a host and report results (manual test helper).
| host | Server host. |
| port | Server port. |
| urls | URI paths to fetch. |
Definition at line 3227 of file NetworkManager.cpp.
References createTCPConnection(), cmlabs::ThreadManager::CreateThread(), cmlabs::NetworkChannel::endConnection(), cmlabs::HTTPServerTestData::host, cmlabs::HTTPServerTest(), cmlabs::ThreadManager::IsThreadRunning(), LOG_SYSTEM, LogPrint, cmlabs::HTTPServerTestData::manager, NetworkChannel, NetworkManager(), NOENC, cmlabs::HTTPServerTestData::port, PROTOCOL_HTTP_CLIENT, cmlabs::utils::Sleep(), cmlabs::HTTPServerTestData::status, and cmlabs::HTTPServerTestData::urls.
|
static |
Basic TCP/message-protocol round-trip self-test.
Definition at line 2129 of file NetworkManager.cpp.
References createListener(), createTCPConnection(), createUDPConnection(), cmlabs::CTRL_TEST, cmlabs::unittest::detail(), cmlabs::NetworkChannel::endConnection(), cmlabs::unittest::fail(), cmlabs::DataMessage::getFrom(), GETIPADDRESSPORT, cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), cmlabs::DataMessage::getType(), LOCALHOSTIP, cmlabs::unittest::metric(), NetworkChannel, NetworkManager(), NOENC, cmlabs::PrintTimeDifString(), cmlabs::unittest::progress(), PROTOCOL_MESSAGE, cmlabs::NetworkChannel::sendMessage(), sendUDPMessage(), cmlabs::DataMessage::setData(), cmlabs::DataMessage::setType(), cmlabs::ThreadManager::Shutdown(), cmlabs::utils::Sleep(), and cmlabs::NetworkChannel::waitForMessage().
Referenced by cmlabs::Register_NetworkManager_Tests().
|
static |
Self-test of non-blocking (delayed) connect handling.
Definition at line 2059 of file NetworkManager.cpp.
References cmlabs::NetworkChannel::addTCPConnection(), addTCPConnection(), createListener(), cmlabs::DataMessage::data, cmlabs::unittest::detail(), cmlabs::unittest::fail(), cmlabs::DataMessage::getSize(), NetworkChannel, NetworkManager(), NOENC, cmlabs::unittest::progress(), PROTOCOL_MESSAGE, cmlabs::DataMessage::setString(), cmlabs::ThreadManager::Shutdown(), and cmlabs::NetworkChannel::waitForMessage().
Referenced by cmlabs::Register_NetworkManager_Tests().
|
static |
Self-test of the built-in HTTP server and client.
Definition at line 2488 of file NetworkManager.cpp.
References createListener(), cmlabs::HTTPRequest::createRequest(), createTCPConnection(), cmlabs::unittest::detail(), cmlabs::NetworkChannel::endConnection(), cmlabs::unittest::fail(), cmlabs::GetTimeNow(), HTTP_GET, cmlabs::unittest::metric(), NetworkChannel, NetworkManager(), NOENC, cmlabs::unittest::progress(), PROTOCOL_HTTP_CLIENT, PROTOCOL_HTTP_SERVER, cmlabs::NetworkChannel::sendReceiveHTTPRequest(), and cmlabs::ThreadManager::Shutdown().
Referenced by cmlabs::Register_NetworkManager_Tests().
|
static |
WebSocket upgrade + echo self-test.
Definition at line 3159 of file NetworkManager.cpp.
References createListener(), createTCPConnection(), cmlabs::HTTPRequest::createWebsocketRequest(), cmlabs::unittest::detail(), cmlabs::NetworkChannel::endConnection(), cmlabs::unittest::fail(), cmlabs::HTTPReply::isWebsocketUpgrade(), NetworkChannel, NetworkManager(), NOENC, cmlabs::unittest::progress(), PROTOCOL_HTTP_CLIENT, PROTOCOL_HTTP_SERVER, cmlabs::NetworkChannel::sendReceiveHTTPRequest(), and cmlabs::ThreadManager::Shutdown().
Referenced by cmlabs::Register_NetworkManager_Tests().
|
friend |
Definition at line 162 of file NetworkManager.h.
References NetworkChannel, sslCertPath, sslKeyPath, THREAD_ARG, THREAD_FUNCTION_CALL, and THREAD_RET.
Referenced by addConnection(), addTCPConnection(), addTCPConnection(), createListener(), createTCPConnection(), createTCPConnection(), createTCPConnection(), createUDPConnection(), createWebsocketConnection(), createWebsocketConnection(), endConnection(), endUDPConnection(), getConnection(), getConnectionType(), getRemoteAddress(), getTCPConnectionByPort(), getUDPConnectionByPort(), makeHTTPRequest(), makeHTTPRequest(), makeHTTPRequest(), NetworkChannel, stopListener(), TestHTTP(), UnitTest(), UnitTestDelayedConnect(), UnitTestHTTP(), and WebsocketTest().
|
protected |
All channels by channel id (owned).
Definition at line 348 of file NetworkManager.h.
Referenced by addTCPConnection(), addTCPConnection(), createListener(), createTCPConnection(), createTCPConnection(), createTCPConnection(), createUDPConnection(), createWebsocketConnection(), createWebsocketConnection(), and ~NetworkManager().
|
protected |
Channel lookup by connection id.
Definition at line 349 of file NetworkManager.h.
Referenced by addConnection(), addTCPConnection(), addTCPConnection(), createTCPConnection(), createTCPConnection(), createTCPConnection(), createUDPConnection(), createWebsocketConnection(), createWebsocketConnection(), endConnection(), getConnection(), getConnectionType(), getRemoteAddress(), removeConnection(), and ~NetworkManager().
|
protected |
Last channel id issued.
Definition at line 359 of file NetworkManager.h.
Referenced by addTCPConnection(), addTCPConnection(), createListener(), createTCPConnection(), createTCPConnection(), createTCPConnection(), createUDPConnection(), createWebsocketConnection(), createWebsocketConnection(), and NetworkManager().
|
protected |
Last connection id issued.
Definition at line 360 of file NetworkManager.h.
Referenced by addConnection(), and NetworkManager().
|
protected |
TCP listeners by port.
Definition at line 350 of file NetworkManager.h.
Referenced by createListener(), getTCPConnectionByPort(), stopListener(), and ~NetworkManager().
| int8 cmlabs::NetworkManager::sslAllowSelfSigned |
Definition at line 200 of file NetworkManager.h.
Referenced by NetworkManager(), and setSSLAllowSelfSigned().
| std::string cmlabs::NetworkManager::sslCAFile |
Definition at line 204 of file NetworkManager.h.
Referenced by setSSLCALocation().
| std::string cmlabs::NetworkManager::sslCAPath |
Definition at line 205 of file NetworkManager.h.
Referenced by setSSLCALocation().
| bool cmlabs::NetworkManager::sslCASet |
Definition at line 206 of file NetworkManager.h.
Referenced by NetworkManager(), and setSSLCALocation().
|
protected |
PEM certificate path for SSL listeners.
Definition at line 353 of file NetworkManager.h.
Referenced by NetworkChannel, and setSSLCertificate().
|
protected |
PEM private key path for SSL listeners.
Definition at line 354 of file NetworkManager.h.
Referenced by NetworkChannel, and setSSLCertificate().
|
protected |
UDP listeners by port.
Definition at line 351 of file NetworkManager.h.
Referenced by createUDPConnection(), endUDPConnection(), and getUDPConnectionByPort().
|
protected |
Shared output-only UDP socket for sendUDPMessage().
Definition at line 356 of file NetworkManager.h.
Referenced by NetworkManager(), sendUDPMessage(), and ~NetworkManager().
|
protected |
Serialises use of ::udpOutputCon.
Definition at line 357 of file NetworkManager.h.
Referenced by sendUDPMessage().