Example #1
0
		void IPNDAgent::listen(const ibrcommon::vinterface &iface) throw ()
		{
			// create sockets for all addresses on the interface
			std::list<ibrcommon::vaddress> addrs = iface.getAddresses();

			for (std::list<ibrcommon::vaddress>::iterator iter = addrs.begin(); iter != addrs.end(); ++iter) {
				ibrcommon::vaddress &addr = (*iter);

				try {
					// handle the addresses according to their family
					switch (addr.family()) {
					case AF_INET:
					case AF_INET6:
					{
						ibrcommon::udpsocket *sock = new ibrcommon::udpsocket(addr);
						if (_send_socket_state) sock->up();
						_send_socket.add(sock, iface);
						break;
					}
					default:
						break;
					}
				} catch (const ibrcommon::vaddress::address_exception &ex) {
					IBRCOMMON_LOGGER_TAG(IPNDAgent::TAG, warning) << ex.what() << IBRCOMMON_LOGGER_ENDL;
				} catch (const ibrcommon::socket_exception &ex) {
					IBRCOMMON_LOGGER_TAG(IPNDAgent::TAG, warning) << ex.what() << IBRCOMMON_LOGGER_ENDL;
				}
			}
		}
Example #2
0
		void IPNDAgent::join(const ibrcommon::vinterface &iface) throw ()
		{
			// register as discovery handler for this interface
			dtn::core::BundleCore::getInstance().getDiscoveryAgent().registerService(iface, this);

			// do not create sockets for any interface
			if (!iface.isAny()) {
				// subscribe to NetLink events on our interfaces
				ibrcommon::LinkManager::getInstance().addEventListener(iface, this);

				/**
				 * create sockets for each address on the interface
				 */
				const std::list<ibrcommon::vaddress> addrs = iface.getAddresses();

				for (std::list<ibrcommon::vaddress>::const_iterator it = addrs.begin(); it != addrs.end(); ++it)
				{
					const ibrcommon::vaddress addr = (*it);

					// join to all multicast addresses on this interface
					join(iface, addr);
				}
			}

			/**
			 * subscribe to multicast address on this interface using the sockets bound to any address
			 */
			const ibrcommon::vinterface any_iface(ibrcommon::vinterface::ANY);
			ibrcommon::socketset anysocks = _socket.get(any_iface);

			for (ibrcommon::socketset::iterator it = anysocks.begin(); it != anysocks.end(); ++it)
			{
				ibrcommon::multicastsocket *msock = dynamic_cast<ibrcommon::multicastsocket*>(*it);
				if (msock == NULL) continue;

				for (std::set<ibrcommon::vaddress>::const_iterator addr_it = _destinations.begin(); addr_it != _destinations.end(); ++addr_it)
				{
					const ibrcommon::vaddress &addr = (*addr_it);

					// join only if family matches
					if (addr.family() != msock->get_family()) continue;

					try {
						msock->join(addr, iface);

						IBRCOMMON_LOGGER_DEBUG_TAG(IPNDAgent::TAG, 10) << "Joined " << addr.toString() << " on " << iface.toString() << IBRCOMMON_LOGGER_ENDL;
					} catch (const ibrcommon::socket_raw_error &e) {
						if (e.error() == EADDRINUSE) {
							// silent error
						} else if (e.error() == 92) {
							// silent error - protocol not available
						} else {
							IBRCOMMON_LOGGER_TAG(IPNDAgent::TAG, warning) << "Join to " << addr.toString() << " failed on " << iface.toString() << "; " << e.what() << IBRCOMMON_LOGGER_ENDL;
						}
					} catch (const ibrcommon::socket_exception &e) {
						IBRCOMMON_LOGGER_DEBUG_TAG(IPNDAgent::TAG, 10) << "Join to " << addr.toString() << " failed on " << iface.toString() << "; " << e.what() << IBRCOMMON_LOGGER_ENDL;
					}
				}
			}
		}
Example #3
0
		void IPNDAgent::join(const ibrcommon::vinterface &iface) throw ()
		{
			std::list<ibrcommon::vaddress> addrs = iface.getAddresses();

			for (std::list<ibrcommon::vaddress>::const_iterator it = addrs.begin(); it != addrs.end(); ++it)
			{
				ibrcommon::vaddress addr = (*it);
				addr.setService(_port);
				join(iface, addr);
			}
		}