mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-15 02:44:20 -05:00
adding a deleted ssl friends persistence in p3disc to avoid getting back a friend we just deleted
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2051 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0318e73917
commit
3f22602b6c
@ -65,6 +65,8 @@ const uint32_t CONFIG_TYPE_MSGS = 0x0004;
|
|||||||
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
|
const uint32_t CONFIG_TYPE_CACHE_OLDID = 0x0005;
|
||||||
const uint32_t CONFIG_TYPE_AUTHGPG = 0x006;
|
const uint32_t CONFIG_TYPE_AUTHGPG = 0x006;
|
||||||
|
|
||||||
|
const uint32_t CONFIG_TYPE_P3DISC = 0x00B;
|
||||||
|
|
||||||
|
|
||||||
/* new FileTransfer */
|
/* new FileTransfer */
|
||||||
const uint32_t CONFIG_TYPE_FT_SHARED = 0x0007;
|
const uint32_t CONFIG_TYPE_FT_SHARED = 0x0007;
|
||||||
|
@ -571,7 +571,7 @@ std::string p3Peers::getGPGId(std::string sslid_or_gpgid)
|
|||||||
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
return AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||||
}
|
}
|
||||||
peerConnectState pcs;
|
peerConnectState pcs;
|
||||||
if (mConnMgr->getFriendNetStatus(sslid_or_gpgid, pcs)) {
|
if (mConnMgr->getFriendNetStatus(sslid_or_gpgid, pcs) || mConnMgr->getOthersNetStatus(sslid_or_gpgid, pcs)) {
|
||||||
return pcs.gpg_id;
|
return pcs.gpg_id;
|
||||||
} else {
|
} else {
|
||||||
if ( AuthGPG::getAuthGPG()->isGPGId(sslid_or_gpgid)) {
|
if ( AuthGPG::getAuthGPG()->isGPGId(sslid_or_gpgid)) {
|
||||||
@ -637,9 +637,14 @@ bool p3Peers::isDummyFriend(std::string ssl_id) {
|
|||||||
bool p3Peers::removeFriend(std::string ssl_or_gpgid)
|
bool p3Peers::removeFriend(std::string ssl_or_gpgid)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::removeFriend() " << id;
|
std::cerr << "p3Peers::removeFriend() " << id << std::endl;
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
if (ssl_or_gpgid == AuthGPG::getAuthGPG()->getGPGOwnId()) {
|
||||||
|
#ifdef P3PEERS_DEBUG
|
||||||
|
std::cerr << "p3Peers::removeFriend() fail : we're not going to remove our own GPG id." << std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//will remove if it's a gpg id
|
//will remove if it's a gpg id
|
||||||
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(ssl_or_gpgid, false);
|
AuthGPG::getAuthGPG()->setAcceptToConnectGPGCertificate(ssl_or_gpgid, false);
|
||||||
|
|
||||||
|
@ -2032,6 +2032,7 @@ int RsServer::StartupRetroShare()
|
|||||||
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
||||||
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
||||||
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
||||||
|
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
||||||
|
|
||||||
ftserver->addConfiguration(mConfigMgr);
|
ftserver->addConfiguration(mConfigMgr);
|
||||||
|
|
||||||
|
@ -81,15 +81,13 @@ const uint32_t P3DISC_FLAGS_ASK_VERSION = 0x0080;
|
|||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
|
|
||||||
p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
|
p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
|
||||||
:p3Service(RS_SERVICE_TYPE_DISC), mConnMgr(cm), mPqiPersonGrp(pqih)
|
:p3Service(RS_SERVICE_TYPE_DISC), mConnMgr(cm), mPqiPersonGrp(pqih), p3Config(CONFIG_TYPE_P3DISC)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
addSerialType(new RsDiscSerialiser());
|
addSerialType(new RsDiscSerialiser());
|
||||||
|
|
||||||
mRemoteDisc = true;
|
lastSentHeartbeatTime = time(NULL);
|
||||||
mLocalDisc = false;
|
|
||||||
lastSentHeartbeatTime = 0;
|
|
||||||
|
|
||||||
//add own version to versions map
|
//add own version to versions map
|
||||||
versions[AuthSSL::getAuthSSL()->OwnId()] = RsUtil::retroshareVersion();
|
versions[AuthSSL::getAuthSSL()->OwnId()] = RsUtil::retroshareVersion();
|
||||||
@ -136,14 +134,9 @@ int p3disc::handleIncoming()
|
|||||||
|
|
||||||
bool discOn;
|
bool discOn;
|
||||||
|
|
||||||
{
|
|
||||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
|
||||||
discOn = mRemoteDisc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if off discard item.
|
// if off discard item.
|
||||||
if (!mRemoteDisc)
|
peerConnectState detail;
|
||||||
{
|
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||||
while(NULL != (item = recvItem()))
|
while(NULL != (item = recvItem()))
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
@ -219,19 +212,24 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << "p3disc::statusChange()";
|
std::cerr << "p3disc::statusChange()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
// if off discard item.
|
||||||
|
peerConnectState detail;
|
||||||
|
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<pqipeer>::const_iterator pit;
|
std::list<pqipeer>::const_iterator pit;
|
||||||
/* if any have switched to 'connected' then we notify */
|
/* if any have switched to 'connected' then we notify */
|
||||||
for(pit = plist.begin(); pit != plist.end(); pit++) {
|
for(pit = plist.begin(); pit != plist.end(); pit++) {
|
||||||
if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED)) {
|
if ((pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_CONNECTED)) {
|
||||||
/* send their own details to them. Usefull for ext ip address detection */
|
|
||||||
// sendPeerDetails(pit->id, pit->id);
|
|
||||||
// /* send our details to them */
|
|
||||||
sendOwnVersion(pit->id);
|
sendOwnVersion(pit->id);
|
||||||
sendAllInfoToJustConnectedPeer(pit->id);
|
sendAllInfoToJustConnectedPeer(pit->id);
|
||||||
sendJustConnectedPeerInfoToAllPeer(pit->id);
|
sendJustConnectedPeerInfoToAllPeer(pit->id);
|
||||||
}
|
}
|
||||||
}
|
if (!(pit->state & RS_PEER_S_FRIEND) && (pit->actions & RS_PEER_MOVED)) {
|
||||||
|
this->removeFriend(pit->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
|
void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
|
||||||
@ -418,6 +416,11 @@ void p3disc::sendHeartbeat(std::string to)
|
|||||||
|
|
||||||
void p3disc::recvPeerDetails(RsDiscReply *item)
|
void p3disc::recvPeerDetails(RsDiscReply *item)
|
||||||
{
|
{
|
||||||
|
// if off discard item.
|
||||||
|
peerConnectState detail;
|
||||||
|
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
std::cerr << "p3disc::recvPeerFriendMsg() From: " << item->PeerId() << " About " << item->aboutId << std::endl;
|
||||||
@ -445,16 +448,24 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (pitem->pid != rsPeers->getOwnId()) {
|
if (pitem->pid != rsPeers->getOwnId()) {
|
||||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, pitem->visState, 0);
|
//check that the friend is not a deleted one
|
||||||
|
if (deletedSSLFriendsIds.find(pitem->pid) == deletedSSLFriendsIds.end()) {
|
||||||
|
//|| {
|
||||||
|
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc bay default. If friend already exist, it will do nothing
|
||||||
|
} else if ((pitem->lastContact - deletedSSLFriendsIds[pitem->pid]) > 3600*48) { // the friend was seen 48hours before we deleted it, we will readd it
|
||||||
|
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, RS_VIS_STATE_NODISC, 0); //add with no disc bay default. If friend already exist, it will do nothing
|
||||||
|
}
|
||||||
RsPeerDetails storedDetails;
|
RsPeerDetails storedDetails;
|
||||||
rsPeers->getPeerDetails(pitem->pid, storedDetails);
|
if (rsPeers->getPeerDetails(pitem->pid, storedDetails) //update only if we got a detail
|
||||||
if ( (!(storedDetails.state & RS_PEER_CONNECTED) && storedDetails.lastConnect < (pitem->lastContact - 10000))
|
&& ((!(storedDetails.state & RS_PEER_CONNECTED) && storedDetails.lastConnect < (pitem->lastContact - 10000))
|
||||||
|| item->PeerId() == pitem->pid) { //update if it's fresh info or if it's from the peer itself
|
|| item->PeerId() == pitem->pid)) { //update if it's fresh info or if it's from the peer itself
|
||||||
//their info is fresher than ours (there is a 10000 seconds margin), update ours
|
//their info is fresher than ours (there is a 10000 seconds margin), update ours
|
||||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
|
||||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||||
|
if (item->PeerId() == pitem->pid) {
|
||||||
|
mConnMgr->setVisState(pitem->pid, pitem->visState); //update vistate only if it's from the peer itself
|
||||||
|
}
|
||||||
if (storedDetails.location == "") {
|
if (storedDetails.location == "") {
|
||||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
mConnMgr->setLocation(pitem->pid, pitem->location);
|
||||||
}
|
}
|
||||||
@ -484,28 +495,6 @@ void p3disc::recvPeerDetails(RsDiscReply *item)
|
|||||||
/* cleanup (handled by caller) */
|
/* cleanup (handled by caller) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//void p3disc::recvPeerIssuerMsg(RsDiscIssuer *item)
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
//#ifdef P3DISC_DEBUG
|
|
||||||
// std::cerr << "p3disc::recvPeerIssuerMsg() From: " << item->PeerId();
|
|
||||||
// std::cerr << std::endl;
|
|
||||||
// std::cerr << "p3disc::recvPeerIssuerMsg() Cert: " << item->issuerCert;
|
|
||||||
// std::cerr << std::endl;
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// /* tells us their exact address (mConnectMgr can ignore if it looks wrong) */
|
|
||||||
//
|
|
||||||
// /* load certificate */
|
|
||||||
// std::string gpgId;
|
|
||||||
// bool loaded = AuthGPG::getAuthGPG()->LoadCertificateFromString(item->issuerCert, gpgId);
|
|
||||||
//
|
|
||||||
// /* cleanup (handled by caller) */
|
|
||||||
//
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
void p3disc::recvPeerVersionMsg(RsDiscVersion *item)
|
void p3disc::recvPeerVersionMsg(RsDiscVersion *item)
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
@ -531,6 +520,24 @@ void p3disc::recvHeartbeatMsg(RsDiscHeartbeat *item)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3disc::removeFriend(std::string ssl_id) {
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::removeFriend() called for : " << ssl_id << std::endl;
|
||||||
|
#endif
|
||||||
|
//if we deleted the gpg_id, don't store the friend deletion as if we add back the gpg_id, we won't have the ssl friends back
|
||||||
|
std::string gpg_id = rsPeers->getGPGId(ssl_id);
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::removeFriend() gpg_id : " << gpg_id << std::endl;
|
||||||
|
#endif
|
||||||
|
if (gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId() || rsPeers->isGPGAccepted(rsPeers->getGPGId(ssl_id))) {
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::removeFriend() storing the friend deletion." << ssl_id << std::endl;
|
||||||
|
#endif
|
||||||
|
deletedSSLFriendsIds[ssl_id] = time(NULL);//just keep track of the deleted time
|
||||||
|
IndicateConfigChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
/* Storing Network Graph */
|
/* Storing Network Graph */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
@ -713,3 +720,65 @@ int convertTRangeToTDelta(int trange)
|
|||||||
return (int) (pow(10.0, trange) - 1.5); // (int) xxx98.5 -> xxx98
|
return (int) (pow(10.0, trange) - 1.5); // (int) xxx98.5 -> xxx98
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
// -------------------------------- Config functions ------------------------------ //
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
//
|
||||||
|
RsSerialiser *p3disc::setupSerialiser()
|
||||||
|
{
|
||||||
|
RsSerialiser *rss = new RsSerialiser ;
|
||||||
|
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||||
|
return rss ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<RsItem*> p3disc::saveList(bool& cleanup)
|
||||||
|
{
|
||||||
|
std::cerr << "p3disc::saveList() called" << std::endl ;
|
||||||
|
cleanup = true ;
|
||||||
|
std::list<RsItem*> lst ;
|
||||||
|
|
||||||
|
// Now save config for network digging strategies
|
||||||
|
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||||
|
std::map<std::string, time_t>::iterator mapIt;
|
||||||
|
for (mapIt = deletedSSLFriendsIds.begin(); mapIt != deletedSSLFriendsIds.end(); mapIt++) {
|
||||||
|
RsTlvKeyValue kv;
|
||||||
|
kv.key = mapIt->first;
|
||||||
|
std::ostringstream time_string;
|
||||||
|
time_string << mapIt->second;
|
||||||
|
kv.value = time_string.str();
|
||||||
|
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||||
|
std::cerr << "p3disc::saveList() saving : " << mapIt->first << " ; " << mapIt->second << std::endl ;
|
||||||
|
}
|
||||||
|
lst.push_back(vitem);
|
||||||
|
|
||||||
|
return lst ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3disc::loadList(std::list<RsItem*> load)
|
||||||
|
{
|
||||||
|
std::cerr << "p3disc::loadList() Item Count: " << load.size() << std::endl;
|
||||||
|
|
||||||
|
RsStackMutex stack(mDiscMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
/* load the list of accepted gpg keys */
|
||||||
|
std::list<RsItem *>::iterator it;
|
||||||
|
for(it = load.begin(); it != load.end(); it++) {
|
||||||
|
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||||
|
|
||||||
|
if(vitem) {
|
||||||
|
std::cerr << "p3disc::loadList() General Variable Config Item:" << std::endl;
|
||||||
|
vitem->print(std::cerr, 10);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
std::list<RsTlvKeyValue>::iterator kit;
|
||||||
|
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); kit++) {
|
||||||
|
std::istringstream instream(kit->value);
|
||||||
|
time_t deleted_time_t;
|
||||||
|
instream >> deleted_time_t;
|
||||||
|
deletedSSLFriendsIds[kit->key] = deleted_time_t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete (*it);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -74,7 +74,7 @@ class autoneighbour: public autoserver
|
|||||||
class p3ConnectMgr;
|
class p3ConnectMgr;
|
||||||
|
|
||||||
|
|
||||||
class p3disc: public p3Service, public pqiMonitor
|
class p3disc: public p3Service, public pqiMonitor, public p3Config
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -91,7 +91,16 @@ int tick();
|
|||||||
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
||||||
void getversions(std::map<std::string, std::string> &versions);
|
void getversions(std::map<std::string, std::string> &versions);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
/*****************************************************************/
|
||||||
|
/*********************** p3config ******************************/
|
||||||
|
/* Key Functions to be overloaded for Full Configuration */
|
||||||
|
virtual RsSerialiser *setupSerialiser();
|
||||||
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
|
/*****************************************************************/
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
void sendAllInfoToJustConnectedPeer(std::string id);
|
void sendAllInfoToJustConnectedPeer(std::string id);
|
||||||
@ -112,7 +121,9 @@ void recvPeerDetails(RsDiscReply *item);
|
|||||||
void recvPeerVersionMsg(RsDiscVersion *item);
|
void recvPeerVersionMsg(RsDiscVersion *item);
|
||||||
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
||||||
|
|
||||||
/* handle network shape */
|
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(std::string fromId, std::string aboutId,
|
int addDiscoveryData(std::string fromId, std::string aboutId,
|
||||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||||
uint32_t flags, time_t ts);
|
uint32_t flags, time_t ts);
|
||||||
@ -129,10 +140,9 @@ int idServers();
|
|||||||
/* data */
|
/* data */
|
||||||
RsMutex mDiscMtx;
|
RsMutex mDiscMtx;
|
||||||
|
|
||||||
bool mRemoteDisc;
|
std::map<std::string, time_t> deletedSSLFriendsIds;
|
||||||
bool mLocalDisc;
|
|
||||||
|
|
||||||
std::map<std::string, autoneighbour> neighbours;
|
std::map<std::string, autoneighbour> neighbours;
|
||||||
std::map<std::string, std::string> versions;
|
std::map<std::string, std::string> versions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user