22 #ifndef __M2ETIS_WRAPPER_TCPWRAPPER_H__
23 #define __M2ETIS_WRAPPER_TCPWRAPPER_H__
25 #include "boost/asio.hpp"
36 #include "boost/make_shared.hpp"
37 #include "boost/thread/mutex.hpp"
52 TcpWrapper(
const std::string & listenIP,
const uint16_t listenPort,
const std::string & connectIP,
const uint16_t connectPort);
71 throw std::runtime_error(
"TCPWrapper: not initialized. call init first!");
77 node->
port_ = _local.getPort();
95 typedef std::pair<std::vector<uint8_t>, boost::asio::ip::tcp::socket *> msgPair;
102 boost::asio::io_service _io_service;
103 boost::asio::ip::tcp::acceptor * _acceptor;
106 std::map<net::NetworkType<net::TCP>::Key, boost::asio::ip::tcp::socket *> _sockets;
108 boost::asio::io_service::strand _strand__;
111 std::deque<msgPair> _outbox;
112 boost::asio::io_service::work * _work;
117 boost::mutex _mapLock;
119 std::mutex _threadLock;
120 std::multimap<uint16_t, boost::thread *> threads_;
122 std::mutex _deleteSocketsLock;
123 std::set<boost::asio::ip::tcp::socket *> _deleteSockets;
131 void readFromSocket(boost::asio::ip::tcp::socket * oldSocket);
133 void write(
const std::vector<uint8_t> & message, boost::asio::ip::tcp::socket * sock);
135 void writeImpl(
const std::vector<uint8_t> & message, boost::asio::ip::tcp::socket * sock);
139 void writeHandler(
const boost::system::error_code & error,
const size_t bytesTransferred);
141 void handleAccept(
const boost::system::error_code & error, boost::asio::ip::tcp::socket * socket);
144 auto it = _mapping_real_metis.find(key);
145 if (it == _mapping_real_metis.end()) {
152 auto it = _mapping_metis_real.find(key);
153 if (it == _mapping_metis_real.end()) {
159 void removeSocket(boost::asio::ip::tcp::socket * sock);
creates connections using boosts TcpSocket
net::NetworkType< net::TCP >::Key getRoot() const
returns root node
NodeHandle in different structured p2p-systems.
net::NodeHandle< net::NetworkType< net::TCP > >::Ptr getSelfNodeHandle() const
returns pointer with own data
void registerMessageType(const message::MessageType type, const bool ack) const
Not used right now.
TcpWrapper(const std::string &listenIP, const uint16_t listenPort, const std::string &connectIP, const uint16_t connectPort)
void send(const message::NetworkMessage< net::NetworkType< net::TCP >>::Ptr msg, net::NodeHandle< net::NetworkType< net::TCP >>::Ptr_const hint)
calls the other send method