39 #include <sys/types.h>
52 using namespace dtn::data;
58 const int UDPConvergenceLayer::DEFAULT_PORT = 4556;
61 : _net(net), _port(port), m_maxmsgsize(mtu),
_running(false), _stats_in(0), _stats_out(0)
78 std::stringstream ss_format;
83 ss_format << _stats_in;
84 data[IN_TAG] = ss_format.str();
87 ss_format << _stats_out;
88 data[OUT_TAG] = ss_format.str();
100 std::stringstream service;
102 service <<
"port=" << _port <<
";";
103 announcement.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
114 bool announced =
false;
121 std::list<ibrcommon::vaddress> list = _net.getAddresses();
126 for (std::list<ibrcommon::vaddress>::const_iterator addr_it = list.begin(); addr_it != list.end(); ++addr_it)
135 sa_family_t f = addr.
family();
136 if ((f != AF_INET) && (f != AF_INET6))
continue;
138 std::stringstream service;
140 service <<
"ip=" << addr.
address() <<
";port=" << _port <<
";";
141 announcement.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
156 std::stringstream service;
157 service <<
"port=" << _port <<
";";
158 announcement.addService(
DiscoveryService(getDiscoveryProtocol(), service.str()));
165 if (uri_list.empty())
176 std::string address =
"0.0.0.0";
177 unsigned int port = 0;
180 uri.
decode(address, port);
201 if (size > m_maxmsgsize)
211 const size_t fragment_size = m_maxmsgsize - header;
212 const size_t fragment_count = (psize / fragment_size) + (((psize % fragment_size) > 0) ? 1 : 0);
217 for (
size_t i = 0; i < fragment_count; ++i)
221 std::stringstream ss;
224 serializer << fragment;
225 std::string data = ss.str();
233 std::stringstream ss;
236 serializer << bundle;
237 std::string data = ss.str();
266 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
270 sock.
sendto(data.c_str(), data.length(), 0, addr);
273 _stats_out += data.length();
287 std::vector<char> data(m_maxmsgsize);
293 _vsocket.select(&readfds, NULL, NULL, NULL);
295 if (readfds.size() > 0) {
299 size_t len = sock->
recvfrom(&data[0], m_maxmsgsize, 0, fromaddr);
304 std::stringstream ss; ss <<
"udp://" << fromaddr.
toString();
311 ss.write(&data[0], len);
329 std::stringstream ss; ss << _port;
344 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
359 for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
378 std::list<ibrcommon::vaddress> addrs = _net.
getAddresses();
381 std::stringstream ss; ss << _port;
383 for (std::list<ibrcommon::vaddress>::iterator iter = addrs.begin(); iter != addrs.end(); ++iter) {
437 receive(bundle, sender);
444 }
catch (
const std::exception&) {
459 return "UDPConvergenceLayer";