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
This commit is contained in:
drbob 2013-09-28 08:09:59 +00:00
parent 70c947ba90
commit 90aa57a0f0
38 changed files with 3248 additions and 1543 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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<RsItem *>& 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<RsItem *>& 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<RsItem *>& 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<RsItem *>& 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<RsItem *>& 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 */

View File

@ -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,

View File

@ -175,9 +175,9 @@ void pqiIpAddrList::extractFromTlv(const RsTlvIpAddrSet &tlvAddrs)
}
}
void pqiIpAddrList::loadTlv(RsTlvIpAddrSet &tlvAddrs)
void pqiIpAddrList::loadTlv(RsTlvIpAddrSet &tlvAddrs) const
{
std::list<pqiIpAddress>::iterator it;
std::list<pqiIpAddress>::const_iterator it;
for(it = mAddrs.begin(); it != mAddrs.end() ; ++it)
{

View File

@ -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<pqiIpAddress> mAddrs;

View File

@ -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"

View File

@ -42,9 +42,9 @@ class RsDisc
RsDisc() { return; }
virtual ~RsDisc() { return; }
virtual bool getDiscFriends(std::string id, std::list<std::string>& friends) = 0;
virtual bool getDiscGPGFriends(std::string id, std::list<std::string>& gpg_friends) = 0;
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
virtual bool getDiscFriends(const std::string &id, std::list<std::string>& friends) = 0;
virtual bool getDiscPgpFriends(const std::string &pgpid, std::list<std::string>& gpg_friends) = 0;
virtual bool getPeerVersion(const std::string &id, std::string &versions) = 0;
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) = 0;
};

View File

@ -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<std::string> 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<std::string>& ip_servers) = 0;
virtual void allowServerIPDetermination(bool) = 0;

View File

@ -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 <iostream>
RsDisc *rsDisc = NULL;
bool p3Discovery::getDiscGPGFriends(std::string id, std::list<std::string>& gpg_friends)
{
if (mDisc)
{
return mDisc->potentialGPGproxies(id, gpg_friends);
}
return false;
}
bool p3Discovery::getDiscFriends(std::string id, std::list<std::string> &friends)
{
if (mDisc)
{
return mDisc->potentialproxies(id, friends);
}
return false;
}
bool p3Discovery::getDiscVersions(std::map<std::string, std::string> &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;
}

View File

@ -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<std::string> &friends);
virtual bool getDiscGPGFriends(std::string id, std::list<std::string> &gpg_friends);
virtual bool getDiscVersions(std::map<std::string, std::string> &versions);
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount);
private:
p3disc *mDisc;
};
#endif

View File

@ -65,7 +65,8 @@ RsServer::RsServer(NotifyBase &callback)
mPluginsManager = NULL;
/* services */
ad = NULL;
mHeart = NULL;
mDisc = NULL;
msgSrv = NULL;
chatSrv = NULL;
mStatusSrv = NULL;

View File

@ -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;

View File

@ -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<std::string>& 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)
{

View File

@ -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<std::string>& ip_servers) ;
virtual void allowServerIPDetermination(bool) ;

View File

@ -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;

View File

@ -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 ;

View File

@ -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);

View File

@ -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;

View File

