52 const std::string TCPConvergenceLayer::TAG =
"TCPConvergenceLayer";
54 const int TCPConvergenceLayer::DEFAULT_PORT = 4556;
57 : _vsocket_state(false), _any_port(0), _stats_in(0), _stats_out(0)
78 if (_any_port > 0)
return;
97 if (_interfaces.find(net) != _interfaces.end())
return;
100 _interfaces.insert(net);
112 _portmap[net] = port;
117 std::list<ibrcommon::vaddress> addrs = net.getAddresses();
120 std::stringstream ss; ss << port;
122 for (std::list<ibrcommon::vaddress>::iterator iter = addrs.begin(); iter != addrs.end(); ++iter) {
134 if (_vsocket_state) sock->
up();
135 _vsocket.add(sock, net);
157 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
159 _vsocket.remove(sock);
170 _portmap.erase(iface);
186 if (_interfaces.empty() && (_any_port > 0)) {
187 std::stringstream service;
190 service <<
"port=" << _portmap[iface] <<
";";
191 beacon.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
199 bool announced =
false;
202 for (std::set<ibrcommon::vinterface>::const_iterator it = _interfaces.begin(); it != _interfaces.end(); ++it)
205 if (it_iface == iface)
212 std::list<ibrcommon::vaddress> list = it_iface.
getAddresses();
217 for (std::list<ibrcommon::vaddress>::const_iterator addr_it = list.begin(); addr_it != list.end(); ++addr_it)
225 sa_family_t f = addr.
family();
226 if ((f != AF_INET) && (f != AF_INET6))
continue;
228 std::stringstream service;
231 service <<
"ip=" << addr.
address() <<
";port=" << _portmap[iface] <<
";";
232 beacon.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
247 std::stringstream service;
250 service <<
"port=" << _portmap[iface] <<
";";
251 beacon.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
262 return TCPConvergenceLayer::TAG;
275 listen(dialup.
iface, 4556);
286 if (_interfaces.find(dialup.
iface) == _interfaces.end())
return;
289 _interfaces.erase(dialup.
iface);
299 unlisten(dialup.
iface);
303 }
catch (std::bad_cast&) {
311 if (_any_port > 0)
return;
315 if (_interfaces.find(evt.
getInterface()) == _interfaces.end())
return;
325 std::stringstream ss; ss << _portmap[evt.
getInterface()];
340 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
358 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
381 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
407 _connections.push_back( conn );
413 _connections_cond.
signal(
true);
424 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
453 _connections.push_back( conn );
462 _connections_cond.
signal(
true);
473 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
482 _connections.push_back( conn );
485 _connections_cond.
signal(
true);
490 void TCPConvergenceLayer::connectionDown(
TCPConnection *conn)
493 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
497 _connections.erase(iter);
501 _connections_cond.
signal(
true);
507 void TCPConvergenceLayer::addTrafficIn(
size_t amount)
throw ()
513 void TCPConvergenceLayer::addTrafficOut(
size_t amount)
throw ()
516 _stats_out += amount;
527 _vsocket.
select(&readfds, NULL, NULL, NULL);
529 for (ibrcommon::socketset::iterator iter = readfds.begin(); iter != readfds.end(); ++iter) {
545 const std::string uri =
"ip=" + peeraddr.
address() +
";port=" + peeraddr.
service() +
";";
564 }
catch (
const std::bad_cast&) {
572 }
catch (
const std::exception&) {
583 void TCPConvergenceLayer::closeAll()
587 for (std::list<TCPConnection*>::iterator iter = _connections.begin(); iter != _connections.end(); ++iter)
605 _vsocket_state =
true;
620 _vsocket_state =
false;
631 while (_connections.size() > 0) _connections_cond.
wait();
638 std::stringstream ss_format;
643 ss_format << _stats_in;
644 data[IN_TAG] = ss_format.str();
647 ss_format << _stats_out;
648 data[OUT_TAG] = ss_format.str();
651 void TCPConvergenceLayer::resetStats()