From 90aa57a0f07ac2734b383e6ade85fb67c2dad68f Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 28 Sep 2013 08:09:59 +0000 Subject: [PATCH] Rewrite of the discovery system to be more private, with less traffic. Split the visState into seperate vs_disc and vs_dht for easier handling. Split the heartbeat system into a separate service. Added IPv4 and IPv6 local/ext addresses into discovery & peer config. Fixed up samenet and samesubnet ipv4 calls. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6773 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/libretroshare.pro | 25 +- libretroshare/src/pqi/p3linkmgr.cc | 13 +- libretroshare/src/pqi/p3netmgr.cc | 15 +- libretroshare/src/pqi/p3netmgr.h | 7 +- libretroshare/src/pqi/p3peermgr.cc | 134 +- libretroshare/src/pqi/p3peermgr.h | 37 +- libretroshare/src/pqi/pqiipset.cc | 4 +- libretroshare/src/pqi/pqiipset.h | 2 +- libretroshare/src/pqi/pqiperson.cc | 1 - libretroshare/src/retroshare/rsdisc.h | 6 +- libretroshare/src/retroshare/rspeers.h | 15 +- libretroshare/src/rsserver/p3discovery.cc | 67 - libretroshare/src/rsserver/p3discovery.h | 51 - libretroshare/src/rsserver/p3face-server.cc | 3 +- libretroshare/src/rsserver/p3face.h | 7 +- libretroshare/src/rsserver/p3peers.cc | 31 +- libretroshare/src/rsserver/p3peers.h | 2 +- libretroshare/src/rsserver/rsinit.cc | 22 +- libretroshare/src/serialiser/itempriorities.h | 9 + libretroshare/src/serialiser/rsconfigitems.cc | 62 +- libretroshare/src/serialiser/rsconfigitems.h | 10 +- libretroshare/src/serialiser/rsdiscitems.cc | 770 ---------- libretroshare/src/serialiser/rsdiscitems.h | 193 --- .../src/serialiser/rsdiscovery2items.cc | 890 +++++++++++ .../src/serialiser/rsdiscovery2items.h | 203 +++ .../src/serialiser/rsheartbeatitems.cc | 206 +++ .../src/serialiser/rsheartbeatitems.h | 72 + libretroshare/src/serialiser/rsserviceids.h | 1 + libretroshare/src/serialiser/rstlvbase.h | 7 +- libretroshare/src/serialiser/rstlvtypes.h | 25 + libretroshare/src/services/p3disc.h | 178 --- .../services/{p3disc.cc => p3discovery2.cc} | 1367 +++++++++++++++-- libretroshare/src/services/p3discovery2.h | 151 ++ libretroshare/src/services/p3heartbeat.cc | 122 ++ libretroshare/src/services/p3heartbeat.h | 61 + libretroshare/src/services/p3posted.cc | 4 +- libretroshare/src/util/rsnet_ss.cc | 16 +- libretroshare/src/zeroconf/p3zeroconf.cc | 2 +- 38 files changed, 3248 insertions(+), 1543 deletions(-) delete mode 100644 libretroshare/src/rsserver/p3discovery.cc delete mode 100644 libretroshare/src/rsserver/p3discovery.h delete mode 100644 libretroshare/src/serialiser/rsdiscitems.cc delete mode 100644 libretroshare/src/serialiser/rsdiscitems.h create mode 100644 libretroshare/src/serialiser/rsdiscovery2items.cc create mode 100644 libretroshare/src/serialiser/rsdiscovery2items.h create mode 100644 libretroshare/src/serialiser/rsheartbeatitems.cc create mode 100644 libretroshare/src/serialiser/rsheartbeatitems.h delete mode 100644 libretroshare/src/services/p3disc.h rename libretroshare/src/services/{p3disc.cc => p3discovery2.cc} (51%) create mode 100644 libretroshare/src/services/p3discovery2.h create mode 100644 libretroshare/src/services/p3heartbeat.cc create mode 100644 libretroshare/src/services/p3heartbeat.h diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 013fa0531..d2028c36a 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -358,8 +358,7 @@ HEADERS += pqi/authssl.h \ # pqi/p3dhtmgr.h \ -HEADERS += rsserver/p3discovery.h \ - rsserver/p3face.h \ +HEADERS += rsserver/p3face.h \ rsserver/p3history.h \ rsserver/p3msgs.h \ rsserver/p3peers.h \ @@ -369,7 +368,6 @@ HEADERS += rsserver/p3discovery.h \ HEADERS += serialiser/rsbaseitems.h \ serialiser/rsbaseserial.h \ serialiser/rsconfigitems.h \ - serialiser/rsdiscitems.h \ serialiser/rshistoryitems.h \ serialiser/rsmsgitems.h \ serialiser/rsserial.h \ @@ -387,17 +385,18 @@ HEADERS += serialiser/rsbaseitems.h \ serialiser/rstlvbanlist.h \ serialiser/rsbanlistitems.h \ serialiser/rsbwctrlitems.h \ + serialiser/rsdiscovery2items.h \ + serialiser/rsheartbeatitems.h \ HEADERS += services/p3chatservice.h \ - services/p3disc.h \ services/p3msgservice.h \ services/p3service.h \ services/p3statusservice.h \ services/p3dsdv.h \ services/p3banlist.h \ - services/p3bwctrl.h - -# services/p3discovery2.h \ + services/p3bwctrl.h \ + services/p3discovery2.h \ + services/p3heartbeat.h \ HEADERS += turtle/p3turtle.h \ turtle/rsturtleitem.h \ @@ -477,8 +476,7 @@ SOURCES += pqi/authgpg.cc \ # pqi/p3dhtmgr.cc \ -SOURCES += rsserver/p3discovery.cc \ - rsserver/p3face-config.cc \ +SOURCES += rsserver/p3face-config.cc \ rsserver/p3face-msgs.cc \ rsserver/p3face-server.cc \ rsserver/p3history.cc \ @@ -497,7 +495,6 @@ SOURCES += plugins/pluginmanager.cc \ SOURCES += serialiser/rsbaseitems.cc \ serialiser/rsbaseserial.cc \ serialiser/rsconfigitems.cc \ - serialiser/rsdiscitems.cc \ serialiser/rshistoryitems.cc \ serialiser/rsmsgitems.cc \ serialiser/rsserial.cc \ @@ -515,18 +512,18 @@ SOURCES += serialiser/rsbaseitems.cc \ serialiser/rstlvbanlist.cc \ serialiser/rsbanlistitems.cc \ serialiser/rsbwctrlitems.cc \ + serialiser/rsdiscovery2items.cc \ + serialiser/rsheartbeatitems.cc \ SOURCES += services/p3chatservice.cc \ - services/p3disc.cc \ services/p3msgservice.cc \ services/p3service.cc \ services/p3statusservice.cc \ services/p3dsdv.cc \ services/p3banlist.cc \ services/p3bwctrl.cc \ - - -# services/p3discovery2.cc \ + services/p3discovery2.cc \ + services/p3heartbeat.cc \ SOURCES += turtle/p3turtle.cc \ turtle/rsturtleitem.cc diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 8e268c207..1557b0498 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -1085,7 +1085,8 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs, details.ts = now; bool updateNetConfig = (source == RS_CB_PERSON); - uint32_t peerVisibility = 0; + uint32_t peer_vs_disc = 0; + uint32_t peer_vs_dht = 0; uint32_t peerNetMode = 0; uint32_t ownNetMode = mNetMgr->getNetworkMode(); @@ -1219,20 +1220,20 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs, /* always update VIS status */ if (flags & RS_NET_FLAGS_USE_DISC) { - peerVisibility &= (~RS_VIS_STATE_NODISC); + peer_vs_disc = RS_VS_DISC_FULL; } else { - peerVisibility |= RS_VIS_STATE_NODISC; + peer_vs_disc = RS_VS_DISC_OFF; } if (flags & RS_NET_FLAGS_USE_DHT) { - peerVisibility &= (~RS_VIS_STATE_NODHT); + peer_vs_dht = RS_VS_DHT_FULL; } else { - peerVisibility |= RS_VIS_STATE_NODHT; + peer_vs_dht = RS_VS_DHT_OFF; } @@ -1303,7 +1304,7 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs, bool newAddrs = mPeerMgr->updateAddressList(id, addrs); if (updateNetConfig) { - mPeerMgr -> setVisState(id, peerVisibility); + mPeerMgr -> setVisState(id, peer_vs_disc, peer_vs_dht); mPeerMgr -> setNetworkMode(id, peerNetMode); } diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index 8eed3d093..960a88ec5 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -140,8 +140,10 @@ p3NetMgrIMPL::p3NetMgrIMPL() mLocalAddr.ss_family = AF_INET; mExtAddr.ss_family = AF_INET; + // default to full. + mVsDisc = RS_VS_DISC_FULL; + mVsDht = RS_VS_DHT_FULL; - mVisState = 0 ; } #ifdef NETMGR_DEBUG @@ -570,10 +572,10 @@ void p3NetMgrIMPL::netDhtInit() uint32_t vs = 0; { RsStackMutex stack(mNetMtx); /*********** LOCKED MUTEX ************/ - vs = mVisState; + vs = mVsDht; } - enableNetAssistConnect(!(vs & RS_VIS_STATE_NODHT)); + enableNetAssistConnect(vs != RS_VS_DHT_OFF); } @@ -1167,15 +1169,16 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode) } -bool p3NetMgrIMPL::setVisState(uint32_t visState) +bool p3NetMgrIMPL::setVisState(uint16_t vs_disc, uint16_t vs_dht) { RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ - mVisState = visState; + mVsDisc = vs_disc; + mVsDht = vs_dht; /* if we've started up - then tweak Dht On/Off */ if (mNetStatus != RS_NET_UNKNOWN) { - enableNetAssistConnect(!(mVisState & RS_VIS_STATE_NODHT)); + enableNetAssistConnect(mVsDht != RS_VS_DHT_OFF); } return true; diff --git a/libretroshare/src/pqi/p3netmgr.h b/libretroshare/src/pqi/p3netmgr.h index b8ca67907..ac35eeab0 100644 --- a/libretroshare/src/pqi/p3netmgr.h +++ b/libretroshare/src/pqi/p3netmgr.h @@ -115,7 +115,7 @@ virtual ~p3NetMgr() { return; } // Setup Network State. virtual bool setNetworkMode(uint32_t netMode) = 0; -virtual bool setVisState(uint32_t visState) = 0; +virtual bool setVisState(uint16_t vs_disc, uint16_t vs_dht) = 0; // Switch DHT On/Off. virtual bool netAssistFriend(const std::string &id, bool on) = 0; @@ -171,7 +171,7 @@ class p3NetMgrIMPL: public p3NetMgr // Setup Network State. virtual bool setNetworkMode(uint32_t netMode); -virtual bool setVisState(uint32_t visState); +virtual bool setVisState(uint16_t vs_disc, uint16_t vs_dht); // Switch DHT On/Off. virtual bool netAssistFriend(const std::string &id, bool on); @@ -330,7 +330,8 @@ void netStatusReset_locked(); struct sockaddr_storage mExtAddr; uint32_t mNetMode; - uint32_t mVisState; + uint16_t mVsDisc; + uint16_t mVsDht; time_t mNetInitTS; uint32_t mNetStatus; diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index fb5d2c425..eb6ead1dc 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -78,7 +78,7 @@ void printConnectState(std::ostream &out, peerState &peer); peerState::peerState() :id("unknown"), gpg_id("unknown"), - netMode(RS_NET_MODE_UNKNOWN), visState(RS_VIS_STATE_STD), lastcontact(0), + netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0), hiddenNode(false), hiddenPort(0) { sockaddr_storage_clear(localaddr); @@ -91,7 +91,7 @@ std::string textPeerConnectState(peerState &state) { std::string out = "Id: " + state.id + "\n"; rs_sprintf_append(out, "NetMode: %lu\n", state.netMode); - rs_sprintf_append(out, "VisState: %lu\n", state.visState); + rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht); out += "laddr: "; out += sockaddr_storage_tostring(state.localaddr); @@ -122,7 +122,8 @@ p3PeerMgrIMPL::p3PeerMgrIMPL( const std::string& ssl_own_id, mOwnState.name = gpg_own_name ; mOwnState.location = ssl_own_location ; mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP. - mOwnState.visState = 0; + mOwnState.vs_disc = RS_VS_DISC_FULL; + mOwnState.vs_dht = RS_VS_DHT_FULL; lastGroupId = 1; @@ -163,7 +164,7 @@ bool p3PeerMgrIMPL::setupHiddenNode(const std::string &hiddenAddress, const uint mOwnState.hiddenDomain = hiddenAddress; // switch off DHT too. - setOwnVisState(RS_VIS_STATE_GRAY); + setOwnVisState(mOwnState.vs_disc, RS_VS_DHT_OFF); // Force the Port. struct sockaddr_storage loopback; @@ -206,29 +207,32 @@ bool p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode) return changed; } -bool p3PeerMgrIMPL::setOwnVisState(uint32_t visState) +bool p3PeerMgrIMPL::setOwnVisState(uint16_t vs_disc, uint16_t vs_dht) { bool changed = false; { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ std::string out; - rs_sprintf(out, "p3PeerMgr::setOwnVisState() Existing vis: %lu Input vis: %lu", mOwnState.visState, visState); + rs_sprintf(out, "p3PeerMgr::setOwnVisState() Existing vis: %u/%u Input vis: %u/%u", + mOwnState.vs_disc, mOwnState.vs_dht, vs_disc, vs_dht); rslog(RSL_WARNING, p3peermgrzone, out); #ifdef PEER_DEBUG std::cerr << out.c_str() << std::endl; #endif - if (mOwnState.visState != visState) { - mOwnState.visState = visState; + if (mOwnState.vs_disc != vs_disc || mOwnState.vs_dht != vs_dht) + { + mOwnState.vs_disc = vs_disc; + mOwnState.vs_dht = vs_dht; changed = true; IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ } } // Pass on Flags to NetMgr. - mNetMgr->setVisState(visState); + mNetMgr->setVisState(vs_disc, vs_dht); return changed; } @@ -594,7 +598,7 @@ bool p3PeerMgrIMPL::haveOnceConnected() /*******************************************************************/ /*******************************************************************/ -bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& input_gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact,ServicePermissionFlags service_flags) +bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& input_gpg_id, uint32_t netMode, uint16_t vs_disc, uint16_t vs_dht, time_t lastContact,ServicePermissionFlags service_flags) { bool notifyLinkMgr = false; std::string id = input_id ; @@ -670,7 +674,9 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in it = mFriendList.find(id); /* setup connectivity parameters */ - it->second.visState = visState; + it->second.vs_disc = vs_disc; + it->second.vs_dht = vs_dht; + it->second.netMode = netMode; it->second.lastcontact = lastContact; @@ -693,7 +699,8 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in pstate.gpg_id = gpg_id; pstate.name = AuthGPG::getAuthGPG()->getGPGName(gpg_id); - pstate.visState = visState; + pstate.vs_disc = vs_disc; + pstate.vs_dht = vs_dht; pstate.netMode = netMode; pstate.lastcontact = lastContact; @@ -711,7 +718,7 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in if (notifyLinkMgr) { - mLinkMgr->addFriend(id, !(visState & RS_VIS_STATE_NODHT)); + mLinkMgr->addFriend(id, vs_dht != RS_VS_DHT_OFF); } service_flags &= servicePermissionFlags(gpg_id) ; // Always reduce the permissions. @@ -1327,20 +1334,19 @@ bool p3PeerMgrIMPL::setLocation(const std::string &id, const std::string &loc return changed; } -bool p3PeerMgrIMPL::setVisState(const std::string &id, uint32_t visState) +bool p3PeerMgrIMPL::setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) { { std::string out; - rs_sprintf(out, "p3PeerMgr::setVisState(%s, %lu)", id.c_str(), visState); + rs_sprintf(out, "p3PeerMgr::setVisState(%s, %u, %u)", id.c_str(), vs_disc, vs_dht); rslog(RSL_WARNING, p3peermgrzone, out); } if (id == AuthSSL::getAuthSSL()->OwnId()) { - return setOwnVisState(visState); + return setOwnVisState(vs_disc, vs_dht); } - bool dht_state ; bool isFriend = false; bool changed = false; { @@ -1361,53 +1367,47 @@ bool p3PeerMgrIMPL::setVisState(const std::string &id, uint32_t visState) } /* "it" points to peer */ - if (it->second.visState != visState) { - it->second.visState = visState; + if ((it->second.vs_disc != vs_disc) || (it->second.vs_dht = vs_dht)) + { + it->second.vs_disc = vs_disc; + it->second.vs_dht = vs_dht; changed = true; - dht_state = it->second.visState & RS_VIS_STATE_NODHT ; - - std::cerr << "p3PeerMgrIMPL::setVisState(" << id << ", " << std::hex << visState << std::dec << ") "; + std::cerr << "p3PeerMgrIMPL::setVisState(" << id << ", DISC: " << vs_disc << " DHT: " << vs_dht << ") "; std::cerr << " NAME: " << it->second.name; - if (it->second.visState & RS_VIS_STATE_NODHT) + switch(it->second.vs_disc) { - std::cerr << " NO-DHT "; + default: + case RS_VS_DISC_OFF: + std::cerr << " NO-DISC "; + break; + case RS_VS_DISC_MINIMAL: + std::cerr << " MIN-DISC "; + break; + case RS_VS_DISC_FULL: + std::cerr << " FULL-DISC "; + break; } - else + switch(it->second.vs_dht) { - std::cerr << " DHT-OK "; - } - if (it->second.visState & RS_VIS_STATE_NODISC) - { - std::cerr << " NO-DISC "; - } - else - { - std::cerr << " DISC-OK "; + default: + case RS_VS_DHT_OFF: + std::cerr << " NO-DHT "; + break; + case RS_VS_DHT_PASSIVE: + std::cerr << " PASSIVE-DHT "; + break; + case RS_VS_DHT_FULL: + std::cerr << " FULL-DHT "; + break; } std::cerr << std::endl; } } if(isFriend && changed) { - /* toggle DHT state */ - if(dht_state) - { - - std::cerr << "p3PeerMgrIMPL::setVisState() setFriendVisibility => false"; - std::cerr << std::endl; - - /* hidden from DHT world */ - mLinkMgr->setFriendVisibility(id, false); - } - else - { - std::cerr << "p3PeerMgrIMPL::setVisState() setFriendVisibility => true"; - std::cerr << std::endl; - - mLinkMgr->setFriendVisibility(id, true); - } + mLinkMgr->setFriendVisibility(id, vs_dht != RS_VS_DHT_OFF); } if (changed) { @@ -1471,11 +1471,16 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) #endif item->netMode = mOwnState.netMode; - item->visState = mOwnState.visState; + item->vs_disc = mOwnState.vs_disc; + item->vs_dht = mOwnState.vs_dht; + item->lastContact = mOwnState.lastcontact; - item->localAddr.addr = mOwnState.localaddr; - item->extAddr.addr = mOwnState.serveraddr; + item->localAddrV4.addr = mOwnState.localaddr; + item->extAddrV4.addr = mOwnState.serveraddr; + sockaddr_storage_clear(item->localAddrV6.addr); + sockaddr_storage_clear(item->extAddrV6.addr); + item->dyndns = mOwnState.dyndns; mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList); mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList); @@ -1502,10 +1507,17 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) item->gpg_id = (it->second).gpg_id; item->location = (it->second).location; item->netMode = (it->second).netMode; - item->visState = (it->second).visState; + item->vs_disc = (it->second).vs_disc; + item->vs_dht = (it->second).vs_dht; + item->lastContact = (it->second).lastcontact; - item->localAddr.addr = (it->second).localaddr; - item->extAddr.addr = (it->second).serveraddr; + + item->localAddrV4.addr = (it->second).localaddr; + item->extAddrV4.addr = (it->second).serveraddr; + sockaddr_storage_clear(item->localAddrV6.addr); + sockaddr_storage_clear(item->extAddrV6.addr); + + item->dyndns = (it->second).dyndns; (it->second).ipAddrs.mLocal.loadTlv(item->localAddrList); (it->second).ipAddrs.mExt.loadTlv(item->extAddrList); @@ -1613,7 +1625,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) #endif /* add ownConfig */ setOwnNetworkMode(pitem->netMode); - setOwnVisState(pitem->visState); + setOwnVisState(pitem->vs_disc, pitem->vs_dht); mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId(); mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation(); @@ -1626,7 +1638,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) std::cerr << std::endl; #endif /* ************* */ - addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, pitem->lastContact, RS_SERVICE_PERM_ALL); + addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->vs_disc, pitem->vs_dht, pitem->lastContact, RS_SERVICE_PERM_ALL); setLocation(pitem->pid, pitem->location); } @@ -1638,8 +1650,8 @@ bool p3PeerMgrIMPL::loadList(std::list& load) } else { - setLocalAddress(pitem->pid, pitem->localAddr.addr); - setExtAddress(pitem->pid, pitem->extAddr.addr); + setLocalAddress(pitem->pid, pitem->localAddrV4.addr); + setExtAddress(pitem->pid, pitem->extAddrV4.addr); setDynDNS (pitem->pid, pitem->dyndns); /* convert addresses */ diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 8d8fcee95..236f45e03 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -35,24 +35,8 @@ #include "util/rsthreads.h" - /* RS_VIS_STATE_XXXX - * determines how public this peer wants to be... - * - * STD = advertise to Peers / DHT checking etc - * GRAY = share with friends / but not DHT - * DARK = hidden from all - * BROWN? = hidden from friends / but on DHT - */ - -const uint32_t RS_VIS_STATE_NODISC = 0x0001; -const uint32_t RS_VIS_STATE_NODHT = 0x0002; - -const uint32_t RS_VIS_STATE_STD = 0x0000; -const uint32_t RS_VIS_STATE_GRAY = RS_VIS_STATE_NODHT; -const uint32_t RS_VIS_STATE_DARK = RS_VIS_STATE_NODISC | RS_VIS_STATE_NODHT; -const uint32_t RS_VIS_STATE_BROWN = RS_VIS_STATE_NODISC; - - +/* RS_VIS_STATE -> specified in rspeers.h + */ /* Startup Modes (confirmed later) */ const uint32_t RS_NET_MODE_TRYMODE = 0xff00; @@ -90,8 +74,9 @@ class peerState std::string gpg_id; uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */ - uint32_t visState; /* STD, GRAY, DARK */ - + /* visState */ + uint16_t vs_disc; + uint16_t vs_dht; struct sockaddr_storage localaddr; struct sockaddr_storage serveraddr; @@ -130,7 +115,8 @@ class p3PeerMgr virtual ~p3PeerMgr() { return; } virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP, - uint32_t visState = RS_VIS_STATE_STD , time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL)) = 0; + uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, + time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL)) = 0; virtual bool removeFriend(const std::string &ssl_id, bool removePgpId) = 0; virtual bool isFriend(const std::string &ssl_id) = 0; @@ -166,7 +152,7 @@ virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage virtual bool setDynDNS(const std::string &id, const std::string &dyndns) = 0; virtual bool setNetworkMode(const std::string &id, uint32_t netMode) = 0; -virtual bool setVisState(const std::string &id, uint32_t visState) = 0; +virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) = 0; virtual bool setLocation(const std::string &pid, const std::string &location) = 0; virtual bool setHiddenDomainPort(const std::string &id, const std::string &domain_addr, const uint16_t domain_port) = 0; @@ -228,7 +214,8 @@ class p3PeerMgrIMPL: public p3PeerMgr, public p3Config /************************************************************************************************/ virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP, - uint32_t visState = RS_VIS_STATE_STD , time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL)); + uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL, + time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_SERVICE_PERM_ALL)); virtual bool removeFriend(const std::string &ssl_id, bool removePgpId); virtual bool isFriend(const std::string &ssl_id); @@ -264,7 +251,7 @@ virtual bool setExtAddress(const std::string &id, const struct sockaddr_storage virtual bool setDynDNS(const std::string &id, const std::string &dyndns); virtual bool setNetworkMode(const std::string &id, uint32_t netMode); -virtual bool setVisState(const std::string &id, uint32_t visState); +virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht); virtual bool setLocation(const std::string &pid, const std::string &location); virtual bool setHiddenDomainPort(const std::string &id, const std::string &domain_addr, const uint16_t domain_port); @@ -323,7 +310,7 @@ void tick(); const std::string getOwnId(); bool setOwnNetworkMode(uint32_t netMode); -bool setOwnVisState(uint32_t visState); +bool setOwnVisState(uint16_t vs_disc, uint16_t vs_dht); int getConnectAddresses(const std::string &id, struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr, diff --git a/libretroshare/src/pqi/pqiipset.cc b/libretroshare/src/pqi/pqiipset.cc index fa6e7c543..f0b033807 100644 --- a/libretroshare/src/pqi/pqiipset.cc +++ b/libretroshare/src/pqi/pqiipset.cc @@ -175,9 +175,9 @@ void pqiIpAddrList::extractFromTlv(const RsTlvIpAddrSet &tlvAddrs) } } -void pqiIpAddrList::loadTlv(RsTlvIpAddrSet &tlvAddrs) +void pqiIpAddrList::loadTlv(RsTlvIpAddrSet &tlvAddrs) const { - std::list::iterator it; + std::list::const_iterator it; for(it = mAddrs.begin(); it != mAddrs.end() ; ++it) { diff --git a/libretroshare/src/pqi/pqiipset.h b/libretroshare/src/pqi/pqiipset.h index f20dc1a5f..1ac7da3ea 100644 --- a/libretroshare/src/pqi/pqiipset.h +++ b/libretroshare/src/pqi/pqiipset.h @@ -51,7 +51,7 @@ class pqiIpAddrList bool updateIpAddressList(const pqiIpAddress &addr); void printIpAddressList(std::string &out) const; void extractFromTlv(const RsTlvIpAddrSet &tlvAddrs); - void loadTlv(RsTlvIpAddrSet &tlvAddrs); + void loadTlv(RsTlvIpAddrSet &tlvAddrs) const; // sorted list... based on seen time. std::list mAddrs; diff --git a/libretroshare/src/pqi/pqiperson.cc b/libretroshare/src/pqi/pqiperson.cc index d104e1326..a28a24382 100644 --- a/libretroshare/src/pqi/pqiperson.cc +++ b/libretroshare/src/pqi/pqiperson.cc @@ -26,7 +26,6 @@ #include "pqi/pqi.h" #include "pqi/pqiperson.h" #include "pqi/pqipersongrp.h" -#include "services/p3disc.h" const int pqipersonzone = 82371; #include "util/rsdebug.h" diff --git a/libretroshare/src/retroshare/rsdisc.h b/libretroshare/src/retroshare/rsdisc.h index c1f25cc15..a4f6352a9 100644 --- a/libretroshare/src/retroshare/rsdisc.h +++ b/libretroshare/src/retroshare/rsdisc.h @@ -42,9 +42,9 @@ class RsDisc RsDisc() { return; } virtual ~RsDisc() { return; } -virtual bool getDiscFriends(std::string id, std::list& friends) = 0; -virtual bool getDiscGPGFriends(std::string id, std::list& gpg_friends) = 0; -virtual bool getDiscVersions(std::map &versions) = 0; +virtual bool getDiscFriends(const std::string &id, std::list& friends) = 0; +virtual bool getDiscPgpFriends(const std::string &pgpid, std::list& gpg_friends) = 0; +virtual bool getPeerVersion(const std::string &id, std::string &versions) = 0; virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) = 0; }; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index fb04c649d..a1a73f9e0 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -58,8 +58,13 @@ const uint32_t RS_NETMODE_HIDDEN = 0x0004; const uint32_t RS_NETMODE_UNREACHABLE = 0x0005; /* Visibility */ -const uint32_t RS_VS_DHT_ON = 0x0001; -const uint32_t RS_VS_DISC_ON = 0x0002; +const uint32_t RS_VS_DISC_OFF = 0x0000; +const uint32_t RS_VS_DISC_MINIMAL = 0x0001; +const uint32_t RS_VS_DISC_FULL = 0x0002; + +const uint32_t RS_VS_DHT_OFF = 0x0000; +const uint32_t RS_VS_DHT_PASSIVE = 0x0001; +const uint32_t RS_VS_DHT_FULL = 0x0002; /* State */ const uint32_t RS_PEER_STATE_FRIEND = 0x0001; @@ -219,7 +224,9 @@ class RsPeerDetails std::list ipAddressList; uint32_t netMode; - uint32_t visState; + /* vis State */ + uint16_t vs_disc; + uint16_t vs_dht; /* basic stats */ uint32_t lastConnect; /* how long ago */ @@ -321,7 +328,7 @@ class RsPeers virtual bool setExtAddress( const std::string &ssl_id, const std::string &addr, uint16_t port) = 0; virtual bool setDynDNS(const std::string &id, const std::string &addr) = 0; virtual bool setNetworkMode(const std::string &ssl_id, uint32_t netMode) = 0; - virtual bool setVisState(const std::string &ssl_id, uint32_t vis) = 0; + virtual bool setVisState(const std::string &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0; virtual void getIPServersList(std::list& ip_servers) = 0; virtual void allowServerIPDetermination(bool) = 0; diff --git a/libretroshare/src/rsserver/p3discovery.cc b/libretroshare/src/rsserver/p3discovery.cc deleted file mode 100644 index 401595304..000000000 --- a/libretroshare/src/rsserver/p3discovery.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * libretroshare/src/rsserver: p3discovery.cc - * - * RetroShare C++ Interface. - * - * Copyright 2008-2008 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "rsserver/p3discovery.h" -#include - -RsDisc *rsDisc = NULL; - -bool p3Discovery::getDiscGPGFriends(std::string id, std::list& gpg_friends) -{ - if (mDisc) - { - return mDisc->potentialGPGproxies(id, gpg_friends); - } - return false; -} - -bool p3Discovery::getDiscFriends(std::string id, std::list &friends) -{ - if (mDisc) - { - return mDisc->potentialproxies(id, friends); - } - return false; -} - -bool p3Discovery::getDiscVersions(std::map &versions) -{ - if (mDisc) - { - mDisc->getversions(versions); - return true; - } - return false; -} - -bool p3Discovery::getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) -{ - if (mDisc) - { - mDisc->getWaitingDiscCount(sendCount, recvCount); - return true; - } - return false; -} diff --git a/libretroshare/src/rsserver/p3discovery.h b/libretroshare/src/rsserver/p3discovery.h deleted file mode 100644 index c1d70584f..000000000 --- a/libretroshare/src/rsserver/p3discovery.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef RETROSHARE_P3_DISC_INTERFACE_H -#define RETROSHARE_P3_DISC_INTERFACE_H - -/* - * libretroshare/src/rsserver: p3discovery.h - * - * RetroShare C++ Interface. - * - * Copyright 2008-2008 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "retroshare/rsdisc.h" -#include "services/p3disc.h" - -class p3Discovery: public RsDisc -{ - public: - - p3Discovery(p3disc *disc) - :mDisc(disc) { return; } -virtual ~p3Discovery() { return; } - -virtual bool getDiscFriends(std::string id, std::list &friends); -virtual bool getDiscGPGFriends(std::string id, std::list &gpg_friends); -virtual bool getDiscVersions(std::map &versions); -virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount); - - private: - - p3disc *mDisc; -}; - -#endif - diff --git a/libretroshare/src/rsserver/p3face-server.cc b/libretroshare/src/rsserver/p3face-server.cc index 406881f6e..d4f6b768d 100644 --- a/libretroshare/src/rsserver/p3face-server.cc +++ b/libretroshare/src/rsserver/p3face-server.cc @@ -65,7 +65,8 @@ RsServer::RsServer(NotifyBase &callback) mPluginsManager = NULL; /* services */ - ad = NULL; + mHeart = NULL; + mDisc = NULL; msgSrv = NULL; chatSrv = NULL; mStatusSrv = NULL; diff --git a/libretroshare/src/rsserver/p3face.h b/libretroshare/src/rsserver/p3face.h index 47f4bdd3b..5de9ca42d 100644 --- a/libretroshare/src/rsserver/p3face.h +++ b/libretroshare/src/rsserver/p3face.h @@ -37,11 +37,13 @@ #include "retroshare/rstypes.h" #include "util/rsthreads.h" -#include "services/p3disc.h" #include "services/p3msgservice.h" #include "services/p3chatservice.h" #include "services/p3statusservice.h" +class p3heartbeat; +class p3discovery2; + /* GXS Classes - just declare the classes. so we don't have to totally recompile to switch */ @@ -171,7 +173,8 @@ class RsServer: public RsControl, public RsThread //sslroot *sslr; /* services */ - p3disc *ad; + p3heartbeat *mHeart; + p3discovery2 *mDisc; p3MsgService *msgSrv; p3ChatService *chatSrv; p3StatusService *mStatusSrv; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 9614708dd..e4b4207e4 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -373,18 +373,8 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d) break; } - d.visState = 0; - if (!(ps.visState & RS_VIS_STATE_NODISC)) - { - d.visState |= RS_VS_DISC_ON; - } - - if (!(ps.visState & RS_VIS_STATE_NODHT)) - { - d.visState |= RS_VS_DHT_ON; - } - - + d.vs_disc = ps.vs_disc; + d.vs_dht = ps.vs_dht; /* Translate */ @@ -645,7 +635,7 @@ bool p3Peers::addFriend(const std::string &ssl_id, const std::string &gpg_id,Se * This will cause the SSL certificate to be retained for 30 days... and give the person a chance to connect! * */ time_t now = time(NULL); - return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VIS_STATE_STD, now, perm_flags); + return mPeerMgr->addFriend(ssl_id, gpg_id, RS_NET_MODE_UDP, RS_VS_DISC_FULL, RS_VS_DHT_FULL, now, perm_flags); } bool p3Peers::removeKeysFromPGPKeyring(const std::list& pgp_ids,std::string& backup_file,uint32_t& error_code) @@ -875,20 +865,15 @@ bool p3Peers::setNetworkMode(const std::string &id, uint32_t extNetMode) bool -p3Peers::setVisState(const std::string &id, uint32_t extVisState) +p3Peers::setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::setVisState() " << id << std::endl; #endif - std::cerr << "p3Peers::setVisState() " << id << " " << extVisState << std::endl; + std::cerr << "p3Peers::setVisState() " << id << " DISC: " << vs_disc; + std::cerr << " DHT: " << vs_dht << std::endl; - uint32_t visState = 0; - if (!(extVisState & RS_VS_DHT_ON)) - visState |= RS_VIS_STATE_NODHT; - if (!(extVisState & RS_VS_DISC_ON)) - visState |= RS_VIS_STATE_NODISC; - - return mPeerMgr->setVisState(id, visState); + return mPeerMgr->setVisState(id, vs_disc, vs_dht); } //=========================================================================== @@ -1242,7 +1227,7 @@ RsPeerDetails::RsPeerDetails() org(""),issuer(""),fpr(""),authcode(""), trustLvl(0), validLvl(0),ownsign(false), hasSignedMe(false),accept_connection(false), - state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),visState(0), + state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),vs_disc(0), vs_dht(0), lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),foundDHT(false), wasDeniedConnection(false), deniedTS(0) { diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 6305dc1d7..d81e74cfd 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -90,7 +90,7 @@ virtual bool setLocalAddress(const std::string &id, const std::string &addr, uin virtual bool setExtAddress(const std::string &id, const std::string &addr, uint16_t port); virtual bool setDynDNS(const std::string &id, const std::string &dyndns); virtual bool setNetworkMode(const std::string &id, uint32_t netMode); -virtual bool setVisState(const std::string &id, uint32_t mode); +virtual bool setVisState(const std::string &id, uint16_t vs_disc, uint16_t vs_dht); virtual void getIPServersList(std::list& ip_servers) ; virtual void allowServerIPDetermination(bool) ; diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index e00337575..f0ad40f4c 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -289,7 +289,6 @@ void RsInit::InitRsConfig() //setZoneLevel(PQL_DEBUG_BASIC, 82371); // pqiperson. //setZoneLevel(PQL_DEBUG_BASIC, 34283); // pqihandler. //setZoneLevel(PQL_DEBUG_BASIC, 44863); // discItems. - //setZoneLevel(PQL_DEBUG_BASIC, 2482); // p3disc //setZoneLevel(PQL_DEBUG_BASIC, 1728); // pqi/p3proxy //setZoneLevel(PQL_DEBUG_BASIC, 1211); // sslroot. //setZoneLevel(PQL_DEBUG_BASIC, 37714); // pqissl. @@ -1780,8 +1779,9 @@ RsTurtle *rsTurtle = NULL ; #include "upnp/upnphandler_miniupnp.h" #endif #endif - -#include "services/p3disc.h" + +#include "services/p3heartbeat.h" +#include "services/p3discovery2.h" #include "services/p3msgservice.h" #include "services/p3chatservice.h" #include "services/p3statusservice.h" @@ -1815,7 +1815,6 @@ RsTurtle *rsTurtle = NULL ; #include "rsserver/p3face.h" #include "rsserver/p3peers.h" #include "rsserver/p3msgs.h" -#include "rsserver/p3discovery.h" #include "rsserver/p3status.h" #include "rsserver/p3history.h" #include "rsserver/p3serverconfig.h" @@ -2238,7 +2237,8 @@ int RsServer::StartupRetroShare() mPluginsManager->setInterfaces(interfaces); /* create Services */ - ad = new p3disc(mPeerMgr, mLinkMgr, mNetMgr, pqih); + mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr); + mHeart = new p3heartbeat(mLinkMgr, pqih); msgSrv = new p3MsgService(mLinkMgr); chatSrv = new p3ChatService(mLinkMgr, mHistoryMgr); mStatusSrv = new p3StatusService(mLinkMgr); @@ -2251,7 +2251,8 @@ int RsServer::StartupRetroShare() chatSrv->connectToTurtleRouter(tr) ; msgSrv->connectToTurtleRouter(tr) ; - pqih -> addService(ad); + pqih -> addService(mHeart); + pqih -> addService(mDisc); pqih -> addService(msgSrv); pqih -> addService(chatSrv); pqih ->addService(mStatusSrv); @@ -2503,7 +2504,7 @@ int RsServer::StartupRetroShare() /* need to Monitor too! */ mLinkMgr->addMonitor(pqih); mLinkMgr->addMonitor(mCacheStrapper); - //mLinkMgr->addMonitor(ad); + mLinkMgr->addMonitor(mDisc); mLinkMgr->addMonitor(msgSrv); mLinkMgr->addMonitor(mStatusSrv); mLinkMgr->addMonitor(chatSrv); @@ -2529,7 +2530,6 @@ int RsServer::StartupRetroShare() mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr); mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv); mConfigMgr->addConfiguration("turtle.cfg", tr); - //mConfigMgr->addConfiguration("p3disc.cfg", ad); #ifdef RS_USE_BITDHT mConfigMgr->addConfiguration("bitdht.cfg", mBitDht); @@ -2583,7 +2583,7 @@ int RsServer::StartupRetroShare() if (RsInitConfig::forceExtPort) { mPeerMgr->setOwnNetworkMode(RS_NET_MODE_EXT); - mPeerMgr->setOwnVisState(RS_VIS_STATE_STD); + mPeerMgr->setOwnVisState(RS_VS_DISC_FULL, RS_VS_DHT_FULL); } @@ -2633,7 +2633,7 @@ int RsServer::StartupRetroShare() /* Add AuthGPG services */ /**************************************************************************/ - AuthGPG::getAuthGPG()->addService(ad); + AuthGPG::getAuthGPG()->addService(mDisc); /**************************************************************************/ /* Force Any Last Configuration Options */ @@ -2701,7 +2701,7 @@ int RsServer::StartupRetroShare() /* Setup GUI Interfaces. */ - rsDisc = new p3Discovery(ad); + rsDisc = mDisc; rsBandwidthControl = mBwCtrl; rsConfig = serverConfig; diff --git a/libretroshare/src/serialiser/itempriorities.h b/libretroshare/src/serialiser/itempriorities.h index ef8dd2072..83f74b867 100644 --- a/libretroshare/src/serialiser/itempriorities.h +++ b/libretroshare/src/serialiser/itempriorities.h @@ -71,6 +71,15 @@ const uint8_t QOS_PRIORITY_RS_DISC_ASK_INFO = 2 ; const uint8_t QOS_PRIORITY_RS_DISC_REPLY = 1 ; const uint8_t QOS_PRIORITY_RS_DISC_VERSION = 1 ; +const uint8_t QOS_PRIORITY_RS_DISC_CONTACT = 2 ; // CONTACT and PGPLIST must have +const uint8_t QOS_PRIORITY_RS_DISC_PGP_LIST = 2 ; // same priority. +const uint8_t QOS_PRIORITY_RS_DISC_SERVICES = 2 ; +const uint8_t QOS_PRIORITY_RS_DISC_PGP_CERT = 1 ; + +// Heartbeat. +// +const uint8_t QOS_PRIORITY_RS_HEARTBEAT_PULSE = 8 ; + // Chat/Msgs // const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ; diff --git a/libretroshare/src/serialiser/rsconfigitems.cc b/libretroshare/src/serialiser/rsconfigitems.cc index a5b5ab03a..c67cdab92 100644 --- a/libretroshare/src/serialiser/rsconfigitems.cc +++ b/libretroshare/src/serialiser/rsconfigitems.cc @@ -780,11 +780,15 @@ void RsPeerNetItem::clear() gpg_id.clear(); location.clear(); netMode = 0; - visState = 0; + vs_disc = 0; + vs_dht = 0; lastContact = 0; - localAddr.TlvClear(); - extAddr.TlvClear(); + localAddrV4.TlvClear(); + extAddrV4.TlvClear(); + localAddrV6.TlvClear(); + extAddrV6.TlvClear(); + dyndns.clear(); localAddrList.TlvClear(); @@ -812,19 +816,29 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent) out << "netMode: " << netMode << std::endl; printIndent(out, int_Indent); - out << "visState: " << visState << std::endl; + out << "vs_disc: " << vs_disc << std::endl; + + printIndent(out, int_Indent); + out << "vs_dht: " << vs_dht << std::endl; printIndent(out, int_Indent); out << "lastContact: " << lastContact << std::endl; printIndent(out, int_Indent); - out << "localAddr: " << std::endl; - localAddr.print(out, int_Indent); + out << "localAddrV4: " << std::endl; + localAddrV4.print(out, int_Indent); printIndent(out, int_Indent); - out << "extAddr: " << std::endl; - extAddr.print(out, int_Indent); - + out << "extAddrV4: " << std::endl; + extAddrV4.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "localAddrV6: " << std::endl; + localAddrV6.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "extAddrV6: " << std::endl; + extAddrV6.print(out, int_Indent); printIndent(out, int_Indent); out << "DynDNS: " << dyndns << std::endl; @@ -845,10 +859,15 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i) s += GetTlvStringSize(i->gpg_id); s += GetTlvStringSize(i->location); s += 4; /* netMode */ - s += 4; /* visState */ + s += 2; /* vs_disc */ + s += 2; /* vs_dht */ s += 4; /* lastContact */ - s += i->localAddr.TlvSize(); /* localaddr */ - s += i->extAddr.TlvSize(); /* remoteaddr */ + + s += i->localAddrV4.TlvSize(); /* localaddr */ + s += i->extAddrV4.TlvSize(); /* remoteaddr */ + s += i->localAddrV6.TlvSize(); /* localaddr */ + s += i->extAddrV6.TlvSize(); /* remoteaddr */ + s += GetTlvStringSize(i->dyndns); //add the size of the ip list @@ -900,10 +919,14 @@ bool RsPeerConfigSerialiser::serialiseNet(RsPeerNetItem *item, void *data, uint3 ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GPGID, item->gpg_id); /* Mandatory */ ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); /* Mandatory */ - ok &= setRawUInt32(data, tlvsize, &offset, item->visState); /* Mandatory */ + ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); /* Mandatory */ + ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); /* Mandatory */ ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ - ok &= item->localAddr.SetTlv(data, tlvsize, &offset); - ok &= item->extAddr.SetTlv(data, tlvsize, &offset); + + ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); + ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); + ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); + ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); @@ -974,11 +997,14 @@ RsPeerNetItem *RsPeerConfigSerialiser::deserialiseNet(void *data, uint32_t *size ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GPGID, item->gpg_id); /* Mandatory */ ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* Mandatory */ ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ - ok &= getRawUInt32(data, rssize, &offset, &(item->visState)); /* Mandatory */ + ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ + ok &= getRawUInt16(data, rssize, &offset, &(item->vs_dht)); /* Mandatory */ ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); /* Mandatory */ - ok &= item->localAddr.GetTlv(data, rssize, &offset); - ok &= item->extAddr.GetTlv(data, rssize, &offset); + ok &= item->localAddrV4.GetTlv(data, rssize, &offset); + ok &= item->extAddrV4.GetTlv(data, rssize, &offset); + ok &= item->localAddrV6.GetTlv(data, rssize, &offset); + ok &= item->extAddrV6.GetTlv(data, rssize, &offset); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); ok &= item->localAddrList.GetTlv(data, rssize, &offset); diff --git a/libretroshare/src/serialiser/rsconfigitems.h b/libretroshare/src/serialiser/rsconfigitems.h index 74ce1e9a8..b06c92370 100644 --- a/libretroshare/src/serialiser/rsconfigitems.h +++ b/libretroshare/src/serialiser/rsconfigitems.h @@ -76,11 +76,15 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0); std::string gpg_id; /* Mandatory */ std::string location; /* not Mandatory */ uint32_t netMode; /* Mandatory */ - uint32_t visState; /* Mandatory */ + uint16_t vs_disc; /* Mandatory */ + uint16_t vs_dht; /* Mandatory */ uint32_t lastContact; /* Mandatory */ - RsTlvIpAddress localAddr; /* Mandatory */ - RsTlvIpAddress extAddr; /* Mandatory */ + RsTlvIpAddress localAddrV4; /* Mandatory */ + RsTlvIpAddress extAddrV4; /* Mandatory */ + RsTlvIpAddress localAddrV6; /* Mandatory */ + RsTlvIpAddress extAddrV6; /* Mandatory */ + std::string dyndns; RsTlvIpAddrSet localAddrList; diff --git a/libretroshare/src/serialiser/rsdiscitems.cc b/libretroshare/src/serialiser/rsdiscitems.cc deleted file mode 100644 index 91e114f03..000000000 --- a/libretroshare/src/serialiser/rsdiscitems.cc +++ /dev/null @@ -1,770 +0,0 @@ - -/* - * libretroshare/src/serialiser: rsdiscitems.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-2008 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "serialiser/rsbaseserial.h" -#include "serialiser/rsbaseserial.h" - -#include "serialiser/rsserviceids.h" -#include "serialiser/rsdiscitems.h" - -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvtypes.h" - -/*** - * #define RSSERIAL_DEBUG 1 - * #define RSSERIAL_ERROR_DEBUG 1 - ***/ - -#define RSSERIAL_ERROR_DEBUG 1 - -#include - -/*************************************************************************/ - -uint32_t RsDiscSerialiser::size(RsItem *i) -{ - RsDiscAskInfo *inf; - RsDiscReply *rdr; - RsDiscVersion *rdv; - RsDiscHeartbeat *rdt; - - /* do reply first - as it is derived from Item */ - if (NULL != (rdr = dynamic_cast(i))) - { - return sizeReply(rdr); - } - else if (NULL != (inf = dynamic_cast(i))) - { - return sizeAskInfo(inf); - } - else if (NULL != (rdv = dynamic_cast(i))) - { - return sizeVersion(rdv); - } - else if (NULL != (rdt = dynamic_cast(i))) - { - return sizeHeartbeat(rdt); - } - - return 0; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsDiscAskInfo *inf; - RsDiscReply *rdr; - RsDiscVersion *rdv; - RsDiscHeartbeat *rdt; - - /* do reply first - as it is derived from Item */ - if (NULL != (rdr = dynamic_cast(i))) - { - return serialiseReply(rdr, data, pktsize); - } - else if (NULL != (inf = dynamic_cast(i))) - { - return serialiseAskInfo(inf, data, pktsize); - } - else if (NULL != (rdv = dynamic_cast(i))) - { - return serialiseVersion(rdv, data, pktsize); - } - else if (NULL != (rdt = dynamic_cast(i))) - { - return serialiseHeartbeat(rdt, data, pktsize); - } - - return false; -} - -RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype))) - { - std::cerr << "RsDiscSerialiser::deserialise() Wrong Type" << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DISC_REPLY: - return deserialiseReply(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_ASK_INFO: - return deserialiseAskInfo(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_VERSION: - return deserialiseVersion(data, pktsize); - break; - case RS_PKT_SUBTYPE_DISC_HEARTBEAT: - return deserialiseHeartbeat(data, pktsize); - break; - default: - return NULL; - break; - } - return NULL; -} - -/*************************************************************************/ - -RsDiscAskInfo::~RsDiscAskInfo() -{ - return; -} - -void RsDiscAskInfo::clear() -{ - gpg_id.clear(); -} - -std::ostream &RsDiscAskInfo::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscAskInfo", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "gpg_id: " << gpg_id << std::endl; - - printRsItemEnd(out, "RsDiscAskInfo", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizeAskInfo(RsDiscAskInfo *item) -{ - uint32_t s = 8; /* header */ - s += GetTlvStringSize(item->gpg_id); - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseAskInfo(RsDiscAskInfo *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeAskInfo(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseAskInfo() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id); - - if (offset != tlvsize) { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseAskInfo() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsDiscAskInfo *RsDiscSerialiser::deserialiseAskInfo(void *data, uint32_t *pktsize) { - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_ASK_INFO != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseAskInfo() Not Enough Space" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscAskInfo *item = new RsDiscAskInfo(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->gpg_id); - - if (offset != rssize) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseAskInfo() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseAskInfo() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - - -RsDiscReply::~RsDiscReply() -{ - return; -} - -void RsDiscReply::clear() -{ - aboutId.clear(); - certGPG.clear(); - rsPeerList.clear(); -} - -std::ostream &RsDiscReply::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscReply", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "AboutId: " << aboutId << std::endl; - - printIndent(out, int_Indent); - out << "certGPG: " << certGPG << std::endl; - - printIndent(out, int_Indent); - out << "RsDiscReply::print() RsPeerNetItem list : " << std::endl; - for (std::list::iterator pitemIt = rsPeerList.begin(); pitemIt!=(rsPeerList.end()); pitemIt++) { - printIndent(out, int_Indent); - pitemIt->print(std::cerr, indent); - } - - printRsItemEnd(out, "RsDiscReply", indent); - return out; -} - - -uint32_t RsDiscSerialiser::sizeReply(RsDiscReply *item) -{ - uint32_t s = 8; /* header */ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeReply() Header Size: " << s << std::endl; -#endif - s += GetTlvStringSize(item->aboutId); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeReply() +AboutId Size: " << s << std::endl; -#endif - s += GetTlvStringSize(item->certGPG); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeReply() +certGPG Size: " << s << std::endl; -#endif - - RsPeerConfigSerialiser rss ; - - for (std::list::iterator it = item->rsPeerList.begin(); it != item->rsPeerList.end(); it++) - { - s += rss.size(&(*it)) ; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeReply() +RsPeerNetItem Size: " << s << std::endl; -#endif - } - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::sizeReply() Total Size: " << s << std::endl; -#endif - - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseReply(RsDiscReply *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeReply(item); - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - - if (*pktsize < tlvsize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() ERROR not enough space" << std::endl; - std::cerr << "RsDiscSerialiser::serialiseReply() ERROR *pktsize: " << *pktsize << " tlvsize: " << tlvsize; - std::cerr << std::endl; -#endif - return false; /* not enough space */ - } - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseReply() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->aboutId); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() Offset After Strings: " << offset << std::endl; -#endif - - //store the ip list - RsPeerConfigSerialiser rss ; - std::list::iterator pitemIt; - - for (pitemIt = item->rsPeerList.begin(); pitemIt!=(item->rsPeerList.end()) && ok; ++pitemIt) - { - uint32_t size = *pktsize - offset ;//~(uint32_t)0; // we must be conservative otherwise the serialiser returns false !! - - ok &= rss.serialise(&(*pitemIt), (void *) (((char *) data) + offset), &size); - - // The size has been updated to its exact value. - offset += size; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() RsPeerNetItem ok?: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseReply() Offset After RsPeerNetItem: " << offset << std::endl; -#endif - - } - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseReply() Size Error: " << tlvsize << " != " << offset << std::endl; -#endif - } - - return ok; -} - -RsDiscReply *RsDiscSerialiser::deserialiseReply(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() Pkt Type: " << std::hex << rstype << std::dec; - std::cerr << "RsDiscSerialiser::deserialiseReply() Pkt Size: " << rssize << std::endl; -#endif - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_REPLY != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() pktsize != rssize" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscReply *item = new RsDiscReply(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->aboutId); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CERT_GPG, item->certGPG); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() offset after Strings: " << offset << std::endl; -#endif - - //get the peernet address list - RsPeerConfigSerialiser rss ; - - while (offset < rssize) - { - uint32_t peerNetSize = rssize - offset ; - - RsPeerNetItem *rsPeerNetItem = (RsPeerNetItem*)rss.deserialise((void *) (((char *) data) + offset), &peerNetSize); - - offset += peerNetSize; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() offset aft PeerNetItem: " << offset << std::endl; -#endif - - if(rsPeerNetItem == NULL) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() ERROR deserialise PeerNetItem Failed" << std::endl; -#endif - break ; - } - - item->rsPeerList.push_back(*rsPeerNetItem); - delete rsPeerNetItem ; - } - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() offset != rssize" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseReply() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - - -RsDiscVersion::~RsDiscVersion() -{ - return; -} -void RsDiscVersion::clear() -{ - version = ""; -} - -std::ostream &RsDiscVersion::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscVersion", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Version String: " << version << std::endl; - - printRsItemEnd(out, "RsDiscVersion", indent); - return out; -} - -uint32_t RsDiscSerialiser::sizeVersion(RsDiscVersion *item) -{ - uint32_t s = 8; /* header */ - s += GetTlvStringSize(item->version); - - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseVersion(RsDiscVersion *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeVersion(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseVersion() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseVersion() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, item->version); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseVersion() Size Error! " << std::endl; - std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl; -#endif - } - - return ok; -} - -RsDiscVersion *RsDiscSerialiser::deserialiseVersion(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_VERSION != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseVersion() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseVersion() pktsize != rssize" << std::endl; - std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscVersion *item = new RsDiscVersion(); - item->clear(); - - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VALUE, item->version); - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseVersion() offset != rssize" << std::endl; - std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseVersion() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - - -RsDiscHeartbeat::~RsDiscHeartbeat() -{ - return; -} -void RsDiscHeartbeat::clear() -{ -} - -std::ostream &RsDiscHeartbeat::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsDiscHeartbeat", indent); - printRsItemEnd(out, "RsDiscHeartbeat", indent); - return out; -} - -uint32_t RsDiscSerialiser::sizeHeartbeat(RsDiscHeartbeat */*item*/) -{ - uint32_t s = 8; /* header */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsDiscSerialiser::serialiseHeartbeat(RsDiscHeartbeat *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeHeartbeat(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsDiscSerialiser::serialiseHeartbeat() Header: " << ok << std::endl; - std::cerr << "RsDiscSerialiser::serialiseHeartbeat() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::serialiseHeartbeat() Size Error! " << std::endl; - std::cerr << "Offset: " << offset << " tlvsize: " << tlvsize << std::endl; -#endif - } - - return ok; -} - -RsDiscHeartbeat *RsDiscSerialiser::deserialiseHeartbeat(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_DISC_HEARTBEAT != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() pktsize != rssize" << std::endl; - std::cerr << "Pktsize: " << *pktsize << " Rssize: " << rssize << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsDiscHeartbeat *item = new RsDiscHeartbeat(); - item->clear(); - - /* skip the header */ - offset += 8; - - if (offset != rssize) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() offset != rssize" << std::endl; - std::cerr << "Offset: " << offset << " Rssize: " << rssize << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_ERROR_DEBUG - std::cerr << "RsDiscSerialiser::deserialiseHeartbeat() ok = false" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ diff --git a/libretroshare/src/serialiser/rsdiscitems.h b/libretroshare/src/serialiser/rsdiscitems.h deleted file mode 100644 index cfa6e70a7..000000000 --- a/libretroshare/src/serialiser/rsdiscitems.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * libretroshare/src/serialiser: rsdiscitems.h - * - * Serialiser for RetroShare. - * - * Copyright 2004-2008 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - - - -#ifndef RS_DISC_ITEMS_H -#define RS_DISC_ITEMS_H - -#include "serialiser/rsserial.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvtypes.h" -#include "serialiser/rsserviceids.h" -#include "serialiser/rsconfigitems.h" - -//const uint8_t RS_PKT_SUBTYPE_DISC_OWN = 0x01; -const uint8_t RS_PKT_SUBTYPE_DISC_REPLY = 0x02; -const uint8_t RS_PKT_SUBTYPE_DISC_ASK_INFO = 0x03; -const uint8_t RS_PKT_SUBTYPE_DISC_VERSION = 0x05; -const uint8_t RS_PKT_SUBTYPE_DISC_HEARTBEAT = 0x06; - -class RsDiscItem: public RsItem -{ - protected: - RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {} -}; - - -//class RsDiscOwnItem: public RsDiscItem -//{ -// public: -// -// RsDiscOwnItem() :RsDiscItem(RS_PKT_SUBTYPE_DISC_OWN ) {} -// -// -// virtual ~RsDiscOwnItem(); -// -// virtual void clear(); -// virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); -// -// //use for transmitting ip address list -// std::list ipAddressList; -// -// //use for transmitting my own adress list -// struct sockaddr_in laddr; -// struct sockaddr_in saddr; -// -// // time frame of recent connections. -// uint16_t contact_tf; -// // flags... -// uint32_t discFlags; -//}; - -class RsDiscReply: public RsDiscItem -{ - public: - - RsDiscReply() - :RsDiscItem(RS_PKT_SUBTYPE_DISC_REPLY) - { - setPriorityLevel(QOS_PRIORITY_RS_DISC_REPLY); - } - -virtual ~RsDiscReply(); - -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - //use for transmitting ip address list - std::list rsPeerList; - - //use for transmitting my own adress list -// struct sockaddr_in currentladdr; -// struct sockaddr_in currentsaddr; - - // time frame of recent connections. - //uint16_t contact_tf; - // flags... - //uint32_t discFlags; - - std::string aboutId; - std::string certGPG; -}; - -class RsDiscAskInfo: public RsDiscItem -{ - public: - - RsDiscAskInfo() - :RsDiscItem(RS_PKT_SUBTYPE_DISC_ASK_INFO) - { - setPriorityLevel(QOS_PRIORITY_RS_DISC_ASK_INFO); - } - -virtual ~RsDiscAskInfo(); - -virtual void clear(); -virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - std::string gpg_id; -}; - -class RsDiscVersion: public RsDiscItem -{ -public: - RsDiscVersion() :RsDiscItem(RS_PKT_SUBTYPE_DISC_VERSION) - { - setPriorityLevel(QOS_PRIORITY_RS_DISC_VERSION); - } - - virtual ~RsDiscVersion(); - - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); - - std::string version; -}; - -class RsDiscHeartbeat: public RsDiscItem -{ -public: - RsDiscHeartbeat() :RsDiscItem(RS_PKT_SUBTYPE_DISC_HEARTBEAT) - { - setPriorityLevel(QOS_PRIORITY_RS_DISC_HEART_BEAT) ; - } - - virtual ~RsDiscHeartbeat(); - - virtual void clear(); - virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); -}; - -class RsDiscSerialiser: public RsSerialType -{ - public: - RsDiscSerialiser() - :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC) - { return; } - -virtual ~RsDiscSerialiser() { return; } - -virtual uint32_t size(RsItem *); -virtual bool serialise (RsItem *item, void *data, uint32_t *size); -virtual RsItem * deserialise(void *data, uint32_t *size); - - private: - -virtual uint32_t sizeAskInfo(RsDiscAskInfo *); -virtual bool serialiseAskInfo(RsDiscAskInfo *item, void *data, uint32_t *size); -virtual RsDiscAskInfo *deserialiseAskInfo(void *data, uint32_t *size); - -virtual uint32_t sizeReply(RsDiscReply *); -virtual bool serialiseReply (RsDiscReply *item, void *data, uint32_t *size); -virtual RsDiscReply *deserialiseReply(void *data, uint32_t *size); - -//virtual uint32_t sizeIssuer(RsDiscIssuer *); -//virtual bool serialiseIssuer (RsDiscIssuer *item, void *data, uint32_t *size); -//virtual RsDiscIssuer *deserialiseIssuer(void *data, uint32_t *size); - -virtual uint32_t sizeVersion(RsDiscVersion *); -virtual bool serialiseVersion(RsDiscVersion *item, void *data, uint32_t *size); -virtual RsDiscVersion *deserialiseVersion(void *data, uint32_t *size); - -virtual uint32_t sizeHeartbeat(RsDiscHeartbeat *); -virtual bool serialiseHeartbeat(RsDiscHeartbeat *item, void *data, uint32_t *size); -virtual RsDiscHeartbeat *deserialiseHeartbeat(void *data, uint32_t *size); - -}; - - -#endif // RS_DISC_ITEMS_H - diff --git a/libretroshare/src/serialiser/rsdiscovery2items.cc b/libretroshare/src/serialiser/rsdiscovery2items.cc new file mode 100644 index 000000000..f66faac67 --- /dev/null +++ b/libretroshare/src/serialiser/rsdiscovery2items.cc @@ -0,0 +1,890 @@ + +/* + * libretroshare/src/serialiser: rsdiscitems.cc + * + * RetroShare Serialiser. + * + * Copyright 2007-2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "serialiser/rsbaseserial.h" +#include "serialiser/rsbaseserial.h" + +#include "serialiser/rsserviceids.h" +#include "serialiser/rsdiscovery2items.h" + +#include "serialiser/rstlvbase.h" +#include "serialiser/rstlvtypes.h" + +/*** + * #define RSSERIAL_DEBUG 1 + * #define RSSERIAL_ERROR_DEBUG 1 + ***/ + +#define RSSERIAL_ERROR_DEBUG 1 + +#include + +/*************************************************************************/ + +uint32_t RsDiscSerialiser::size(RsItem *i) +{ + RsDiscPgpListItem *pgplist; + RsDiscPgpCertItem *pgpcert; + RsDiscContactItem *contact; + //RsDiscServicesItem *services; + + if (NULL != (pgplist = dynamic_cast(i))) + { + return sizePgpList(pgplist); + } + else if (NULL != (pgpcert = dynamic_cast(i))) + { + return sizePgpCert(pgpcert); + } + else if (NULL != (contact = dynamic_cast(i))) + { + return sizeContact(contact); + } +#if 0 + else if (NULL != (services = dynamic_cast(i))) + { + return sizeServices(services); + } +#endif + return 0; +} + +/* serialise the data to the buffer */ +bool RsDiscSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) +{ + RsDiscPgpListItem *pgplist; + RsDiscPgpCertItem *pgpcert; + RsDiscContactItem *contact; + //RsDiscServicesItem *services; + + if (NULL != (pgplist = dynamic_cast(i))) + { + return serialisePgpList(pgplist, data, pktsize); + } + else if (NULL != (pgpcert = dynamic_cast(i))) + { + return serialisePgpCert(pgpcert, data, pktsize); + } + else if (NULL != (contact = dynamic_cast(i))) + { + return serialiseContact(contact, data, pktsize); + } +#if 0 + else if (NULL != (services = dynamic_cast(i))) + { + return serialiseServices(services, data, pktsize); + } +#endif + + return false; +} + +RsItem *RsDiscSerialiser::deserialise(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_DISC != getRsItemService(rstype))) + { + std::cerr << "RsDiscSerialiser::deserialise() Wrong Type" << std::endl; + return NULL; /* wrong type */ + } + + switch(getRsItemSubType(rstype)) + { + case RS_PKT_SUBTYPE_DISC_PGP_LIST: + return deserialisePgpList(data, pktsize); + break; + case RS_PKT_SUBTYPE_DISC_PGP_CERT: + return deserialisePgpCert(data, pktsize); + break; + case RS_PKT_SUBTYPE_DISC_CONTACT: + return deserialiseContact(data, pktsize); + break; +#if 0 + case RS_PKT_SUBTYPE_DISC_SERVICES: + return deserialiseServices(data, pktsize); + break; +#endif + default: + return NULL; + break; + } + return NULL; +} + +/*************************************************************************/ + +RsDiscPgpListItem::~RsDiscPgpListItem() +{ + return; +} + +void RsDiscPgpListItem::clear() +{ + mode = DISC_PGP_LIST_MODE_NONE; + pgpIdSet.TlvClear(); +} + +std::ostream &RsDiscPgpListItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsDiscPgpListItem", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "mode: " << mode << std::endl; + pgpIdSet.print(out, int_Indent); + + printRsItemEnd(out, "RsDiscPgpList", indent); + return out; +} + + +uint32_t RsDiscSerialiser::sizePgpList(RsDiscPgpListItem *item) +{ + uint32_t s = 8; /* header */ + s += 4; /* mode */ + s += item->pgpIdSet.TlvSize(); + return s; +} + +/* serialise the data to the buffer */ +bool RsDiscSerialiser::serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *pktsize) +{ + uint32_t tlvsize = sizePgpList(item); + uint32_t offset = 0; + + if (*pktsize < tlvsize) + return false; /* not enough space */ + + *pktsize = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::serialisePgpList() Header: " << ok << std::endl; + std::cerr << "RsDiscSerialiser::serialisePgpList() Size: " << tlvsize << std::endl; +#endif + + /* skip the header */ + offset += 8; + + /* add mandatory parts first */ + ok &= setRawUInt32(data, tlvsize, &offset, item->mode); + ok &= item->pgpIdSet.SetTlv(data, tlvsize, &offset); + + if (offset != tlvsize) { + ok = false; +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::serialisePgpList() Size Error! " << std::endl; +#endif + } + + return ok; +} + +RsDiscPgpListItem *RsDiscSerialiser::deserialisePgpList(void *data, uint32_t *pktsize) { + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype))) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpList() Wrong Type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpList() Not Enough Space" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsDiscPgpListItem *item = new RsDiscPgpListItem(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + ok &= getRawUInt32(data, rssize, &offset, &(item->mode)); + ok &= item->pgpIdSet.GetTlv(data, rssize, &offset); + + if (offset != rssize) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpList() offset != rssize" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpList() ok = false" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + + +/*************************************************************************/ +/*************************************************************************/ +#if 0 + +RsDiscServicesItem::~RsDiscServicesItem() +{ + return; +} + +void RsDiscServicesItem::clear() +{ + version.clear(); + mServiceIdMap.TlvClear(); +} + +std::ostream &RsDiscServicesItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsDiscServicesItem", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "version: " << version << std::endl; + mServiceIdMap.print(out, int_Indent); + + printRsItemEnd(out, "RsDiscServicesItem", indent); + return out; +} + + +uint32_t RsDiscSerialiser::sizeServices(RsDiscServicesItem *item) +{ + uint32_t s = 8; /* header */ + s += GetTlvStringSize(item->version); /* version */ + s += item->mServiceIdMap.TlvSize(); + return s; +} + +/* serialise the data to the buffer */ +bool RsDiscSerialiser::serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *pktsize) +{ + uint32_t tlvsize = sizeServices(item); + uint32_t offset = 0; + + if (*pktsize < tlvsize) + return false; /* not enough space */ + + *pktsize = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::serialiseServices() Header: " << ok << std::endl; + std::cerr << "RsDiscSerialiser::serialiseServices() Size: " << tlvsize << std::endl; +#endif + + /* skip the header */ + offset += 8; + + /* add mandatory parts first */ + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version); + ok &= item->mServiceIdMap.SetTlv(data, tlvsize, &offset); + + if (offset != tlvsize) { + ok = false; +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::serialiseServices() Size Error! " << std::endl; +#endif + } + + return ok; +} + +RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(void *data, uint32_t *pktsize) { + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype))) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseServices() Wrong Type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseServices() Not Enough Space" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsDiscServicesItem *item = new RsDiscServicesItem(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version); + ok &= item->mServiceIdMap.GetTlv(data, rssize, &offset); + + if (offset != rssize) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseServices() offset != rssize" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseServices() ok = false" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + +#endif + + +/*************************************************************************/ + +RsDiscPgpCertItem::~RsDiscPgpCertItem() +{ + return; +} + +void RsDiscPgpCertItem::clear() +{ + pgpId.clear(); + pgpCert.clear(); +} + +std::ostream &RsDiscPgpCertItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsDiscPgpCertItem", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "pgpId: " << pgpId << std::endl; + printIndent(out, int_Indent); + out << "pgpCert: " << pgpCert << std::endl; + + printRsItemEnd(out, "RsDiscPgpCert", indent); + return out; +} + + +uint32_t RsDiscSerialiser::sizePgpCert(RsDiscPgpCertItem *item) +{ + uint32_t s = 8; /* header */ + s += GetTlvStringSize(item->pgpId); + s += GetTlvStringSize(item->pgpCert); + return s; +} + +/* serialise the data to the buffer */ +bool RsDiscSerialiser::serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *pktsize) +{ + uint32_t tlvsize = sizePgpCert(item); + uint32_t offset = 0; + + if (*pktsize < tlvsize) + return false; /* not enough space */ + + *pktsize = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::serialisePgpCert() Header: " << ok << std::endl; + std::cerr << "RsDiscSerialiser::serialisePgpCert() Size: " << tlvsize << std::endl; +#endif + + /* skip the header */ + offset += 8; + + /* add mandatory parts first */ + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPID, item->pgpId); + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); + + if (offset != tlvsize) { + ok = false; +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::serialisePgpCert() Size Error! " << std::endl; +#endif + } + + return ok; +} + +RsDiscPgpCertItem *RsDiscSerialiser::deserialisePgpCert(void *data, uint32_t *pktsize) { + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_DISC_PGP_CERT != getRsItemSubType(rstype))) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpCert() Wrong Type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpCert() Not Enough Space" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsDiscPgpCertItem *item = new RsDiscPgpCertItem(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPID, item->pgpId); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert); + + if (offset != rssize) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpCert() offset != rssize" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialisePgpCert() ok = false" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + + +/*************************************************************************/ + + +RsDiscContactItem::~RsDiscContactItem() +{ + return; +} + +void RsDiscContactItem::clear() +{ + pgpId.clear(); + sslId.clear(); + + location.clear(); + version.clear(); + + netMode = 0; + vs_disc = 0; + vs_dht = 0; + lastContact = 0; + + isHidden = false; + hiddenAddr.clear(); + hiddenPort = 0; + + localAddrV4.TlvClear(); + extAddrV4.TlvClear(); + localAddrV6.TlvClear(); + extAddrV6.TlvClear(); + + + dyndns.clear(); + + localAddrList.TlvClear(); + extAddrList.TlvClear(); +} + +std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsDiscContact", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "pgpId: " << pgpId << std::endl; + + printIndent(out, int_Indent); + out << "sslId: " << sslId << std::endl; + + printIndent(out, int_Indent); + out << "location: " << location << std::endl; + + printIndent(out, int_Indent); + out << "version: " << version << std::endl; + + printIndent(out, int_Indent); + out << "netMode: " << netMode << std::endl; + + printIndent(out, int_Indent); + out << "vs_disc: " << vs_disc << std::endl; + + printIndent(out, int_Indent); + out << "vs_dht: " << vs_dht << std::endl; + + printIndent(out, int_Indent); + out << "lastContact: " << lastContact << std::endl; + + if (isHidden) + { + printIndent(out, int_Indent); + out << "hiddenAddr: " << hiddenAddr << std::endl; + + printIndent(out, int_Indent); + out << "hiddenPort: " << hiddenPort << std::endl; + } + else + { + printIndent(out, int_Indent); + out << "localAddrV4: " << std::endl; + localAddrV4.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "extAddrV4: " << std::endl; + extAddrV4.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "localAddrV6: " << std::endl; + localAddrV6.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "extAddrV6: " << std::endl; + extAddrV6.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "DynDNS: " << dyndns << std::endl; + + printIndent(out, int_Indent); + out << "localAddrList: " << std::endl; + localAddrList.print(out, int_Indent); + + printIndent(out, int_Indent); + out << "extAddrList: " << std::endl; + extAddrList.print(out, int_Indent); + } + + printRsItemEnd(out, "RsDiscContact", indent); + return out; +} + + +uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item) +{ + uint32_t s = 8; /* header */ + s += GetTlvStringSize(item->pgpId); + s += GetTlvStringSize(item->sslId); + + s += GetTlvStringSize(item->location); + s += GetTlvStringSize(item->version); + + s += 4; // netMode + s += 2; // vs_disc + s += 2; // vs_dht + s += 4; // last contact + + if (item->isHidden) + { + s += GetTlvStringSize(item->hiddenAddr); + s += 2; /* hidden port */ + } + else + { + s += item->localAddrV4.TlvSize(); /* localaddr */ + s += item->extAddrV4.TlvSize(); /* remoteaddr */ + + s += item->localAddrV6.TlvSize(); /* localaddr */ + s += item->extAddrV6.TlvSize(); /* remoteaddr */ + + s += GetTlvStringSize(item->dyndns); + + //add the size of the ip list + s += item->localAddrList.TlvSize(); + s += item->extAddrList.TlvSize(); + } + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::sizeContact() Total Size: " << s << std::endl; +#endif + + return s; +} + +/* serialise the data to the buffer */ +bool RsDiscSerialiser::serialiseContact(RsDiscContactItem *item, void *data, uint32_t *pktsize) +{ + uint32_t tlvsize = sizeContact(item); + uint32_t offset = 0; + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::serialiseContact() tlvsize: " << tlvsize; + std::cerr << std::endl; +#endif + + if (*pktsize < tlvsize) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::serialiseContact() ERROR not enough space" << std::endl; + std::cerr << "RsDiscSerialiser::serialiseContact() ERROR *pktsize: " << *pktsize << " tlvsize: " << tlvsize; + std::cerr << std::endl; +#endif + return false; /* not enough space */ + } + + *pktsize = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::serialiseContact() Header: " << ok << std::endl; + std::cerr << "RsDiscSerialiser::serialiseContact() Size: " << tlvsize << std::endl; +#endif + + /* skip the header */ + offset += 8; + + /* add mandatory parts first */ + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPID, item->pgpId); + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, item->sslId); + + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version); + + ok &= setRawUInt32(data, tlvsize, &offset, item->netMode); + ok &= setRawUInt16(data, tlvsize, &offset, item->vs_disc); + ok &= setRawUInt16(data, tlvsize, &offset, item->vs_dht); + ok &= setRawUInt32(data, tlvsize, &offset, item->lastContact); /* Mandatory */ + + if (item->isHidden) + { + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); + ok &= setRawUInt16(data, tlvsize, &offset, item->hiddenPort); + } + else + { + ok &= item->localAddrV4.SetTlv(data, tlvsize, &offset); + ok &= item->extAddrV4.SetTlv(data, tlvsize, &offset); + ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); + ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); + + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); + + ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); + ok &= item->extAddrList.SetTlv(data, tlvsize, &offset); + } + + + if (offset != tlvsize) + { + ok = false; +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::serialiseContact() Size Error: " << tlvsize << " != " << offset << std::endl; +#endif + } + + return ok; +} + +RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + +#ifdef RSSERIAL_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Type: " << std::hex << rstype << std::dec; + std::cerr << "RsDiscSerialiser::deserialiseContact() Pkt Size: " << rssize << std::endl; +#endif + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_DISC_CONTACT != getRsItemSubType(rstype))) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() Wrong Type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() Not enough space" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsDiscContactItem *item = new RsDiscContactItem(); + item->clear(); + + /* skip the header */ + offset += 8; + + /* get mandatory parts first */ + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPID, item->pgpId); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PEERID, item->sslId); + + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version); + + ok &= getRawUInt32(data, rssize, &offset, &(item->netMode)); /* Mandatory */ + ok &= getRawUInt16(data, rssize, &offset, &(item->vs_disc)); /* Mandatory */ + ok &= getRawUInt16(data, rssize, &offset, &(item->vs_dht)); /* Mandatory */ + ok &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); + + if (rssize < offset + TLV_HEADER_SIZE) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() missized" << std::endl; +#endif + /* no extra */ + delete item; + return NULL; + } + + uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[offset]) ); + + if (tlvtype == TLV_TYPE_STR_DOMADDR) + { + item->isHidden = true; + + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DOMADDR, item->hiddenAddr); + ok &= getRawUInt16(data, rssize, &offset, &(item->hiddenPort)); /* Mandatory */ + + } + else + { + item->isHidden = false; + + ok &= item->localAddrV4.GetTlv(data, rssize, &offset); + ok &= item->extAddrV4.GetTlv(data, rssize, &offset); + ok &= item->localAddrV6.GetTlv(data, rssize, &offset); + ok &= item->extAddrV6.GetTlv(data, rssize, &offset); + + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); + ok &= item->localAddrList.GetTlv(data, rssize, &offset); + ok &= item->extAddrList.GetTlv(data, rssize, &offset); + } + + + if (offset != rssize) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() offset != rssize" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) + { +#ifdef RSSERIAL_ERROR_DEBUG + std::cerr << "RsDiscSerialiser::deserialiseContact() ok = false" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + +/*************************************************************************/ + diff --git a/libretroshare/src/serialiser/rsdiscovery2items.h b/libretroshare/src/serialiser/rsdiscovery2items.h new file mode 100644 index 000000000..ff8ac1491 --- /dev/null +++ b/libretroshare/src/serialiser/rsdiscovery2items.h @@ -0,0 +1,203 @@ +/* + * libretroshare/src/serialiser: rsdiscitems.h + * + * Serialiser for RetroShare. + * + * Copyright 2004-2008 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + + +#ifndef RS_DISC_ITEMS_H +#define RS_DISC_ITEMS_H + +#include "serialiser/rsserial.h" +#include "serialiser/rstlvbase.h" +#include "serialiser/rstlvtypes.h" +#include "serialiser/rsserviceids.h" +#include "serialiser/rsconfigitems.h" + +const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; +const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; +const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT = 0x03; +const uint8_t RS_PKT_SUBTYPE_DISC_SERVICES = 0x04; + +class RsDiscItem: public RsItem +{ + protected: + RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {} +}; + + +#define DISC_PGP_LIST_MODE_NONE 0x00 +#define DISC_PGP_LIST_MODE_FRIENDS 0x01 +#define DISC_PGP_LIST_MODE_GETCERT 0x02 + +class RsDiscPgpListItem: public RsDiscItem +{ + public: + + RsDiscPgpListItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_LIST) + { + setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_LIST); + } + +virtual ~RsDiscPgpListItem(); + +virtual void clear(); +virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + + uint32_t mode; + RsTlvPgpIdSet pgpIdSet; +}; + + + +class RsDiscPgpCertItem: public RsDiscItem +{ + public: + + RsDiscPgpCertItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_CERT) + { + setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); + } + +virtual ~RsDiscPgpCertItem(); + +virtual void clear(); +virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + + std::string pgpId; + std::string pgpCert; +}; + + +class RsDiscContactItem: public RsDiscItem +{ + public: + + RsDiscContactItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_CONTACT) + { + setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT); + } + +virtual ~RsDiscContactItem(); + +virtual void clear(); +virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + + std::string pgpId; + std::string sslId; + + // COMMON + std::string location; + std::string version; + + uint32_t netMode; /* Mandatory */ + uint16_t vs_disc; /* Mandatory */ + uint16_t vs_dht; /* Mandatory */ + uint32_t lastContact; + + bool isHidden; /* not serialised */ + + // HIDDEN. + std::string hiddenAddr; + uint16_t hiddenPort; + + // STANDARD. + + RsTlvIpAddress localAddrV4; /* Mandatory */ + RsTlvIpAddress extAddrV4; /* Mandatory */ + + RsTlvIpAddress localAddrV6; /* Mandatory */ + RsTlvIpAddress extAddrV6; /* Mandatory */ + + std::string dyndns; + + RsTlvIpAddrSet localAddrList; + RsTlvIpAddrSet extAddrList; +}; + +#if 0 +class RsDiscServicesItem: public RsDiscItem +{ + public: + + RsDiscServicesItem() + :RsDiscItem(RS_PKT_SUBTYPE_DISC_SERVICES) + { + setPriorityLevel(QOS_PRIORITY_RS_DISC_SERVICES); + } + +virtual ~RsDiscServicesItem(); + +virtual void clear(); +virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); + + + std::string version; + RsTlvServiceIdMap mServiceIdMap; +}; + +#endif + + +class RsDiscSerialiser: public RsSerialType +{ + public: + RsDiscSerialiser() + :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC) + { return; } + +virtual ~RsDiscSerialiser() { return; } + +virtual uint32_t size(RsItem *); +virtual bool serialise (RsItem *item, void *data, uint32_t *size); +virtual RsItem * deserialise(void *data, uint32_t *size); + + private: + +virtual uint32_t sizePgpList(RsDiscPgpListItem *); +virtual bool serialisePgpList(RsDiscPgpListItem *item, void *data, uint32_t *size); +virtual RsDiscPgpListItem *deserialisePgpList(void *data, uint32_t *size); + +virtual uint32_t sizePgpCert(RsDiscPgpCertItem *); +virtual bool serialisePgpCert(RsDiscPgpCertItem *item, void *data, uint32_t *size); +virtual RsDiscPgpCertItem *deserialisePgpCert(void *data, uint32_t *size); + +virtual uint32_t sizeContact(RsDiscContactItem *); +virtual bool serialiseContact(RsDiscContactItem *item, void *data, uint32_t *size); +virtual RsDiscContactItem *deserialiseContact(void *data, uint32_t *size); + +#if 0 +virtual uint32_t sizeServices(RsDiscServicesItem *); +virtual bool serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *size); +virtual RsDiscServicesItem *deserialiseServices(void *data, uint32_t *size); + +#endif + +}; + + +#endif // RS_DISC_ITEMS_H + diff --git a/libretroshare/src/serialiser/rsheartbeatitems.cc b/libretroshare/src/serialiser/rsheartbeatitems.cc new file mode 100644 index 000000000..55f1e844a --- /dev/null +++ b/libretroshare/src/serialiser/rsheartbeatitems.cc @@ -0,0 +1,206 @@ + +/* + * libretroshare/src/serialiser: rsheartbeatitems.cc + * + * RetroShare Serialiser. + * + * Copyright 2013-2013 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "serialiser/rsbaseserial.h" +#include "serialiser/rsserviceids.h" +#include "serialiser/rsheartbeatitems.h" + +/*** + * #define HEART_DEBUG 1 + ***/ + +#define HEART_DEBUG 1 + +#include + +/*************************************************************************/ + +uint32_t RsHeartbeatSerialiser::size(RsItem *i) +{ + RsHeartbeatItem *beat; + + if (NULL != (beat = dynamic_cast(i))) + { + return sizeHeartbeat(beat); + } + return 0; +} + +/* serialise the data to the buffer */ +bool RsHeartbeatSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) +{ + RsHeartbeatItem *beat; + + if (NULL != (beat = dynamic_cast(i))) + { + return serialiseHeartbeat(beat, data, pktsize); + } + return false; +} + +RsItem *RsHeartbeatSerialiser::deserialise(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_HEARTBEAT != getRsItemService(rstype))) + { + +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::deserialise() Wrong Type" << std::endl; +#endif + return NULL; + } + + switch(getRsItemSubType(rstype)) + { + case RS_PKT_SUBTYPE_HEARTBEAT_PULSE: + return deserialiseHeartbeat(data, pktsize); + break; + default: + return NULL; + break; + } + return NULL; +} + +/*************************************************************************/ + + +void RsHeartbeatItem::clear() +{ +} + +std::ostream &RsHeartbeatItem::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsHeartbeatItem", indent); + printRsItemEnd(out, "RsHeartbeatItem", indent); + return out; +} + +uint32_t RsHeartbeatSerialiser::sizeHeartbeat(RsHeartbeatItem */*item*/) +{ + uint32_t s = 8; /* header */ + return s; +} + +/* serialise the data to the buffer */ +bool RsHeartbeatSerialiser::serialiseHeartbeat(RsHeartbeatItem *item, void *data, uint32_t *pktsize) +{ + uint32_t tlvsize = sizeHeartbeat(item); + uint32_t offset = 0; + + if (*pktsize < tlvsize) + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::serialiseHeartbeat() Not enough space" << std::endl; +#endif + return false; /* not enough space */ + } + + *pktsize = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, *pktsize, item->PacketId(), *pktsize); + + /* skip the header */ + offset += 8; + + if (offset != tlvsize) + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::serialiseHeartbeat() size error" << std::endl; +#endif + ok = false; + } + + return ok; +} + +RsHeartbeatItem *RsHeartbeatSerialiser::deserialiseHeartbeat(void *data, uint32_t *pktsize) +{ + /* get the type and size */ + uint32_t rstype = getRsItemId(data); + uint32_t rssize = getRsItemSize(data); + + uint32_t offset = 0; + + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || + (RS_SERVICE_TYPE_HEARTBEAT != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_HEARTBEAT_PULSE != getRsItemSubType(rstype))) + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() Wrong Type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*pktsize < rssize) /* check size */ + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() size error" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *pktsize = rssize; + + bool ok = true; + + /* ready to load */ + RsHeartbeatItem *item = new RsHeartbeatItem(); + item->clear(); + + /* skip the header */ + offset += 8; + + if (offset != rssize) + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() size error2" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) + { +#ifdef HEART_DEBUG + std::cerr << "RsHeartbeatSerialiser::deserialiseHeartbeat() ok = false" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + + +/*************************************************************************/ diff --git a/libretroshare/src/serialiser/rsheartbeatitems.h b/libretroshare/src/serialiser/rsheartbeatitems.h new file mode 100644 index 000000000..cfabae2ee --- /dev/null +++ b/libretroshare/src/serialiser/rsheartbeatitems.h @@ -0,0 +1,72 @@ +/* + * libretroshare/src/serialiser: rsheartbeatitems.h + * + * Serialiser for RetroShare. + * + * Copyright 2004-2013 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + + +#ifndef RS_HEARTBEAT_ITEMS_H +#define RS_HEARTBEAT_ITEMS_H + +#include "serialiser/rsserial.h" +#include "serialiser/rsserviceids.h" + +const uint8_t RS_PKT_SUBTYPE_HEARTBEAT_PULSE = 0x01; + +class RsHeartbeatItem: public RsItem +{ +public: + RsHeartbeatItem() :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_HEARTBEAT, RS_PKT_SUBTYPE_HEARTBEAT_PULSE) + { + setPriorityLevel(QOS_PRIORITY_RS_HEARTBEAT_PULSE) ; + } + virtual ~RsHeartbeatItem() {} + + virtual void clear(); + virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); +}; + +class RsHeartbeatSerialiser: public RsSerialType +{ + public: + RsHeartbeatSerialiser() + :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_HEARTBEAT) + { return; } + +virtual ~RsHeartbeatSerialiser() { return; } + +virtual uint32_t size(RsItem *); +virtual bool serialise (RsItem *item, void *data, uint32_t *size); +virtual RsItem * deserialise(void *data, uint32_t *size); + + private: + +virtual uint32_t sizeHeartbeat(RsHeartbeatItem *); +virtual bool serialiseHeartbeat(RsHeartbeatItem *item, void *data, uint32_t *size); +virtual RsHeartbeatItem *deserialiseHeartbeat(void *data, uint32_t *size); + +}; + + +#endif // RS_DISC_ITEMS_H + diff --git a/libretroshare/src/serialiser/rsserviceids.h b/libretroshare/src/serialiser/rsserviceids.h index 8095ed575..73e08d42d 100644 --- a/libretroshare/src/serialiser/rsserviceids.h +++ b/libretroshare/src/serialiser/rsserviceids.h @@ -46,6 +46,7 @@ const uint16_t RS_SERVICE_TYPE_CHAT = 0x0012; const uint16_t RS_SERVICE_TYPE_MSG = 0x0013; const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014; const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015; +const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016; /* BanList Still Testing at the moment - Service Only */ const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101; diff --git a/libretroshare/src/serialiser/rstlvbase.h b/libretroshare/src/serialiser/rstlvbase.h index a7697c6cd..0f1ecb97c 100644 --- a/libretroshare/src/serialiser/rstlvbase.h +++ b/libretroshare/src/serialiser/rstlvbase.h @@ -131,10 +131,13 @@ const uint16_t TLV_TYPE_STR_MSG = 0x0057; const uint16_t TLV_TYPE_STR_SUBJECT = 0x0058; const uint16_t TLV_TYPE_STR_LINK = 0x0059; const uint16_t TLV_TYPE_STR_GENID = 0x005a; -const uint16_t TLV_TYPE_STR_GPGID = 0x005b; +const uint16_t TLV_TYPE_STR_GPGID = 0x005b; /* depreciated */ +const uint16_t TLV_TYPE_STR_PGPID = 0x005b; /* same as GPG */ const uint16_t TLV_TYPE_STR_LOCATION = 0x005c; -const uint16_t TLV_TYPE_STR_CERT_GPG = 0x005d; +const uint16_t TLV_TYPE_STR_CERT_GPG = 0x005d; +const uint16_t TLV_TYPE_STR_PGPCERT = 0x005d; /* same as CERT_GPG */ const uint16_t TLV_TYPE_STR_CERT_SSL = 0x005e; +const uint16_t TLV_TYPE_STR_VERSION = 0x005f; /* Wide Chars (4 bytes per char) for internationalisation */ const uint16_t TLV_TYPE_WSTR_PEERID = 0x0060; diff --git a/libretroshare/src/serialiser/rstlvtypes.h b/libretroshare/src/serialiser/rstlvtypes.h index 45e6e1e68..4fd45bd4a 100644 --- a/libretroshare/src/serialiser/rstlvtypes.h +++ b/libretroshare/src/serialiser/rstlvtypes.h @@ -33,6 +33,8 @@ #include #include +#include + #include #include @@ -246,6 +248,29 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent); }; +class RsTlvIntStringMap: public RsTlvItem +{ + public: + RsTlvIntStringMap() { return; } +virtual ~RsTlvIntStringMap() { return; } +virtual uint32_t TlvSize(); +virtual void TlvClear(); +virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */ +virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */ +virtual std::ostream &print(std::ostream &out, uint16_t indent); + + uint32_t mapType; + std::map map; +}; + + +class RsTlvServiceIdMap: public RsTlvIntStringMap +{ + public: + RsTlvServiceIdMap(); +}; + + class RsTlvImage: public RsTlvItem { public: diff --git a/libretroshare/src/services/p3disc.h b/libretroshare/src/services/p3disc.h deleted file mode 100644 index 4a3e8aca5..000000000 --- a/libretroshare/src/services/p3disc.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * libretroshare/src/services: p3disc.h - * - * Services for RetroShare. - * - * Copyright 2004-2008 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#ifndef MRK_PQI_AUTODISC_H -#define MRK_PQI_AUTODISC_H - -// The AutoDiscovery Class - -#include -#include - -// system specific network headers -#include "pqi/pqinetwork.h" - -#include "pqi/pqi.h" -#include "pqi/pqipersongrp.h" - -class p3ConnectMgr; - -#include "pqi/pqimonitor.h" -#include "serialiser/rsdiscitems.h" -#include "services/p3service.h" -#include "pqi/authgpg.h" - -class autoserver -{ - public: - autoserver() - :ts(0), discFlags(0) { return;} - - std::string id; - struct sockaddr_storage localAddr; - struct sockaddr_storage remoteAddr; - - time_t ts; - uint32_t discFlags; -}; - - -class autoneighbour: public autoserver -{ - public: - autoneighbour() - :autoserver(), authoritative(false) {} - - bool authoritative; - bool validAddrs; - - std::map neighbour_of; - -}; - -class p3PeerMgr; -class p3LinkMgr; -class p3NetMgr; - - -class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthGPGService -{ - public: - - - p3disc(p3PeerMgr *pm, p3LinkMgr *lm, p3NetMgr *nm, pqipersongrp *persGrp); - - /************* from pqiMonitor *******************/ -virtual void statusChange(const std::list &plist); - /************* from pqiMonitor *******************/ - -int tick(); - - /* GUI requires access */ -bool potentialGPGproxies(const std::string& id, std::list &proxyGPGIds); -bool potentialproxies(const std::string& id, std::list &proxyIds); -void getversions(std::map &versions); -void getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount); - - /************* from AuthGPService ****************/ -virtual AuthGPGOperation *getGPGOperation(); -virtual void setGPGOperation(AuthGPGOperation *operation); - - protected: -/*****************************************************************/ -/*********************** p3config ******************************/ -/* Key Functions to be overloaded for Full Configuration */ -virtual RsSerialiser *setupSerialiser(); -virtual bool saveList(bool &cleanup, std::list&); -virtual bool loadList(std::list& load); -/*****************************************************************/ - - private: - - -void sendAllInfoToJustConnectedPeer(const std::string &id); -void sendJustConnectedPeerInfoToAllPeer(const std::string &id); - - /* Network Output */ -//void sendOwnDetails(std::string to); -void sendOwnVersion(std::string to); -RsDiscReply *createDiscReply(const std::string &to, const std::string &about); -//void sendPeerIssuer(std::string to, std::string about); -void sendHeartbeat(std::string to); -void askInfoToAllPeers(std::string about); - - /* Network Input */ -int handleIncoming(); -void recvAskInfo(RsDiscAskInfo *item); -void recvPeerDetails(RsDiscReply *item, const std::string &certGpgId); -//void recvPeerIssuerMsg(RsDiscIssuer *item); -void recvPeerVersionMsg(RsDiscVersion *item); -void recvHeartbeatMsg(RsDiscHeartbeat *item); -void recvDiscReply(RsDiscReply *dri); - -void removeFriend(std::string ssl_id); //keep tracks of removed friend so we're not gonna add them again immediately - -/* handle network shape */ -int addDiscoveryData(const std::string& fromId, const std::string& aboutId, - const std::string& fromGPGId,const std::string& aboutGPGId, - const struct sockaddr_storage &laddr, const struct sockaddr_storage &raddr, - uint32_t flags, time_t ts,bool& new_info); - -//int idServers(); - - private: - - p3PeerMgr *mPeerMgr; - p3LinkMgr *mLinkMgr; - p3NetMgr *mNetMgr; - - pqipersongrp *mPqiPersonGrp; - - /* data */ - RsMutex mDiscMtx; - - time_t mLastSentHeartbeatTime; - bool mDiscEnabled; - - //std::map deletedSSLFriendsIds; - - - std::map > mSendIdList; - std::list mPendingDiscReplyInList; - - // Neighbors at the gpg level. - std::map > gpg_neighbors ; - - // Original mapping. - std::map neighbours; - - // Rs Version. - std::map versions; -}; - - - - -#endif // MRK_PQI_AUTODISC_H diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3discovery2.cc similarity index 51% rename from libretroshare/src/services/p3disc.cc rename to libretroshare/src/services/p3discovery2.cc index 710c5c929..606c6e631 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3discovery2.cc @@ -1,13 +1,13 @@ /* - * libretroshare/src/services: p3disc.cc + * libretroshare/src/services: p3discovery2.cc * * Services for RetroShare. * - * Copyright 2004-2008 by Robert Fernie. + * Copyright 2004-2013 by Robert Fernie. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public - * License Version 2 as published by the Free Software Foundation. + * License Version 2.1 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,6 +23,1269 @@ * */ +#include "services/p3discovery2.h" +#include "util/rsversion.h" + +#include "retroshare/rsiface.h" + + +// Interface pointer. +RsDisc *rsDisc = NULL; + +#define P3DISC_DEBUG 1 + + + +bool populateContactInfo(const peerState &detail, RsDiscContactItem *pkt) +{ + pkt->clear(); + + pkt->pgpId = detail.gpg_id; + pkt->sslId = detail.id; + pkt->location = detail.location; + pkt->version = ""; + pkt->netMode = detail.netMode; + pkt->vs_disc = detail.vs_disc; + pkt->vs_dht = detail.vs_dht; + + pkt->lastContact = time(NULL); + + if (detail.hiddenNode) + { + pkt->isHidden = true; + pkt->hiddenAddr = detail.hiddenDomain; + pkt->hiddenPort = detail.hiddenPort; + } + else + { + pkt->isHidden = false; + + pkt->localAddrV4.addr = detail.localaddr; + pkt->extAddrV4.addr = detail.serveraddr; + sockaddr_storage_clear(pkt->localAddrV6.addr); + sockaddr_storage_clear(pkt->extAddrV6.addr); + + pkt->dyndns = detail.dyndns; + detail.ipAddrs.mLocal.loadTlv(pkt->localAddrList); + detail.ipAddrs.mExt.loadTlv(pkt->extAddrList); + } + + return true; +} + +void DiscPgpInfo::mergeFriendList(const std::list &friends) +{ + std::list::const_iterator it; + for(it = friends.begin(); it != friends.end(); it++) + { + mFriendSet.insert(*it); + } +} + + +p3discovery2::p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr) +:p3Service(RS_SERVICE_TYPE_DISC), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), + mDiscMtx("p3discovery2") +{ + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + addSerialType(new RsDiscSerialiser()); + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::p3discovery2()"; + std::cerr << std::endl; +#endif + + mLastPgpUpdate = 0; + + // Add self into PGP FriendList. + mFriendList[AuthGPG::getAuthGPG()->getGPGOwnId()] = DiscPgpInfo(); + + return; +} + +p3discovery2::~p3discovery2() +{ + return; + +} + + +void p3discovery2::addFriend(const SSLID &sslId) +{ + PGPID pgpId = getPGPId(sslId); + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mFriendList.find(pgpId); + if (it == mFriendList.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() adding pgp entry: " << pgpId; + std::cerr << std::endl; +#endif + + mFriendList[pgpId] = DiscPgpInfo(); + + it = mFriendList.find(pgpId); + } + + + /* now add SSLID */ + + std::map::iterator sit; + sit = it->second.mSslIds.find(sslId); + if (sit == it->second.mSslIds.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() adding ssl entry: " << sslId; + std::cerr << std::endl; +#endif + + it->second.mSslIds[sslId] = DiscSslInfo(); + sit = it->second.mSslIds.find(sslId); + } + + /* update Settings from peerMgr */ + peerState detail; + if (mPeerMgr->getFriendNetStatus(sit->first, detail)) + { + sit->second.mDiscStatus = detail.vs_disc; + } + else + { + sit->second.mDiscStatus = RS_VS_DISC_OFF; + } +} + +void p3discovery2::removeFriend(const SSLID &sslId) +{ + PGPID pgpId = getPGPId(sslId); + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mFriendList.find(pgpId); + if (it == mFriendList.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::removeFriend() missing pgp entry: " << pgpId; + std::cerr << std::endl; +#endif + return; + } + + std::map::iterator sit; + sit = it->second.mSslIds.find(sslId); + if (sit == it->second.mSslIds.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() missing ssl entry: " << sslId; + std::cerr << std::endl; +#endif + return; + } + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() removing ssl entry: " << sslId; + std::cerr << std::endl; +#endif + it->second.mSslIds.erase(sit); + + if (it->second.mSslIds.empty()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() pgpId now has no sslIds"; + std::cerr << std::endl; +#endif + /* pgp peer without any ssl entries -> check if they are still a real friend */ + if (!(AuthGPG::getAuthGPG()->isGPGAccepted(pgpId))) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::addFriend() pgpId is no longer a friend, removing"; + std::cerr << std::endl; +#endif + mFriendList.erase(it); + } + } +} + + +PGPID p3discovery2::getPGPId(const SSLID &id) +{ + PGPID pgpId; + mPeerMgr->getGpgId(id, pgpId); + return pgpId; +} + + +int p3discovery2::tick() +{ + return handleIncoming(); +} + +int p3discovery2::handleIncoming() +{ + RsItem *item = NULL; + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::handleIncoming()" << std::endl; +#endif + + int nhandled = 0; + // While messages read + while(NULL != (item = recvItem())) + { + RsDiscPgpListItem *pgplist = NULL; + RsDiscPgpCertItem *pgpcert = NULL; + RsDiscContactItem *contact = NULL; + nhandled++; + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::handleIncoming() Received Message!" << std::endl; + item -> print(std::cerr); + std::cerr << std::endl; +#endif + + if (NULL != (contact = dynamic_cast (item))) + { + if (item->PeerId() == contact->sslId) /* self describing */ + { + recvOwnContactInfo(item->PeerId(), contact); + } + else if (rsPeers->servicePermissionFlags_sslid(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY) + { + processContactInfo(item->PeerId(), contact); + } + else + { + /* not allowed */ + delete item; + } + continue; + } + + /* any other packets should be dropped if they don't have permission */ + if(!(rsPeers->servicePermissionFlags_sslid(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY)) + { + delete item; + continue; + } + + if (NULL != (pgpcert = dynamic_cast (item))) + { + recvPGPCertificate(item->PeerId(), pgpcert); + } + else if (NULL != (pgplist = dynamic_cast (item))) + { + /* two types */ + if (pgplist->mode == DISC_PGP_LIST_MODE_FRIENDS) + { + processPGPList(pgplist->PeerId(), pgplist); + + } + else if (pgplist->mode == DISC_PGP_LIST_MODE_GETCERT) + { + recvPGPCertificateRequest(pgplist->PeerId(), pgplist); + } + else + { + delete item ; + } + } + else + { +#ifdef P3DISC_DEBUG + std::cerr << "p3disc::handleIncoming() Unknown Received Message!" << std::endl; + item -> print(std::cerr); + std::cerr << std::endl; +#endif + delete item; + } + } + +#ifdef P3DISC_DEBUG + std::cerr << "p3disc::handleIncoming() finished." << std::endl; +#endif + + return nhandled; +} + + + +void p3discovery2::sendOwnContactInfo(const SSLID &sslid) +{ + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendOwnContactInfo()"; + std::cerr << std::endl; +#endif + peerState detail; + if (mPeerMgr->getOwnNetStatus(detail)) + { + RsDiscContactItem *pkt = new RsDiscContactItem(); + populateContactInfo(detail, pkt); + pkt->version = RsUtil::retroshareVersion(); + + pkt->PeerId(sslid); + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendOwnContactInfo() sending:" << std::endl; + pkt -> print(std::cerr); + std::cerr << std::endl; +#endif + sendItem(pkt); + } +} + + +void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +{ + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvOwnContactInfo()"; + std::cerr << std::endl; + + std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl; + std::cerr << " -> vs_disc : " << item->vs_disc << std::endl; + std::cerr << " -> vs_dht : " << item->vs_dht << std::endl; + std::cerr << " -> network mode : " << item->netMode << std::endl; + std::cerr << " -> location : " << item->location << std::endl; + std::cerr << std::endl; +#endif + + // Peer Own Info replaces the existing info, because the + // peer is the primary source of his own IPs. + + mPeerMgr->setNetworkMode(fromId, item->netMode); + mPeerMgr->setLocation(fromId, item->location); + mPeerMgr->setVisState(fromId, item->vs_disc, item->vs_dht); + + setPeerVersion(fromId, item->version); + updatePeerAddresses(item); + + // This information will be sent out to online peers, at the receipt of their PGPList. + // It is important that PGPList is received after the OwnContactItem. + // This should happen, but is not enforced by the protocol. + + // start peer list exchange. + sendPGPList(fromId); + + // Update mDiscStatus. + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + PGPID pgpId = getPGPId(fromId); + std::map::iterator it = mFriendList.find(pgpId); + if (it != mFriendList.end()) + { + std::map::iterator sit = it->second.mSslIds.find(fromId); + if (sit != it->second.mSslIds.end()) + { + sit->second.mDiscStatus = item->vs_disc; +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvOwnContactInfo()"; + std::cerr << "updating mDiscStatus to: " << sit->second.mDiscStatus; + std::cerr << std::endl; +#endif + } + else + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvOwnContactInfo()"; + std::cerr << " ERROR missing SSL Entry: " << fromId; + std::cerr << std::endl; +#endif + } + } + else + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvOwnContactInfo()"; + std::cerr << " ERROR missing PGP Entry: " << pgpId; + std::cerr << std::endl; +#endif + } + + // cleanup. + delete item; +} + +void p3discovery2::updatePeerAddresses(const RsDiscContactItem *item) +{ + if (item->isHidden) + { + mPeerMgr->setHiddenDomainPort(item->sslId, item->hiddenAddr, item->hiddenPort); + } + else + { + mPeerMgr->setLocalAddress(item->sslId, item->localAddrV4.addr); + mPeerMgr->setExtAddress(item->sslId, item->extAddrV4.addr); + mPeerMgr->setDynDNS(item->sslId, item->dyndns); + + updatePeerAddressList(item); + } +} + + +void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item) +{ + if (item->isHidden) + { + } + else + { + pqiIpAddrSet addrsFromPeer; + addrsFromPeer.mLocal.extractFromTlv(item->localAddrList); + addrsFromPeer.mExt.extractFromTlv(item->extAddrList); + +#ifdef P3DISC_DEBUG + std::cerr << "Setting address list to peer " << item->sslId << ", to be:" << std::endl ; + + std::string addrstr; + addrsFromPeer.printAddrs(addrstr); + std::cerr << addrstr; + std::cerr << std::endl; +#endif + mPeerMgr->updateAddressList(item->sslId, addrsFromPeer); + } +} + + +// Starts the Discovery process. +// should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status). +void p3discovery2::sendPGPList(const SSLID &toId) +{ + updatePgpFriendList(); + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendPGPList() to " << toId; + std::cerr << std::endl; +#endif + + RsDiscPgpListItem *pkt = new RsDiscPgpListItem(); + + pkt->mode = DISC_PGP_LIST_MODE_FRIENDS; + + std::map::const_iterator it; + for(it = mFriendList.begin(); it != mFriendList.end(); it++) + { + pkt->pgpIdSet.ids.push_back(it->first); + } + + pkt->PeerId(toId); + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendPGPList() sending:" << std::endl; + pkt->print(std::cerr); + std::cerr << std::endl; +#endif + + sendItem(pkt); +} + +void p3discovery2::updatePgpFriendList() +{ +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePgpFriendList()"; + std::cerr << std::endl; +#endif + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + +#define PGP_MAX_UPDATE_PERIOD 300 + + if (time(NULL) < mLastPgpUpdate + PGP_MAX_UPDATE_PERIOD ) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePgpFriendList() Already uptodate"; + std::cerr << std::endl; +#endif + return; + } + + mLastPgpUpdate = time(NULL); + + std::list pgpList; + std::set pgpSet; + + std::set::iterator sit; + std::list::iterator lit; + std::map::iterator it; + + PGPID ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId(); + AuthGPG::getAuthGPG()->getGPGAcceptedList(pgpList); + pgpList.push_back(ownPgpId); + + // convert to set for ordering. + for(lit = pgpList.begin(); lit != pgpList.end(); lit++) + { + pgpSet.insert(*lit); + } + + std::list pgpToAdd; + std::list pgpToRemove; + + + sit = pgpSet.begin(); + it = mFriendList.begin(); + while (sit != pgpSet.end() && it != mFriendList.end()) + { + if (*sit < it->first) + { + /* to add */ + pgpToAdd.push_back(*sit); + ++sit; + } + else if (it->first < *sit) + { + /* to remove */ + pgpToRemove.push_back(it->first); + ++it; + } + else + { + /* same - okay */ + ++sit; + ++it; + } + } + + /* more to add? */ + for(; sit != pgpSet.end(); sit++) + { + pgpToAdd.push_back(*sit); + } + + for(; it != mFriendList.end(); it++) + { + /* more to remove */ + pgpToRemove.push_back(it->first); + } + + for(lit = pgpToRemove.begin(); lit != pgpToRemove.end(); lit++) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePgpFriendList() Removing pgpId: " << *lit; + std::cerr << std::endl; +#endif + + it = mFriendList.find(*lit); + mFriendList.erase(it); + } + + for(lit = pgpToAdd.begin(); lit != pgpToAdd.end(); lit++) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePgpFriendList() Adding pgpId: " << *lit; + std::cerr << std::endl; +#endif + + mFriendList[*lit] = DiscPgpInfo(); + } + + /* finally install the pgpList on our own entry */ + DiscPgpInfo &ownInfo = mFriendList[ownPgpId]; + ownInfo.mergeFriendList(pgpList); + +} + + + + +void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item) +{ + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processPGPList() from " << fromId; + std::cerr << std::endl; +#endif + + std::map::iterator it; + PGPID fromPgpId = getPGPId(fromId); + it = mFriendList.find(fromPgpId); + if (it == mFriendList.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processPGPList() is not friend: " << fromId; + std::cerr << std::endl; +#endif + + // cleanup. + delete item; + return; + } + + bool requestUnknownPgpCerts = true; + peerState pstate; + mPeerMgr->getOwnNetStatus(pstate); + if (pstate.vs_disc != RS_VS_DISC_FULL) + { + requestUnknownPgpCerts = false; + } + + uint32_t linkType = mLinkMgr->getLinkType(fromId); + if ((linkType & RS_NET_CONN_SPEED_TRICKLE) || + (linkType & RS_NET_CONN_SPEED_LOW)) + { + std::cerr << "p3discovery2::processPGPList() Not requesting Certificates from: " << fromId; + std::cerr << " (low bandwidth)" << std::endl; + requestUnknownPgpCerts = false; + } + + if (requestUnknownPgpCerts) + { + std::list::const_iterator fit; + for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); fit++) + { + if (!AuthGPG::getAuthGPG()->isGPGId(*fit)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processPGPList() requesting PgpId: " << *fit; + std::cerr << " from SslId: " << fromId; + std::cerr << std::endl; +#endif + requestPGPCertificate(*fit, fromId); + } + } + } + + it->second.mergeFriendList(item->pgpIdSet.ids); + updatePeers_locked(fromId); + + // cleanup. + delete item; +} + + +/* + * -> Update Other Peers about B. + * -> Update B about Other Peers. + */ +void p3discovery2::updatePeers_locked(const SSLID &aboutId) +{ + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeers_locked() about " << aboutId; + std::cerr << std::endl; +#endif + + PGPID aboutPgpId = getPGPId(aboutId); + + std::map::const_iterator ait; + ait = mFriendList.find(aboutPgpId); + if (ait == mFriendList.end()) + { + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeers_locked() PgpId is not a friend: " << aboutPgpId; + std::cerr << std::endl; +#endif + return; + } + + std::set mutualFriends; + std::set onlineFriends; + std::set::const_iterator sit; + + const std::set &friendSet = ait->second.mFriendSet; + std::set::const_iterator fit; + for(fit = friendSet.begin(); fit != friendSet.end(); fit++) + { + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() checking their friend: " << *fit; + std::cerr << std::endl; +#endif + + std::map::const_iterator ffit; + ffit = mFriendList.find(*fit); + if (ffit == mFriendList.end()) + { + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() Ignoring not our friend"; + std::cerr << std::endl; +#endif + // Not our friend, or we have no Locations (SSL) for this PGPID (same difference) + continue; + } + + if (ffit->second.mFriendSet.find(aboutPgpId) != ffit->second.mFriendSet.end()) + { + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() Adding as Mutual Friend"; + std::cerr << std::endl; +#endif + mutualFriends.insert(*fit); + + std::map::const_iterator mit; + for(mit = ffit->second.mSslIds.begin(); + mit != ffit->second.mSslIds.end(); mit++) + { + SSLID sslid = mit->first; + if (mLinkMgr->isOnline(sslid)) + { + // TODO IGNORE if sslid == aboutId, or sslid == ownId. +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() Adding Online SSLID: " << sslid; + std::cerr << std::endl; +#endif + onlineFriends.insert(sslid); + } + } + } + } + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() Updating " << aboutId << " about Mutual Friends"; + std::cerr << std::endl; +#endif + // update aboutId about Other Peers. + for(fit = mutualFriends.begin(); fit != mutualFriends.end(); fit++) + { + sendContactInfo_locked(*fit, aboutId); + } + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::updatePeer_locked() Updating Online Peers about " << aboutId; + std::cerr << std::endl; +#endif + // update Other Peers about aboutPgpId. + for(sit = onlineFriends.begin(); sit != onlineFriends.end(); sit++) + { + // This could be more efficient, and only be specific about aboutId. + // but we'll leave it like this for the moment. + sendContactInfo_locked(aboutPgpId, *sit); + } +} + + +void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId) +{ +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() aboutPGPId: " << aboutId << " toId: " << toId; + std::cerr << std::endl; +#endif + if (!(rsPeers->servicePermissionFlags_sslid(toId) & RS_SERVICE_PERM_DISCOVERY)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() discovery disabled for SSLID: " << toId; + std::cerr << std::endl; +#endif + return; + } + + std::map::const_iterator it; + it = mFriendList.find(aboutId); + if (it == mFriendList.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() ERROR aboutId is not a friend"; + std::cerr << std::endl; +#endif + return; + } + + std::map::const_iterator sit; + for(sit = it->second.mSslIds.begin(); sit != it->second.mSslIds.end(); sit++) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() related sslId: " << sit->first; + std::cerr << std::endl; +#endif + + if ((sit->first == rsPeers->getOwnId()) || (sit->first == toId)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processContactInfo() not sending info on self or theirself"; + std::cerr << std::endl; +#endif + continue; + } + + if (sit->second.mDiscStatus != RS_VS_DISC_OFF) + { + peerState detail; + if (mPeerMgr->getFriendNetStatus(sit->first, detail)) + { + RsDiscContactItem *pkt = new RsDiscContactItem(); + populateContactInfo(detail, pkt); + pkt->PeerId(toId); + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() Sending"; + std::cerr << std::endl; + pkt->print(std::cerr); + std::cerr << std::endl; +#endif + sendItem(pkt); + } + else + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() No Net Status"; + std::cerr << std::endl; +#endif + } + } + else + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendContactInfo_locked() SSLID Hidden"; + std::cerr << std::endl; +#endif + } + } +} + + +void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactItem *item) +{ + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + if (item->sslId == rsPeers->getOwnId()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: "; + std::cerr << item->pgpId << " Ignoring Info on self"; + std::cerr << std::endl; +#endif + return; + } + + + /* */ + std::map::iterator it; + it = mFriendList.find(item->pgpId); + if (it == mFriendList.end()) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: "; + std::cerr << item->pgpId << " Not Friend."; + std::cerr << std::endl; + std::cerr << "p3discovery2::processContactInfo(" << fromId << ") THIS SHOULD NEVER HAPPEN!"; + std::cerr << std::endl; +#endif + + /* THESE ARE OUR FRIEND OF FRIENDS ... pass this information along to NetMgr & DHT... + * as we can track FOF and use them as potential Proxies / Relays + */ + + if (!item->isHidden) + { + /* add into NetMgr and non-search, so we can detect connect attempts */ + mNetMgr->netAssistFriend(item->sslId,false); + + /* inform NetMgr that we know this peer */ + mNetMgr->netAssistKnownPeer(item->sslId, item->extAddrV4.addr, + NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE); + } + return; + } + + bool should_notify_discovery = false; + std::map::iterator sit; + sit = it->second.mSslIds.find(item->sslId); + if (sit == it->second.mSslIds.end()) + { + /* insert! */ + DiscSslInfo sslInfo; + it->second.mSslIds[item->sslId] = sslInfo; + sit = it->second.mSslIds.find(item->sslId); + + should_notify_discovery = true; + + if (!mPeerMgr->isFriend(item->sslId)) + { + // Add with no disc by default. If friend already exists, it will do nothing + // NO DISC is important - otherwise, we'll just enter a nasty loop, + // where every addition triggers requests, then they are cleaned up, and readded... + + // This way we get their addresses, but don't advertise them until we get a + // connection. +#ifdef P3DISC_DEBUG + std::cerr << "--> Adding to friends list " << item->sslId << " - " << item->pgpId << std::endl; +#endif + mPeerMgr->addFriend(item->sslId, item->pgpId, item->netMode, RS_VS_DISC_OFF, RS_VS_DHT_FULL,(time_t)0,RS_SERVICE_PERM_ALL); + updatePeerAddresses(item); + } + } + + updatePeerAddressList(item); + + + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD); + + if(should_notify_discovery) + rsicontrol->getNotify().notifyDiscInfoChanged(); +} + + + +/* we explictly request certificates, instead of getting them all the time + */ +void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId) +{ +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::requestPGPCertificate() aboutId: " << aboutId << " to: " << toId; + std::cerr << std::endl; +#endif + + RsDiscPgpListItem *pkt = new RsDiscPgpListItem(); + + pkt->mode = DISC_PGP_LIST_MODE_GETCERT; + pkt->pgpIdSet.ids.push_back(aboutId); + pkt->PeerId(toId); + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::requestPGPCertificate() sending:" << std::endl; + pkt->print(std::cerr); + std::cerr << std::endl; +#endif + + sendItem(pkt); +} + + /* comment */ +void p3discovery2::recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item) +{ +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvPPGPCertificateRequest() from " << fromId; + std::cerr << std::endl; +#endif + + std::list::const_iterator it; + for(it = item->pgpIdSet.ids.begin(); it != item->pgpIdSet.ids.end(); it++) + { + // NB: This doesn't include own certificates? why not. + // shouldn't be a real problem. Peer must have own PgpCert already. + if (AuthGPG::getAuthGPG()->isGPGAccepted(*it)) + { + sendPGPCertificate(*it, fromId); + } + } + delete item; +} + + +void p3discovery2::sendPGPCertificate(const PGPID &aboutId, const SSLID &toId) +{ + + /* for Relay Connections (and other slow ones) we don't want to + * to waste bandwidth sending certificates. So don't add it. + */ + + uint32_t linkType = mLinkMgr->getLinkType(toId); + if ((linkType & RS_NET_CONN_SPEED_TRICKLE) || + (linkType & RS_NET_CONN_SPEED_LOW)) + { + std::cerr << "p3disc::sendPGPCertificate() Not sending Certificates to: " << toId; + std::cerr << " (low bandwidth)" << std::endl; + return; + } + + RsDiscPgpCertItem *item = new RsDiscPgpCertItem(); + item->pgpId = aboutId; + item->PeerId(toId); + + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::sendPGPCertificate() queuing for Cert generation:" << std::endl; + item->print(std::cerr); + std::cerr << std::endl; +#endif + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + /* queue it! */ + + mPendingDiscPgpCertOutList.push_back(item); +} + + +void p3discovery2::recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item) +{ + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::recvPGPCertificate() queuing for Cert loading" << std::endl; + std::cerr << std::endl; +#endif + + + /* should only happen if in FULL Mode */ + peerState pstate; + mPeerMgr->getOwnNetStatus(pstate); + if (pstate.vs_disc != RS_VS_DISC_FULL) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3disc::recvPGPCertificate() Not Loading Certificates as in MINIMAL MODE"; + std::cerr << std::endl; +#endif + + delete item; + } + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + /* push this back to be processed by pgp when possible */ + + mPendingDiscPgpCertInList.push_back(item); +} + + + + + + /************* from pqiMonitor *******************/ +void p3discovery2::statusChange(const std::list &plist) +{ +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::statusChange()" << std::endl; +#endif + + std::list::const_iterator pit; + for(pit = plist.begin(); pit != plist.end(); pit++) + { + if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::statusChange() Starting Disc with: " << pit->id << std::endl; +#endif + sendOwnContactInfo(pit->id); + } + else if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::statusChange() Removing Friend: " << pit->id << std::endl; +#endif + removeFriend(pit->id); + } + else if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_NEW)) + { +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::statusChange() Adding Friend: " << pit->id << std::endl; +#endif + addFriend(pit->id); + } + } +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::statusChange() finished." << std::endl; +#endif + return; +} + + + + /*************************************************************************************/ + /* Extracting Network Graph Details */ + /*************************************************************************************/ +bool p3discovery2::getDiscFriends(const std::string& id, std::list &proxyIds) +{ + // This is treated appart, because otherwise we don't receive any disc info about us + if(id == rsPeers->getOwnId()) // SSL id + return rsPeers->getFriendList(proxyIds) ; + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::const_iterator it; + PGPID pgp_id = getPGPId(id); + + it = mFriendList.find(pgp_id); + if (it == mFriendList.end()) + { + // ERROR. + return false; + } + + // For each of their friends that we know, grab that set of SSLIDs. + const std::set &friendSet = it->second.mFriendSet; + std::set::const_iterator fit; + for(fit = friendSet.begin(); fit != friendSet.end(); fit++) + { + it = mFriendList.find(*fit); + if (it == mFriendList.end()) + { + continue; + } + + std::map::const_iterator sit; + for(sit = it->second.mSslIds.begin(); + sit != it->second.mSslIds.end(); sit++) + { + proxyIds.push_back(sit->first); + } + } + return true; + +} + + +bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list &proxyPgpIds) +{ + /* find id -> and extract the neighbour_of ids */ + + if(pgp_id == rsPeers->getGPGOwnId()) // SSL id // This is treated appart, because otherwise we don't receive any disc info about us + return rsPeers->getGPGAcceptedList(proxyPgpIds) ; + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::const_iterator it; + it = mFriendList.find(pgp_id); + if (it == mFriendList.end()) + { + // ERROR. + return false; + } + + std::set::const_iterator fit; + for(fit = it->second.mFriendSet.begin(); fit != it->second.mFriendSet.end(); fit++) + { + proxyPgpIds.push_back(*fit); + } + return true; +} + + +bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) +{ + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::const_iterator it; + it = mLocationMap.find(peerId); + if (it == mLocationMap.end()) + { + // MISSING. + return false; + } + + version = it->second.mVersion; + return true; +} + + +bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version) +{ + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it; + it = mLocationMap.find(peerId); + if (it == mLocationMap.end()) + { + mLocationMap[peerId] = DiscPeerInfo(); + it = mLocationMap.find(peerId); + } + + it->second.mVersion = version; + return true; +} + + +bool p3discovery2::getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) +{ + if (sendCount == NULL && recvCount == NULL) { + /* Nothing to do */ + return false; + } + + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + if (sendCount) { + *sendCount = mPendingDiscPgpCertOutList.size(); + } + + if (recvCount) { + *recvCount = mPendingDiscPgpCertInList.size(); + } + return true; +} + + + +/*************************************************************************************/ +/* AuthGPGService */ +/*************************************************************************************/ +AuthGPGOperation *p3discovery2::getGPGOperation() +{ + { + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + /* process disc reply in list */ + if (!mPendingDiscPgpCertInList.empty()) { + RsDiscPgpCertItem *item = mPendingDiscPgpCertInList.front(); + mPendingDiscPgpCertInList.pop_front(); + + return new AuthGPGOperationLoadOrSave(true, item->pgpId, item->pgpCert, item); + } + } + + { + RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ + + /* process disc reply in list */ + if (!mPendingDiscPgpCertOutList.empty()) { + RsDiscPgpCertItem *item = mPendingDiscPgpCertOutList.front(); + mPendingDiscPgpCertOutList.pop_front(); + + return new AuthGPGOperationLoadOrSave(false, item->pgpId, "", item); + } + } + return NULL; +} + +void p3discovery2::setGPGOperation(AuthGPGOperation *operation) +{ + AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast(operation); + if (loadOrSave) + { + RsDiscPgpCertItem *item = (RsDiscPgpCertItem *) loadOrSave->m_userdata; + if (!item) + { + return; + } + + if (loadOrSave->m_load) + { + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::setGPGOperation() Loaded Cert" << std::endl; + item->print(std::cerr, 5); + std::cerr << std::endl; +#endif + // It has already been processed by PGP. + delete item; + } + else + { + // Attaching Certificate. + item->pgpCert = loadOrSave->m_certGpg; + +#ifdef P3DISC_DEBUG + std::cerr << "p3discovery2::setGPGOperation() Sending Message:" << std::endl; + item->print(std::cerr, 5); +#endif + + // Send off message + sendItem(item); + } + return; + } + + /* ignore other operations */ +} + + + +#if 0 +/***************************************************************************************/ +/***************************************************************************************/ +/************** OLD CODE ***************************/ +/***************************************************************************************/ +/***************************************************************************************/ + #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" @@ -496,8 +1759,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a rsPeerNetItem.netMode = detail.netMode; rsPeerNetItem.visState = detail.visState; rsPeerNetItem.lastContact = detail.lastcontact; - rsPeerNetItem.localAddr.addr = detail.localaddr; - rsPeerNetItem.extAddr.addr = detail.serveraddr; + rsPeerNetItem.currentlocaladdr = detail.localaddr; + rsPeerNetItem.currentremoteaddr = detail.serveraddr; rsPeerNetItem.dyndns = detail.dyndns; detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList); detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList); @@ -526,8 +1789,8 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a rsPeerNetItem.netMode = detail.netMode; rsPeerNetItem.visState = detail.visState; rsPeerNetItem.lastContact = time(NULL); - rsPeerNetItem.localAddr.addr = detail.localaddr; - rsPeerNetItem.extAddr.addr = detail.serveraddr; + rsPeerNetItem.currentlocaladdr = detail.localaddr; + rsPeerNetItem.currentremoteaddr = detail.serveraddr; rsPeerNetItem.dyndns = detail.dyndns; detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem.localAddrList); detail.ipAddrs.mExt.loadTlv(rsPeerNetItem.extAddrList); @@ -677,7 +1940,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId) bool new_info = false; addDiscoveryData(item->PeerId(), pit->pid,item_gpg_id, - item->aboutId, pit->localAddr.addr, pit->extAddr.addr, 0, time(NULL),new_info); + item->aboutId, pit->currentlocaladdr, pit->currentremoteaddr, 0, time(NULL),new_info); if(new_info) should_notify_discovery = true ; @@ -724,7 +1987,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId) mNetMgr->netAssistFriend(pit->pid,false); /* inform NetMgr that we know this peer */ - mNetMgr->netAssistKnownPeer(pit->pid, pit->extAddr.addr, + mNetMgr->netAssistKnownPeer(pit->pid, pit->currentremoteaddr, NETASSIST_KNOWN_PEER_FOF | NETASSIST_KNOWN_PEER_OFFLINE); continue; @@ -752,10 +2015,10 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId) if (mPeerMgr->setLocation(pit->pid, pit->location)) { peerDataChanged = true; } - if (mPeerMgr->setLocalAddress(pit->pid, pit->localAddr.addr)) { + if (mPeerMgr->setLocalAddress(pit->pid, pit->currentlocaladdr)) { peerDataChanged = true; } - if (mPeerMgr->setExtAddress(pit->pid, pit->extAddr.addr)) { + if (mPeerMgr->setExtAddress(pit->pid, pit->currentremoteaddr)) { peerDataChanged = true; } if (mPeerMgr->setVisState(pit->pid, pit->visState)) { @@ -1024,7 +2287,7 @@ void p3disc::setGPGOperation(AuthGPGOperation *operation) /*************************************************************************************/ /* Storing Network Graph */ /*************************************************************************************/ -int p3disc::addDiscoveryData(const std::string& fromId, const std::string& aboutId,const std::string& from_gpg_id,const std::string& about_gpg_id, const struct sockaddr_storage &laddr, const struct sockaddr_storage &raddr, uint32_t flags, time_t ts,bool& new_info) +int p3disc::addDiscoveryData(const std::string& fromId, const std::string& aboutId,const std::string& from_gpg_id,const std::string& about_gpg_id, const struct sockaddr_in& laddr, const struct sockaddr_in& raddr, uint32_t flags, time_t ts,bool& new_info) { RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ @@ -1242,82 +2505,4 @@ int p3disc::idServers() // return (int) (pow(10.0, trange) - 1.5); // (int) xxx98.5 -> xxx98 //} -// -----------------------------------------------------------------------------------// -// -------------------------------- Config functions ------------------------------ // -// -----------------------------------------------------------------------------------// -// -RsSerialiser *p3disc::setupSerialiser() -{ - RsSerialiser *rss = new RsSerialiser ; - rss->addSerialType(new RsGeneralConfigSerialiser()); - return rss ; -} - -bool p3disc::saveList(bool& cleanup, std::list& /*lst*/) -{ - #ifdef P3DISC_DEBUG - std::cerr << "p3disc::saveList() called" << std::endl; - #endif - cleanup = true ; - -// DON'T KNOW WHY SSL IDS were saved -> the results are never used -#if 0 - // Now save config for network digging strategies - RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ; - std::map::iterator mapIt; - for (mapIt = deletedSSLFriendsIds.begin(); mapIt != deletedSSLFriendsIds.end(); mapIt++) - { - RsTlvKeyValue kv; - kv.key = mapIt->first; - rs_sprintf(kv.value, "%ld", mapIt->second); - vitem->tlvkvs.pairs.push_back(kv) ; - #ifdef P3DISC_DEBUG - std::cerr << "p3disc::saveList() saving : " << mapIt->first << " ; " << mapIt->second << std::endl ; - #endif - } - lst.push_back(vitem); -#endif - - return true ; -} - -bool p3disc::loadList(std::list& load) -{ - #ifdef P3DISC_DEBUG - std::cerr << "p3disc::loadList() Item Count: " << load.size() << std::endl; - #endif - - - RsStackMutex stack(mDiscMtx); /****** STACK LOCK MUTEX *******/ - - /* load the list of accepted gpg keys */ - std::list::iterator it; - for(it = load.begin(); it != load.end(); it++) - { -// DON'T KNOW WHY SSL IDS were saved -> the results are never used -#if 0 - RsConfigKeyValueSet *vitem = dynamic_cast(*it); - - if(vitem) - { - #ifdef P3DISC_DEBUG - std::cerr << "p3disc::loadList() General Variable Config Item:" << std::endl; - vitem->print(std::cerr, 10); - std::cerr << std::endl; - #endif - - std::list::iterator kit; - for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) - { - std::istringstream instream(kit->value); // please do not use std::istringstream - time_t deleted_time_t; - instream >> deleted_time_t; - deletedSSLFriendsIds[kit->key] = deleted_time_t; - } - } -#endif - - delete (*it); - } - return true; -} +#endif // #if 0 diff --git a/libretroshare/src/services/p3discovery2.h b/libretroshare/src/services/p3discovery2.h new file mode 100644 index 000000000..2b3984890 --- /dev/null +++ b/libretroshare/src/services/p3discovery2.h @@ -0,0 +1,151 @@ +/* + * libretroshare/src/services: p3discovery2.h + * + * Services for RetroShare. + * + * Copyright 2004-2013 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_SERVICES_DISCOVERY2_H +#define MRK_SERVICES_DISCOVERY2_H + +// Discovery2: Improved discovery service. + +#include "retroshare/rsdisc.h" + +#include "pqi/p3peermgr.h" +#include "pqi/p3linkmgr.h" +#include "pqi/p3netmgr.h" + +#include "pqi/pqimonitor.h" +#include "serialiser/rsdiscovery2items.h" +#include "services/p3service.h" +#include "pqi/authgpg.h" + + + +typedef std::string PGPID; +typedef std::string SSLID; + +class DiscSslInfo +{ + public: + DiscSslInfo() { mDiscStatus = 0; } + uint16_t mDiscStatus; +}; + +class DiscPeerInfo +{ + public: + DiscPeerInfo() {} + + std::string mVersion; + //uint32_t mStatus; +}; + +class DiscPgpInfo +{ + public: + DiscPgpInfo() {} + +void mergeFriendList(const std::list &friends); + + //PGPID mPgpId; + std::set mFriendSet; + std::map mSslIds; +}; + + + +class p3discovery2: public RsDisc, public p3Service, public pqiMonitor, public AuthGPGService +{ + public: + + p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr); +virtual ~p3discovery2(); + + /************* from pqiMonitor *******************/ + virtual void statusChange(const std::list &plist); + /************* from pqiMonitor *******************/ + + int tick(); + + /* external interface */ +virtual bool getDiscFriends(const std::string &id, std::list &friends); +virtual bool getDiscPgpFriends(const std::string &pgpid, std::list &gpg_friends); +virtual bool getPeerVersion(const std::string &id, std::string &version); +virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount); + + /************* from AuthGPService ****************/ +virtual AuthGPGOperation *getGPGOperation(); +virtual void setGPGOperation(AuthGPGOperation *operation); + + + private: + + PGPID getPGPId(const SSLID &id); + + int handleIncoming(); + void updatePgpFriendList(); + + void addFriend(const SSLID &sslId); + void removeFriend(const SSLID &sslId); + + void updatePeerAddresses(const RsDiscContactItem *item); + void updatePeerAddressList(const RsDiscContactItem *item); + + void sendOwnContactInfo(const SSLID &sslid); + void recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item); + + void sendPGPList(const SSLID &toId); + void processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item); + + void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info); + + void requestPGPCertificate(const PGPID &aboutId, const SSLID &toId); + void recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item); + void sendPGPCertificate(const PGPID &aboutId, const SSLID &toId); + void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); + + bool setPeerVersion(const SSLID &peerId, const std::string &version); + + private: + + p3PeerMgr *mPeerMgr; + p3LinkMgr *mLinkMgr; + p3NetMgr *mNetMgr; + + /* data */ + RsMutex mDiscMtx; + + void updatePeers_locked(const SSLID &aboutId); + void sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId); + + time_t mLastPgpUpdate; + + std::map mFriendList; + std::map mLocationMap; + + std::list mPendingDiscPgpCertInList; + std::list mPendingDiscPgpCertOutList; +}; + + +#endif // MRK_SERVICES_DISCOVERY2_H diff --git a/libretroshare/src/services/p3heartbeat.cc b/libretroshare/src/services/p3heartbeat.cc new file mode 100644 index 000000000..b431fdae7 --- /dev/null +++ b/libretroshare/src/services/p3heartbeat.cc @@ -0,0 +1,122 @@ +/* + * libretroshare/src/services: p3heartbeat.cc + * + * Services for RetroShare. + * + * Copyright 2004-2013 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "services/p3heartbeat.h" +#include "serialiser/rsheartbeatitems.h" + +#define HEART_DEBUG 1 + + +p3heartbeat::p3heartbeat(p3LinkMgr *linkMgr, pqipersongrp *pqipg) +:p3Service(RS_SERVICE_TYPE_HEARTBEAT), mLinkMgr(linkMgr), mPqiPersonGrp(pqipg), + mHeartMtx("p3heartbeat") +{ + RsStackMutex stack(mHeartMtx); /********** STACK LOCKED MTX ******/ + + addSerialType(new RsHeartbeatSerialiser()); + +#ifdef HEART_DEBUG + std::cerr << "p3heartbeat::p3heartbeat()"; + std::cerr << std::endl; +#endif + + mLastHeartbeat = 0; + + return; +} + +p3heartbeat::~p3heartbeat() +{ + return; + +} + +int p3heartbeat::tick() +{ + //send a heartbeat to all connected peers + RsStackMutex stack(mHeartMtx); /********** STACK LOCKED MTX ******/ + + if (time(NULL) - mLastHeartbeat > HEARTBEAT_REPEAT_TIME) + { + mLastHeartbeat = time(NULL); + + std::list peers; + std::list::const_iterator pit; + + mLinkMgr->getOnlineList(peers); + for (pit = peers.begin(); pit != peers.end(); ++pit) + { + sendHeartbeat(*pit); + } + } + + int nhandled = 0; + RsItem *item = NULL; + + // While messages read + while(NULL != (item = recvItem())) + { + RsHeartbeatItem *beat = NULL; + nhandled++; + + // if discovery reply then respond if haven't already. + if (NULL != (beat = dynamic_cast (item))) + { + recvHeartbeat(beat->PeerId()); + } + else + { + // unknown. + } + + delete item; + } +} + +void p3heartbeat::sendHeartbeat(const std::string &toId) +{ + +#ifdef HEART_DEBUG + std::cerr << "p3heartbeat::sendHeartbeat() to " << toId; + std::cerr << std::endl; +#endif + RsHeartbeatItem *item = new RsHeartbeatItem(); + item->PeerId(toId); + sendItem(item); +} + + +void p3heartbeat::recvHeartbeat(const std::string &fromId) +{ + +#ifdef HEART_DEBUG + std::cerr << "p3heartbeat::recvHeartbeat() from " << fromId; + std::cerr << std::endl; +#endif + + mPqiPersonGrp->tagHeartbeatRecvd(fromId); +} + + diff --git a/libretroshare/src/services/p3heartbeat.h b/libretroshare/src/services/p3heartbeat.h new file mode 100644 index 000000000..1f686a73f --- /dev/null +++ b/libretroshare/src/services/p3heartbeat.h @@ -0,0 +1,61 @@ +/* + * libretroshare/src/services: p3heartbeat.h + * + * Services for RetroShare. + * + * Copyright 2004-2013 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_SERVICES_HEARTBEAT_H +#define MRK_SERVICES_HEARTBEAT_H + +// Moved Heartbeat to a seperate service. + +#include "pqi/p3linkmgr.h" +#include "pqi/pqipersongrp.h" +#include "services/p3service.h" + + +class p3heartbeat: public p3Service +{ + public: + + p3heartbeat(p3LinkMgr *linkMgr, pqipersongrp *pqipg); +virtual ~p3heartbeat(); + + int tick(); + + private: + + void sendHeartbeat(const std::string &toId); + void recvHeartbeat(const std::string &fromId); + + private: + + p3LinkMgr *mLinkMgr; + pqipersongrp *mPqiPersonGrp; + + /* data */ + RsMutex mHeartMtx; + + time_t mLastHeartbeat; +}; + +#endif // MRK_SERVICES_HEARTBEAT_H diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index b6afe5e2d..2f74fb554 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -560,7 +560,7 @@ bool p3Posted::generatePost(uint32_t &token, const RsGxsGroupId &grpId) uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32()); uint32_t i = 0; - for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++); + for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ; if (it != ownIds.end()) { @@ -605,7 +605,7 @@ bool p3Posted::generateComment(uint32_t &token, const RsGxsGroupId &grpId, const uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32()); uint32_t i = 0; - for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++); + for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ; if (it != ownIds.end()) { diff --git a/libretroshare/src/util/rsnet_ss.cc b/libretroshare/src/util/rsnet_ss.cc index ed4f188eb..4eb343a1a 100644 --- a/libretroshare/src/util/rsnet_ss.cc +++ b/libretroshare/src/util/rsnet_ss.cc @@ -25,6 +25,7 @@ #include "util/rsnet.h" #include "util/rsstring.h" +#include "pqi/pqinetwork.h" /***************************** Internal Helper Fns ******************************/ @@ -173,8 +174,10 @@ bool sockaddr_storage_copyip(struct sockaddr_storage &dst, const struct sockaddr uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr) { +#ifdef SS_DEBUG std::cerr << "sockaddr_storage_port()"; std::cerr << std::endl; +#endif switch(addr.ss_family) { case AF_INET: @@ -629,8 +632,10 @@ bool sockaddr_storage_ipv4_copyip(struct sockaddr_storage &dst, const struct soc uint16_t sockaddr_storage_ipv4_port(const struct sockaddr_storage &addr) { +#ifdef SS_DEBUG std::cerr << "sockaddr_storage_ipv4_port()"; std::cerr << std::endl; +#endif const struct sockaddr_in *ipv4_ptr = to_const_ipv4_ptr(addr); uint16_t port = ntohs(ipv4_ptr->sin_port); @@ -740,7 +745,10 @@ bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const st std::cerr << "sockaddr_storage_ipv4_samenet()"; std::cerr << std::endl; - return false; + + const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr); + const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2); + return sameNet(&(ptr1->sin_addr),&(ptr2->sin_addr)); } bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2) @@ -748,10 +756,12 @@ bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const (void) addr; (void) addr2; - std::cerr << "sockaddr_storage_ipv4_samesubnet()"; + std::cerr << "sockaddr_storage_ipv4_samesubnet() using pqinetwork::isSameSubnet()"; std::cerr << std::endl; - return false; + const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr); + const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2); + return isSameSubnet((struct in_addr *) &(ptr1->sin_addr),(struct in_addr *) &(ptr2->sin_addr)); } // IPV6 diff --git a/libretroshare/src/zeroconf/p3zeroconf.cc b/libretroshare/src/zeroconf/p3zeroconf.cc index 34cd22105..31d6368fa 100644 --- a/libretroshare/src/zeroconf/p3zeroconf.cc +++ b/libretroshare/src/zeroconf/p3zeroconf.cc @@ -500,7 +500,7 @@ int p3ZeroConf::checkLocationResults() std::cerr << std::endl; time_t now = time(NULL); - mPeerMgr->addFriend(lr.sslId, lr.gpgId, RS_NET_MODE_UDP, RS_VIS_STATE_STD, now); + mPeerMgr->addFriend(lr.sslId, lr.gpgId, RS_NET_MODE_UDP, RS_VS_DISC_FULL, RS_VS_DHT_FULL, now); return 1; }