@ -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 <iostream>
/*************************************************************************/
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<RsDiscReply *>(i)))
{
return sizeReply(rdr);
}
else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *>(i)))
{
return sizeAskInfo(inf);
}
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{
return sizeVersion(rdv);
}
else if (NULL != (rdt = dynamic_cast<RsDiscHeartbeat *>(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<RsDiscReply *>(i)))
{
return serialiseReply(rdr, data, pktsize);
}
else if (NULL != (inf = dynamic_cast<RsDiscAskInfo *>(i)))
{
return serialiseAskInfo(inf, data, pktsize);
}
else if (NULL != (rdv = dynamic_cast<RsDiscVersion *>(i)))
{
return serialiseVersion(rdv, data, pktsize);
}
else if (NULL != (rdt = dynamic_cast<RsDiscHeartbeat *>(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<RsPeerNetItem>::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<RsPeerNetItem>::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<RsPeerNetItem>::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;
}
/*************************************************************************/

View File

@ -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<IpAddressTimed> 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<RsPeerNetItem> 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

View File

@ -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 <iostream>
/*************************************************************************/
uint32_t RsDiscSerialiser::size(RsItem *i)
{
RsDiscPgpListItem *pgplist;
RsDiscPgpCertItem *pgpcert;
RsDiscContactItem *contact;
//RsDiscServicesItem *services;
if (NULL != (pgplist = dynamic_cast<RsDiscPgpListItem *>(i)))
{
return sizePgpList(pgplist);
}
else if (NULL != (pgpcert = dynamic_cast<RsDiscPgpCertItem *>(i)))
{
return sizePgpCert(pgpcert);
}
else if (NULL != (contact = dynamic_cast<RsDiscContactItem *>(i)))
{
return sizeContact(contact);
}
#if 0
else if (NULL != (services = dynamic_cast<RsDiscServicesItem *>(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<RsDiscPgpListItem *>(i)))
{
return serialisePgpList(pgplist, data, pktsize);
}
else if (NULL != (pgpcert = dynamic_cast<RsDiscPgpCertItem *>(i)))
{
return serialisePgpCert(pgpcert, data, pktsize);
}
else if (NULL != (contact = dynamic_cast<RsDiscContactItem *>(i)))
{
return serialiseContact(contact, data, pktsize);
}
#if 0
else if (NULL != (services = dynamic_cast<RsDiscServicesItem *>(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;
}
/*************************************************************************/

View File

@ -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

View File

@ -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 <iostream>
/*************************************************************************/
uint32_t RsHeartbeatSerialiser::size(RsItem *i)
{
RsHeartbeatItem *beat;
if (NULL != (beat = dynamic_cast<RsHeartbeatItem *>(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<RsHeartbeatItem *>(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;
}
/*************************************************************************/

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -33,6 +33,8 @@
#include <string>
#include <list>
#include <map>
#include <stdlib.h>
#include <stdint.h>
@ -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<uint32_t, std::string> map;
};
class RsTlvServiceIdMap: public RsTlvIntStringMap
{
public:
RsTlvServiceIdMap();
};
class RsTlvImage: public RsTlvItem
{
public:

View File

@ -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 <string>
#include <list>
// 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<std::string, autoserver> 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<pqipeer> &plist);
/************* from pqiMonitor *******************/
int tick();
/* GUI requires access */
bool potentialGPGproxies(const std::string& id, std::list<std::string> &proxyGPGIds);
bool potentialproxies(const std::string& id, std::list<std::string> &proxyIds);
void getversions(std::map<std::string, std::string> &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<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& 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<std::string, time_t> deletedSSLFriendsIds;
std::map<std::string, std::list<std::string> > mSendIdList;
std::list<RsDiscReply*> mPendingDiscReplyInList;
// Neighbors at the gpg level.
std::map<std::string,std::set<std::string> > gpg_neighbors ;
// Original mapping.
std::map<std::string, autoneighbour> neighbours;
// Rs Version.
std::map<std::string, std::string> versions;
};
#endif // MRK_PQI_AUTODISC_H

View File

@ -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<PGPID> &friends);
//PGPID mPgpId;
std::set<PGPID> mFriendSet;
std::map<SSLID, DiscSslInfo> 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<pqipeer> &plist);
/************* from pqiMonitor *******************/
int tick();
/* external interface */
virtual bool getDiscFriends(const std::string &id, std::list<std::string> &friends);
virtual bool getDiscPgpFriends(const std::string &pgpid, std::list<std::string> &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<PGPID, DiscPgpInfo> mFriendList;
std::map<SSLID, DiscPeerInfo> mLocationMap;
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertInList;
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertOutList;
};
#endif // MRK_SERVICES_DISCOVERY2_H

View File

@ -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<std::string> peers;
std::list<std::string>::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<RsHeartbeatItem *> (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);
}

View File

@ -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

View File

@ -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())
{

View File

@ -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

View File

@ -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;
}