mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-15 09:36:23 -04:00
ID cleaning - saving work
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7108 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
328d820421
commit
4b7a2160b9
21 changed files with 327 additions and 309 deletions
|
@ -239,7 +239,7 @@ virtual int getConfigNetStatus(RsConfigNetStatus &status) = 0;
|
|||
//virtual int getConfigStartup(RsConfigStartup ¶ms) = 0;
|
||||
|
||||
virtual int getTotalBandwidthRates(RsConfigDataRates &rates) = 0;
|
||||
virtual int getAllBandwidthRates(std::map<std::string, RsConfigDataRates> &ratemap) = 0;
|
||||
virtual int getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap) = 0;
|
||||
|
||||
/* From RsInit */
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsDisc;
|
||||
|
@ -42,9 +43,9 @@ class RsDisc
|
|||
RsDisc() { return; }
|
||||
virtual ~RsDisc() { return; }
|
||||
|
||||
virtual bool getDiscFriends(const std::string &id, std::list<std::string>& friends) = 0;
|
||||
virtual bool getDiscPgpFriends(const std::string &pgpid, std::list<std::string>& gpg_friends) = 0;
|
||||
virtual bool getPeerVersion(const std::string &id, std::string &versions) = 0;
|
||||
virtual bool getDiscFriends(const RsPeerId &id, std::list<RsPeerId>& friends) = 0;
|
||||
virtual bool getDiscPgpFriends(const PGPIdType &pgpid, std::list<PGPIdType>& gpg_friends) = 0;
|
||||
virtual bool getPeerVersion(const RsPeerId &id, std::string &versions) = 0;
|
||||
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount) = 0;
|
||||
|
||||
};
|
||||
|
|
|
@ -238,7 +238,7 @@ extern RsMsgs *rsMsgs;
|
|||
struct DistantOfflineMessengingInvite
|
||||
{
|
||||
PGPIdType issuer_pgp_id ;
|
||||
std::string hash ;
|
||||
Sha1CheckSum hash ;
|
||||
time_t time_of_validity ;
|
||||
};
|
||||
|
||||
|
@ -290,7 +290,7 @@ virtual bool createDistantOfflineMessengingInvite(time_t validity_time_stamp, st
|
|||
virtual bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) = 0 ;
|
||||
virtual void enableDistantMessaging(bool b) = 0;
|
||||
virtual bool distantMessagingEnabled() = 0;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id, std::string& hash) = 0;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id, Sha1CheckSum& hash) = 0;
|
||||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
|
|
|
@ -34,6 +34,7 @@ extern RsStatus *rsStatus;
|
|||
#include <string>
|
||||
#include <inttypes.h>
|
||||
#include <list>
|
||||
#include <retroshare/rstypes.h>
|
||||
|
||||
|
||||
const uint32_t RS_STATUS_OFFLINE = 0x0000;
|
||||
|
@ -58,7 +59,7 @@ class StatusInfo
|
|||
}
|
||||
|
||||
public:
|
||||
std::string id;
|
||||
RsPeerId id;
|
||||
uint32_t status;
|
||||
time_t time_stamp; /// for owner time set, and for their peers time sent
|
||||
};
|
||||
|
@ -88,7 +89,7 @@ class RsStatus
|
|||
* This retrieves the status info one peer
|
||||
* @param statusInfo is populated with client's peer's status
|
||||
*/
|
||||
virtual bool getStatus(const std::string &id, StatusInfo &statusInfo) = 0;
|
||||
virtual bool getStatus(const RsPeerId &id, StatusInfo &statusInfo) = 0;
|
||||
|
||||
/**
|
||||
* send the client's status to his/her peers
|
||||
|
@ -96,7 +97,7 @@ class RsStatus
|
|||
* @param status the status of the peers
|
||||
* @return will return false if status info does not belong to client
|
||||
*/
|
||||
virtual bool sendStatus(const std::string &id, uint32_t status) = 0;
|
||||
virtual bool sendStatus(const RsPeerId &id, uint32_t status) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ bool p3Msgs::distantMessagingEnabled()
|
|||
{
|
||||
return mMsgSrv->distantMessagingEnabled();
|
||||
}
|
||||
bool p3Msgs::getDistantMessageHash(const PGPIdType& pgp_id,std::string& hash)
|
||||
bool p3Msgs::getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash)
|
||||
{
|
||||
return mMsgSrv->getDistantMessageHash(pgp_id,hash);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ class p3Msgs: public RsMsgs
|
|||
|
||||
virtual void enableDistantMessaging(bool b) ;
|
||||
virtual bool distantMessagingEnabled() ;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id,std::string& hash) ;
|
||||
virtual bool getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash) ;
|
||||
|
||||
/*!
|
||||
* gets avatar from peer, image data in jpeg format
|
||||
|
|
|
@ -206,7 +206,7 @@ int p3ServerConfig::getTotalBandwidthRates(RsConfigDataRates &rates)
|
|||
}
|
||||
|
||||
|
||||
int p3ServerConfig::getAllBandwidthRates(std::map<std::string, RsConfigDataRates> &ratemap)
|
||||
int p3ServerConfig::getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap)
|
||||
{
|
||||
if (rsBandwidthControl)
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ virtual int getConfigStartup(RsConfigStartup ¶ms);
|
|||
/***** for RsConfig -> p3BandwidthControl ****/
|
||||
|
||||
virtual int getTotalBandwidthRates(RsConfigDataRates &rates);
|
||||
virtual int getAllBandwidthRates(std::map<std::string, RsConfigDataRates> &ratemap);
|
||||
virtual int getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap);
|
||||
|
||||
/* From RsInit */
|
||||
|
||||
|
|
|
@ -47,12 +47,12 @@ bool p3Status::getStatusList(std::list<StatusInfo>& statusInfo){
|
|||
return mStatusSrv->getStatusList(statusInfo);
|
||||
}
|
||||
|
||||
bool p3Status::getStatus(const std::string &id, StatusInfo &statusInfo)
|
||||
bool p3Status::getStatus(const RsPeerId &id, StatusInfo &statusInfo)
|
||||
{
|
||||
return mStatusSrv->getStatus(id, statusInfo);
|
||||
}
|
||||
|
||||
bool p3Status::sendStatus(const std::string &id, uint32_t status){
|
||||
bool p3Status::sendStatus(const RsPeerId &id, uint32_t status){
|
||||
|
||||
return mStatusSrv->sendStatus(id, status);
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ public:
|
|||
|
||||
virtual bool getOwnStatus(StatusInfo& statusInfo);
|
||||
virtual bool getStatusList(std::list<StatusInfo>& statusInfo);
|
||||
virtual bool getStatus(const std::string &id, StatusInfo &statusInfo);
|
||||
virtual bool sendStatus(const std::string &id, uint32_t status);
|
||||
virtual bool getStatus(const RsPeerId &id, StatusInfo &statusInfo);
|
||||
virtual bool sendStatus(const RsPeerId &id, uint32_t status);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@ std::ostream &RsDiscPgpCertItem::print(std::ostream &out, uint16_t indent)
|
|||
uint32_t RsDiscSerialiser::sizePgpCert(RsDiscPgpCertItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->pgpId);
|
||||
s += item->pgpId.serial_size();
|
||||
s += GetTlvStringSize(item->pgpCert);
|
||||
return s;
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ bool RsDiscSerialiser::serialisePgpCert(RsDiscPgpCertItem *item, void *data,
|
|||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPID, item->pgpId);
|
||||
ok &= item->pgpId.serialise(data, tlvsize, offset) ;
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert);
|
||||
|
||||
if (offset != tlvsize) {
|
||||
|
@ -523,7 +523,7 @@ RsDiscPgpCertItem *RsDiscSerialiser::deserialisePgpCert(void *data, uint32_t *pk
|
|||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPID, item->pgpId);
|
||||
ok &= item->pgpId.deserialise(data, rssize, offset) ;
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_PGPCERT, item->pgpCert);
|
||||
|
||||
if (offset != rssize) {
|
||||
|
@ -659,8 +659,8 @@ std::ostream &RsDiscContactItem::print(std::ostream &out, uint16_t indent)
|
|||
uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->pgpId);
|
||||
s += GetTlvStringSize(item->sslId);
|
||||
s += item->pgpId.serial_size();
|
||||
s += item->sslId.serial_size();
|
||||
|
||||
s += GetTlvStringSize(item->location);
|
||||
s += GetTlvStringSize(item->version);
|
||||
|
@ -733,8 +733,8 @@ bool RsDiscSerialiser::serialiseContact(RsDiscContactItem *item, void *data,
|
|||
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 &= item->pgpId.serialise(data, tlvsize, offset) ;
|
||||
ok &= item->sslId.serialise(data, tlvsize, offset) ;
|
||||
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LOCATION, item->location);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
|
@ -818,8 +818,8 @@ RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pk
|
|||
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 &= item->pgpId.deserialise(data, rssize, offset) ;
|
||||
ok &= item->pgpId.deserialise(data, rssize, offset) ;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_LOCATION, item->location);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version);
|
||||
|
|
|
@ -86,7 +86,7 @@ virtual ~RsDiscPgpCertItem();
|
|||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string pgpId;
|
||||
PGPIdType pgpId;
|
||||
std::string pgpCert;
|
||||
};
|
||||
|
||||
|
@ -106,8 +106,8 @@ virtual ~RsDiscContactItem();
|
|||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string pgpId;
|
||||
std::string sslId;
|
||||
PGPIdType pgpId;
|
||||
RsPeerId sslId;
|
||||
|
||||
// COMMON
|
||||
std::string location;
|
||||
|
|
|
@ -143,9 +143,9 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
|
|||
}
|
||||
|
||||
/* overloaded from pqiNetAssistSharePeer */
|
||||
void p3BanList::updatePeer(std::string /*id*/, const struct sockaddr_storage &addr, int /*type*/, int /*reason*/, int age)
|
||||
void p3BanList::updatePeer(const RsPeerId& /*id*/, const struct sockaddr_storage &addr, int /*type*/, int /*reason*/, int age)
|
||||
{
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
RsPeerId ownId = mLinkMgr->getOwnId();
|
||||
|
||||
int int_reason = 0;
|
||||
addBanEntry(ownId, addr, RSBANLIST_SOURCE_SELF, int_reason, age);
|
||||
|
@ -160,7 +160,7 @@ void p3BanList::updatePeer(std::string /*id*/, const struct sockaddr_storage &ad
|
|||
}
|
||||
|
||||
|
||||
bool p3BanList::addBanEntry(const std::string &peerId, const struct sockaddr_storage &addr, int level, uint32_t reason, uint32_t age)
|
||||
bool p3BanList::addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr, int level, uint32_t reason, uint32_t age)
|
||||
{
|
||||
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
|
@ -184,7 +184,7 @@ bool p3BanList::addBanEntry(const std::string &peerId, const struct sockaddr_sto
|
|||
}
|
||||
|
||||
|
||||
std::map<std::string, BanList>::iterator it;
|
||||
std::map<RsPeerId, BanList>::iterator it;
|
||||
it = mBanSources.find(peerId);
|
||||
if (it == mBanSources.end())
|
||||
{
|
||||
|
@ -247,14 +247,14 @@ bool p3BanList::addBanEntry(const std::string &peerId, const struct sockaddr_sto
|
|||
int p3BanList::condenseBanSources_locked()
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
RsPeerId ownId = mLinkMgr->getOwnId();
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "p3BanList::condenseBanSources_locked()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, BanList>::const_iterator it;
|
||||
std::map<RsPeerId, BanList>::const_iterator it;
|
||||
for(it = mBanSources.begin(); it != mBanSources.end(); it++)
|
||||
{
|
||||
if (now - it->second.mLastUpdate > RSBANLIST_ENTRY_MAX_AGE)
|
||||
|
@ -385,7 +385,7 @@ void p3BanList::sendBanLists()
|
|||
|
||||
/* we ping our peers */
|
||||
/* who is online? */
|
||||
std::list<std::string> idList;
|
||||
std::list<RsPeerId> idList;
|
||||
|
||||
mLinkMgr->getOnlineList(idList);
|
||||
|
||||
|
@ -395,7 +395,7 @@ void p3BanList::sendBanLists()
|
|||
#endif
|
||||
|
||||
/* prepare packets */
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsPeerId>::iterator it;
|
||||
for(it = idList.begin(); it != idList.end(); it++)
|
||||
{
|
||||
#ifdef DEBUG_BANLIST
|
||||
|
@ -408,7 +408,7 @@ void p3BanList::sendBanLists()
|
|||
|
||||
|
||||
|
||||
int p3BanList::sendBanSet(std::string peerid)
|
||||
int p3BanList::sendBanSet(const RsPeerId& peerid)
|
||||
{
|
||||
/* */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
|
@ -471,7 +471,7 @@ int p3BanList::printBanSources_locked(std::ostream &out)
|
|||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
std::map<std::string, BanList>::const_iterator it;
|
||||
std::map<RsPeerId, BanList>::const_iterator it;
|
||||
for(it = mBanSources.begin(); it != mBanSources.end(); it++)
|
||||
{
|
||||
out << "BanList from: " << it->first;
|
||||
|
|
|
@ -92,12 +92,12 @@ int p3BandwidthControl::status()
|
|||
bool p3BandwidthControl::checkAvailableBandwidth()
|
||||
{
|
||||
/* check each connection status */
|
||||
std::map<std::string, RsBwRates> rateMap;
|
||||
std::map<RsPeerId, RsBwRates> rateMap;
|
||||
RsBwRates total;
|
||||
|
||||
mPg->ExtractRates(rateMap, total);
|
||||
std::map<std::string, RsBwRates>::iterator it;
|
||||
std::map<std::string, BwCtrlData>::iterator bit;
|
||||
std::map<RsPeerId, RsBwRates>::iterator it;
|
||||
std::map<RsPeerId, BwCtrlData>::iterator bit;
|
||||
|
||||
/* have to merge with existing list,
|
||||
* erasing as we go ... then any left have to deal with
|
||||
|
@ -107,7 +107,7 @@ bool p3BandwidthControl::checkAvailableBandwidth()
|
|||
mTotalRates = total;
|
||||
|
||||
time_t now = time(NULL);
|
||||
std::list<std::string> oldIds; // unused for now!
|
||||
std::list<RsPeerId> oldIds; // unused for now!
|
||||
|
||||
for(bit = mBwMap.begin(); bit != mBwMap.end(); bit++)
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ bool p3BandwidthControl::processIncoming()
|
|||
|
||||
/* For each packet */
|
||||
RsStackMutex stack(mBwMtx); /****** LOCKED MUTEX *******/
|
||||
std::map<std::string, BwCtrlData>::iterator bit;
|
||||
std::map<RsPeerId, BwCtrlData>::iterator bit;
|
||||
|
||||
bit = mBwMap.find(bci->PeerId());
|
||||
if (bit == mBwMap.end())
|
||||
|
@ -231,11 +231,11 @@ int p3BandwidthControl::getTotalBandwidthRates(RsConfigDataRates &rates)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int p3BandwidthControl::getAllBandwidthRates(std::map<std::string, RsConfigDataRates> &ratemap)
|
||||
int p3BandwidthControl::getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap)
|
||||
{
|
||||
RsStackMutex stack(mBwMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
std::map<std::string, BwCtrlData>::iterator bit;
|
||||
std::map<RsPeerId, BwCtrlData>::iterator bit;
|
||||
for(bit = mBwMap.begin(); bit != mBwMap.end(); bit++)
|
||||
{
|
||||
RsConfigDataRates rates;
|
||||
|
@ -279,7 +279,7 @@ int p3BandwidthControl::printRateInfo_locked(std::ostream &out)
|
|||
out << " MaxOut: " << mTotalRates.mMaxRateOut;
|
||||
out << std::endl;
|
||||
|
||||
std::map<std::string, BwCtrlData>::iterator bit;
|
||||
std::map<RsPeerId, BwCtrlData>::iterator bit;
|
||||
for(bit = mBwMap.begin(); bit != mBwMap.end(); bit++)
|
||||
{
|
||||
out << "\t" << bit->first;
|
||||
|
@ -305,7 +305,7 @@ void p3BandwidthControl::statusChange(const std::list<pqipeer> &plist)
|
|||
if (it->actions & RS_PEER_DISCONNECTED)
|
||||
{
|
||||
/* remove from map */
|
||||
std::map<std::string, BwCtrlData>::iterator bit;
|
||||
std::map<RsPeerId, BwCtrlData>::iterator bit;
|
||||
bit = mBwMap.find(it->id);
|
||||
if (bit == mBwMap.end())
|
||||
{
|
||||
|
|
|
@ -88,7 +88,7 @@ class p3BandwidthControl: public p3Service, public pqiMonitor
|
|||
/***** for RsConfig (not directly overloaded) ****/
|
||||
|
||||
virtual int getTotalBandwidthRates(RsConfigDataRates &rates);
|
||||
virtual int getAllBandwidthRates(std::map<std::string, RsConfigDataRates> &ratemap);
|
||||
virtual int getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap);
|
||||
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ class p3BandwidthControl: public p3Service, public pqiMonitor
|
|||
time_t mLastCheck;
|
||||
|
||||
RsBwRates mTotalRates;
|
||||
std::map<std::string, BwCtrlData> mBwMap;
|
||||
std::map<RsPeerId, BwCtrlData> mBwMap;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ int p3discovery2::handleIncoming()
|
|||
{
|
||||
recvOwnContactInfo(item->PeerId(), contact);
|
||||
}
|
||||
else if (rsPeers->servicePermissionFlags_sslid(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY)
|
||||
else if (rsPeers->servicePermissionFlags(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY)
|
||||
{
|
||||
processContactInfo(item->PeerId(), contact);
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ int p3discovery2::handleIncoming()
|
|||
}
|
||||
|
||||
/* any other packets should be dropped if they don't have permission */
|
||||
if(!(rsPeers->servicePermissionFlags_sslid(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY))
|
||||
if(!(rsPeers->servicePermissionFlags(item->PeerId()) & RS_SERVICE_PERM_DISCOVERY))
|
||||
{
|
||||
delete item;
|
||||
continue;
|
||||
|
@ -773,7 +773,7 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI
|
|||
std::cerr << "p3discovery2::sendContactInfo_locked() aboutPGPId: " << aboutId << " toId: " << toId;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (!(rsPeers->servicePermissionFlags_sslid(toId) & RS_SERVICE_PERM_DISCOVERY))
|
||||
if (!(rsPeers->servicePermissionFlags(toId) & RS_SERVICE_PERM_DISCOVERY))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::sendContactInfo_locked() discovery disabled for SSLID: " << toId;
|
||||
|
@ -961,7 +961,7 @@ void p3discovery2::recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPg
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<std::string>::const_iterator it;
|
||||
std::list<PGPIdType>::const_iterator it;
|
||||
for(it = item->pgpIdSet.ids.begin(); it != item->pgpIdSet.ids.end(); it++)
|
||||
{
|
||||
// NB: This doesn't include own certificates? why not.
|
||||
|
@ -1084,7 +1084,7 @@ void p3discovery2::statusChange(const std::list<pqipeer> &plist)
|
|||
/*************************************************************************************/
|
||||
/* Extracting Network Graph Details */
|
||||
/*************************************************************************************/
|
||||
bool p3discovery2::getDiscFriends(const std::string& id, std::list<std::string> &proxyIds)
|
||||
bool p3discovery2::getDiscFriends(const RsPeerId& id, std::list<RsPeerId> &proxyIds)
|
||||
{
|
||||
// This is treated appart, because otherwise we don't receive any disc info about us
|
||||
if(id == rsPeers->getOwnId()) // SSL id
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
|
||||
|
||||
|
||||
typedef std::string PGPID;
|
||||
typedef std::string SSLID;
|
||||
typedef PGPIdType PGPID;
|
||||
typedef SSLIdType SSLID;
|
||||
|
||||
class DiscSslInfo
|
||||
{
|
||||
|
@ -88,9 +88,9 @@ virtual ~p3discovery2();
|
|||
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 getDiscFriends(const RsPeerId &id, std::list<RsPeerId> &friends);
|
||||
virtual bool getDiscPgpFriends(const PGPIdType &pgpid, std::list<PGPIdType> &gpg_friends);
|
||||
virtual bool getPeerVersion(const RsPeerId &id, std::string &version);
|
||||
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount);
|
||||
|
||||
/************* from AuthGPService ****************/
|
||||
|
|
|
@ -90,8 +90,8 @@ p3MsgService::p3MsgService(p3LinkMgr *lm)
|
|||
|
||||
#ifdef GROUTER
|
||||
// Debug stuff. Create a random key and register it.
|
||||
std::string own_ssl_id = rsPeers->getOwnId() ;
|
||||
std::string gpg_id = rsPeers->getGPGOwnId() ;
|
||||
const RsPeerId& own_ssl_id = rsPeers->getOwnId() ;
|
||||
const PGPIdType& gpg_id = rsPeers->getGPGOwnId() ;
|
||||
|
||||
RsPeerDetails d;
|
||||
rsPeers->getPeerDetails(gpg_id,d) ;
|
||||
|
@ -276,6 +276,22 @@ void p3MsgService::checkSizeAndSendMessage(RsMsgItem *msg)
|
|||
static const uint32_t MAX_STRING_SIZE = 15000 ;
|
||||
|
||||
std::cerr << "Msg is size " << msg->message.size() << std::endl;
|
||||
Sha1CheckSum hash ;
|
||||
|
||||
if( msg->msgFlags & RS_MSG_FLAGS_DISTANT )
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "checkOutgoingMessages(): removing pending message flag for hash " << (*it)->PeerId() << "." << std::endl;
|
||||
#endif
|
||||
if(!locked_findHashForVirtualPeerId(msg->PeerId(),hash))
|
||||
{
|
||||
std::cerr << "p3MsgService::checkSizeAndSendMessage(): Cannot find hash for virtual peer id " << msg->PeerId() << ". This is unexpected!" << std::endl;
|
||||
return ;
|
||||
}
|
||||
_messenging_contacts[hash].pending_messages = false ;
|
||||
}
|
||||
|
||||
while(msg->message.size() > MAX_STRING_SIZE)
|
||||
{
|
||||
|
@ -295,7 +311,11 @@ void p3MsgService::checkSizeAndSendMessage(RsMsgItem *msg)
|
|||
item->msgFlags |= RS_MSG_FLAGS_PARTIAL ;
|
||||
|
||||
if(msg->msgFlags & RS_MSG_FLAGS_DISTANT)
|
||||
sendPrivateMsgItem(item) ;
|
||||
{
|
||||
|
||||
|
||||
sendPrivateMsgItem(hash,item) ;
|
||||
}
|
||||
else
|
||||
sendItem(item) ;
|
||||
}
|
||||
|
@ -304,7 +324,7 @@ void p3MsgService::checkSizeAndSendMessage(RsMsgItem *msg)
|
|||
#endif
|
||||
|
||||
if(msg->msgFlags & RS_MSG_FLAGS_DISTANT)
|
||||
sendPrivateMsgItem(msg) ;
|
||||
sendPrivateMsgItem(hash,msg) ;
|
||||
else
|
||||
sendItem(msg) ;
|
||||
}
|
||||
|
@ -344,29 +364,29 @@ int p3MsgService::checkOutgoingMessages()
|
|||
#ifdef GROUTER
|
||||
tunnel_is_ok = true ;
|
||||
#else
|
||||
const RsPeerId& hash = mit->second->PeerId() ;
|
||||
std::map<std::string,DistantMessengingContact>::iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
if(it != _messenging_contacts.end())
|
||||
{
|
||||
tunnel_is_ok = (it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_OK) ;
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "checkOutGoingMessages(): distant contact found. tunnel_is_ok = " << tunnel_is_ok << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "checkOutGoingMessages(): distant contact not found. Asking for tunnels for hash " << hash << std::endl;
|
||||
#endif
|
||||
// no. Ask for monitoring tunnels.
|
||||
rsTurtle->monitorTunnels(hash,this) ;
|
||||
tunnel_is_ok = false ;
|
||||
|
||||
DistantMessengingContact& contact( _messenging_contacts[hash] ) ;
|
||||
contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_DN ;
|
||||
contact.pending_messages = true ;
|
||||
}
|
||||
// const RsPeerId& hash = mit->second->PeerId() ;
|
||||
// std::map<Sha1CheckSum,DistantMessengingContact>::iterator it = _messenging_contacts.find(hash) ;
|
||||
//
|
||||
// if(it != _messenging_contacts.end())
|
||||
// {
|
||||
// tunnel_is_ok = (it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_OK) ;
|
||||
//#ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "checkOutGoingMessages(): distant contact found. tunnel_is_ok = " << tunnel_is_ok << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
//#ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "checkOutGoingMessages(): distant contact not found. Asking for tunnels for hash " << hash << std::endl;
|
||||
//#endif
|
||||
// // no. Ask for monitoring tunnels.
|
||||
// rsTurtle->monitorTunnels(hash,this) ;
|
||||
// tunnel_is_ok = false ;
|
||||
//
|
||||
// DistantMessengingContact& contact( _messenging_contacts[hash] ) ;
|
||||
// contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_DN ;
|
||||
// contact.pending_messages = true ;
|
||||
// }
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -413,20 +433,8 @@ int p3MsgService::checkOutgoingMessages()
|
|||
}
|
||||
|
||||
for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it)
|
||||
{
|
||||
checkSizeAndSendMessage(*it) ;
|
||||
|
||||
if( (*it)->msgFlags & RS_MSG_FLAGS_DISTANT )
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
_messenging_contacts[(*it)->PeerId()].pending_messages = false ;
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "checkOutgoingMessages(): removing pending message flag for hash " << (*it)->PeerId() << "." << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(changed)
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
||||
|
||||
|
@ -467,14 +475,14 @@ bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)
|
|||
for(mit4 = mParentId.begin(); mit4 != mParentId.end(); mit4++)
|
||||
itemList.push_back(mit4->second);
|
||||
|
||||
for(std::map<std::string,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
{
|
||||
RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem ;
|
||||
item->hash = it->first ;
|
||||
item->time_stamp = it->second.time_of_validity ;
|
||||
|
||||
itemList.push_back(item) ;
|
||||
}
|
||||
// for(std::map<Sha1CheckSum,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
// {
|
||||
// RsPublicMsgInviteConfigItem *item = new RsPublicMsgInviteConfigItem ;
|
||||
// item->hash = it->first ;
|
||||
// item->time_stamp = it->second.time_of_validity ;
|
||||
//
|
||||
// itemList.push_back(item) ;
|
||||
// }
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "DISTANT_MESSAGES_ENABLED" ;
|
||||
|
@ -550,7 +558,7 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
RsMsgTags* mti;
|
||||
RsMsgSrcId* msi;
|
||||
RsMsgParentId* msp;
|
||||
RsPublicMsgInviteConfigItem* msv;
|
||||
// RsPublicMsgInviteConfigItem* msv;
|
||||
|
||||
std::list<RsMsgItem*> items;
|
||||
std::list<RsItem*>::iterator it;
|
||||
|
@ -600,10 +608,10 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
|
|||
{
|
||||
mParentId.insert(std::pair<uint32_t, RsMsgParentId*>(msp->msgId, msp));
|
||||
}
|
||||
else if(NULL != (msv = dynamic_cast<RsPublicMsgInviteConfigItem *>(*it)))
|
||||
{
|
||||
_messenging_invites[msv->hash].time_of_validity = msv->time_stamp ;
|
||||
}
|
||||
// else if(NULL != (msv = dynamic_cast<RsPublicMsgInviteConfigItem *>(*it)))
|
||||
// {
|
||||
// _messenging_invites[msv->hash].time_of_validity = msv->time_stamp ;
|
||||
// }
|
||||
|
||||
RsConfigKeyValueSet *vitem = NULL ;
|
||||
|
||||
|
@ -1082,16 +1090,16 @@ bool p3MsgService::MessageSend(MessageInfo &info)
|
|||
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
|
||||
if (msg)
|
||||
{
|
||||
std::list<RsPeerId>::iterator it ;
|
||||
std::list<PGPIdType>::iterator it ;
|
||||
|
||||
// Update destination ids in place of distant message hash, since this Outgoing message is for display
|
||||
//
|
||||
for(it = msg->msgbcc.ids.begin(); it != msg->msgbcc.ids.end(); it++)
|
||||
if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
for(it = msg->msgcc.ids.begin(); it != msg->msgcc.ids.end(); it++)
|
||||
if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
for(it = msg->msgto.ids.begin(); it != msg->msgto.ids.end(); it++)
|
||||
if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
// for(it = msg->msgbcc.ids.begin(); it != msg->msgbcc.ids.end(); it++)
|
||||
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
// for(it = msg->msgcc.ids.begin(); it != msg->msgcc.ids.end(); it++)
|
||||
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
// for(it = msg->msgto.ids.begin(); it != msg->msgto.ids.end(); it++)
|
||||
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
|
||||
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED)
|
||||
msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message
|
||||
|
@ -1774,15 +1782,17 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const RsPeerId &to)
|
|||
// all its content.
|
||||
//
|
||||
|
||||
if(info.encryption_keys.find(to) != info.encryption_keys.end())
|
||||
encryptMessage(info.encryption_keys[to],msg) ;
|
||||
if(!info.encryption_keys.empty())
|
||||
std::cerr << "(WW) Cannot encrypt message. Code needs to be improved." << std::endl;
|
||||
// if(info.encryption_keys.find(to) != info.encryption_keys.end())
|
||||
// encryptMessage(info.encryption_keys[to],msg) ;
|
||||
|
||||
//std::cerr << "p3MsgService::initMIRsMsg()" << std::endl;
|
||||
//msg->print(std::cerr);
|
||||
return msg;
|
||||
}
|
||||
|
||||
bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
||||
bool p3MsgService::encryptMessage(const PGPIdType& pgp_id,RsMsgItem *item)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "Encrypting message with public key " << pgp_id << " in place." << std::endl;
|
||||
|
@ -2009,7 +2019,7 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
std::cerr << " Fingerprint = " << fingerprint.toStdString() << std::endl;
|
||||
|
||||
signature_present = true ;
|
||||
signature_ok = AuthGPG::getAuthGPG()->VerifySignBin(decrypted_data, 1+PGP_KEY_ID_SIZE+item_size, &decrypted_data[1+PGP_KEY_ID_SIZE+item_size], decrypted_size - PGP_KEY_ID_SIZE - item_size - 1, fingerprint.toStdString()) ;
|
||||
signature_ok = AuthGPG::getAuthGPG()->VerifySignBin(decrypted_data, 1+PGP_KEY_ID_SIZE+item_size, &decrypted_data[1+PGP_KEY_ID_SIZE+item_size], decrypted_size - PGP_KEY_ID_SIZE - item_size - 1, fingerprint) ;
|
||||
}
|
||||
else if(1 + item_size + PGP_KEY_ID_SIZE == decrypted_size)
|
||||
std::cerr << " No signature in this packet" << std::endl;
|
||||
|
@ -2027,8 +2037,8 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
std::cerr << " Decrypted message was succesfully deserialized. New message:" << std::endl;
|
||||
item->print(std::cerr,0) ;
|
||||
#endif
|
||||
std::string own_hash ;
|
||||
const PGPIdType& own_pgp_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
Sha1CheckSum own_hash ;
|
||||
const PGPIdType& own_pgp_id = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
getDistantMessageHash(own_pgp_id,own_hash) ;
|
||||
|
||||
{
|
||||
|
@ -2041,11 +2051,12 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
msgi.msgId = msgId ; // restore the correct message id, to make it consistent
|
||||
msgi.msgFlags &= ~RS_MSG_FLAGS_ENCRYPTED ; // just in case.
|
||||
msgi.msgFlags |= RS_MSG_FLAGS_DECRYPTED ; // previousy encrypted msg is now decrypted
|
||||
msgi.PeerId(senders_id.toStdString()) ;
|
||||
|
||||
for(std::list<RsPeerId>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
for(std::list<RsPeerId>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
for(std::list<RsPeerId>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
|
||||
// NEEDS TO BE DONE
|
||||
// msgi.PeerId(senders_id) ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
// for(std::list<RsPeerId>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
|
||||
|
||||
if(signature_present)
|
||||
{
|
||||
|
@ -2065,14 +2076,16 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||
|
||||
RsMsgSrcId* msi = new RsMsgSrcId();
|
||||
msi->msgId = msgi.msgId;
|
||||
msi->srcId = senders_id ;
|
||||
// NEEDS TO BE DONE
|
||||
// msi->srcId = senders_id ;
|
||||
|
||||
mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Substituting source name for message id " << msgi.msgId << ": " << it->second->srcId << " -> " << senders_id << std::endl;
|
||||
it->second->srcId = senders_id ;
|
||||
std::cerr << "Substituting source name for message id " << msgi.msgId << ": " << it->second->srcId << " -> " << senders_id << std::endl;
|
||||
// NEEDS TO BE DONE
|
||||
//it->second->srcId = senders_id ;
|
||||
}
|
||||
}
|
||||
delete item ;
|
||||
|
@ -2098,17 +2111,14 @@ void p3MsgService::connectToTurtleRouter(p3turtle *pt)
|
|||
|
||||
bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,TurtleFileHash& hash)
|
||||
{
|
||||
unsigned char hash_bytes[DISTANT_MSG_HASH_SIZE] ;
|
||||
RSRandom::random_bytes( hash_bytes, DISTANT_MSG_HASH_SIZE) ;
|
||||
|
||||
hash = Sha1CheckSum(hash_bytes).toStdString() ;
|
||||
hash = Sha1CheckSum::random().toStdString() ;
|
||||
|
||||
DistantMessengingInvite invite ;
|
||||
invite.time_of_validity = time_of_validity + time(NULL);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
_messenging_invites[hash] = invite ;
|
||||
_messenging_invites[Sha1CheckSum(hash)] = invite ;
|
||||
}
|
||||
IndicateConfigChanged() ;
|
||||
|
||||
|
@ -2119,7 +2129,7 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||
{
|
||||
// compute the hash
|
||||
|
||||
std::string hash ;
|
||||
Sha1CheckSum hash ;
|
||||
|
||||
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
|
||||
return ;
|
||||
|
@ -2132,7 +2142,7 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string,DistantMessengingInvite>::iterator it = _messenging_invites.find(hash) ;
|
||||
std::map<Sha1CheckSum,DistantMessengingInvite>::iterator it = _messenging_invites.find(hash) ;
|
||||
|
||||
if(b && it == _messenging_invites.end())
|
||||
{
|
||||
|
@ -2144,8 +2154,8 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||
std::cerr << "Notifying the global router." << std::endl;
|
||||
|
||||
// Debug stuff. Create a random key and register it.
|
||||
std::string own_ssl_id = rsPeers->getOwnId() ;
|
||||
std::string gpg_id = rsPeers->getGPGOwnId() ;
|
||||
const RsPeerId& own_ssl_id = rsPeers->getOwnId() ;
|
||||
const PGPIdType& gpg_id = rsPeers->getGPGOwnId() ;
|
||||
|
||||
RsPeerDetails d;
|
||||
rsPeers->getPeerDetails(gpg_id,d) ;
|
||||
|
@ -2178,7 +2188,7 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "List of distant message invites: " << std::endl;
|
||||
for(std::map<std::string,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
for(std::map<Sha1CheckSum,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
std::cerr << " hash = " << it->first << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
@ -2186,7 +2196,7 @@ bool p3MsgService::distantMessagingEnabled()
|
|||
{
|
||||
// compute the hash
|
||||
|
||||
std::string hash ;
|
||||
Sha1CheckSum hash ;
|
||||
|
||||
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
|
||||
return false;
|
||||
|
@ -2200,13 +2210,7 @@ bool p3MsgService::distantMessagingEnabled()
|
|||
}
|
||||
bool p3MsgService::getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum& hash)
|
||||
{
|
||||
if(pgp_id.length() != 16)
|
||||
{
|
||||
std::cerr << "pgp id \"" << pgp_id << "\" is not valid! Something definitly wrong." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
hash = RsDirUtil::sha1sum((uint8_t*)pgp_id.c_str(),16).toStdString() ;
|
||||
hash = RsDirUtil::sha1sum((uint8_t*)pgp_id.toByteArray(),PGPIdType::SIZE_IN_BYTES);
|
||||
|
||||
// Also check that we have the public key.
|
||||
|
||||
|
@ -2217,7 +2221,7 @@ bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOffline
|
|||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
for(std::map<std::string,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
for(std::map<Sha1CheckSum,DistantMessengingInvite>::const_iterator it(_messenging_invites.begin());it!=_messenging_invites.end();++it)
|
||||
{
|
||||
DistantOfflineMessengingInvite invite ;
|
||||
invite.hash = it->first ;
|
||||
|
@ -2263,13 +2267,13 @@ void p3MsgService::manageDistantPeers()
|
|||
|
||||
// clean dead invites.
|
||||
//
|
||||
for(std::map<std::string,DistantMessengingInvite>::iterator it(_messenging_invites.begin());it!=_messenging_invites.end();)
|
||||
for(std::map<Sha1CheckSum,DistantMessengingInvite>::iterator it(_messenging_invites.begin());it!=_messenging_invites.end();)
|
||||
if(it->second.time_of_validity < now)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << " Removing outdated invite " << it->second.time_of_validity << ", hash=" << it->first << std::endl;
|
||||
#endif
|
||||
std::map<std::string,DistantMessengingInvite>::iterator tmp(it) ;
|
||||
std::map<Sha1CheckSum,DistantMessengingInvite>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_messenging_invites.erase(it) ;
|
||||
it = tmp ;
|
||||
|
@ -2277,68 +2281,68 @@ void p3MsgService::manageDistantPeers()
|
|||
else
|
||||
++it ;
|
||||
|
||||
// clean dead contacts.
|
||||
//
|
||||
for(std::map<std::string,DistantMessengingContact>::iterator it(_messenging_contacts.begin());it!=_messenging_contacts.end();)
|
||||
if((!it->second.pending_messages) && it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_DN)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << " Removing dead contact with no pending msgs and dead tunnel. hash=" << it->first << std::endl;
|
||||
#endif
|
||||
std::map<std::string,DistantMessengingContact>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_messenging_contacts.erase(it) ;
|
||||
it = tmp ;
|
||||
}
|
||||
else
|
||||
++it ;
|
||||
// // clean dead contacts.
|
||||
// //
|
||||
// for(std::map<Sha1CheckSum,DistantMessengingContact>::iterator it(_messenging_contacts.begin());it!=_messenging_contacts.end();)
|
||||
// if((!it->second.pending_messages) && it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_DN)
|
||||
// {
|
||||
//#ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << " Removing dead contact with no pending msgs and dead tunnel. hash=" << it->first << std::endl;
|
||||
//#endif
|
||||
// std::map<Sha1CheckSum,DistantMessengingContact>::iterator tmp(it) ;
|
||||
// ++tmp ;
|
||||
// _messenging_contacts.erase(it) ;
|
||||
// it = tmp ;
|
||||
// }
|
||||
// else
|
||||
// ++it ;
|
||||
}
|
||||
}
|
||||
|
||||
void p3MsgService::addVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid,RsTurtleGenericTunnelItem::Direction /*dir*/)
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
// A new tunnel has been created. We need to flush pending messages for the corresponding peer.
|
||||
|
||||
//std::map<std::string,DistantMessengingContact>::const_iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
DistantMessengingContact& contact(_messenging_contacts[hash]) ; // possibly creates it.
|
||||
|
||||
contact.virtual_peer_id = vpid ;
|
||||
contact.last_hit_time = time(NULL) ;
|
||||
contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_OK ;
|
||||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "p3MsgService::addVirtualPeer(): adding virtual peer " << vpid << " for hash " << hash << std::endl;
|
||||
#endif
|
||||
}
|
||||
void p3MsgService::removeVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "Removing virtual peer " << vpid << " for hash " << hash << std::endl;
|
||||
#endif
|
||||
|
||||
bool remove_tunnel = false ;
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
DistantMessengingContact& contact(_messenging_contacts[hash]) ; // possibly creates it.
|
||||
|
||||
contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_DN ;
|
||||
contact.virtual_peer_id.clear() ;
|
||||
|
||||
if(!contact.pending_messages)
|
||||
remove_tunnel = true ;
|
||||
}
|
||||
|
||||
if(remove_tunnel) // We do that whenever we're client or server. But normally, we should only do it when we're client.
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "Also removing tunnel, since pending messages have been sent." << std::endl;
|
||||
#endif
|
||||
mTurtle->stopMonitoringTunnels(hash) ;
|
||||
}
|
||||
}
|
||||
// void p3MsgService::addVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid,RsTurtleGenericTunnelItem::Direction /*dir*/)
|
||||
// {
|
||||
// RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
// // A new tunnel has been created. We need to flush pending messages for the corresponding peer.
|
||||
//
|
||||
// //std::map<Sha1CheckSum,DistantMessengingContact>::const_iterator it = _messenging_contacts.find(hash) ;
|
||||
//
|
||||
// DistantMessengingContact& contact(_messenging_contacts[hash]) ; // possibly creates it.
|
||||
//
|
||||
// contact.virtual_peer_id = vpid ;
|
||||
// contact.last_hit_time = time(NULL) ;
|
||||
// contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_OK ;
|
||||
//
|
||||
// #ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "p3MsgService::addVirtualPeer(): adding virtual peer " << vpid << " for hash " << hash << std::endl;
|
||||
// #endif
|
||||
// }
|
||||
// void p3MsgService::removeVirtualPeer(const TurtleFileHash& hash, const TurtleVirtualPeerId& vpid)
|
||||
// {
|
||||
// #ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "Removing virtual peer " << vpid << " for hash " << hash << std::endl;
|
||||
// #endif
|
||||
//
|
||||
// bool remove_tunnel = false ;
|
||||
// {
|
||||
// RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
//
|
||||
// DistantMessengingContact& contact(_messenging_contacts[hash]) ; // possibly creates it.
|
||||
//
|
||||
// contact.status = RS_DISTANT_MSG_STATUS_TUNNEL_DN ;
|
||||
// contact.virtual_peer_id.clear() ;
|
||||
//
|
||||
// if(!contact.pending_messages)
|
||||
// remove_tunnel = true ;
|
||||
// }
|
||||
//
|
||||
// if(remove_tunnel) // We do that whenever we're client or server. But normally, we should only do it when we're client.
|
||||
// {
|
||||
// #ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "Also removing tunnel, since pending messages have been sent." << std::endl;
|
||||
// #endif
|
||||
// mTurtle->stopMonitoringTunnels(hash) ;
|
||||
// }
|
||||
// }
|
||||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
static void printBinaryData(void *data,uint32_t size)
|
||||
|
@ -2353,7 +2357,7 @@ static void printBinaryData(void *data,uint32_t size)
|
|||
}
|
||||
#endif
|
||||
|
||||
void p3MsgService::sendTurtleData(const std::string& hash,RsMsgItem *msgitem)
|
||||
void p3MsgService::sendTurtleData(const Sha1CheckSum& hash,RsMsgItem *msgitem)
|
||||
{
|
||||
// The item is serialized and turned into a generic turtle item.
|
||||
|
||||
|
@ -2386,7 +2390,7 @@ void p3MsgService::sendTurtleData(const std::string& hash,RsMsgItem *msgitem)
|
|||
RsPeerId virtual_peer_id ;
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<std::string,DistantMessengingContact>::const_iterator it = _messenging_contacts.find(hash) ;
|
||||
std::map<Sha1CheckSum,DistantMessengingContact>::const_iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
if(it == _messenging_contacts.end())
|
||||
{
|
||||
|
@ -2410,63 +2414,63 @@ void p3MsgService::sendTurtleData(const std::string& hash,RsMsgItem *msgitem)
|
|||
|
||||
mTurtle->sendTurtleData(virtual_peer_id,item) ;
|
||||
}
|
||||
void p3MsgService::receiveTurtleData(RsTurtleGenericTunnelItem *gitem,const std::string& hash,
|
||||
const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/)
|
||||
{
|
||||
RsTurtleGenericDataItem *item = dynamic_cast<RsTurtleGenericDataItem*>(gitem) ;
|
||||
|
||||
if(item == NULL)
|
||||
{
|
||||
std::cerr << "(EE) p3MsgService::receiveTurtleData(): item is not a data item. That is an error." << std::endl;
|
||||
return ;
|
||||
}
|
||||
#ifdef DISABLE_DISTANT_MESSAGES
|
||||
std::cerr << "Received distant message item. Protocol is not yet finalized. Droping the item." << std::endl;
|
||||
delete item ;
|
||||
return ;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "p3MsgService::sendTurtleData(): Receiving through virtual peer: " << virtual_peer_id << std::endl;
|
||||
std::cerr << " gitem->data_size = " << item->data_size << std::endl;
|
||||
std::cerr << " data = " ;
|
||||
printBinaryData(item->data_bytes,item->data_size) ;
|
||||
std::cerr << std::endl;
|
||||
#else
|
||||
(void) virtual_peer_id;
|
||||
#endif
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
std::map<std::string,DistantMessengingContact>::iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
if(it == _messenging_contacts.end())
|
||||
{
|
||||
std::cerr << "(EE) p3MsgService::sendTurtleData(): Can't find hash " << hash << " in recorded contact list." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
it->second.status = RS_DISTANT_MSG_STATUS_TUNNEL_OK ;
|
||||
it->second.last_hit_time = time(NULL) ;
|
||||
}
|
||||
|
||||
RsItem *itm = _serialiser->deserialise(item->data_bytes,&item->data_size) ;
|
||||
RsMsgItem *mitm = dynamic_cast<RsMsgItem*>(itm) ;
|
||||
|
||||
if(mitm != NULL)
|
||||
{
|
||||
mitm->PeerId(hash) ;
|
||||
mitm->msgto.ids.push_back(rsPeers->getGPGOwnId()) ;
|
||||
handleIncomingItem(mitm) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) p3MsgService::receiveTurtleData(): received item is not a RsMsgItem!!" << std::endl;
|
||||
delete itm ;
|
||||
}
|
||||
}
|
||||
//void p3MsgService::receiveTurtleData(RsTurtleGenericTunnelItem *gitem,const Sha1CheckSum& hash,
|
||||
// const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/)
|
||||
//{
|
||||
// RsTurtleGenericDataItem *item = dynamic_cast<RsTurtleGenericDataItem*>(gitem) ;
|
||||
//
|
||||
// if(item == NULL)
|
||||
// {
|
||||
// std::cerr << "(EE) p3MsgService::receiveTurtleData(): item is not a data item. That is an error." << std::endl;
|
||||
// return ;
|
||||
// }
|
||||
//#ifdef DISABLE_DISTANT_MESSAGES
|
||||
// std::cerr << "Received distant message item. Protocol is not yet finalized. Droping the item." << std::endl;
|
||||
// delete item ;
|
||||
// return ;
|
||||
//#endif
|
||||
//
|
||||
//#ifdef DEBUG_DISTANT_MSG
|
||||
// std::cerr << "p3MsgService::sendTurtleData(): Receiving through virtual peer: " << virtual_peer_id << std::endl;
|
||||
// std::cerr << " gitem->data_size = " << item->data_size << std::endl;
|
||||
// std::cerr << " data = " ;
|
||||
// printBinaryData(item->data_bytes,item->data_size) ;
|
||||
// std::cerr << std::endl;
|
||||
//#else
|
||||
// (void) virtual_peer_id;
|
||||
//#endif
|
||||
//
|
||||
// {
|
||||
// RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
// std::map<Sha1CheckSum,DistantMessengingContact>::iterator it = _messenging_contacts.find(hash) ;
|
||||
//
|
||||
// if(it == _messenging_contacts.end())
|
||||
// {
|
||||
// std::cerr << "(EE) p3MsgService::sendTurtleData(): Can't find hash " << hash << " in recorded contact list." << std::endl;
|
||||
// return ;
|
||||
// }
|
||||
//
|
||||
// it->second.status = RS_DISTANT_MSG_STATUS_TUNNEL_OK ;
|
||||
// it->second.last_hit_time = time(NULL) ;
|
||||
// }
|
||||
//
|
||||
// RsItem *itm = _serialiser->deserialise(item->data_bytes,&item->data_size) ;
|
||||
// RsMsgItem *mitm = dynamic_cast<RsMsgItem*>(itm) ;
|
||||
//
|
||||
// if(mitm != NULL)
|
||||
// {
|
||||
// mitm->PeerId(hash) ;
|
||||
// mitm->msgto.ids.push_back(rsPeers->getGPGOwnId()) ;
|
||||
// handleIncomingItem(mitm) ;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// std::cerr << "(EE) p3MsgService::receiveTurtleData(): received item is not a RsMsgItem!!" << std::endl;
|
||||
// delete itm ;
|
||||
// }
|
||||
//}
|
||||
#ifdef GROUTER
|
||||
void p3MsgService::sendGRouterData(const std::string& hash,RsMsgItem *msgitem)
|
||||
void p3MsgService::sendGRouterData(const Sha1CheckSum& hash,RsMsgItem *msgitem)
|
||||
{
|
||||
// The item is serialized and turned into a generic turtle item.
|
||||
|
||||
|
@ -2496,7 +2500,18 @@ void p3MsgService::receiveGRouterData(RsGRouterGenericDataItem *gitem,const GRou
|
|||
}
|
||||
#endif
|
||||
|
||||
void p3MsgService::sendPrivateMsgItem(RsMsgItem *msgitem)
|
||||
bool p3MsgService::locked_findHashForVirtualPeerId(const RsPeerId& vpid,Sha1CheckSum& hash)
|
||||
{
|
||||
for(std::map<Sha1CheckSum,DistantMessengingContact>::const_iterator it = _messenging_contacts.begin(); it!=_messenging_contacts.end();++it)
|
||||
if(it->second.virtual_peer_id == vpid)
|
||||
{
|
||||
hash = it->first ;
|
||||
return true ;
|
||||
}
|
||||
return false ;
|
||||
}
|
||||
|
||||
void p3MsgService::sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *msgitem)
|
||||
{
|
||||
#ifdef DEBUG_DISTANT_MSG
|
||||
std::cerr << "p3MsgService::sendDistanteMsgItem(): sending distant msg item to peer " << msgitem->PeerId() << std::endl;
|
||||
|
@ -2506,7 +2521,7 @@ void p3MsgService::sendPrivateMsgItem(RsMsgItem *msgitem)
|
|||
|
||||
// allocate a new contact. If it does not exist, set its tunnel state to DN
|
||||
//
|
||||
std::map<std::string,DistantMessengingContact>::iterator it = _messenging_contacts.find(msgitem->PeerId()) ;
|
||||
std::map<Sha1CheckSum,DistantMessengingContact>::iterator it = _messenging_contacts.find(hash) ;
|
||||
|
||||
if(it == _messenging_contacts.end())
|
||||
{
|
||||
|
@ -2528,9 +2543,9 @@ void p3MsgService::sendPrivateMsgItem(RsMsgItem *msgitem)
|
|||
std::cerr << " Flushing msg " << msgitem->msgId << " for peer id " << msgitem->PeerId() << std::endl;
|
||||
#endif
|
||||
#ifdef GROUTER
|
||||
sendGRouterData(msgitem->PeerId(),msgitem) ;
|
||||
sendGRouterData(hash,msgitem) ;
|
||||
#else
|
||||
sendTurtleData(msgitem->PeerId(),msgitem) ;
|
||||
sendTurtleData(hash,msgitem) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -134,16 +134,16 @@ int checkOutgoingMessages();
|
|||
bool distantMessagingEnabled() ;
|
||||
bool getDistantMessageHash(const PGPIdType& pgp_id,Sha1CheckSum &hash) ;
|
||||
|
||||
void sendPrivateMsgItem(RsMsgItem *) ;
|
||||
|
||||
private:
|
||||
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
|
||||
|
||||
// This maps contains the current invitations to respond to.
|
||||
// The map is indexed by the hash
|
||||
std::map<std::string,DistantMessengingInvite> _messenging_invites ;
|
||||
// The map is indexed by the hash
|
||||
std::map<Sha1CheckSum,DistantMessengingInvite> _messenging_invites ;
|
||||
|
||||
// This contains the ongoing tunnel handling contacts.
|
||||
// The map is indexed by the hash
|
||||
std::map<std::string,DistantMessengingContact> _messenging_contacts ;
|
||||
// The map is indexed by the hash
|
||||
std::map<Sha1CheckSum,DistantMessengingContact> _messenging_contacts ;
|
||||
|
||||
// Overloaded from RsTurtleClientService
|
||||
|
||||
|
@ -151,18 +151,19 @@ int checkOutgoingMessages();
|
|||
virtual void receiveGRouterData(RsGRouterGenericDataItem *item, const GRouterKeyId& key) ;
|
||||
#endif
|
||||
virtual bool handleTunnelRequest(const Sha1CheckSum& hash,const RsPeerId& peer_id) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const Sha1CheckSum& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
|
||||
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
|
||||
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
|
||||
|
||||
// Utility functions
|
||||
|
||||
bool encryptMessage(const PGPIdType& pgp_id,RsMsgItem *msg) ;
|
||||
bool locked_findHashForVirtualPeerId(const RsPeerId& pid,Sha1CheckSum& hash) ;
|
||||
|
||||
void manageDistantPeers() ;
|
||||
void sendTurtleData(const std::string& hash,RsMsgItem *) ;
|
||||
void sendTurtleData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
||||
#ifdef GROUTER
|
||||
void sendGRouterData(const std::string& hash,RsMsgItem *) ;
|
||||
void sendGRouterData(const Sha1CheckSum& hash,RsMsgItem *) ;
|
||||
#endif
|
||||
void handleIncomingItem(RsMsgItem *) ;
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
|
|||
std::cerr << "p3StatusService::getOwnStatus() " << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, StatusInfo>::iterator it;
|
||||
std::string ownId = mLinkMgr->getOwnId();
|
||||
std::map<RsPeerId, StatusInfo>::iterator it;
|
||||
const RsPeerId& ownId = mLinkMgr->getOwnId();
|
||||
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
it = mStatusInfoMap.find(ownId);
|
||||
|
@ -77,7 +77,7 @@ bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
|
|||
statusInfo.id = ownId;
|
||||
statusInfo.status = RS_STATUS_ONLINE;
|
||||
|
||||
std::pair<std::string, StatusInfo> pr(ownId, statusInfo);
|
||||
std::pair<RsPeerId, StatusInfo> pr(ownId, statusInfo);
|
||||
mStatusInfoMap.insert(pr);
|
||||
IndicateConfigChanged();
|
||||
|
||||
|
@ -100,7 +100,7 @@ bool p3StatusService::getStatusList(std::list<StatusInfo>& statusInfo)
|
|||
RsStackMutex stack(mStatusMtx);
|
||||
|
||||
// fill up statusInfo list with this information
|
||||
std::map<std::string, StatusInfo>::iterator mit;
|
||||
std::map<RsPeerId, StatusInfo>::iterator mit;
|
||||
for(mit = mStatusInfoMap.begin(); mit != mStatusInfoMap.end(); mit++){
|
||||
statusInfo.push_back(mit->second);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ bool p3StatusService::getStatusList(std::list<StatusInfo>& statusInfo)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3StatusService::getStatus(const std::string &id, StatusInfo &statusInfo)
|
||||
bool p3StatusService::getStatus(const RsPeerId &id, StatusInfo &statusInfo)
|
||||
{
|
||||
#ifdef STATUS_DEBUG
|
||||
std::cerr << "p3StatusService::getStatus() " << std::endl;
|
||||
|
@ -116,7 +116,7 @@ bool p3StatusService::getStatus(const std::string &id, StatusInfo &statusInfo)
|
|||
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
|
||||
std::map<std::string, StatusInfo>::iterator mit = mStatusInfoMap.find(id);
|
||||
std::map<RsPeerId, StatusInfo>::iterator mit = mStatusInfoMap.find(id);
|
||||
|
||||
if (mit == mStatusInfoMap.end()) {
|
||||
/* return fake status info as offline */
|
||||
|
@ -133,10 +133,10 @@ bool p3StatusService::getStatus(const std::string &id, StatusInfo &statusInfo)
|
|||
}
|
||||
|
||||
/* id = "", status is sent to all online peers */
|
||||
bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
||||
bool p3StatusService::sendStatus(const RsPeerId &id, uint32_t status)
|
||||
{
|
||||
StatusInfo statusInfo;
|
||||
std::list<std::string> onlineList;
|
||||
std::list<RsPeerId> onlineList;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
|
@ -150,7 +150,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
|||
// If your id is not set, set it
|
||||
if(mStatusInfoMap.find(statusInfo.id) == mStatusInfoMap.end()){
|
||||
|
||||
std::pair<std::string, StatusInfo> pr(statusInfo.id, statusInfo);
|
||||
std::pair<RsPeerId, StatusInfo> pr(statusInfo.id, statusInfo);
|
||||
mStatusInfoMap.insert(pr);
|
||||
IndicateConfigChanged();
|
||||
} else if(mStatusInfoMap[statusInfo.id].status != statusInfo.status){
|
||||
|
@ -160,14 +160,14 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
|||
}
|
||||
}
|
||||
|
||||
if (id.empty()) {
|
||||
if (id.isNull()) {
|
||||
mLinkMgr->getOnlineList(onlineList);
|
||||
} else {
|
||||
onlineList.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<RsPeerId>::iterator it;
|
||||
|
||||
#ifdef STATUS_DEBUG
|
||||
std::cerr << "p3StatusService::sendStatus() " << std::endl;
|
||||
|
@ -184,7 +184,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
|||
}
|
||||
|
||||
/* send notify of own status change */
|
||||
RsServer::notify()->notifyPeerStatusChanged(statusInfo.id, statusInfo.status);
|
||||
RsServer::notify()->notifyPeerStatusChanged(statusInfo.id.toStdString(), statusInfo.status);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ bool p3StatusService::sendStatus(const std::string &id, uint32_t status)
|
|||
|
||||
void p3StatusService::receiveStatusQueue()
|
||||
{
|
||||
std::map<std::string, uint32_t> changed;
|
||||
std::map<RsPeerId, uint32_t> changed;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
|
@ -217,7 +217,7 @@ void p3StatusService::receiveStatusQueue()
|
|||
std::cerr << "Got status Item" << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, StatusInfo>::iterator mit = mStatusInfoMap.find(status_item->PeerId());
|
||||
std::map<RsPeerId, StatusInfo>::iterator mit = mStatusInfoMap.find(status_item->PeerId());
|
||||
|
||||
if(mit != mStatusInfoMap.end()){
|
||||
mit->second.id = status_item->PeerId();
|
||||
|
@ -241,9 +241,9 @@ void p3StatusService::receiveStatusQueue()
|
|||
} /* UNLOCKED */
|
||||
|
||||
if (changed.size()) {
|
||||
std::map<std::string, uint32_t>::iterator it;
|
||||
std::map<RsPeerId, uint32_t>::iterator it;
|
||||
for (it = changed.begin(); it != changed.end(); it++) {
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->first, it->second);
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->first.toStdString(), it->second);
|
||||
}
|
||||
RsServer::notify()->notifyPeerStatusChangedSummary();
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ bool p3StatusService::saveList(bool& cleanup, std::list<RsItem*>& ilist){
|
|||
RsStatusItem* own_status = new RsStatusItem;
|
||||
StatusInfo own_info;
|
||||
|
||||
std::map<std::string, StatusInfo>::iterator it;
|
||||
std::map<RsPeerId, StatusInfo>::iterator it;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
|
@ -315,7 +315,7 @@ bool p3StatusService::loadList(std::list<RsItem*>& load){
|
|||
|
||||
{
|
||||
RsStackMutex stack(mStatusMtx);
|
||||
std::pair<std::string, StatusInfo> pr(mLinkMgr->getOwnId(), own_info);
|
||||
std::pair<RsPeerId, StatusInfo> pr(mLinkMgr->getOwnId(), own_info);
|
||||
mStatusInfoMap.insert(pr);
|
||||
}
|
||||
|
||||
|
@ -362,12 +362,12 @@ void p3StatusService::statusChange(const std::list<pqipeer> &plist)
|
|||
} /* UNLOCKED */
|
||||
|
||||
changedState = true;
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id, RS_STATUS_OFFLINE);
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE);
|
||||
}
|
||||
|
||||
if (it->actions & RS_PEER_CONNECTED) {
|
||||
/* send current status, only call getOwnStatus once in the loop */
|
||||
if (statusInfo.id.empty() == false || getOwnStatus(statusInfo)) {
|
||||
if (statusInfo.id.isNull() == false || getOwnStatus(statusInfo)) {
|
||||
sendStatus(it->id, statusInfo.status);
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ void p3StatusService::statusChange(const std::list<pqipeer> &plist)
|
|||
} /* UNLOCKED */
|
||||
|
||||
changedState = true;
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id, RS_STATUS_ONLINE);
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_ONLINE);
|
||||
}
|
||||
} else if (it->actions & RS_PEER_MOVED) {
|
||||
/* now handle remove */
|
||||
|
@ -395,7 +395,7 @@ void p3StatusService::statusChange(const std::list<pqipeer> &plist)
|
|||
} /* UNLOCKED */
|
||||
|
||||
changedState = true;
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id, RS_STATUS_OFFLINE);
|
||||
RsServer::notify()->notifyPeerStatusChanged(it->id.toStdString(), RS_STATUS_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
|||
*/
|
||||
virtual bool getOwnStatus(StatusInfo& statusInfo);
|
||||
virtual bool getStatusList(std::list<StatusInfo>& statusInfo);
|
||||
virtual bool getStatus(const std::string &id, StatusInfo &statusInfo);
|
||||
virtual bool getStatus(const RsPeerId &id, StatusInfo &statusInfo);
|
||||
/* id = "", status is sent to all online peers */
|
||||
virtual bool sendStatus(const std::string &id, uint32_t status);
|
||||
virtual bool sendStatus(const RsPeerId &id, uint32_t status);
|
||||
|
||||
/******************************/
|
||||
|
||||
|
@ -95,7 +95,7 @@ virtual void receiveStatusQueue();
|
|||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
|
||||
std::map<std::string, StatusInfo> mStatusInfoMap;
|
||||
std::map<RsPeerId, StatusInfo> mStatusInfoMap;
|
||||
|
||||
RsMutex mStatusMtx;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue