mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
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:
parent
70c947ba90
commit
90aa57a0f0
@ -358,8 +358,7 @@ HEADERS += pqi/authssl.h \
|
|||||||
|
|
||||||
# pqi/p3dhtmgr.h \
|
# pqi/p3dhtmgr.h \
|
||||||
|
|
||||||
HEADERS += rsserver/p3discovery.h \
|
HEADERS += rsserver/p3face.h \
|
||||||
rsserver/p3face.h \
|
|
||||||
rsserver/p3history.h \
|
rsserver/p3history.h \
|
||||||
rsserver/p3msgs.h \
|
rsserver/p3msgs.h \
|
||||||
rsserver/p3peers.h \
|
rsserver/p3peers.h \
|
||||||
@ -369,7 +368,6 @@ HEADERS += rsserver/p3discovery.h \
|
|||||||
HEADERS += serialiser/rsbaseitems.h \
|
HEADERS += serialiser/rsbaseitems.h \
|
||||||
serialiser/rsbaseserial.h \
|
serialiser/rsbaseserial.h \
|
||||||
serialiser/rsconfigitems.h \
|
serialiser/rsconfigitems.h \
|
||||||
serialiser/rsdiscitems.h \
|
|
||||||
serialiser/rshistoryitems.h \
|
serialiser/rshistoryitems.h \
|
||||||
serialiser/rsmsgitems.h \
|
serialiser/rsmsgitems.h \
|
||||||
serialiser/rsserial.h \
|
serialiser/rsserial.h \
|
||||||
@ -387,17 +385,18 @@ HEADERS += serialiser/rsbaseitems.h \
|
|||||||
serialiser/rstlvbanlist.h \
|
serialiser/rstlvbanlist.h \
|
||||||
serialiser/rsbanlistitems.h \
|
serialiser/rsbanlistitems.h \
|
||||||
serialiser/rsbwctrlitems.h \
|
serialiser/rsbwctrlitems.h \
|
||||||
|
serialiser/rsdiscovery2items.h \
|
||||||
|
serialiser/rsheartbeatitems.h \
|
||||||
|
|
||||||
HEADERS += services/p3chatservice.h \
|
HEADERS += services/p3chatservice.h \
|
||||||
services/p3disc.h \
|
|
||||||
services/p3msgservice.h \
|
services/p3msgservice.h \
|
||||||
services/p3service.h \
|
services/p3service.h \
|
||||||
services/p3statusservice.h \
|
services/p3statusservice.h \
|
||||||
services/p3dsdv.h \
|
services/p3dsdv.h \
|
||||||
services/p3banlist.h \
|
services/p3banlist.h \
|
||||||
services/p3bwctrl.h
|
services/p3bwctrl.h \
|
||||||
|
services/p3discovery2.h \
|
||||||
# services/p3discovery2.h \
|
services/p3heartbeat.h \
|
||||||
|
|
||||||
HEADERS += turtle/p3turtle.h \
|
HEADERS += turtle/p3turtle.h \
|
||||||
turtle/rsturtleitem.h \
|
turtle/rsturtleitem.h \
|
||||||
@ -477,8 +476,7 @@ SOURCES += pqi/authgpg.cc \
|
|||||||
|
|
||||||
# pqi/p3dhtmgr.cc \
|
# pqi/p3dhtmgr.cc \
|
||||||
|
|
||||||
SOURCES += rsserver/p3discovery.cc \
|
SOURCES += rsserver/p3face-config.cc \
|
||||||
rsserver/p3face-config.cc \
|
|
||||||
rsserver/p3face-msgs.cc \
|
rsserver/p3face-msgs.cc \
|
||||||
rsserver/p3face-server.cc \
|
rsserver/p3face-server.cc \
|
||||||
rsserver/p3history.cc \
|
rsserver/p3history.cc \
|
||||||
@ -497,7 +495,6 @@ SOURCES += plugins/pluginmanager.cc \
|
|||||||
SOURCES += serialiser/rsbaseitems.cc \
|
SOURCES += serialiser/rsbaseitems.cc \
|
||||||
serialiser/rsbaseserial.cc \
|
serialiser/rsbaseserial.cc \
|
||||||
serialiser/rsconfigitems.cc \
|
serialiser/rsconfigitems.cc \
|
||||||
serialiser/rsdiscitems.cc \
|
|
||||||
serialiser/rshistoryitems.cc \
|
serialiser/rshistoryitems.cc \
|
||||||
serialiser/rsmsgitems.cc \
|
serialiser/rsmsgitems.cc \
|
||||||
serialiser/rsserial.cc \
|
serialiser/rsserial.cc \
|
||||||
@ -515,18 +512,18 @@ SOURCES += serialiser/rsbaseitems.cc \
|
|||||||
serialiser/rstlvbanlist.cc \
|
serialiser/rstlvbanlist.cc \
|
||||||
serialiser/rsbanlistitems.cc \
|
serialiser/rsbanlistitems.cc \
|
||||||
serialiser/rsbwctrlitems.cc \
|
serialiser/rsbwctrlitems.cc \
|
||||||
|
serialiser/rsdiscovery2items.cc \
|
||||||
|
serialiser/rsheartbeatitems.cc \
|
||||||
|
|
||||||
SOURCES += services/p3chatservice.cc \
|
SOURCES += services/p3chatservice.cc \
|
||||||
services/p3disc.cc \
|
|
||||||
services/p3msgservice.cc \
|
services/p3msgservice.cc \
|
||||||
services/p3service.cc \
|
services/p3service.cc \
|
||||||
services/p3statusservice.cc \
|
services/p3statusservice.cc \
|
||||||
services/p3dsdv.cc \
|
services/p3dsdv.cc \
|
||||||
services/p3banlist.cc \
|
services/p3banlist.cc \
|
||||||
services/p3bwctrl.cc \
|
services/p3bwctrl.cc \
|
||||||
|
services/p3discovery2.cc \
|
||||||
|
services/p3heartbeat.cc \
|
||||||
# services/p3discovery2.cc \
|
|
||||||
|
|
||||||
SOURCES += turtle/p3turtle.cc \
|
SOURCES += turtle/p3turtle.cc \
|
||||||
turtle/rsturtleitem.cc
|
turtle/rsturtleitem.cc
|
||||||
|
@ -1085,7 +1085,8 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
|||||||
details.ts = now;
|
details.ts = now;
|
||||||
|
|
||||||
bool updateNetConfig = (source == RS_CB_PERSON);
|
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 peerNetMode = 0;
|
||||||
|
|
||||||
uint32_t ownNetMode = mNetMgr->getNetworkMode();
|
uint32_t ownNetMode = mNetMgr->getNetworkMode();
|
||||||
@ -1219,20 +1220,20 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
|||||||
/* always update VIS status */
|
/* always update VIS status */
|
||||||
if (flags & RS_NET_FLAGS_USE_DISC)
|
if (flags & RS_NET_FLAGS_USE_DISC)
|
||||||
{
|
{
|
||||||
peerVisibility &= (~RS_VIS_STATE_NODISC);
|
peer_vs_disc = RS_VS_DISC_FULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
peerVisibility |= RS_VIS_STATE_NODISC;
|
peer_vs_disc = RS_VS_DISC_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & RS_NET_FLAGS_USE_DHT)
|
if (flags & RS_NET_FLAGS_USE_DHT)
|
||||||
{
|
{
|
||||||
peerVisibility &= (~RS_VIS_STATE_NODHT);
|
peer_vs_dht = RS_VS_DHT_FULL;
|
||||||
}
|
}
|
||||||
else
|
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);
|
bool newAddrs = mPeerMgr->updateAddressList(id, addrs);
|
||||||
if (updateNetConfig)
|
if (updateNetConfig)
|
||||||
{
|
{
|
||||||
mPeerMgr -> setVisState(id, peerVisibility);
|
mPeerMgr -> setVisState(id, peer_vs_disc, peer_vs_dht);
|
||||||
mPeerMgr -> setNetworkMode(id, peerNetMode);
|
mPeerMgr -> setNetworkMode(id, peerNetMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +140,10 @@ p3NetMgrIMPL::p3NetMgrIMPL()
|
|||||||
mLocalAddr.ss_family = AF_INET;
|
mLocalAddr.ss_family = AF_INET;
|
||||||
mExtAddr.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
|
#ifdef NETMGR_DEBUG
|
||||||
@ -570,10 +572,10 @@ void p3NetMgrIMPL::netDhtInit()
|
|||||||
uint32_t vs = 0;
|
uint32_t vs = 0;
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNetMtx); /*********** LOCKED MUTEX ************/
|
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 *******/
|
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 we've started up - then tweak Dht On/Off */
|
||||||
if (mNetStatus != RS_NET_UNKNOWN)
|
if (mNetStatus != RS_NET_UNKNOWN)
|
||||||
{
|
{
|
||||||
enableNetAssistConnect(!(mVisState & RS_VIS_STATE_NODHT));
|
enableNetAssistConnect(mVsDht != RS_VS_DHT_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -115,7 +115,7 @@ virtual ~p3NetMgr() { return; }
|
|||||||
|
|
||||||
// Setup Network State.
|
// Setup Network State.
|
||||||
virtual bool setNetworkMode(uint32_t netMode) = 0;
|
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.
|
// Switch DHT On/Off.
|
||||||
virtual bool netAssistFriend(const std::string &id, bool on) = 0;
|
virtual bool netAssistFriend(const std::string &id, bool on) = 0;
|
||||||
@ -171,7 +171,7 @@ class p3NetMgrIMPL: public p3NetMgr
|
|||||||
|
|
||||||
// Setup Network State.
|
// Setup Network State.
|
||||||
virtual bool setNetworkMode(uint32_t netMode);
|
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.
|
// Switch DHT On/Off.
|
||||||
virtual bool netAssistFriend(const std::string &id, bool on);
|
virtual bool netAssistFriend(const std::string &id, bool on);
|
||||||
@ -330,7 +330,8 @@ void netStatusReset_locked();
|
|||||||
struct sockaddr_storage mExtAddr;
|
struct sockaddr_storage mExtAddr;
|
||||||
|
|
||||||
uint32_t mNetMode;
|
uint32_t mNetMode;
|
||||||
uint32_t mVisState;
|
uint16_t mVsDisc;
|
||||||
|
uint16_t mVsDht;
|
||||||
|
|
||||||
time_t mNetInitTS;
|
time_t mNetInitTS;
|
||||||
uint32_t mNetStatus;
|
uint32_t mNetStatus;
|
||||||
|
@ -78,7 +78,7 @@ void printConnectState(std::ostream &out, peerState &peer);
|
|||||||
peerState::peerState()
|
peerState::peerState()
|
||||||
:id("unknown"),
|
:id("unknown"),
|
||||||
gpg_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)
|
hiddenNode(false), hiddenPort(0)
|
||||||
{
|
{
|
||||||
sockaddr_storage_clear(localaddr);
|
sockaddr_storage_clear(localaddr);
|
||||||
@ -91,7 +91,7 @@ std::string textPeerConnectState(peerState &state)
|
|||||||
{
|
{
|
||||||
std::string out = "Id: " + state.id + "\n";
|
std::string out = "Id: " + state.id + "\n";
|
||||||
rs_sprintf_append(out, "NetMode: %lu\n", state.netMode);
|
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 += "laddr: ";
|
||||||
out += sockaddr_storage_tostring(state.localaddr);
|
out += sockaddr_storage_tostring(state.localaddr);
|
||||||
@ -122,7 +122,8 @@ p3PeerMgrIMPL::p3PeerMgrIMPL( const std::string& ssl_own_id,
|
|||||||
mOwnState.name = gpg_own_name ;
|
mOwnState.name = gpg_own_name ;
|
||||||
mOwnState.location = ssl_own_location ;
|
mOwnState.location = ssl_own_location ;
|
||||||
mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP.
|
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;
|
lastGroupId = 1;
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ bool p3PeerMgrIMPL::setupHiddenNode(const std::string &hiddenAddress, const uint
|
|||||||
mOwnState.hiddenDomain = hiddenAddress;
|
mOwnState.hiddenDomain = hiddenAddress;
|
||||||
|
|
||||||
// switch off DHT too.
|
// switch off DHT too.
|
||||||
setOwnVisState(RS_VIS_STATE_GRAY);
|
setOwnVisState(mOwnState.vs_disc, RS_VS_DHT_OFF);
|
||||||
|
|
||||||
// Force the Port.
|
// Force the Port.
|
||||||
struct sockaddr_storage loopback;
|
struct sockaddr_storage loopback;
|
||||||
@ -206,29 +207,32 @@ bool p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3PeerMgrIMPL::setOwnVisState(uint32_t visState)
|
bool p3PeerMgrIMPL::setOwnVisState(uint16_t vs_disc, uint16_t vs_dht)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
std::string out;
|
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);
|
rslog(RSL_WARNING, p3peermgrzone, out);
|
||||||
|
|
||||||
#ifdef PEER_DEBUG
|
#ifdef PEER_DEBUG
|
||||||
std::cerr << out.c_str() << std::endl;
|
std::cerr << out.c_str() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mOwnState.visState != visState) {
|
if (mOwnState.vs_disc != vs_disc || mOwnState.vs_dht != vs_dht)
|
||||||
mOwnState.visState = visState;
|
{
|
||||||
|
mOwnState.vs_disc = vs_disc;
|
||||||
|
mOwnState.vs_dht = vs_dht;
|
||||||
changed = true;
|
changed = true;
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass on Flags to NetMgr.
|
// Pass on Flags to NetMgr.
|
||||||
mNetMgr->setVisState(visState);
|
mNetMgr->setVisState(vs_disc, vs_dht);
|
||||||
|
|
||||||
return changed;
|
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;
|
bool notifyLinkMgr = false;
|
||||||
std::string id = input_id ;
|
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);
|
it = mFriendList.find(id);
|
||||||
|
|
||||||
/* setup connectivity parameters */
|
/* 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.netMode = netMode;
|
||||||
it->second.lastcontact = lastContact;
|
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.gpg_id = gpg_id;
|
||||||
pstate.name = AuthGPG::getAuthGPG()->getGPGName(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.netMode = netMode;
|
||||||
pstate.lastcontact = lastContact;
|
pstate.lastcontact = lastContact;
|
||||||
|
|
||||||
@ -711,7 +718,7 @@ bool p3PeerMgrIMPL::addFriend(const std::string& input_id, const std::string& in
|
|||||||
|
|
||||||
if (notifyLinkMgr)
|
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.
|
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;
|
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;
|
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);
|
rslog(RSL_WARNING, p3peermgrzone, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
return setOwnVisState(visState);
|
return setOwnVisState(vs_disc, vs_dht);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dht_state ;
|
|
||||||
bool isFriend = false;
|
bool isFriend = false;
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
{
|
{
|
||||||
@ -1361,53 +1367,47 @@ bool p3PeerMgrIMPL::setVisState(const std::string &id, uint32_t visState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* "it" points to peer */
|
/* "it" points to peer */
|
||||||
if (it->second.visState != visState) {
|
if ((it->second.vs_disc != vs_disc) || (it->second.vs_dht = vs_dht))
|
||||||
it->second.visState = visState;
|
{
|
||||||
|
it->second.vs_disc = vs_disc;
|
||||||
|
it->second.vs_dht = vs_dht;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
||||||
dht_state = it->second.visState & RS_VIS_STATE_NODHT ;
|
std::cerr << "p3PeerMgrIMPL::setVisState(" << id << ", DISC: " << vs_disc << " DHT: " << vs_dht << ") ";
|
||||||
|
|
||||||
std::cerr << "p3PeerMgrIMPL::setVisState(" << id << ", " << std::hex << visState << std::dec << ") ";
|
|
||||||
std::cerr << " NAME: " << it->second.name;
|
std::cerr << " NAME: " << it->second.name;
|
||||||
|
|
||||||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
switch(it->second.vs_disc)
|
||||||
{
|
|
||||||
std::cerr << " NO-DHT ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << " DHT-OK ";
|
|
||||||
}
|
|
||||||
if (it->second.visState & RS_VIS_STATE_NODISC)
|
|
||||||
{
|
{
|
||||||
|
default:
|
||||||
|
case RS_VS_DISC_OFF:
|
||||||
std::cerr << " NO-DISC ";
|
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 << " 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;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isFriend && changed)
|
if(isFriend && changed)
|
||||||
{
|
{
|
||||||
/* toggle DHT state */
|
mLinkMgr->setFriendVisibility(id, vs_dht != RS_VS_DHT_OFF);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
@ -1471,11 +1471,16 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
|
|||||||
#endif
|
#endif
|
||||||
item->netMode = mOwnState.netMode;
|
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->lastContact = mOwnState.lastcontact;
|
||||||
|
|
||||||
item->localAddr.addr = mOwnState.localaddr;
|
item->localAddrV4.addr = mOwnState.localaddr;
|
||||||
item->extAddr.addr = mOwnState.serveraddr;
|
item->extAddrV4.addr = mOwnState.serveraddr;
|
||||||
|
sockaddr_storage_clear(item->localAddrV6.addr);
|
||||||
|
sockaddr_storage_clear(item->extAddrV6.addr);
|
||||||
|
|
||||||
item->dyndns = mOwnState.dyndns;
|
item->dyndns = mOwnState.dyndns;
|
||||||
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
|
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||||
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
|
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->gpg_id = (it->second).gpg_id;
|
||||||
item->location = (it->second).location;
|
item->location = (it->second).location;
|
||||||
item->netMode = (it->second).netMode;
|
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->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;
|
item->dyndns = (it->second).dyndns;
|
||||||
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
|
||||||
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
|
||||||
@ -1613,7 +1625,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||||||
#endif
|
#endif
|
||||||
/* add ownConfig */
|
/* add ownConfig */
|
||||||
setOwnNetworkMode(pitem->netMode);
|
setOwnNetworkMode(pitem->netMode);
|
||||||
setOwnVisState(pitem->visState);
|
setOwnVisState(pitem->vs_disc, pitem->vs_dht);
|
||||||
|
|
||||||
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
mOwnState.gpg_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||||
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
mOwnState.location = AuthSSL::getAuthSSL()->getOwnLocation();
|
||||||
@ -1626,7 +1638,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#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);
|
setLocation(pitem->pid, pitem->location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1638,8 +1650,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLocalAddress(pitem->pid, pitem->localAddr.addr);
|
setLocalAddress(pitem->pid, pitem->localAddrV4.addr);
|
||||||
setExtAddress(pitem->pid, pitem->extAddr.addr);
|
setExtAddress(pitem->pid, pitem->extAddrV4.addr);
|
||||||
setDynDNS (pitem->pid, pitem->dyndns);
|
setDynDNS (pitem->pid, pitem->dyndns);
|
||||||
|
|
||||||
/* convert addresses */
|
/* convert addresses */
|
||||||
|
@ -35,25 +35,9 @@
|
|||||||
|
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
/* RS_VIS_STATE_XXXX
|
/* RS_VIS_STATE -> specified in rspeers.h
|
||||||
* 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;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Startup Modes (confirmed later) */
|
/* Startup Modes (confirmed later) */
|
||||||
const uint32_t RS_NET_MODE_TRYMODE = 0xff00;
|
const uint32_t RS_NET_MODE_TRYMODE = 0xff00;
|
||||||
|
|
||||||
@ -90,8 +74,9 @@ class peerState
|
|||||||
std::string gpg_id;
|
std::string gpg_id;
|
||||||
|
|
||||||
uint32_t netMode; /* EXT / UPNP / UDP / HIDDEN / INVALID */
|
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 localaddr;
|
||||||
struct sockaddr_storage serveraddr;
|
struct sockaddr_storage serveraddr;
|
||||||
@ -130,7 +115,8 @@ class p3PeerMgr
|
|||||||
virtual ~p3PeerMgr() { return; }
|
virtual ~p3PeerMgr() { return; }
|
||||||
|
|
||||||
virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
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 removeFriend(const std::string &ssl_id, bool removePgpId) = 0;
|
||||||
|
|
||||||
virtual bool isFriend(const std::string &ssl_id) = 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 setDynDNS(const std::string &id, const std::string &dyndns) = 0;
|
||||||
|
|
||||||
virtual bool setNetworkMode(const std::string &id, uint32_t netMode) = 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 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;
|
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,
|
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 removeFriend(const std::string &ssl_id, bool removePgpId);
|
||||||
|
|
||||||
virtual bool isFriend(const std::string &ssl_id);
|
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 setDynDNS(const std::string &id, const std::string &dyndns);
|
||||||
|
|
||||||
virtual bool setNetworkMode(const std::string &id, uint32_t netMode);
|
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 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);
|
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();
|
const std::string getOwnId();
|
||||||
bool setOwnNetworkMode(uint32_t netMode);
|
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,
|
int getConnectAddresses(const std::string &id,
|
||||||
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
struct sockaddr_storage &lAddr, struct sockaddr_storage &eAddr,
|
||||||
|
@ -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)
|
for(it = mAddrs.begin(); it != mAddrs.end() ; ++it)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ class pqiIpAddrList
|
|||||||
bool updateIpAddressList(const pqiIpAddress &addr);
|
bool updateIpAddressList(const pqiIpAddress &addr);
|
||||||
void printIpAddressList(std::string &out) const;
|
void printIpAddressList(std::string &out) const;
|
||||||
void extractFromTlv(const RsTlvIpAddrSet &tlvAddrs);
|
void extractFromTlv(const RsTlvIpAddrSet &tlvAddrs);
|
||||||
void loadTlv(RsTlvIpAddrSet &tlvAddrs);
|
void loadTlv(RsTlvIpAddrSet &tlvAddrs) const;
|
||||||
|
|
||||||
// sorted list... based on seen time.
|
// sorted list... based on seen time.
|
||||||
std::list<pqiIpAddress> mAddrs;
|
std::list<pqiIpAddress> mAddrs;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include "pqi/pqi.h"
|
#include "pqi/pqi.h"
|
||||||
#include "pqi/pqiperson.h"
|
#include "pqi/pqiperson.h"
|
||||||
#include "pqi/pqipersongrp.h"
|
#include "pqi/pqipersongrp.h"
|
||||||
#include "services/p3disc.h"
|
|
||||||
|
|
||||||
const int pqipersonzone = 82371;
|
const int pqipersonzone = 82371;
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
|
@ -42,9 +42,9 @@ class RsDisc
|
|||||||
RsDisc() { return; }
|
RsDisc() { return; }
|
||||||
virtual ~RsDisc() { return; }
|
virtual ~RsDisc() { return; }
|
||||||
|
|
||||||
virtual bool getDiscFriends(std::string id, std::list<std::string>& friends) = 0;
|
virtual bool getDiscFriends(const std::string &id, std::list<std::string>& friends) = 0;
|
||||||
virtual bool getDiscGPGFriends(std::string id, std::list<std::string>& gpg_friends) = 0;
|
virtual bool getDiscPgpFriends(const std::string &pgpid, std::list<std::string>& gpg_friends) = 0;
|
||||||
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
|
virtual bool getPeerVersion(const std::string &id, std::string &versions) = 0;
|
||||||
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) = 0;
|
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -58,8 +58,13 @@ const uint32_t RS_NETMODE_HIDDEN = 0x0004;
|
|||||||
const uint32_t RS_NETMODE_UNREACHABLE = 0x0005;
|
const uint32_t RS_NETMODE_UNREACHABLE = 0x0005;
|
||||||
|
|
||||||
/* Visibility */
|
/* Visibility */
|
||||||
const uint32_t RS_VS_DHT_ON = 0x0001;
|
const uint32_t RS_VS_DISC_OFF = 0x0000;
|
||||||
const uint32_t RS_VS_DISC_ON = 0x0002;
|
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 */
|
/* State */
|
||||||
const uint32_t RS_PEER_STATE_FRIEND = 0x0001;
|
const uint32_t RS_PEER_STATE_FRIEND = 0x0001;
|
||||||
@ -219,7 +224,9 @@ class RsPeerDetails
|
|||||||
std::list<std::string> ipAddressList;
|
std::list<std::string> ipAddressList;
|
||||||
|
|
||||||
uint32_t netMode;
|
uint32_t netMode;
|
||||||
uint32_t visState;
|
/* vis State */
|
||||||
|
uint16_t vs_disc;
|
||||||
|
uint16_t vs_dht;
|
||||||
|
|
||||||
/* basic stats */
|
/* basic stats */
|
||||||
uint32_t lastConnect; /* how long ago */
|
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 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 setDynDNS(const std::string &id, const std::string &addr) = 0;
|
||||||
virtual bool setNetworkMode(const std::string &ssl_id, uint32_t netMode) = 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 getIPServersList(std::list<std::string>& ip_servers) = 0;
|
||||||
virtual void allowServerIPDetermination(bool) = 0;
|
virtual void allowServerIPDetermination(bool) = 0;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -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
|
|
||||||
|
|
@ -65,7 +65,8 @@ RsServer::RsServer(NotifyBase &callback)
|
|||||||
mPluginsManager = NULL;
|
mPluginsManager = NULL;
|
||||||
|
|
||||||
/* services */
|
/* services */
|
||||||
ad = NULL;
|
mHeart = NULL;
|
||||||
|
mDisc = NULL;
|
||||||
msgSrv = NULL;
|
msgSrv = NULL;
|
||||||
chatSrv = NULL;
|
chatSrv = NULL;
|
||||||
mStatusSrv = NULL;
|
mStatusSrv = NULL;
|
||||||
|
@ -37,11 +37,13 @@
|
|||||||
#include "retroshare/rstypes.h"
|
#include "retroshare/rstypes.h"
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
#include "services/p3disc.h"
|
|
||||||
#include "services/p3msgservice.h"
|
#include "services/p3msgservice.h"
|
||||||
#include "services/p3chatservice.h"
|
#include "services/p3chatservice.h"
|
||||||
#include "services/p3statusservice.h"
|
#include "services/p3statusservice.h"
|
||||||
|
|
||||||
|
class p3heartbeat;
|
||||||
|
class p3discovery2;
|
||||||
|
|
||||||
/* GXS Classes - just declare the classes.
|
/* GXS Classes - just declare the classes.
|
||||||
so we don't have to totally recompile to switch */
|
so we don't have to totally recompile to switch */
|
||||||
|
|
||||||
@ -171,7 +173,8 @@ class RsServer: public RsControl, public RsThread
|
|||||||
//sslroot *sslr;
|
//sslroot *sslr;
|
||||||
|
|
||||||
/* services */
|
/* services */
|
||||||
p3disc *ad;
|
p3heartbeat *mHeart;
|
||||||
|
p3discovery2 *mDisc;
|
||||||
p3MsgService *msgSrv;
|
p3MsgService *msgSrv;
|
||||||
p3ChatService *chatSrv;
|
p3ChatService *chatSrv;
|
||||||
p3StatusService *mStatusSrv;
|
p3StatusService *mStatusSrv;
|
||||||
|
@ -373,18 +373,8 @@ bool p3Peers::getPeerDetails(const std::string &id, RsPeerDetails &d)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
d.visState = 0;
|
d.vs_disc = ps.vs_disc;
|
||||||
if (!(ps.visState & RS_VIS_STATE_NODISC))
|
d.vs_dht = ps.vs_dht;
|
||||||
{
|
|
||||||
d.visState |= RS_VS_DISC_ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ps.visState & RS_VIS_STATE_NODHT))
|
|
||||||
{
|
|
||||||
d.visState |= RS_VS_DHT_ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Translate */
|
/* 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!
|
* 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);
|
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)
|
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
|
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
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::setVisState() " << id << std::endl;
|
std::cerr << "p3Peers::setVisState() " << id << std::endl;
|
||||||
#endif
|
#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;
|
return mPeerMgr->setVisState(id, vs_disc, vs_dht);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
@ -1242,7 +1227,7 @@ RsPeerDetails::RsPeerDetails()
|
|||||||
org(""),issuer(""),fpr(""),authcode(""),
|
org(""),issuer(""),fpr(""),authcode(""),
|
||||||
trustLvl(0), validLvl(0),ownsign(false),
|
trustLvl(0), validLvl(0),ownsign(false),
|
||||||
hasSignedMe(false),accept_connection(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),
|
lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),foundDHT(false),
|
||||||
wasDeniedConnection(false), deniedTS(0)
|
wasDeniedConnection(false), deniedTS(0)
|
||||||
{
|
{
|
||||||
|
@ -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 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 setDynDNS(const std::string &id, const std::string &dyndns);
|
||||||
virtual bool setNetworkMode(const std::string &id, uint32_t netMode);
|
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 getIPServersList(std::list<std::string>& ip_servers) ;
|
||||||
virtual void allowServerIPDetermination(bool) ;
|
virtual void allowServerIPDetermination(bool) ;
|
||||||
|
@ -289,7 +289,6 @@ void RsInit::InitRsConfig()
|
|||||||
//setZoneLevel(PQL_DEBUG_BASIC, 82371); // pqiperson.
|
//setZoneLevel(PQL_DEBUG_BASIC, 82371); // pqiperson.
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 34283); // pqihandler.
|
//setZoneLevel(PQL_DEBUG_BASIC, 34283); // pqihandler.
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 44863); // discItems.
|
//setZoneLevel(PQL_DEBUG_BASIC, 44863); // discItems.
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 2482); // p3disc
|
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 1728); // pqi/p3proxy
|
//setZoneLevel(PQL_DEBUG_BASIC, 1728); // pqi/p3proxy
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 1211); // sslroot.
|
//setZoneLevel(PQL_DEBUG_BASIC, 1211); // sslroot.
|
||||||
//setZoneLevel(PQL_DEBUG_BASIC, 37714); // pqissl.
|
//setZoneLevel(PQL_DEBUG_BASIC, 37714); // pqissl.
|
||||||
@ -1781,7 +1780,8 @@ RsTurtle *rsTurtle = NULL ;
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "services/p3disc.h"
|
#include "services/p3heartbeat.h"
|
||||||
|
#include "services/p3discovery2.h"
|
||||||
#include "services/p3msgservice.h"
|
#include "services/p3msgservice.h"
|
||||||
#include "services/p3chatservice.h"
|
#include "services/p3chatservice.h"
|
||||||
#include "services/p3statusservice.h"
|
#include "services/p3statusservice.h"
|
||||||
@ -1815,7 +1815,6 @@ RsTurtle *rsTurtle = NULL ;
|
|||||||
#include "rsserver/p3face.h"
|
#include "rsserver/p3face.h"
|
||||||
#include "rsserver/p3peers.h"
|
#include "rsserver/p3peers.h"
|
||||||
#include "rsserver/p3msgs.h"
|
#include "rsserver/p3msgs.h"
|
||||||
#include "rsserver/p3discovery.h"
|
|
||||||
#include "rsserver/p3status.h"
|
#include "rsserver/p3status.h"
|
||||||
#include "rsserver/p3history.h"
|
#include "rsserver/p3history.h"
|
||||||
#include "rsserver/p3serverconfig.h"
|
#include "rsserver/p3serverconfig.h"
|
||||||
@ -2238,7 +2237,8 @@ int RsServer::StartupRetroShare()
|
|||||||
mPluginsManager->setInterfaces(interfaces);
|
mPluginsManager->setInterfaces(interfaces);
|
||||||
|
|
||||||
/* create Services */
|
/* create Services */
|
||||||
ad = new p3disc(mPeerMgr, mLinkMgr, mNetMgr, pqih);
|
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr);
|
||||||
|
mHeart = new p3heartbeat(mLinkMgr, pqih);
|
||||||
msgSrv = new p3MsgService(mLinkMgr);
|
msgSrv = new p3MsgService(mLinkMgr);
|
||||||
chatSrv = new p3ChatService(mLinkMgr, mHistoryMgr);
|
chatSrv = new p3ChatService(mLinkMgr, mHistoryMgr);
|
||||||
mStatusSrv = new p3StatusService(mLinkMgr);
|
mStatusSrv = new p3StatusService(mLinkMgr);
|
||||||
@ -2251,7 +2251,8 @@ int RsServer::StartupRetroShare()
|
|||||||
chatSrv->connectToTurtleRouter(tr) ;
|
chatSrv->connectToTurtleRouter(tr) ;
|
||||||
msgSrv->connectToTurtleRouter(tr) ;
|
msgSrv->connectToTurtleRouter(tr) ;
|
||||||
|
|
||||||
pqih -> addService(ad);
|
pqih -> addService(mHeart);
|
||||||
|
pqih -> addService(mDisc);
|
||||||
pqih -> addService(msgSrv);
|
pqih -> addService(msgSrv);
|
||||||
pqih -> addService(chatSrv);
|
pqih -> addService(chatSrv);
|
||||||
pqih ->addService(mStatusSrv);
|
pqih ->addService(mStatusSrv);
|
||||||
@ -2503,7 +2504,7 @@ int RsServer::StartupRetroShare()
|
|||||||
/* need to Monitor too! */
|
/* need to Monitor too! */
|
||||||
mLinkMgr->addMonitor(pqih);
|
mLinkMgr->addMonitor(pqih);
|
||||||
mLinkMgr->addMonitor(mCacheStrapper);
|
mLinkMgr->addMonitor(mCacheStrapper);
|
||||||
//mLinkMgr->addMonitor(ad);
|
mLinkMgr->addMonitor(mDisc);
|
||||||
mLinkMgr->addMonitor(msgSrv);
|
mLinkMgr->addMonitor(msgSrv);
|
||||||
mLinkMgr->addMonitor(mStatusSrv);
|
mLinkMgr->addMonitor(mStatusSrv);
|
||||||
mLinkMgr->addMonitor(chatSrv);
|
mLinkMgr->addMonitor(chatSrv);
|
||||||
@ -2529,7 +2530,6 @@ int RsServer::StartupRetroShare()
|
|||||||
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
|
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
|
||||||
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
||||||
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
||||||
//mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
|
||||||
|
|
||||||
#ifdef RS_USE_BITDHT
|
#ifdef RS_USE_BITDHT
|
||||||
mConfigMgr->addConfiguration("bitdht.cfg", mBitDht);
|
mConfigMgr->addConfiguration("bitdht.cfg", mBitDht);
|
||||||
@ -2583,7 +2583,7 @@ int RsServer::StartupRetroShare()
|
|||||||
if (RsInitConfig::forceExtPort)
|
if (RsInitConfig::forceExtPort)
|
||||||
{
|
{
|
||||||
mPeerMgr->setOwnNetworkMode(RS_NET_MODE_EXT);
|
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 */
|
/* Add AuthGPG services */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
AuthGPG::getAuthGPG()->addService(ad);
|
AuthGPG::getAuthGPG()->addService(mDisc);
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* Force Any Last Configuration Options */
|
/* Force Any Last Configuration Options */
|
||||||
@ -2701,7 +2701,7 @@ int RsServer::StartupRetroShare()
|
|||||||
|
|
||||||
/* Setup GUI Interfaces. */
|
/* Setup GUI Interfaces. */
|
||||||
|
|
||||||
rsDisc = new p3Discovery(ad);
|
rsDisc = mDisc;
|
||||||
rsBandwidthControl = mBwCtrl;
|
rsBandwidthControl = mBwCtrl;
|
||||||
rsConfig = serverConfig;
|
rsConfig = serverConfig;
|
||||||
|
|
||||||
|
@ -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_REPLY = 1 ;
|
||||||
const uint8_t QOS_PRIORITY_RS_DISC_VERSION = 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
|
// Chat/Msgs
|
||||||
//
|
//
|
||||||
const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ;
|
const uint8_t QOS_PRIORITY_RS_CHAT_ITEM = 7 ;
|
||||||
|
@ -780,11 +780,15 @@ void RsPeerNetItem::clear()
|
|||||||
gpg_id.clear();
|
gpg_id.clear();
|
||||||
location.clear();
|
location.clear();
|
||||||
netMode = 0;
|
netMode = 0;
|
||||||
visState = 0;
|
vs_disc = 0;
|
||||||
|
vs_dht = 0;
|
||||||
lastContact = 0;
|
lastContact = 0;
|
||||||
|
|
||||||
localAddr.TlvClear();
|
localAddrV4.TlvClear();
|
||||||
extAddr.TlvClear();
|
extAddrV4.TlvClear();
|
||||||
|
localAddrV6.TlvClear();
|
||||||
|
extAddrV6.TlvClear();
|
||||||
|
|
||||||
dyndns.clear();
|
dyndns.clear();
|
||||||
|
|
||||||
localAddrList.TlvClear();
|
localAddrList.TlvClear();
|
||||||
@ -812,19 +816,29 @@ std::ostream &RsPeerNetItem::print(std::ostream &out, uint16_t indent)
|
|||||||
out << "netMode: " << netMode << std::endl;
|
out << "netMode: " << netMode << std::endl;
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
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);
|
printIndent(out, int_Indent);
|
||||||
out << "lastContact: " << lastContact << std::endl;
|
out << "lastContact: " << lastContact << std::endl;
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "localAddr: " << std::endl;
|
out << "localAddrV4: " << std::endl;
|
||||||
localAddr.print(out, int_Indent);
|
localAddrV4.print(out, int_Indent);
|
||||||
|
|
||||||
printIndent(out, int_Indent);
|
printIndent(out, int_Indent);
|
||||||
out << "extAddr: " << std::endl;
|
out << "extAddrV4: " << std::endl;
|
||||||
extAddr.print(out, int_Indent);
|
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);
|
printIndent(out, int_Indent);
|
||||||
out << "DynDNS: " << dyndns << std::endl;
|
out << "DynDNS: " << dyndns << std::endl;
|
||||||
@ -845,10 +859,15 @@ uint32_t RsPeerConfigSerialiser::sizeNet(RsPeerNetItem *i)
|
|||||||
s += GetTlvStringSize(i->gpg_id);
|
s += GetTlvStringSize(i->gpg_id);
|
||||||
s += GetTlvStringSize(i->location);
|
s += GetTlvStringSize(i->location);
|
||||||
s += 4; /* netMode */
|
s += 4; /* netMode */
|
||||||
s += 4; /* visState */
|
s += 2; /* vs_disc */
|
||||||
|
s += 2; /* vs_dht */
|
||||||
s += 4; /* lastContact */
|
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);
|
s += GetTlvStringSize(i->dyndns);
|
||||||
|
|
||||||
//add the size of the ip list
|
//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_GPGID, item->gpg_id); /* Mandatory */
|
||||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* 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->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 &= 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);
|
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_GPGID, item->gpg_id); /* Mandatory */
|
||||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location); /* 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->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 &= getRawUInt32(data, rssize, &offset, &(item->lastContact)); /* Mandatory */
|
||||||
|
|
||||||
ok &= item->localAddr.GetTlv(data, rssize, &offset);
|
ok &= item->localAddrV4.GetTlv(data, rssize, &offset);
|
||||||
ok &= item->extAddr.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 &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns);
|
||||||
ok &= item->localAddrList.GetTlv(data, rssize, &offset);
|
ok &= item->localAddrList.GetTlv(data, rssize, &offset);
|
||||||
|
@ -76,11 +76,15 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|||||||
std::string gpg_id; /* Mandatory */
|
std::string gpg_id; /* Mandatory */
|
||||||
std::string location; /* not Mandatory */
|
std::string location; /* not Mandatory */
|
||||||
uint32_t netMode; /* Mandatory */
|
uint32_t netMode; /* Mandatory */
|
||||||
uint32_t visState; /* Mandatory */
|
uint16_t vs_disc; /* Mandatory */
|
||||||
|
uint16_t vs_dht; /* Mandatory */
|
||||||
uint32_t lastContact; /* Mandatory */
|
uint32_t lastContact; /* Mandatory */
|
||||||
|
|
||||||
RsTlvIpAddress localAddr; /* Mandatory */
|
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||||
RsTlvIpAddress extAddr; /* Mandatory */
|
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||||
|
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||||
|
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||||
|
|
||||||
std::string dyndns;
|
std::string dyndns;
|
||||||
|
|
||||||
RsTlvIpAddrSet localAddrList;
|
RsTlvIpAddrSet localAddrList;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************/
|
|
@ -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
|
|
||||||
|
|
890
libretroshare/src/serialiser/rsdiscovery2items.cc
Normal file
890
libretroshare/src/serialiser/rsdiscovery2items.cc
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*************************************************************************/
|
||||||
|
|
203
libretroshare/src/serialiser/rsdiscovery2items.h
Normal file
203
libretroshare/src/serialiser/rsdiscovery2items.h
Normal 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
|
||||||
|
|
206
libretroshare/src/serialiser/rsheartbeatitems.cc
Normal file
206
libretroshare/src/serialiser/rsheartbeatitems.cc
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************/
|
72
libretroshare/src/serialiser/rsheartbeatitems.h
Normal file
72
libretroshare/src/serialiser/rsheartbeatitems.h
Normal 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
|
||||||
|
|
@ -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_MSG = 0x0013;
|
||||||
const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
|
const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
|
||||||
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
||||||
|
const uint16_t RS_SERVICE_TYPE_HEARTBEAT = 0x0016;
|
||||||
|
|
||||||
/* BanList Still Testing at the moment - Service Only */
|
/* BanList Still Testing at the moment - Service Only */
|
||||||
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
|
||||||
|
@ -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_SUBJECT = 0x0058;
|
||||||
const uint16_t TLV_TYPE_STR_LINK = 0x0059;
|
const uint16_t TLV_TYPE_STR_LINK = 0x0059;
|
||||||
const uint16_t TLV_TYPE_STR_GENID = 0x005a;
|
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_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_CERT_SSL = 0x005e;
|
||||||
|
const uint16_t TLV_TYPE_STR_VERSION = 0x005f;
|
||||||
|
|
||||||
/* Wide Chars (4 bytes per char) for internationalisation */
|
/* Wide Chars (4 bytes per char) for internationalisation */
|
||||||
const uint16_t TLV_TYPE_WSTR_PEERID = 0x0060;
|
const uint16_t TLV_TYPE_WSTR_PEERID = 0x0060;
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.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
|
class RsTlvImage: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -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
|
|
File diff suppressed because it is too large
Load Diff
151
libretroshare/src/services/p3discovery2.h
Normal file
151
libretroshare/src/services/p3discovery2.h
Normal 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
|
122
libretroshare/src/services/p3heartbeat.cc
Normal file
122
libretroshare/src/services/p3heartbeat.cc
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
61
libretroshare/src/services/p3heartbeat.h
Normal file
61
libretroshare/src/services/p3heartbeat.h
Normal 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
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "util/rsnet.h"
|
#include "util/rsnet.h"
|
||||||
#include "util/rsstring.h"
|
#include "util/rsstring.h"
|
||||||
|
#include "pqi/pqinetwork.h"
|
||||||
|
|
||||||
/***************************** Internal Helper Fns ******************************/
|
/***************************** 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)
|
uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
|
||||||
{
|
{
|
||||||
|
#ifdef SS_DEBUG
|
||||||
std::cerr << "sockaddr_storage_port()";
|
std::cerr << "sockaddr_storage_port()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
switch(addr.ss_family)
|
switch(addr.ss_family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
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)
|
uint16_t sockaddr_storage_ipv4_port(const struct sockaddr_storage &addr)
|
||||||
{
|
{
|
||||||
|
#ifdef SS_DEBUG
|
||||||
std::cerr << "sockaddr_storage_ipv4_port()";
|
std::cerr << "sockaddr_storage_ipv4_port()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
const struct sockaddr_in *ipv4_ptr = to_const_ipv4_ptr(addr);
|
const struct sockaddr_in *ipv4_ptr = to_const_ipv4_ptr(addr);
|
||||||
uint16_t port = ntohs(ipv4_ptr->sin_port);
|
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 << "sockaddr_storage_ipv4_samenet()";
|
||||||
std::cerr << std::endl;
|
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)
|
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) addr;
|
||||||
(void) addr2;
|
(void) addr2;
|
||||||
|
|
||||||
std::cerr << "sockaddr_storage_ipv4_samesubnet()";
|
std::cerr << "sockaddr_storage_ipv4_samesubnet() using pqinetwork::isSameSubnet()";
|
||||||
std::cerr << std::endl;
|
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
|
// IPV6
|
||||||
|
@ -500,7 +500,7 @@ int p3ZeroConf::checkLocationResults()
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user