2 #ifndef comfrm_ifc_NodeH
3 #define comfrm_ifc_NodeH
6 #include "stringtools.h"
9 #include <unordered_map>
10 #include <boost/asio.hpp>
11 #include <boost/thread/mutex.hpp>
42 NodeAddress(
const std::string& p_machineIp,
const std::string& p_appSid)
43 : m_machineIp(boost::asio::ip::address::from_string(p_machineIp))
50 NodeAddress(
const boost::asio::ip::address& p_machineIp,
const std::string& p_appSid)
51 : m_machineIp(p_machineIp)
60 std::string machineIpStr;
62 m_machineIp = boost::asio::ip::address::from_string(machineIpStr);
70 return m_machineIp.to_string() +
"/" + m_appSid;
75 boost::asio::ip::address m_machineIp;
98 struct hash< com::interproc::NodeAddress >
102 if (p_addr.m_machineIp.is_v4())
103 return ((hash<unsigned long>()(p_addr.m_machineIp.to_v4().to_ulong()) >> 1)
104 ^ (hash<string>()(p_addr.m_appSid) << 1));
108 return ((hash<unsigned long>()(0) >> 1)
109 ^ (hash<string>()(p_addr.m_appSid) << 1));
116 namespace interproc {
169 , m_callback(p_callback)
172 std::shared_ptr< NodeConnection > m_conn;
180 : m_bytearray(p_bytearray)
181 , m_nodeAddr(p_nodeAddr)
182 , m_callback(p_callback)
185 std::vector< char > m_bytearray;
191 static const unsigned short m_port = 8221;
197 Node(
const std::string& p_appId, boost::asio::io_service& p_service);
209 void setDefaultCallback(
OnReplyClb p_callback);
232 void onAccepted(std::shared_ptr< NodeConnection > p_conn,
const boost::system::error_code & p_error);
233 void onConnectionClosed(std::shared_ptr< NodeConnection > p_conn);
234 void onMessageReceived(std::shared_ptr< NodeConnection > p_nodeConn, std::vector< char >& p_message);
235 void handshake(std::shared_ptr< NodeConnection > p_nodeConn,
NodeHandshake p_handshake);
236 void proxyMessage(std::shared_ptr< NodeConnection > p_nodeConn, std::vector< char >& p_message);
237 void onAnyMapReceived(std::shared_ptr< NodeConnection > p_nodeConn, std::string p_appSid,
238 std::shared_ptr< Anymap > p_anymap);
239 void sendBytearrayToNode(
const std::vector< char >& p_bytearray,
const NodeAddress& p_nodeAddr,
OnReplyClb p_callback = 0);
244 std::string m_masterAppSid;
247 unsigned int m_threadsCount;
248 std::shared_ptr< boost::asio::ip::tcp::acceptor > m_acceptor;
252 std::unordered_map< NodeAddress, RemoteNodeData > m_establishedNodes;
253 std::set< std::shared_ptr< NodeConnection > > m_anonymousNodes;
254 std::vector< BufferedMessage > m_msgBuffer;
255 boost::asio::io_service& m_service;
257 boost::mutex m_mutex;
Адрес узла
Definition: node.h:34
Definition: node_protocol.h:41
NodeAddress(const std::string &p_machineIp, const std::string &p_appSid)
Definition: node.h:42
Узел не найден
Definition: node.h:148
Класс узла
Definition: node.h:131
NodeAddress(const boost::asio::ip::address &p_machineIp, const std::string &p_appSid)
Definition: node.h:50
CommunicationError
Ошибки взаимодействия
Definition: node.h:145
Не удалось соединиться с master-узлом
Definition: node.h:149
NodeAddress(const std::string &p_appAddress)
Definition: node.h:58
Статус не задан
Definition: node.h:159
Definition: node_protocol.h:23
std::function< void(std::shared_ptr< Message >, CommunicationError) > OnReplyClb
Тип коллбэка для входящих сообщений
Definition: node.h:163
Словарь
Definition: node.h:151
Словарь
Definition: node.h:150
Master-узел
Definition: node.h:157
Сетевое сообщение
Definition: message.h:17
NodeStatus
Статус узла
Definition: node.h:155
MAC_DLLEXPORT bool paramValueSplit(const std::string &p_pair, const std::string &p_delimeter, std::string &o_param, std::string &o_value)
Definition: stringtools.cpp:102
Slave-узел
Definition: node.h:158
std::string toString() const
Definition: node.h:68