2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* 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"
|
2009-12-22 05:41:19 -05:00
|
|
|
#include "pqi/pqipersongrp.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
class p3ConnectMgr;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
#include "pqi/pqimonitor.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "serialiser/rsdiscitems.h"
|
|
|
|
#include "services/p3service.h"
|
2010-10-13 12:15:26 -04:00
|
|
|
#include "pqi/authgpg.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
class autoserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
autoserver()
|
2008-02-03 01:29:02 -05:00
|
|
|
:ts(0), discFlags(0) { return;}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
std::string id;
|
2008-02-03 01:29:02 -05:00
|
|
|
struct sockaddr_in localAddr;
|
|
|
|
struct sockaddr_in remoteAddr;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
time_t ts;
|
|
|
|
uint32_t discFlags;
|
2007-12-11 20:43:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class autoneighbour: public autoserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
autoneighbour()
|
2008-02-03 01:29:02 -05:00
|
|
|
:autoserver(), authoritative(false) {}
|
|
|
|
|
|
|
|
bool authoritative;
|
|
|
|
bool validAddrs;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
std::map<std::string, autoserver> neighbour_of;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
class p3PeerMgr;
|
|
|
|
class p3LinkMgr;
|
2011-11-22 08:24:42 -05:00
|
|
|
class p3NetMgr;
|
2008-02-03 01:29:02 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
class p3disc: public p3Service, public pqiMonitor, public p3Config, public AuthGPGService
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2011-11-22 08:24:42 -05:00
|
|
|
p3disc(p3PeerMgr *pm, p3LinkMgr *lm, p3NetMgr *nm, pqipersongrp *persGrp);
|
2008-02-03 01:29:02 -05:00
|
|
|
|
|
|
|
/************* from pqiMonitor *******************/
|
|
|
|
virtual void statusChange(const std::list<pqipeer> &plist);
|
|
|
|
/************* from pqiMonitor *******************/
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
int tick();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
/* GUI requires access */
|
2010-11-14 16:03:36 -05:00
|
|
|
bool potentialGPGproxies(const std::string& id, std::list<std::string> &proxyGPGIds);
|
|
|
|
bool potentialproxies(const std::string& id, std::list<std::string> &proxyIds);
|
2009-06-28 16:57:02 -04:00
|
|
|
void getversions(std::map<std::string, std::string> &versions);
|
2011-01-07 11:56:57 -05:00
|
|
|
void getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount);
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
/************* from AuthGPService ****************/
|
|
|
|
virtual AuthGPGOperation *getGPGOperation();
|
|
|
|
virtual void setGPGOperation(AuthGPGOperation *operation);
|
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
protected:
|
|
|
|
/*****************************************************************/
|
|
|
|
/*********************** p3config ******************************/
|
|
|
|
/* Key Functions to be overloaded for Full Configuration */
|
|
|
|
virtual RsSerialiser *setupSerialiser();
|
2010-12-18 14:35:07 -05:00
|
|
|
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
|
|
|
virtual bool loadList(std::list<RsItem *>& load);
|
2010-01-15 16:09:25 -05:00
|
|
|
/*****************************************************************/
|
|
|
|
|
|
|
|
private:
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
void sendAllInfoToJustConnectedPeer(const std::string &id);
|
|
|
|
void sendJustConnectedPeerInfoToAllPeer(const std::string &id);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* Network Output */
|
2010-01-13 16:33:54 -05:00
|
|
|
//void sendOwnDetails(std::string to);
|
2009-06-28 16:57:02 -04:00
|
|
|
void sendOwnVersion(std::string to);
|
2010-10-13 12:15:26 -04:00
|
|
|
RsDiscReply *createDiscReply(const std::string &to, const std::string &about);
|
2010-01-13 16:33:54 -05:00
|
|
|
//void sendPeerIssuer(std::string to, std::string about);
|
2009-12-22 05:41:19 -05:00
|
|
|
void sendHeartbeat(std::string to);
|
2010-01-19 14:15:22 -05:00
|
|
|
void askInfoToAllPeers(std::string about);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
/* Network Input */
|
|
|
|
int handleIncoming();
|
2010-01-19 14:15:22 -05:00
|
|
|
void recvAskInfo(RsDiscAskInfo *item);
|
2010-10-13 12:15:26 -04:00
|
|
|
void recvPeerDetails(RsDiscReply *item, const std::string &certGpgId);
|
2010-01-13 16:33:54 -05:00
|
|
|
//void recvPeerIssuerMsg(RsDiscIssuer *item);
|
2009-06-28 16:57:02 -04:00
|
|
|
void recvPeerVersionMsg(RsDiscVersion *item);
|
2009-12-22 05:41:19 -05:00
|
|
|
void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
2011-08-07 17:11:00 -04:00
|
|
|
void recvDiscReply(RsDiscReply *dri);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-01-15 16:09:25 -05:00
|
|
|
void removeFriend(std::string ssl_id); //keep tracks of removed friend so we're not gonna add them again immediately
|
|
|
|
|
|
|
|
/* handle network shape */
|
2010-11-14 16:03:36 -05:00
|
|
|
int addDiscoveryData(const std::string& fromId, const std::string& aboutId,
|
|
|
|
const std::string& fromGPGId,const std::string& aboutGPGId,
|
|
|
|
const struct sockaddr_in& laddr, const struct sockaddr_in& raddr,
|
2010-11-05 18:46:40 -04:00
|
|
|
uint32_t flags, time_t ts,bool& new_info);
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
int idServers();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
private:
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
p3PeerMgr *mPeerMgr;
|
|
|
|
p3LinkMgr *mLinkMgr;
|
2011-11-22 08:24:42 -05:00
|
|
|
p3NetMgr *mNetMgr;
|
2011-07-09 14:39:34 -04:00
|
|
|
|
|
|
|
pqipersongrp *mPqiPersonGrp;
|
2008-02-04 16:40:34 -05:00
|
|
|
|
|
|
|
/* data */
|
|
|
|
RsMutex mDiscMtx;
|
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
time_t mLastSentHeartbeatTime;
|
|
|
|
bool mDiscEnabled;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
//std::map<std::string, time_t> deletedSSLFriendsIds;
|
2010-09-22 19:45:54 -04:00
|
|
|
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
std::map<std::string, std::list<std::string> > mSendIdList;
|
|
|
|
std::list<RsDiscReply*> mPendingDiscReplyInList;
|
2010-11-14 16:03:36 -05:00
|
|
|
|
|
|
|
// Neighbors at the gpg level.
|
|
|
|
std::map<std::string,std::set<std::string> > gpg_neighbors ;
|
2011-08-07 17:11:00 -04:00
|
|
|
|
|
|
|
// Original mapping.
|
|
|
|
std::map<std::string, autoneighbour> neighbours;
|
|
|
|
|
|
|
|
// Rs Version.
|
|
|
|
std::map<std::string, std::string> versions;
|
2008-02-03 01:29:02 -05:00
|
|
|
};
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
#endif // MRK_PQI_AUTODISC_H
|