24 #include <ibrcommon/Logger.h>
32 const std::string WifiP2PManager::TAG =
"WifiP2PManager";
36 :
_running(false), _timeout(120), _priority(10),
37 ce(ctrlpath, dtn::core::
BundleCore::local.getString(), *this, *this)
39 ce.setTime_ST_SCAN(20);
54 IBRCOMMON_LOGGER_TAG(WifiP2PManager::TAG, info) <<
"initialized" << IBRCOMMON_LOGGER_ENDL;
66 ce.addService(
"IBRDTN");
68 }
catch (wifip2p::SupplicantHandleException &ex) {
69 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
70 <<
"CoreEngine is not able to successfully communicate with SupplicantHandle. "
71 <<
"Exception raised: " << ex.what()
72 << IBRCOMMON_LOGGER_ENDL;
73 ibrcommon::Thread::sleep(2000);
83 list<wifip2p::Connection>::iterator conn_it = connections.begin();
85 for (; conn_it != connections.end(); ++conn_it) {
88 ce.disconnect(*conn_it);
89 }
catch (wifip2p::SupplicantHandleException &ex) {
90 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
91 <<
"could not remove " << conn_it->getNetworkIntf().getName()
92 <<
" due to some exception: " << ex.what()
93 << IBRCOMMON_LOGGER_ENDL;
99 IBRCOMMON_LOGGER_TAG(WifiP2PManager::TAG, info) <<
"stopped" << IBRCOMMON_LOGGER_ENDL;
110 return WifiP2PManager::TAG;
120 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10) <<
"connect request to " << uri.
value << IBRCOMMON_LOGGER_ENDL;
122 wifip2p::Peer p(uri.
value);
124 list<wifip2p::Peer>::iterator peer_it = peers.begin();
125 bool contained =
false;
127 for (; peer_it != peers.end(); ++peer_it) {
139 }
catch (wifip2p::SupplicantHandleException &ex) {
140 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
141 <<
"could not connect to peer " << p.getName()
142 <<
"@" << p.getMacAddr()
143 <<
" due to some exception: " << ex.what()
144 << IBRCOMMON_LOGGER_ENDL;
147 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
148 <<
"could not connect to peer " << p.getName()
149 <<
"@" << p.getMacAddr()
150 <<
"; peer not avaialable" << IBRCOMMON_LOGGER_ENDL;
157 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10) <<
"disconnect request from " << uri.
value << IBRCOMMON_LOGGER_ENDL;
159 wifip2p::Peer p(uri.
value);
163 }
catch (wifip2p::SupplicantHandleException &ex) {
164 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
165 <<
"could not disconnect from peer " << p.getName()
166 <<
"@" << p.getMacAddr()
167 <<
" due to some exception: " << ex.what()
168 << IBRCOMMON_LOGGER_ENDL;
176 std::cout <<
"Found peer " << peer.getName() <<
" reported as discovered." << std::endl;
178 list<wifip2p::Peer>::iterator peer_it = peers.begin();
179 bool contained =
false;
181 for (; peer_it != peers.end(); ++peer_it) {
182 if (*peer_it == peer) {
192 std::cout <<
"Peer discovered as new peer." << std::endl;
194 peers.push_back(peer);
204 std::cout <<
"Peer is still available." << std::endl;
219 list<wifip2p::Connection>::iterator conn_it = connections.begin();
220 bool contained =
false;
222 for (; conn_it != connections.end(); ++conn_it) {
223 if (conn_it->getPeer() == peer) {
234 }
catch (wifip2p::SupplicantHandleException &ex) {
235 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
236 <<
"could not connect to peer " << peer.getName()
237 <<
"@" << peer.getMacAddr()
238 <<
" due to some exception: " << ex.what()
239 << IBRCOMMON_LOGGER_ENDL;
242 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
243 <<
"peer " << peer.getName() <<
"@" << peer.getMacAddr()
244 <<
" already connected through p2p group interface "
245 << conn_it->getNetworkIntf().getName() << IBRCOMMON_LOGGER_ENDL;
253 const ibrcommon::vinterface iface(conn.getNetworkIntf().getName());
255 std::cout <<
"Will fire interface " << conn.getNetworkIntf().getName()<<
" up." << std::endl;
258 connections.push_back(conn);
260 ibrcommon::Thread::sleep(2000);
270 const ibrcommon::vinterface iface(conn.getNetworkIntf().getName());
272 std::cout <<
"Connection at interface " << conn.getNetworkIntf().getName()
273 <<
" lost. Will fire interface down." << std::endl;
275 list<wifip2p::Connection>::iterator conn_it = connections.begin();
278 for (; conn_it != connections.end(); ++conn_it) {
279 if (conn_it->getNetworkIntf() == conn.getNetworkIntf()) {
280 connections.erase(conn_it++);
281 std::cout <<
"Connection removed from being locally registered." << std::endl;
287 }
catch (wifip2p::SupplicantHandleException &ex) {
288 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG, 10)
289 <<
"could not remove " << conn.getNetworkIntf().getName()
290 <<
" due to some exception: " << ex.what()
291 << IBRCOMMON_LOGGER_ENDL;
301 IBRCOMMON_LOGGER_TAG(WifiP2PManager::TAG +
"[" + tag +
"]", notice) << msg << IBRCOMMON_LOGGER_ENDL;
306 IBRCOMMON_LOGGER_TAG(WifiP2PManager::TAG +
"[" + tag +
"]", error) << msg << IBRCOMMON_LOGGER_ENDL;
311 IBRCOMMON_LOGGER_DEBUG_TAG(WifiP2PManager::TAG +
"[" + tag +
"]", debug) << msg << IBRCOMMON_LOGGER_ENDL;
virtual void componentDown()
virtual void __cancellation()
virtual const std::string getName() const
virtual void componentRun()
virtual void connect(const dtn::core::Node::URI &uri)
void remove(const dtn::core::Node &n)
virtual void log_debug(int debug, const std::string &tag, const std::string &msg)
virtual void log_err(const std::string &tag, const std::string &msg)
dtn::net::ConnectionManager & getConnectionManager()
virtual void connectionRequest(const wifip2p::Peer &peer)
void fireInterfaceDown(const ibrcommon::vinterface &iface) const
void add(const dtn::core::Node &n)
virtual void peerFound(const wifip2p::Peer &peer)
virtual ~WifiP2PManager()
WifiP2PManager(const std::string &ctrlpath)
virtual void componentUp()
void fireInterfaceUp(const ibrcommon::vinterface &iface) const
virtual dtn::core::Node::Protocol getProtocol() const
virtual void connectionEstablished(const wifip2p::Connection &conn)
virtual void connectionLost(const wifip2p::Connection &conn)
virtual void log(const std::string &tag, const std::string &msg)
void fireDiscovered(const dtn::data::EID &eid, const dtn::core::Node::URI &uri) const
static BundleCore & getInstance()
virtual void disconnect(const dtn::core::Node::URI &uri)