mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04: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
38 changed files with 3248 additions and 1543 deletions
|
@ -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
|
|
@ -560,7 +560,7 @@ bool p3Posted::generatePost(uint32_t &token, const RsGxsGroupId &grpId)
|
|||
|
||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
||||
uint32_t i = 0;
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
||||
|
||||
if (it != ownIds.end())
|
||||
{
|
||||
|
@ -605,7 +605,7 @@ bool p3Posted::generateComment(uint32_t &token, const RsGxsGroupId &grpId, const
|
|||
|
||||
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
||||
uint32_t i = 0;
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++);
|
||||
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
||||
|
||||
if (it != ownIds.end())
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue