merge of branch v0.6-idclean 7180

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2014-03-17 20:56:06 +00:00
parent 7815efb16f
commit 0f29d28b1b
397 changed files with 6503 additions and 5702 deletions

View file

@ -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;

View file

@ -52,7 +52,7 @@ class BanList
{
public:
std::string mPeerId; /* from */
RsPeerId mPeerId; /* from */
time_t mLastUpdate;
std::map<struct sockaddr_storage, BanListPeer> mBanPeers;
};
@ -74,7 +74,7 @@ class p3BanList: /* public RsBanList, */ public p3Service, public pqiNetAssistPe
/***** overloaded from pqiNetAssistPeerShare *****/
virtual void updatePeer(std::string id, const struct sockaddr_storage &addr, int type, int reason, int age);
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int age);
/***** overloaded from p3Service *****/
@ -93,10 +93,10 @@ class p3BanList: /* public RsBanList, */ public p3Service, public pqiNetAssistPe
bool processIncoming();
bool recvBanItem(RsBanListItem *item);
bool addBanEntry(const std::string &peerId, const struct sockaddr_storage &addr,
bool addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr,
int level, uint32_t reason, uint32_t age);
void sendBanLists();
int sendBanSet(std::string peerid);
int sendBanSet(const RsPeerId& peerid);
/*!
@ -122,7 +122,7 @@ class p3BanList: /* public RsBanList, */ public p3Service, public pqiNetAssistPe
int printBanSet_locked(std::ostream &out);
time_t mSentListTime;
std::map<std::string, BanList> mBanSources;
std::map<RsPeerId, BanList> mBanSources;
std::map<struct sockaddr_storage, BanListPeer> mBanSet;
p3LinkMgr *mLinkMgr;

View file

@ -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())
{

View file

@ -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;
};

View file

@ -153,12 +153,12 @@ int p3ChatService::sendPublicChat(const std::string &msg)
{
/* go through all the peers */
std::list<std::string> ids;
std::list<std::string>::iterator it;
std::list<RsPeerId> ids;
std::list<RsPeerId>::iterator it;
mLinkMgr->getOnlineList(ids);
/* add in own id -> so get reflection */
std::string ownId = mLinkMgr->getOwnId();
RsPeerId ownId = mLinkMgr->getOwnId();
ids.push_back(ownId);
#ifdef CHAT_DEBUG
@ -184,7 +184,7 @@ int p3ChatService::sendPublicChat(const std::string &msg)
#endif
if (*it == ownId) {
mHistoryMgr->addMessage(false, "", ownId, ci);
mHistoryMgr->addMessage(false, RsPeerId(), ownId, ci);
}
sendItem(ci);
}
@ -242,7 +242,7 @@ class p3ChatService::AvatarInfo
void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
{
std::list<std::string> ids;
std::list<RsPeerId> ids;
mLinkMgr->getOnlineList(ids);
#ifdef CHAT_DEBUG
@ -250,7 +250,7 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
std::cerr << std::endl;
#endif
for(std::list<std::string>::iterator it = ids.begin(); it != ids.end(); ++it)
for(std::list<RsPeerId>::iterator it = ids.begin(); it != ids.end(); ++it)
{
RsChatStatusItem *cs = new RsChatStatusItem ;
@ -263,7 +263,7 @@ void p3ChatService::sendGroupChatStatusString(const std::string& status_string)
}
}
void p3ChatService::sendStatusString( const std::string& id , const std::string& status_string)
void p3ChatService::sendStatusString( const RsPeerId& id , const std::string& status_string)
{
ChatLobbyId lobby_id ;
if(isLobbyId(id,lobby_id))
@ -291,8 +291,12 @@ void p3ChatService::sendPrivateChatItem(RsChatItem *item)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
if(_distant_chat_peers.find(item->PeerId()) != _distant_chat_peers.end())
found = true ;
for(std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it=_distant_chat_peers.begin();it!=_distant_chat_peers.end();++it)
if( it->second.virtual_peer_id == item->PeerId()) // _distant_chat_peers.find(item->PeerId()) !=_distant_chat_peers.end())
{
found = true ;
break ;
}
}
if(found)
@ -363,7 +367,7 @@ void p3ChatService::checkSizeAndSendMessage(RsChatLobbyMsgItem *msg)
sendItem(msg) ;
}
bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,std::string& vpid)
bool p3ChatService::getVirtualPeerId(const ChatLobbyId& id,ChatLobbyVirtualPeerId& vpid)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -409,7 +413,7 @@ void p3ChatService::locked_printDebugInfo() const
std::cerr << " Participating friends: " << std::endl;
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
std::cerr << " " << *it2 << std::endl;
std::cerr << " Participating nick names: " << std::endl;
@ -421,7 +425,7 @@ void p3ChatService::locked_printDebugInfo() const
std::cerr << "Recorded lobby names: " << std::endl;
for( std::map<std::string,ChatLobbyId>::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it)
for( std::map<RsPeerId,ChatLobbyId>::const_iterator it(_lobby_ids.begin()) ;it!=_lobby_ids.end();++it)
std::cerr << " \"" << it->first << "\" id = " << std::hex << it->second << std::dec << std::endl;
std::cerr << "Visible public lobbies: " << std::endl;
@ -429,7 +433,7 @@ void p3ChatService::locked_printDebugInfo() const
for( std::map<ChatLobbyId,VisibleChatLobbyRecord>::const_iterator it(_visible_lobbies.begin()) ;it!=_visible_lobbies.end();++it)
{
std::cerr << " " << std::hex << it->first << " name = " << std::dec << it->second.lobby_name << it->second.lobby_topic << std::endl;
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
std::cerr << " With friend: " << *it2 << std::endl;
}
@ -439,11 +443,11 @@ void p3ChatService::locked_printDebugInfo() const
std::cerr << " \"" << std::hex << it->first << "\" flags = " << it->second << std::dec << std::endl;
}
bool p3ChatService::isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id)
bool p3ChatService::isLobbyId(const RsPeerId& virtual_peer_id,ChatLobbyId& lobby_id)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,ChatLobbyId>::const_iterator it(_lobby_ids.find(virtual_peer_id)) ;
std::map<ChatLobbyVirtualPeerId,ChatLobbyId>::const_iterator it(_lobby_ids.find(virtual_peer_id)) ;
if(it != _lobby_ids.end())
{
@ -455,20 +459,21 @@ bool p3ChatService::isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lo
return false ;
}
bool p3ChatService::isOnline(const std::string& id)
bool p3ChatService::isOnline(const DistantChatPeerId& pid)
{
// check if the id is a tunnel id or a peer id.
uint32_t status ;
std::string pgp_id ;
RsPgpId pgp_id ;
if(!getDistantChatStatus(id,status,pgp_id))
return mLinkMgr->isOnline(id) ;
return true ;
std::string hash ;
if(getDistantChatStatus(pid,status,pgp_id))
return true ;
else
return mLinkMgr->isOnline(pid) ;
}
bool p3ChatService::sendPrivateChat(const std::string &id, const std::string &msg)
bool p3ChatService::sendPrivateChat(const RsPeerId &id, const std::string &msg)
{
// look into ID. Is it a peer, or a chat lobby?
@ -508,7 +513,7 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::string
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,AvatarInfo*>::iterator it = _avatars.find(id) ;
std::map<RsPeerId,AvatarInfo*>::iterator it = _avatars.find(id) ;
if(it == _avatars.end())
{
@ -543,7 +548,7 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::string
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,StateStringInfo>::iterator it = _state_strings.find(id) ;
std::map<RsPeerId,StateStringInfo>::iterator it = _state_strings.find(id) ;
if(it == _state_strings.end())
{
@ -575,7 +580,7 @@ bool p3ChatService::locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgIte
{
// Check is the item is ending an incomplete item.
//
std::map<std::string,RsChatMsgItem*>::iterator it = _pendingPartialMessages.find(ci->PeerId()) ;
std::map<RsPeerId,RsChatMsgItem*>::iterator it = _pendingPartialMessages.find(ci->PeerId()) ;
bool ci_is_incomplete = ci->chatFlags & RS_CHAT_FLAG_PARTIAL_MESSAGE ;
@ -720,14 +725,14 @@ class MsgCounter
};
bool p3ChatService::locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const std::string& peer_id,uint32_t lobby_count)
bool p3ChatService::locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id,uint32_t lobby_count)
{
static std::map<std::string, std::list<time_t> > message_counts ;
std::ostringstream os ;
os << obj->lobby_id ;
std::string pid = peer_id + "_" + os.str() ;
std::string pid = peer_id.toStdString() + "_" + os.str() ;
// Check for the number of peers in the lobby. First look into visible lobbies, because the number
// of peers there is more accurate. If non existant (because it's a private lobby), take the count from
@ -1079,7 +1084,7 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca)
#ifdef CHAT_DEBUG
std::cerr << "Received avatar data for peer " << ca->PeerId() << ". Notifying." << std::endl ;
#endif
RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId()) ;
RsServer::notify()->notifyPeerHasNewAvatar(ca->PeerId().toStdString()) ;
}
bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci)
@ -1131,7 +1136,7 @@ bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci)
//
std::cout << "handleRecvChatMsgItem: " << ci->message << std::endl;
std::cout << "**********" << std::endl;
std::cout << "********** entity attack by " << ci->PeerId().c_str() << std::endl;
std::cout << "********** entity attack by " << ci->PeerId().toStdString().c_str() << std::endl;
std::cout << "**********" << std::endl;
ci->message = "**** This message (from peer id " + rsPeers->getPeerName(ci->PeerId()) + ") has been removed because it contains the string \"<!\".****" ;
@ -1215,7 +1220,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
// setup the peer id to the virtual peer id of the lobby.
//
std::string virtual_peer_id ;
RsPeerId virtual_peer_id ;
getVirtualPeerId(cli->lobby_id,virtual_peer_id) ;
cli->PeerId(virtual_peer_id) ;
name = cli->nick;
@ -1256,7 +1261,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ;
}
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
std::map<RsPeerId,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
#ifdef CHAT_DEBUG
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
@ -1276,11 +1281,11 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
if (ci->chatFlags & RS_CHAT_FLAG_PRIVATE) {
/* notify private chat message */
RsServer::notify()->AddPopupMessage(popupChatFlag, ci->PeerId(), name, message);
RsServer::notify()->AddPopupMessage(popupChatFlag, ci->PeerId().toStdString(), name, message);
} else {
/* notify public chat message */
RsServer::notify()->AddPopupMessage(RS_POPUP_GROUPCHAT, ci->PeerId(), "", message);
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId(), message, "");
RsServer::notify()->AddPopupMessage(RS_POPUP_GROUPCHAT, ci->PeerId().toStdString(), "", message);
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_CHAT_NEW, ci->PeerId().toStdString(), message, "");
}
{
@ -1303,7 +1308,7 @@ bool p3ChatService::handleRecvChatMsgItem(RsChatMsgItem *ci)
if (ci->PeerId() != mLinkMgr->getOwnId()) {
/* not from loop back */
mHistoryMgr->addMessage(true, "", ci->PeerId(), ci);
mHistoryMgr->addMessage(true, RsPeerId(), ci->PeerId(), ci);
}
}
} /* UNLOCK */
@ -1331,7 +1336,7 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE) // Check if new custom string is available at peer's.
{ // If so, send a request to get the custom string.
receiveStateString(cs->PeerId(),cs->status_string) ; // store it
RsServer::notify()->notifyCustomState(cs->PeerId(), cs->status_string) ;
RsServer::notify()->notifyCustomState(cs->PeerId().toStdString(), cs->status_string) ;
}
else if(cs->flags & RS_CHAT_FLAG_CUSTOM_STATE_AVAILABLE)
{
@ -1342,13 +1347,13 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
}
else if(cs->flags & RS_CHAT_FLAG_PRIVATE)
{
RsServer::notify()->notifyChatStatus(cs->PeerId(),cs->status_string,true) ;
RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,true) ;
if(cs->flags & RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION)
markDistantChatAsClosed(cs->PeerId()) ;
}
else if(cs->flags & RS_CHAT_FLAG_PUBLIC)
RsServer::notify()->notifyChatStatus(cs->PeerId(),cs->status_string,false) ;
RsServer::notify()->notifyChatStatus(cs->PeerId().toStdString(),cs->status_string,false) ;
}
void p3ChatService::getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& visible_lobbies)
@ -1366,10 +1371,10 @@ void p3ChatService::getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecor
if(now > MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ + last_visible_lobby_info_request_time)
{
std::list<std::string> ids ;
std::list<RsPeerId> ids ;
mLinkMgr->getOnlineList(ids);
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
{
#ifdef CHAT_DEBUG
std::cerr << " asking list of public lobbies to " << *it << std::endl;
@ -1436,7 +1441,7 @@ int p3ChatService::getPrivateChatQueueCount(bool incoming)
return privateOutgoingList.size();
}
bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids)
bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids)
{
ids.clear();
@ -1467,7 +1472,7 @@ bool p3ChatService::getPrivateChatQueueIds(bool incoming, std::list<std::string>
return true;
}
bool p3ChatService::getPrivateChatQueue(bool incoming, const std::string &id, std::list<ChatInfo> &chats)
bool p3ChatService::getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list<ChatInfo> &chats)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -1498,7 +1503,7 @@ bool p3ChatService::getPrivateChatQueue(bool incoming, const std::string &id, st
return (chats.size() > 0);
}
bool p3ChatService::clearPrivateChatQueue(bool incoming, const std::string &id)
bool p3ChatService::clearPrivateChatQueue(bool incoming, const RsPeerId &id)
{
bool changed = false;
@ -1569,7 +1574,7 @@ void p3ChatService::initRsChatInfo(RsChatMsgItem *c, ChatInfo &i)
void p3ChatService::setOwnCustomStateString(const std::string& s)
{
std::list<std::string> onlineList;
std::list<RsPeerId> onlineList;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -1578,7 +1583,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s)
#endif
_custom_status_string = s ;
for(std::map<std::string,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
for(std::map<RsPeerId,StateStringInfo>::iterator it(_state_strings.begin());it!=_state_strings.end();++it)
it->second._own_is_new = true ;
mLinkMgr->getOnlineList(onlineList);
@ -1587,7 +1592,7 @@ void p3ChatService::setOwnCustomStateString(const std::string& s)
RsServer::notify()->notifyOwnStatusMessageChanged() ;
// alert your online peers to your newly set status
std::list<std::string>::iterator it(onlineList.begin());
std::list<RsPeerId>::iterator it(onlineList.begin());
for(; it != onlineList.end(); it++){
RsChatStatusItem *cs = new RsChatStatusItem();
@ -1619,7 +1624,7 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
_own_avatar = new AvatarInfo(data,size) ;
// set the info that our avatar is new, for all peers
for(std::map<std::string,AvatarInfo *>::iterator it(_avatars.begin());it!=_avatars.end();++it)
for(std::map<RsPeerId,AvatarInfo *>::iterator it(_avatars.begin());it!=_avatars.end();++it)
it->second->_own_is_new = true ;
}
IndicateConfigChanged();
@ -1632,7 +1637,7 @@ void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
}
void p3ChatService::receiveStateString(const std::string& id,const std::string& s)
void p3ChatService::receiveStateString(const RsPeerId& id,const std::string& s)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
#ifdef CHAT_DEBUG
@ -1696,13 +1701,13 @@ void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
}
}
std::string p3ChatService::getCustomStateString(const std::string& peer_id)
std::string p3ChatService::getCustomStateString(const RsPeerId& peer_id)
{
{
// should be a Mutex here.
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,StateStringInfo>::iterator it = _state_strings.find(peer_id) ;
std::map<RsPeerId,StateStringInfo>::iterator it = _state_strings.find(peer_id) ;
// has it. Return it strait away.
//
@ -1717,13 +1722,13 @@ std::string p3ChatService::getCustomStateString(const std::string& peer_id)
return std::string() ;
}
void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size)
void p3ChatService::getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size)
{
{
// should be a Mutex here.
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(peer_id) ;
std::map<RsPeerId,AvatarInfo *>::const_iterator it = _avatars.find(peer_id) ;
#ifdef CHAT_DEBUG
std::cerr << "p3chatservice:: avatar for peer " << peer_id << " requested from above. " << std::endl ;
@ -1750,7 +1755,7 @@ void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *
sendAvatarRequest(peer_id);
}
void p3ChatService::sendAvatarRequest(const std::string& peer_id)
void p3ChatService::sendAvatarRequest(const RsPeerId& peer_id)
{
// Doesn't have avatar. Request it.
//
@ -1769,7 +1774,7 @@ void p3ChatService::sendAvatarRequest(const std::string& peer_id)
sendPrivateChatItem(ci);
}
void p3ChatService::sendCustomStateRequest(const std::string& peer_id){
void p3ChatService::sendCustomStateRequest(const RsPeerId& peer_id){
RsChatStatusItem* cs = new RsChatStatusItem;
@ -1806,7 +1811,7 @@ RsChatAvatarItem *p3ChatService::makeOwnAvatarItem()
}
void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
void p3ChatService::sendAvatarJpegData(const RsPeerId& peer_id)
{
#ifdef CHAT_DEBUG
std::cerr << "p3chatservice: sending requested for peer " << peer_id << ", data=" << (void*)_own_avatar << std::endl ;
@ -1833,7 +1838,7 @@ void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
}
}
void p3ChatService::sendCustomState(const std::string& peer_id){
void p3ChatService::sendCustomState(const RsPeerId& peer_id){
#ifdef CHAT_DEBUG
std::cerr << "p3chatservice: sending requested status string for peer " << peer_id << std::endl ;
@ -1847,7 +1852,7 @@ std::cerr << "p3chatservice: sending requested status string for peer " << peer_
bool p3ChatService::loadList(std::list<RsItem*>& load)
{
std::list<std::string> ssl_peers;
std::list<RsPeerId> ssl_peers;
mLinkMgr->getFriendList(ssl_peers);
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
@ -2069,7 +2074,7 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::string ownId = mLinkMgr->getOwnId();
RsPeerId ownId = mLinkMgr->getOwnId();
std::list<RsChatMsgItem *>::iterator cit = privateOutgoingList.begin();
while (cit != privateOutgoingList.end()) {
@ -2115,7 +2120,7 @@ void p3ChatService::statusChange(const std::list<pqipeer> &plist)
// true: the object is not a duplicate and should be used
// false: the object is a duplicate or there is an error, and it should be destroyed.
//
bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const std::string& peer_id)
bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const RsPeerId& peer_id)
{
time_t now = time(NULL) ;
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -2173,7 +2178,7 @@ bool p3ChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,const std:
// Forward to allparticipating friends, except this peer.
for(std::set<std::string>::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it)
for(std::set<RsPeerId>::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it)
if((*it)!=peer_id && mLinkMgr->isOnline(*it))
{
RsChatLobbyBouncingObject *obj2 = item->duplicate() ; // makes a copy
@ -2248,7 +2253,7 @@ void p3ChatService::sendLobbyStatusItem(const ChatLobbyId& lobby_id,int type,con
item.string1 = status_string ;
item.sendTime = time(NULL) ;
}
std::string ownId = mLinkMgr->getOwnId();
RsPeerId ownId = mLinkMgr->getOwnId();
bounceLobbyObject(&item,ownId) ;
}
@ -2281,7 +2286,7 @@ bool p3ChatService::locked_initLobbyBouncableObject(const ChatLobbyId& lobby_id,
return true ;
}
bool p3ChatService::sendLobbyChat(const std::string &id, const std::string& msg, const ChatLobbyId& lobby_id)
bool p3ChatService::sendLobbyChat(const RsPeerId &id, const std::string& msg, const ChatLobbyId& lobby_id)
{
#ifdef CHAT_DEBUG
std::cerr << "Sending chat lobby message to lobby " << std::hex << lobby_id << std::dec << std::endl;
@ -2306,7 +2311,7 @@ bool p3ChatService::sendLobbyChat(const std::string &id, const std::string& msg,
item.message = msg;
}
std::string ownId = rsPeers->getOwnId();
RsPeerId ownId = rsPeers->getOwnId();
mHistoryMgr->addMessage(false, id, ownId, &item);
@ -2327,7 +2332,8 @@ void p3ChatService::handleConnectionChallenge(RsChatLobbyConnectChallengeItem *i
time_t now = time(NULL) ;
ChatLobbyId lobby_id ;
std::string ownId = rsPeers->getOwnId();
const RsPeerId& ownId = rsPeers->getOwnId();
bool found = false ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -2406,10 +2412,10 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id)
// Broadcast to all direct friends
std::list<std::string> ids ;
std::list<RsPeerId> ids ;
mLinkMgr->getOnlineList(ids);
for(std::list<std::string>::const_iterator it(ids.begin());it!=ids.end();++it)
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
{
RsChatLobbyConnectChallengeItem *item = new RsChatLobbyConnectChallengeItem ;
@ -2425,16 +2431,16 @@ void p3ChatService::sendConnectionChallenge(ChatLobbyId lobby_id)
}
}
uint64_t p3ChatService::makeConnexionChallengeCode(const std::string& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id)
uint64_t p3ChatService::makeConnexionChallengeCode(const RsPeerId& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id)
{
uint64_t result = 0 ;
for(uint32_t i=0;i<peer_id.size();++i)
for(uint32_t i=0;i<RsPeerId::SIZE_IN_BYTES;++i)
{
result += msg_id ;
result ^= result >> 35 ;
result += result << 6 ;
result ^= peer_id[i] * lobby_id ;
result ^= peer_id.toByteArray()[i] * lobby_id ;
result += result << 26 ;
result ^= result >> 13 ;
}
@ -2452,7 +2458,7 @@ void p3ChatService::getChatLobbyList(std::list<ChatLobbyInfo>& cl_infos)
for(std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it)
cl_infos.push_back(it->second) ;
}
void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const std::string& peer_id,bool connexion_challenge)
void p3ChatService::invitePeerToLobby(const ChatLobbyId& lobby_id, const RsPeerId& peer_id,bool connexion_challenge)
{
#ifdef CHAT_DEBUG
if(connexion_challenge)
@ -2623,12 +2629,13 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
return true ;
}
std::string p3ChatService::makeVirtualPeerId(ChatLobbyId lobby_id)
ChatLobbyVirtualPeerId p3ChatService::makeVirtualPeerId(ChatLobbyId lobby_id)
{
std::string s;
rs_sprintf(s, "Chat Lobby 0x%llx", lobby_id);
uint8_t bytes[RsPeerId::SIZE_IN_BYTES] ;
memset(bytes,0,RsPeerId::SIZE_IN_BYTES) ;
memcpy(bytes,&lobby_id,sizeof(lobby_id)) ;
return s ;
return ChatLobbyVirtualPeerId(bytes) ;
}
@ -2655,7 +2662,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id)
#ifdef CHAT_DEBUG
std::cerr << "Joining public chat lobby " << std::hex << lobby_id << std::dec << std::endl;
#endif
std::list<std::string> invited_friends ;
std::list<RsPeerId> invited_friends ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -2702,7 +2709,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id)
_lobby_ids[entry.virtual_peer_id] = lobby_id ;
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
{
invited_friends.push_back(*it2) ;
entry.participating_friends.insert(*it2) ;
@ -2710,7 +2717,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id)
_chat_lobbys[lobby_id] = entry ;
}
for(std::list<std::string>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
for(std::list<RsPeerId>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
invitePeerToLobby(lobby_id,*it) ;
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
@ -2719,7 +2726,7 @@ bool p3ChatService::joinVisibleChatLobby(const ChatLobbyId& lobby_id)
return true ;
}
ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<std::string>& invited_friends,uint32_t privacy_level)
ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<RsPeerId>& invited_friends,uint32_t privacy_level)
{
#ifdef CHAT_DEBUG
std::cerr << "Creating a new Chat lobby !!" << std::endl;
@ -2754,7 +2761,7 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s
_chat_lobbys[lobby_id] = entry ;
}
for(std::list<std::string>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
for(std::list<RsPeerId>::const_iterator it(invited_friends.begin());it!=invited_friends.end();++it)
invitePeerToLobby(lobby_id,*it) ;
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
@ -2778,7 +2785,7 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite
return ;
}
for(std::set<std::string>::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
for(std::set<RsPeerId>::iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
if(*it2 == item->PeerId())
{
#ifdef CHAT_DEBUG
@ -2811,7 +2818,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
// send a lobby leaving packet to all friends
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
for(std::set<RsPeerId>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
{
RsChatLobbyUnsubscribeItem *item = new RsChatLobbyUnsubscribeItem ;
@ -2833,7 +2840,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
_chat_lobbys.erase(it) ;
for(std::map<std::string,ChatLobbyId>::iterator it2(_lobby_ids.begin());it2!=_lobby_ids.end();++it2)
for(std::map<ChatLobbyVirtualPeerId,ChatLobbyId>::iterator it2(_lobby_ids.begin());it2!=_lobby_ids.end();++it2)
if(it2->second == id)
{
_lobby_ids.erase(it2) ;
@ -3065,7 +3072,7 @@ void p3ChatService::cleanLobbyCaches()
sendConnectionChallenge(*it) ;
}
bool p3ChatService::handleTunnelRequest(const std::string& hash,const std::string& /*peer_id*/)
bool p3ChatService::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& /*peer_id*/)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -3156,7 +3163,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua
cs->status_string = "Tunnel is working. You can talk!" ;
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_ACK_DISTANT_CONNECTION;
cs->PeerId(hash);
cs->PeerId(virtual_peer_id);
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -3165,7 +3172,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua
// Notify the GUI that the tunnel is up.
//
RsServer::notify()->notifyChatStatus(hash,"tunnel is up again!",true) ;
RsServer::notify()->notifyChatStatus(hash.toStdString(),"tunnel is up again!",true) ;
}
void p3ChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id)
@ -3173,7 +3180,7 @@ void p3ChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVir
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
std::map<RsFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end())
{
@ -3183,8 +3190,8 @@ void p3ChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVir
it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ;
}
RsServer::notify()->notifyChatStatus(hash,"tunnel is down...",true) ;
RsServer::notify()->notifyPeerStatusChanged(hash,RS_STATUS_OFFLINE) ;
RsServer::notify()->notifyChatStatus(hash.toStdString(),"tunnel is down...",true) ;
RsServer::notify()->notifyPeerStatusChanged(hash.toStdString(),RS_STATUS_OFFLINE) ;
}
#ifdef DEBUG_DISTANT_CHAT
@ -3200,8 +3207,8 @@ static void printBinaryData(void *data,uint32_t size)
}
#endif
void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const std::string& hash,
const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/)
void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const RsFileHash& hash,
const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction /*direction*/)
{
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "p3ChatService::receiveTurtleData(): Received turtle data. " << std::endl;
@ -3231,7 +3238,7 @@ void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const st
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
std::map<RsFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end())
{
@ -3285,7 +3292,7 @@ void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const st
// Setup the virtual peer to be the origin, and pass it on.
//
citem->PeerId(hash) ;
citem->PeerId(virtualPeerIdFromHash(hash)) ;
//RsServer::notify()->notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ;
handleIncomingItem(citem) ; // Treats the item, and deletes it
@ -3311,21 +3318,23 @@ void p3ChatService::sendTurtleData(RsChatItem *item)
#endif
uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
std::string virtual_peer_id ;
TurtleFileHash hash = hashFromVirtualPeerId(item->PeerId());
TurtleVirtualPeerId virtual_peer_id ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(item->PeerId()) ;
std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end())
{
std::cerr << "(EE) item is not going into a registered tunnel. Weird. peer id = " << virtual_peer_id << std::endl;
std::cerr << "(EE) item is not going into a registered tunnel. Weird. peer id = " << item->PeerId() << std::endl;
delete[] buff ;
return ;
}
it->second.last_contact = time(NULL) ;
virtual_peer_id = it->second.virtual_peer_id ;
memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
virtual_peer_id = it->second.virtual_peer_id ;
}
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "p3ChatService::sendTurtleData(): tunnel found. Encrypting data." << std::endl;
@ -3377,7 +3386,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item)
mTurtle->sendTurtleData(virtual_peer_id,gitem) ;
}
bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_radix64_string)
bool p3ChatService::createDistantChatInvite(const RsPgpId& pgp_id,time_t time_of_validity,std::string& encrypted_radix64_string)
{
// create the invite
@ -3391,19 +3400,13 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim
// Create a random hash for that invite.
//
unsigned char hash_bytes[DISTANT_CHAT_HASH_SIZE] ;
RAND_bytes( hash_bytes, DISTANT_CHAT_HASH_SIZE) ;
std::string hash = Sha1CheckSum(hash_bytes).toStdString(false) ;
RsFileHash hash = RsFileHash::random();
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "Created new distant chat invite: " << std::endl;
std::cerr << " validity time stamp = " << invite.time_of_validity << std::endl;
std::cerr << " hash = " << hash << std::endl;
std::cerr << " encryption key = " ;
static const char outl[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' } ;
for(uint32_t j = 0; j < 16; j++) { std::cerr << outl[ (invite.aes_key[j]>>4) ] ; std::cerr << outl[ invite.aes_key[j] & 0xf ] ; }
std::cerr << std::endl;
std::cerr << " encryption key = " << t_GenericIdType<DISTANT_CHAT_AES_KEY_SIZE,true,0x0001>(invite.aes_key) << std::endl;
#endif
// Now encrypt the data to create the link info. We need
@ -3421,9 +3424,9 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim
uint32_t header_size = DISTANT_CHAT_AES_KEY_SIZE + DISTANT_CHAT_HASH_SIZE + PGP_KEY_ID_SIZE;
unsigned char *data = new unsigned char[header_size+800] ;
PGPIdType OwnId(AuthGPG::getAuthGPG()->getGPGOwnId());
RsPgpId OwnId(AuthGPG::getAuthGPG()->getGPGOwnId());
memcpy(data ,hash_bytes ,DISTANT_CHAT_HASH_SIZE) ;
memcpy(data ,Sha1CheckSum(hash).toByteArray(),DISTANT_CHAT_HASH_SIZE) ;
memcpy(data+DISTANT_CHAT_HASH_SIZE ,invite.aes_key ,DISTANT_CHAT_AES_KEY_SIZE) ;
memcpy(data+DISTANT_CHAT_HASH_SIZE+DISTANT_CHAT_AES_KEY_SIZE,OwnId.toByteArray(),PGP_KEY_ID_SIZE) ;
@ -3468,7 +3471,7 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim
return true ;
}
bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,time_t time_of_validity,std::string& hash,uint32_t& error_code)
bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,time_t time_of_validity,DistantChatPeerId& pid,uint32_t& error_code)
{
// Un-radix the string.
//
@ -3495,7 +3498,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
uint32_t header_size = DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE + PGP_KEY_ID_SIZE ;
PGPIdType pgp_id( data + DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE ) ;
RsPgpId pgp_id( data + DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE ) ;
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "Got this PGP id: " << pgp_id.toStdString() << std::endl;
@ -3508,21 +3511,22 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
return false ;
}
bool signature_checked = AuthGPG::getAuthGPG()->VerifySignBin(data,header_size,data+header_size,data_size-header_size,fingerprint.toStdString()) ;
bool signature_checked = AuthGPG::getAuthGPG()->VerifySignBin(data,header_size,data+header_size,data_size-header_size,fingerprint) ;
#ifdef DEBUG_DISTANT_CHAT
std::cerr << "Signature successfuly verified!" << std::endl;
#endif
hash = Sha1CheckSum(data).toStdString(false) ;
TurtleFileHash hash(data);
pid = virtualPeerIdFromHash(hash) ;
startClientDistantChatConnection(hash,pgp_id.toStdString(),data+DISTANT_CHAT_HASH_SIZE) ;
startClientDistantChatConnection(hash,pgp_id,data+DISTANT_CHAT_HASH_SIZE) ;
// Finally, save the decrypted chat info, so that we can display some info in the GUI in case we want to re-use the link
//
DistantChatInvite dinvite ;
dinvite.encrypted_radix64_string = "" ; // means that it's not issued by us
dinvite.destination_pgp_id = pgp_id.toStdString() ;
dinvite.destination_pgp_id = pgp_id;
dinvite.time_of_validity = time_of_validity ;
dinvite.last_hit_time = time(NULL) ;
dinvite.flags = RS_DISTANT_CHAT_FLAG_SIGNED | (signature_checked ? RS_DISTANT_CHAT_FLAG_SIGNATURE_OK : 0) ;
@ -3545,7 +3549,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
error_code = signature_checked ? RS_DISTANT_CHAT_ERROR_NO_ERROR : RS_DISTANT_CHAT_ERROR_UNKNOWN_KEY;
RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, hash.toStdString(), "Distant peer", "Conversation starts...");
// Save config, since a new invite was added.
//
@ -3553,17 +3557,18 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
return true ;
}
bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code)
bool p3ChatService::initiateDistantChatConnexion(const DistantChatPeerId& pid,uint32_t& error_code)
{
std::string pgp_id ;
RsPgpId pgp_id ;
unsigned char aes_key[DISTANT_CHAT_AES_KEY_SIZE] ;
TurtleFileHash hash = hashFromVirtualPeerId(pid) ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
std::map<RsFileHash,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
if(it == _distant_chat_invites.end())
if(it == _distant_chat_invites.end())
{
error_code = RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH ;
return false ;
@ -3576,13 +3581,13 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_
startClientDistantChatConnection(hash,pgp_id,aes_key) ;
RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
RsServer::notify()->AddPopupMessage(RS_POPUP_CHAT, hash.toStdString(), "Distant peer", "Conversation starts...");
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
return true ;
}
void p3ChatService::startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf)
void p3ChatService::startClientDistantChatConnection(const RsFileHash& hash,const RsPgpId& pgp_id,const unsigned char *aes_key_buf)
{
DistantChatPeerInfo info ;
@ -3635,15 +3640,33 @@ void p3ChatService::cleanDistantChatInvites()
}
}
DistantChatPeerId p3ChatService::virtualPeerIdFromHash(const TurtleFileHash& hash)
{
if(DistantChatPeerId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
std::cerr << __PRETTY_FUNCTION__ << ": Serious inconsistency error." << std::endl;
return DistantChatPeerId(hash.toByteArray()) ;
}
TurtleFileHash p3ChatService::hashFromVirtualPeerId(const DistantChatPeerId& pid)
{
if(DistantChatPeerId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES)
std::cerr << __PRETTY_FUNCTION__ << ": Serious inconsistency error." << std::endl;
unsigned char tmp[Sha1CheckSum::SIZE_IN_BYTES] ;
memset(tmp,0,Sha1CheckSum::SIZE_IN_BYTES) ;
memcpy(tmp,pid.toByteArray(),DistantChatPeerId::SIZE_IN_BYTES) ;
return Sha1CheckSum(tmp);
}
bool p3ChatService::getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites)
{
invites.clear() ;
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
for(std::map<std::string,DistantChatInvite>::const_iterator it(_distant_chat_invites.begin());it!=_distant_chat_invites.end();++it)
for(std::map<TurtleFileHash,DistantChatInvite>::const_iterator it(_distant_chat_invites.begin());it!=_distant_chat_invites.end();++it)
{
DistantChatInviteInfo info ;
info.hash = it->first ;
info.pid = virtualPeerIdFromHash(it->first) ;
info.encrypted_radix64_string = it->second.encrypted_radix64_string ;
info.time_of_validity = it->second.time_of_validity ;
info.destination_pgp_id = it->second.destination_pgp_id ;
@ -3654,10 +3677,11 @@ bool p3ChatService::getDistantChatInviteList(std::vector<DistantChatInviteInfo>&
return true ;
}
bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id)
bool p3ChatService::getDistantChatStatus(const DistantChatPeerId& pid,uint32_t& status,RsPgpId& pgp_id)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
TurtleFileHash hash = hashFromVirtualPeerId(pid) ;
std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end())
@ -3672,17 +3696,20 @@ bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& statu
return true ;
}
bool p3ChatService::closeDistantChatConnexion(const std::string& hash)
bool p3ChatService::closeDistantChatConnexion(const DistantChatPeerId& pid)
{
// two cases:
// - client needs to stop asking for tunnels => remove the hash from the list of tunnelled files
// - server needs to only close the window and let the tunnel die. But the window should only open if a message arrives.
TurtleFileHash hash = hashFromVirtualPeerId(pid) ;
bool is_client = false ;
RsPeerId virtual_peer_id ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
std::map<RsFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
{
@ -3691,6 +3718,8 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash)
}
if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
is_client = true ;
virtual_peer_id = it->second.virtual_peer_id ;
}
if(is_client)
@ -3701,12 +3730,12 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash)
cs->status_string = "" ;
cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION;
cs->PeerId(hash);
cs->PeerId(virtual_peer_id);
sendTurtleData(cs) ; // that needs to be done off-mutex!
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
std::map<RsFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
{
@ -3725,10 +3754,12 @@ bool p3ChatService::closeDistantChatConnexion(const std::string& hash)
return true ;
}
void p3ChatService::markDistantChatAsClosed(const std::string& hash)
void p3ChatService::markDistantChatAsClosed(const DistantChatPeerId& pid)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
TurtleFileHash hash = hashFromVirtualPeerId(pid) ;
std::map<TurtleFileHash,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
{
@ -3739,10 +3770,12 @@ void p3ChatService::markDistantChatAsClosed(const std::string& hash)
it->second.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ;
}
bool p3ChatService::removeDistantChatInvite(const std::string& hash)
bool p3ChatService::removeDistantChatInvite(const DistantChatPeerId& pid)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
TurtleFileHash hash= hashFromVirtualPeerId(pid) ;
std::map<TurtleFileHash,DistantChatInvite>::iterator it = _distant_chat_invites.find(hash) ;
if(it == _distant_chat_invites.end()) // server side. Nothing to do.
{

View file

@ -41,6 +41,8 @@ class p3LinkMgr;
class p3HistoryMgr;
class p3turtle ;
typedef RsPeerId ChatLobbyVirtualPeerId ;
//!The basic Chat service.
/**
*
@ -77,13 +79,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
* chat is sent to specifc peer
* @param id peer to send chat msg to
*/
bool sendPrivateChat(const std::string &id, const std::string &msg);
bool sendPrivateChat(const RsPeerId &id, const std::string &msg);
/*!
* can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs)
* e.g currently used to update user when a peer 'is typing' during a chat
*/
void sendStatusString(const std::string& peer_id,const std::string& status_str) ;
void sendStatusString(const RsPeerId& peer_id,const std::string& status_str) ;
/*!
* send to all peers online
@ -95,7 +97,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
* this retrieves custom status for a peers, generate a requests to the peer
* @param peer_id the id of the peer you want status string for
*/
std::string getCustomStateString(const std::string& peer_id) ;
std::string getCustomStateString(const RsPeerId& peer_id) ;
/*!
* sets the client's custom status, generates 'status available' item sent to all online peers
@ -111,7 +113,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
* its avatar, if not already available. Creates a new unsigned char array. It's the caller's
* responsibility to delete this ones used.
*/
void getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) ;
void getAvatarJpegData(const RsPeerId& peer_id,unsigned char *& data,int& size) ;
/*!
* Sets the avatar data and size for client's account
@ -145,12 +147,12 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
/*!
* @param id's of available private chat messages
*/
bool getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids);
bool getPrivateChatQueueIds(bool incoming, std::list<RsPeerId> &ids);
/*!
* This retrieves all private chat msg items for peer
*/
bool getPrivateChatQueue(bool incoming, const std::string &id, std::list<ChatInfo> &chats);
bool getPrivateChatQueue(bool incoming, const RsPeerId &id, std::list<ChatInfo> &chats);
/*!
* Checks message security, especially remove billion laughs attacks
@ -161,15 +163,15 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
/*!
* @param clear private chat queue
*/
bool clearPrivateChatQueue(bool incoming, const std::string &id);
bool clearPrivateChatQueue(bool incoming, const RsPeerId &id);
bool getVirtualPeerId(const ChatLobbyId& lobby_id, std::string& virtual_peer_id) ;
bool isLobbyId(const std::string& virtual_peer_id, ChatLobbyId& lobby_id) ;
bool getVirtualPeerId(const ChatLobbyId& lobby_id, RsPeerId& virtual_peer_id) ;
bool isLobbyId(const RsPeerId& virtual_peer_id, ChatLobbyId& lobby_id) ;
void getChatLobbyList(std::list<ChatLobbyInfo, std::allocator<ChatLobbyInfo> >& cl_infos) ;
bool acceptLobbyInvite(const ChatLobbyId& id) ;
void denyLobbyInvite(const ChatLobbyId& id) ;
void getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites) ;
void invitePeerToLobby(const ChatLobbyId&, const std::string& peer_id,bool connexion_challenge = false) ;
void invitePeerToLobby(const ChatLobbyId&, const RsPeerId& peer_id,bool connexion_challenge = false) ;
void unsubscribeChatLobby(const ChatLobbyId& lobby_id) ;
bool setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick) ;
bool getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& nick) ;
@ -178,7 +180,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list<std::string>& invited_friends,uint32_t privacy_type) ;
ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list<RsPeerId>& invited_friends,uint32_t privacy_type) ;
void getListOfNearbyChatLobbies(std::vector<VisibleChatLobbyRecord>& public_lobbies) ;
bool joinVisibleChatLobby(const ChatLobbyId& id) ;
@ -194,7 +196,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
virtual void saveDone();
virtual bool loadList(std::list<RsItem*>& load) ;
bool isOnline(const std::string& id) ;
bool isOnline(const RsPeerId& id) ;
private:
RsMutex mChatMtx;
@ -211,14 +213,14 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
void addTimeShiftStatistics(int shift) ;
/// Send avatar info to peer in jpeg format.
void sendAvatarJpegData(const std::string& peer_id) ;
void sendAvatarJpegData(const RsPeerId& peer_id) ;
/// Send custom state info to peer
void sendCustomState(const std::string& peer_id);
void sendCustomState(const RsPeerId& peer_id);
/// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag.
void receiveAvatarJpegData(RsChatAvatarItem *ci) ; // new method
void receiveStateString(const std::string& id,const std::string& s) ;
void receiveStateString(const RsPeerId& id,const std::string& s) ;
/// methods for handling various Chat items.
bool handleRecvChatMsgItem(RsChatMsgItem *item) ; // returns false if the item should be deleted.
@ -229,13 +231,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
void handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) ;
/// Checks that the lobby object is not flooding a lobby.
bool locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const std::string& peer_id,uint32_t lobby_count) ;
bool locked_bouncingObjectCheck(RsChatLobbyBouncingObject *obj,const RsPeerId& peer_id,uint32_t lobby_count) ;
/// Sends a request for an avatar to the peer of given id
void sendAvatarRequest(const std::string& peer_id) ;
void sendAvatarRequest(const RsPeerId& peer_id) ;
/// Send a request for custom status string
void sendCustomStateRequest(const std::string& peer_id);
void sendCustomStateRequest(const RsPeerId& peer_id);
/// called as a proxy to sendItem(). Possibly splits item into multiple items of size lower than the maximum item size.
void checkSizeAndSendMessage(RsChatLobbyMsgItem *item) ;
@ -246,15 +248,15 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
bool locked_checkAndRebuildPartialMessage_deprecated(RsChatMsgItem*) ;
/// receive and handle chat lobby item
bool recvLobbyChat(RsChatLobbyMsgItem*,const std::string& src_peer_id) ;
bool sendLobbyChat(const std::string &id, const std::string&, const ChatLobbyId&) ;
bool recvLobbyChat(RsChatLobbyMsgItem*,const RsPeerId& src_peer_id) ;
bool sendLobbyChat(const RsPeerId &id, const std::string&, const ChatLobbyId&) ;
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;
void sendConnectionChallenge(ChatLobbyId id) ;
void handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem*) ;
void cleanLobbyCaches() ;
bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const std::string& peer_id) ;
bool bounceLobbyObject(RsChatLobbyBouncingObject *obj, const RsPeerId& peer_id) ;
void sendLobbyStatusItem(const ChatLobbyId&, int type, const std::string& status_string) ;
void sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id) ;
@ -265,8 +267,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
bool locked_initLobbyBouncableObject(const ChatLobbyId& id,RsChatLobbyBouncingObject&) ;
static std::string makeVirtualPeerId(ChatLobbyId) ;
static uint64_t makeConnexionChallengeCode(const std::string& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ;
static ChatLobbyVirtualPeerId makeVirtualPeerId(ChatLobbyId) ;
static uint64_t makeConnexionChallengeCode(const RsPeerId& peer_id,ChatLobbyId lobby_id,ChatLobbyMsgId msg_id) ;
void locked_printDebugInfo() const ;
RsChatAvatarItem *makeOwnAvatarItem() ;
@ -280,28 +282,28 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
std::list<RsChatMsgItem *> privateOutgoingList;
AvatarInfo *_own_avatar ;
std::map<std::string,AvatarInfo *> _avatars ;
std::map<std::string,RsChatMsgItem *> _pendingPartialMessages ;
std::map<RsPeerId,AvatarInfo *> _avatars ;
std::map<RsPeerId,RsChatMsgItem *> _pendingPartialMessages ;
std::map<ChatLobbyMsgId,std::vector<RsChatLobbyMsgItem*> > _pendingPartialLobbyMessages ; // should be used for all chat msgs after version updgrade
std::string _custom_status_string ;
std::map<std::string,StateStringInfo> _state_strings ;
std::map<RsPeerId,StateStringInfo> _state_strings ;
class ChatLobbyEntry: public ChatLobbyInfo
{
public:
std::map<ChatLobbyMsgId,time_t> msg_cache ;
std::string virtual_peer_id ;
RsPeerId virtual_peer_id ;
int connexion_challenge_count ;
time_t last_connexion_challenge_time ;
time_t last_keep_alive_packet_time ;
std::set<std::string> previously_known_peers ;
std::set<RsPeerId> previously_known_peers ;
uint32_t flags ;
};
std::map<ChatLobbyId,ChatLobbyEntry> _chat_lobbys ;
std::map<ChatLobbyId,ChatLobbyInvite> _lobby_invites_queue ;
std::map<ChatLobbyId,VisibleChatLobbyRecord> _visible_lobbies ;
std::map<std::string,ChatLobbyId> _lobby_ids ;
std::map<ChatLobbyVirtualPeerId,ChatLobbyId> _lobby_ids ;
std::map<ChatLobbyId,ChatLobbyFlags> _known_lobbies_flags ; // flags for all lobbies, including the ones that are not known. So we can't
// store them in _chat_lobbies (subscribed lobbies) nor _visible_lobbies.
// Known flags:
@ -325,21 +327,21 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
// Creates the invite if the public key of the distant peer is available.
// Om success, stores the invite in the map above, so that we can respond to tunnel requests.
//
bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ;
bool createDistantChatInvite(const RsPgpId& pgp_id,time_t time_of_validity,std::string& enc_b64_string) ;
bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites) ;
bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t time_of_validity,std::string& hash,uint32_t& error_code) ; // from encrypted data
bool initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) ; // from known hash of a decrypted link
bool closeDistantChatConnexion(const std::string& hash) ;
bool removeDistantChatInvite(const std::string& hash) ;
bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t time_of_validity,DistantChatPeerId& pid,uint32_t& error_code) ; // from encrypted data
bool initiateDistantChatConnexion(const DistantChatPeerId& pid,uint32_t& error_code) ; // from known hash of a decrypted link
bool closeDistantChatConnexion(const DistantChatPeerId& pid) ;
bool removeDistantChatInvite(const DistantChatPeerId& pid) ;
virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ;
virtual bool getDistantChatStatus(const DistantChatPeerId& hash,uint32_t& status,RsPgpId& pgp_id) ;
private:
struct DistantChatInvite
{
unsigned char aes_key[16] ;
std::string encrypted_radix64_string ;
std::string destination_pgp_id ;
RsPgpId destination_pgp_id ;
time_t time_of_validity ;
time_t last_hit_time ;
uint32_t flags ;
@ -349,8 +351,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
time_t last_contact ; // used to send keep alive packets
unsigned char aes_key[16] ; // key to encrypt packets
uint32_t status ; // info: do we have a tunnel ?
std::string virtual_peer_id; // given by the turtle router. Identifies the tunnel.
std::string pgp_id ; // pgp id of the peer we're talking to.
RsPeerId virtual_peer_id; // given by the turtle router. Identifies the tunnel.
RsPgpId pgp_id ; // pgp id of the peer we're talking to.
RsTurtleGenericTunnelItem::Direction direction ; // specifiec wether we are client(managing the tunnel) or server.
};
@ -361,7 +363,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
// This maps contains the current peers to talk to with distant chat.
//
std::map<std::string,DistantChatPeerInfo> _distant_chat_peers ;
std::map<TurtleFileHash,DistantChatPeerInfo> _distant_chat_peers ;
// List of items to be sent asap. Used to store items that we cannot pass directly to
// sendTurtleData(), because of Mutex protection.
@ -370,12 +372,13 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
// Overloaded from RsTurtleClientService
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
virtual bool handleTunnelRequest(const RsFileHash &hash,const RsPeerId& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
void markDistantChatAsClosed(const TurtleFileHash& hash) ;
void startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf) ;
void markDistantChatAsClosed(const TurtleVirtualPeerId& vpid) ;
void startClientDistantChatConnection(const RsFileHash& hash,const RsPgpId& pgp_id,const unsigned char *aes_key_buf) ;
bool findHashForVirtualPeerId(const TurtleVirtualPeerId& pid,RsFileHash& hash) ;
// Utility functions
@ -383,6 +386,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
void sendTurtleData(RsChatItem *) ;
void sendPrivateChatItem(RsChatItem *) ;
static TurtleFileHash hashFromVirtualPeerId(const DistantChatPeerId& peerId) ; // converts IDs so that we can talk to RsPeerId from outside
static DistantChatPeerId virtualPeerIdFromHash(const TurtleFileHash& hash ) ; // ... and to a hash for p3turtle
p3turtle *mTurtle ;
};

View file

@ -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<RsPgpId>::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

View file

@ -41,8 +41,8 @@
typedef std::string PGPID;
typedef std::string SSLID;
typedef RsPgpId PGPID;
typedef RsPeerId 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 RsPgpId &pgpid, std::list<RsPgpId> &gpg_friends);
virtual bool getPeerVersion(const RsPeerId &id, std::string &version);
virtual bool getWaitingDiscCount(unsigned int *sendCount, unsigned int *recvCount);
/************* from AuthGPService ****************/

View file

@ -598,17 +598,15 @@ void p3GxsChannels::handleUnprocessedPost(const RsGxsChannelPost &msg)
for(fit = msg.mFiles.begin(); fit != msg.mFiles.end(); fit++)
{
std::string fname = fit->mName;
std::string hash = fit->mHash;
Sha1CheckSum hash = Sha1CheckSum(fit->mHash);
uint64_t size = fit->mSize;
std::list<std::string> srcIds;
std::list<RsPeerId> srcIds;
std::string localpath = "";
TransferRequestFlags flags = RS_FILE_REQ_BACKGROUND | RS_FILE_REQ_ANONYMOUS_ROUTING;
if (size < CHANNEL_MAX_AUTO_DL)
{
rsFiles->FileRequest(fname, hash, size, localpath, flags, srcIds);
}
}
}
@ -847,10 +845,11 @@ bool p3GxsChannels::ExtraFileHash(const std::string &path, std::string filename)
}
bool p3GxsChannels::ExtraFileRemove(const std::string &hash)
bool p3GxsChannels::ExtraFileRemove(const RsFileHash &hash)
{
TransferRequestFlags tflags = RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA;
return rsFiles->ExtraFileRemove(hash, tflags);
RsFileHash fh = RsFileHash(hash);
return rsFiles->ExtraFileRemove(fh, tflags);
}
@ -1031,7 +1030,7 @@ void p3GxsChannels::dummy_tick()
RsGxsGroupId grpId = ref.mGroupId;
RsGxsMessageId parentId = ref.mMsgId;
mGenThreadId = ref.mThreadId;
if (mGenThreadId.empty())
if (mGenThreadId.isNull())
{
mGenThreadId = parentId;
}
@ -1053,7 +1052,7 @@ void p3GxsChannels::dummy_tick()
RsGxsGroupId grpId = ref.mGroupId;
RsGxsMessageId parentId = ref.mMsgId;
mGenThreadId = ref.mThreadId;
if (mGenThreadId.empty())
if (mGenThreadId.isNull())
{
mGenThreadId = parentId;
}
@ -1075,7 +1074,7 @@ void p3GxsChannels::dummy_tick()
RsGxsGroupId grpId = ref.mGroupId;
RsGxsMessageId parentId = ref.mMsgId;
mGenThreadId = ref.mThreadId;
if (mGenThreadId.empty())
if (mGenThreadId.isNull())
{
mGenThreadId = parentId;
}
@ -1100,7 +1099,7 @@ bool p3GxsChannels::generatePost(uint32_t &token, const RsGxsGroupId &grpId)
std::string rndId = genRandomId();
rs_sprintf(msg.mMsg, "Channel Msg: GroupId: %s, some randomness: %s",
grpId.c_str(), rndId.c_str());
grpId.toStdString().c_str(), rndId.c_str());
msg.mMeta.mMsgName = msg.mMsg;
@ -1123,7 +1122,7 @@ bool p3GxsChannels::generateComment(uint32_t &token, const RsGxsGroupId &grpId,
std::string rndId = genRandomId();
rs_sprintf(msg.mComment, "Channel Comment: GroupId: %s, ThreadId: %s, ParentId: %s + some randomness: %s",
grpId.c_str(), threadId.c_str(), parentId.c_str(), rndId.c_str());
grpId.toStdString().c_str(), threadId.toStdString().c_str(), parentId.toStdString().c_str(), rndId.c_str());
msg.mMeta.mMsgName = msg.mComment;

View file

@ -144,7 +144,7 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
// File Interface
virtual bool ExtraFileHash(const std::string &path, std::string filename);
virtual bool ExtraFileRemove(const std::string &hash);
virtual bool ExtraFileRemove(const RsFileHash &hash);
protected:

View file

@ -199,7 +199,8 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
// for new circles we need to add them to the list.
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleExternalIdList.push_back(*git);
RsGxsCircleId tempId(git->toStdString());
mCircleExternalIdList.push_back(tempId);
}
}
}
@ -311,7 +312,7 @@ bool p3GxsCircles::loadCircle(const RsGxsCircleId &circleId)
return cache_request_load(circleId);
}
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const std::string &id)
int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
if (mCircleCache.is_cached(circleId))
@ -426,7 +427,7 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
if (item->meta.mCircleType == GXS_CIRCLE_TYPE_EXT_SELF)
{
item->meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
item->meta.mCircleId = item->meta.mGroupId;
item->meta.mCircleId = item->meta.mGroupId.toStdString();
}
@ -435,11 +436,11 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
if (item->meta.mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
mCirclePersonalIdList.push_back(item->meta.mGroupId);
mCirclePersonalIdList.push_back(RsGxsCircleId(item->meta.mGroupId.toStdString()));
}
else
{
mCircleExternalIdList.push_back(item->meta.mGroupId);
mCircleExternalIdList.push_back(RsGxsCircleId(item->meta.mGroupId.toStdString()));
}
}
@ -470,7 +471,7 @@ RsGxsCircleCache::RsGxsCircleCache()
bool RsGxsCircleCache::loadBaseCircle(const RsGxsCircleGroup &circle)
{
mCircleId = circle.mMeta.mGroupId;
mCircleId = circle.mMeta.mGroupId.toStdString();
mCircleName = circle.mMeta.mGroupName;
mUpdateTime = time(NULL);
mProcessedCircles.insert(mCircleId);
@ -583,13 +584,14 @@ bool p3GxsCircles::load_CircleIdList(uint32_t token)
for(it = groups.begin(); it != groups.end(); it++)
{
RsGxsCircleId tempId(it->mGroupId.toStdString());
if (it->mCircleType == GXS_CIRCLE_TYPE_LOCAL)
{
mCirclePersonalIdList.push_back(it->mGroupId);
mCirclePersonalIdList.push_back(tempId);
}
else
{
mCircleExternalIdList.push_back(it->mGroupId);
mCircleExternalIdList.push_back(tempId);
}
}
}
@ -782,7 +784,7 @@ bool p3GxsCircles::cache_start_load()
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_start_load()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
#endif // DEBUG_CIRCLESmatch
/* trigger request to load missing ids into cache */
std::list<RsGxsGroupId> groupIds;
@ -790,7 +792,7 @@ bool p3GxsCircles::cache_start_load()
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
/* now we process the modGroupList -> a map so we can use it easily later, and create id list too */
std::list<RsGxsId>::iterator it;
std::list<RsGxsCircleId>::iterator it;
for(it = mCacheLoad_ToCache.begin(); it != mCacheLoad_ToCache.end(); it++)
{
#ifdef DEBUG_CIRCLES
@ -798,7 +800,7 @@ bool p3GxsCircles::cache_start_load()
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
groupIds.push_back(*it); // might need conversion?
groupIds.push_back(RsGxsGroupId(it->toStdString())); // might need conversion?
}
mCacheLoad_ToCache.clear();
@ -859,7 +861,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
/* should already have a LoadingCache entry */
RsGxsCircleId id = item->meta.mGroupId;
RsGxsCircleId id = RsGxsCircleId(item->meta.mGroupId.toStdString());
std::map<RsGxsCircleId, RsGxsCircleCache>::iterator it;
it = mLoadingCache.find(id);
if (it == mLoadingCache.end())
@ -1013,7 +1015,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
if (isUnprocessedPeers)
{
/* schedule event to try reload gxsIds */
RsTickEvent::schedule_in(CIRCLE_EVENT_RELOADIDS, GXSID_LOAD_CYCLE, id);
RsTickEvent::schedule_in(CIRCLE_EVENT_RELOADIDS, GXSID_LOAD_CYCLE, id.toStdString());
}
}
}
@ -1039,7 +1041,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
}
bool p3GxsCircles::cache_reloadids(const std::string &circleId)
bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids()";
@ -1171,7 +1173,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
}
/* if we appear in the group - then autosubscribe, and mark as processed */
std::string ownId = AuthGPG::getAuthGPG()->getGPGOwnId();
const RsPgpId& ownId = AuthGPG::getAuthGPG()->getGPGOwnId();
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId);
if (it != cache.mAllowedPeers.end())
{
@ -1181,8 +1183,8 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
uint32_t token, token2;
RsGenExchange::subscribeToGroup(token, cache.mCircleId, true);
RsGenExchange::setGroupStatusFlags(token2, cache.mCircleId, 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
RsGenExchange::subscribeToGroup(token, RsGxsGroupId(cache.mCircleId.toStdString()), true);
RsGenExchange::setGroupStatusFlags(token2, RsGxsGroupId(cache.mCircleId.toStdString()), 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
return true;
}
@ -1193,7 +1195,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
/* we know all the peers - we are not part - we can flag as PROCESSED. */
uint32_t token;
RsGenExchange::setGroupStatusFlags(token, cache.mCircleId, 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
RsGenExchange::setGroupStatusFlags(token, RsGxsGroupId(cache.mCircleId.toStdString()), 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
}
else
@ -1453,7 +1455,7 @@ void p3GxsCircles::checkDummyIdData()
std::cerr << "p3GxsCircles::checkDummyIdData() PgpLinkedId: " << it->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
mDummyPgpLinkedIds.push_back(it->mMeta.mGroupId);
mDummyPgpLinkedIds.push_back(RsGxsId(it->mMeta.mGroupId.toStdString()));
if (it->mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
{
@ -1461,7 +1463,7 @@ void p3GxsCircles::checkDummyIdData()
std::cerr << "p3GxsCircles::checkDummyIdData() OwnId: " << it->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
mDummyOwnIds.push_back(it->mMeta.mGroupId);
mDummyOwnIds.push_back(RsGxsId(it->mMeta.mGroupId.toStdString()));
}
}
else
@ -1647,7 +1649,7 @@ void p3GxsCircles::handle_event(uint32_t event_type, const std::string &elabel)
break;
case CIRCLE_EVENT_RELOADIDS:
cache_reloadids(elabel);
cache_reloadids(RsGxsCircleId(elabel));
break;
#if 0

View file

@ -188,7 +188,7 @@ class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
bool cache_request_load(const RsGxsCircleId &id);
bool cache_start_load();
bool cache_load_for_token(uint32_t token);
bool cache_reloadids(const std::string &circleId);
bool cache_reloadids(const RsGxsCircleId &circleId);
bool checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache);

View file

@ -414,28 +414,28 @@ bool p3GxsCommentService::createGxsVote(uint32_t &token, RsGxsVote &vote)
std::cerr << std::endl;
/* vote must be associated with another item */
if (vote.mMeta.mThreadId.empty())
if (vote.mMeta.mThreadId.isNull())
{
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required ThreadId";
std::cerr << std::endl;
return false;
}
if (vote.mMeta.mParentId.empty())
if (vote.mMeta.mParentId.isNull())
{
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required ParentId";
std::cerr << std::endl;
return false;
}
if (vote.mMeta.mGroupId.empty())
if (vote.mMeta.mGroupId.isNull())
{
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required GroupId";
std::cerr << std::endl;
return false;
}
if (vote.mMeta.mAuthorId.empty())
if (vote.mMeta.mAuthorId.isNull())
{
std::cerr << "p3GxsCommentService::createGxsVote() ERROR Missing Required AuthorId";
std::cerr << std::endl;

View file

@ -219,6 +219,10 @@ bool p3GxsForums::updateGroup(uint32_t &token, RsGxsForumGroup &group)
{
std::cerr << "p3GxsForums::updateGroup()" << std::endl;
if(meta.getGroupId().isNull())
return false;
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
grpItem->mGroup = group;
grpItem->meta = group.mMeta;
@ -392,7 +396,7 @@ void p3GxsForums::dummy_tick()
RsGxsGroupId grpId = ref.mGroupId;
RsGxsMessageId parentId = ref.mMsgId;
mGenThreadId = ref.mThreadId;
if (mGenThreadId.empty())
if (mGenThreadId.isNull())
{
mGenThreadId = parentId;
}
@ -416,7 +420,7 @@ bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, co
std::string rndId = genRandomId();
rs_sprintf(msg.mMsg, "Forum Msg: GroupId: %s, ThreadId: %s, ParentId: %s + some randomness: %s",
grpId.c_str(), threadId.c_str(), parentId.c_str(), rndId.c_str());
grpId.toStdString().c_str(), threadId.toStdString().c_str(), parentId.toStdString().c_str(), rndId.c_str());
msg.mMeta.mMsgName = msg.mMsg;

View file

@ -28,7 +28,7 @@
#include "services/p3heartbeat.h"
#include "serialiser/rsheartbeatitems.h"
#define HEART_DEBUG 1
//#define HEART_DEBUG 1
p3heartbeat::p3heartbeat(p3LinkMgr *linkMgr, pqipersongrp *pqipg)
@ -64,8 +64,8 @@ int p3heartbeat::tick()
{
mLastHeartbeat = time(NULL);
std::list<std::string> peers;
std::list<std::string>::const_iterator pit;
std::list<RsPeerId> peers;
std::list<RsPeerId>::const_iterator pit;
mLinkMgr->getOnlineList(peers);
for (pit = peers.begin(); pit != peers.end(); ++pit)
@ -99,7 +99,7 @@ int p3heartbeat::tick()
return nhandled ;
}
void p3heartbeat::sendHeartbeat(const std::string &toId)
void p3heartbeat::sendHeartbeat(const RsPeerId &toId)
{
#ifdef HEART_DEBUG
@ -112,7 +112,7 @@ void p3heartbeat::sendHeartbeat(const std::string &toId)
}
void p3heartbeat::recvHeartbeat(const std::string &fromId)
void p3heartbeat::recvHeartbeat(const RsPeerId &fromId)
{
#ifdef HEART_DEBUG

View file

@ -44,8 +44,8 @@ virtual ~p3heartbeat();
private:
void sendHeartbeat(const std::string &toId);
void recvHeartbeat(const std::string &fromId);
void sendHeartbeat(const RsPeerId &toId);
void recvHeartbeat(const RsPeerId &fromId);
private:

View file

@ -473,7 +473,7 @@ bool p3IdService::haveReputation(const RsGxsId &id)
return haveKey(id);
}
bool p3IdService::loadReputation(const RsGxsId &id, const std::list<std::string>& peers)
bool p3IdService::loadReputation(const RsGxsId &id, const std::list<PeerId>& peers)
{
if (haveKey(id))
return true;
@ -684,7 +684,7 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
else
{
group.mPgpKnown = false;
group.mPgpId = "";
group.mPgpId.clear();
std::cerr << "p3IdService::getGroupData() Failed to decode ServiceString";
std::cerr << std::endl;
@ -720,7 +720,7 @@ bool p3IdService::createGroup(uint32_t& token, RsGxsIdGroup &group)
bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
{
RsGxsId id = group.mMeta.mGroupId;
RsGxsId id = RsGxsId(group.mMeta.mGroupId.toStdString());
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
item->group = group;
item->meta = group.mMeta;
@ -730,8 +730,10 @@ bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
RsGenExchange::updateGroup(token, item);
//RsGxsGroupUpdateMeta updateMeta(id);
//RsGenExchange::updateGroup(token, updateMeta, item);
RsGxsGroupUpdateMeta updateMeta(RsGxsGroupId(id.toStdString()));
RsGenExchange::updateGroup(token, updateMeta, item);
// if its in the cache - clear it.
{
@ -782,7 +784,8 @@ bool SSGxsIdPgp::load(const std::string &input)
if (1 == sscanf(input.c_str(), "K:1 I:%[^)]", pgpline))
{
idKnown = true;
pgpId = pgpline;
std::string str_line = pgpline;
pgpId = RsPgpId(str_line);
}
else if (1 == sscanf(input.c_str(), "K:0 T:%d", &timestamp))
{
@ -802,7 +805,7 @@ std::string SSGxsIdPgp::save() const
if (idKnown)
{
output += "K:1 I:";
output += pgpId;
output += pgpId.toStdString();
}
else
{
@ -819,7 +822,7 @@ std::string SSGxsIdPgp::save() const
bool SSGxsIdRecognTags::load(const std::string &input)
{
char pgpline[RSGXSID_MAX_SERVICE_STRING];
//char pgpline[RSGXSID_MAX_SERVICE_STRING];
int pubTs = 0;
int lastTs = 0;
uint32_t flags = 0;
@ -1122,7 +1125,7 @@ RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvSecurityKey
// Fill in Details.
details.mNickname = item->meta.mGroupName;
details.mId = item->meta.mGroupId;
details.mId = item->meta.mGroupId.toStdString();
#ifdef DEBUG_IDS
std::cerr << "RsGxsIdCache::RsGxsIdCache() for: " << details.mId;
@ -1153,7 +1156,7 @@ void RsGxsIdCache::updateServiceString(std::string serviceString)
}
else
{
details.mPgpId = "";
details.mPgpId.clear();
}
}
@ -1211,7 +1214,7 @@ void RsGxsIdCache::updateServiceString(std::string serviceString)
else
{
details.mPgpKnown = false;
details.mPgpId = "";
details.mPgpId.clear();
details.mReputation.updateIdScore(false, false);
details.mReputation.update();
}
@ -1312,12 +1315,12 @@ bool p3IdService::cache_process_recogntaginfo(const RsGxsIdGroupItem *item, std:
recogn_extract_taginfo(item, tagItems);
time_t now = time(NULL);
//time_t now = time(NULL);
for(it = tagItems.begin(); it != tagItems.end(); it++)
{
RsRecognTag info((*it)->tag_class, (*it)->tag_type, false);
bool isPending = false;
if (recogn_checktag(item->meta.mGroupId, item->meta.mGroupName, *it, false, isPending))
if (recogn_checktag(RsGxsId(item->meta.mGroupId.toStdString()), item->meta.mGroupName, *it, false, isPending))
{
info.valid = true;
}
@ -1368,8 +1371,8 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
bool pub_key_ok = false;
bool full_key_ok = false;
RsGxsId id = item->meta.mGroupId;
if (!getGroupKeys(id, keySet))
RsGxsId id (item->meta.mGroupId.toStdString());
if (!getGroupKeys(RsGxsGroupId(id.toStdString()), keySet))
{
std::cerr << "p3IdService::cache_store() ERROR getting GroupKeys for: ";
std::cerr << item->meta.mGroupId;
@ -1442,7 +1445,7 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
#define MIN_CYCLE_GAP 2
bool p3IdService::cache_request_load(const RsGxsId &id, const std::list<std::string>& peers)
bool p3IdService::cache_request_load(const RsGxsId &id, const std::list<PeerId>& peers)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_request_load(" << id << ")";
@ -1483,14 +1486,14 @@ bool p3IdService::cache_start_load()
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
/* now we process the modGroupList -> a map so we can use it easily later, and create id list too */
std::map<RsGxsId, std::list<std::string> >::iterator it;
std::map<RsGxsId, std::list<RsPeerId> >::iterator it;
for(it = mCacheLoad_ToCache.begin(); it != mCacheLoad_ToCache.end(); it++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_start_load() GroupId: " << it->first;
std::cerr << std::endl;
#endif // DEBUG_IDS
groupIds.push_back(it->first); // might need conversion?
groupIds.push_back(RsGxsGroupId(it->first.toStdString())); // might need conversion?
}
mPendingCache.insert(mCacheLoad_ToCache.begin(), mCacheLoad_ToCache.end());
@ -1550,7 +1553,7 @@ bool p3IdService::cache_load_for_token(uint32_t token)
{
// remove identities that are present
RsStackMutex stack(mIdMtx);
mPendingCache.erase(item->meta.mGroupId);
mPendingCache.erase(RsGxsId(item->meta.mGroupId.toStdString()));
}
/* cache the data */
@ -1584,8 +1587,8 @@ void p3IdService::requestIdsFromNet()
{
RsStackMutex stack(mIdMtx);
std::map<RsGxsId, std::list<std::string> >::const_iterator cit;
std::map<std::string, std::list<RsGxsId> > requests;
std::map<RsGxsId, std::list<RsPeerId> >::const_iterator cit;
std::map<RsPeerId, std::list<RsGxsId> > requests;
// transform to appropriate structure (<peer, std::list<RsGxsId> > map) to make request to nes
for(cit = mIdsNotPresent.begin(); cit != mIdsNotPresent.end(); cit++)
@ -1599,18 +1602,26 @@ void p3IdService::requestIdsFromNet()
}
const std::list<std::string>& peers = cit->second;
std::list<std::string>::const_iterator cit2;
const std::list<RsPeerId>& peers = cit->second;
std::list<RsPeerId>::const_iterator cit2;
for(cit2 = peers.begin(); cit2 != peers.end(); cit2++)
requests[*cit2].push_back(cit->first);
}
std::map<std::string, std::list<RsGxsId> >::const_iterator cit2;
std::map<RsPeerId, std::list<RsGxsId> >::const_iterator cit2;
for(cit2 = requests.begin(); cit2 != requests.end(); cit2++)
{
if(mNes)
mNes->requestGrp(cit2->second, cit2->first);
{
std::list<RsGxsId>::const_iterator gxs_id_it = cit2->second.begin();
std::list<RsGxsGroupId> grpIds;
for(; gxs_id_it != cit2->second.end(); gxs_id_it++)
grpIds.push_back(RsGxsGroupId(gxs_id_it->toStdString()));
mNes->requestGrp(grpIds, cit2->first);
}
}
mIdsNotPresent.clear();
@ -1711,7 +1722,7 @@ bool p3IdService::cache_load_ownids(uint32_t token)
if (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
{
mOwnIds.push_back(item->meta.mGroupId);
mOwnIds.push_back(RsGxsId(item->meta.mGroupId.toStdString()));
}
delete item ;
}
@ -1780,7 +1791,12 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
#endif // DEBUG_IDS
std::list<RsGxsId> grpIds;
bool ok = RsGenExchange::getGroupList(token, grpIds);
std::list<RsGxsGroupId> grpIdsC;
bool ok = RsGenExchange::getGroupList(token, grpIdsC);
std::list<RsGxsGroupId>::const_iterator cit = grpIdsC.begin();
for(; cit != grpIdsC.end(); cit++)
grpIds.push_back(RsGxsId(cit->toStdString()));
if(ok)
{
@ -2051,7 +2067,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
/* */
PGPFingerprintType ownFinger;
PGPIdType ownId(AuthGPG::getAuthGPG()->getGPGOwnId());
RsPgpId ownId(AuthGPG::getAuthGPG()->getGPGOwnId());
std::cerr << "p3IdService::service_CreateGroup() OwnPgpID: " << ownId.toStdString();
std::cerr << std::endl;
@ -2059,7 +2075,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
#ifdef GXSID_GEN_DUMMY_DATA
if (item->group.mMeta.mAuthorId != "")
{
ownId = PGPIdType(item->group.mMeta.mAuthorId);
ownId = RsPgpId(item->group.mMeta.mAuthorId);
}
#endif
@ -2075,7 +2091,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
std::cerr << "p3IdService::service_CreateGroup() OwnFingerprint: " << ownFinger.toStdString();
std::cerr << std::endl;
calcPGPHash(item->group.mMeta.mGroupId, ownFinger, hash);
calcPGPHash(RsGxsId(item->group.mMeta.mGroupId.toStdString()), ownFinger, hash);
item->group.mPgpIdHash = hash.toStdString();
#ifdef DEBUG_IDS
@ -2332,7 +2348,7 @@ bool p3IdService::pgphash_process()
SSGxsIdGroup ssdata;
ssdata.load(pg.mMeta.mServiceString); // attempt load - okay if fails.
PGPIdType pgpId;
RsPgpId pgpId;
if (checkId(pg, pgpId))
{
@ -2347,7 +2363,7 @@ bool p3IdService::pgphash_process()
/* update */
ssdata.pgp.idKnown = true;
ssdata.pgp.pgpId = pgpId.toStdString();
ssdata.pgp.pgpId = pgpId;
}
else
@ -2370,7 +2386,7 @@ bool p3IdService::pgphash_process()
std::string serviceString = ssdata.save();
setGroupServiceString(dummyToken, pg.mMeta.mGroupId, serviceString);
cache_update_if_cached(pg.mMeta.mGroupId, serviceString);
cache_update_if_cached(RsGxsId(pg.mMeta.mGroupId.toStdString()), serviceString);
// Schedule Next Processing.
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH_PROC, PGPHASH_PROC_PERIOD);
@ -2379,7 +2395,7 @@ bool p3IdService::pgphash_process()
bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
bool p3IdService::checkId(const RsGxsIdGroup &grp, RsPgpId &pgpId)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::checkId() Starting Match Check for RsGxsId: ";
@ -2411,11 +2427,11 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
std::map<PGPIdType, PGPFingerprintType>::iterator mit;
std::map<RsPgpId, PGPFingerprintType>::iterator mit;
for(mit = mPgpFingerprintMap.begin(); mit != mPgpFingerprintMap.end(); mit++)
{
GxsIdPgpHash hash;
calcPGPHash(grp.mMeta.mGroupId, mit->second, hash);
calcPGPHash(RsGxsId(grp.mMeta.mGroupId.toStdString()), mit->second, hash);
if (ans == hash)
{
std::cerr << "p3IdService::checkId() HASH MATCH!";
@ -2429,7 +2445,7 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
/* check signature too */
if (AuthGPG::getAuthGPG()->VerifySignBin((void *) hash.toByteArray(), hash.SIZE_IN_BYTES,
(unsigned char *) grp.mPgpIdSign.c_str(), grp.mPgpIdSign.length(),
mit->second.toStdString()))
mit->second))
{
std::cerr << "p3IdService::checkId() Signature Okay too!";
std::cerr << std::endl;
@ -2489,17 +2505,17 @@ void p3IdService::getPgpIdList()
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<std::string> list;
std::list<RsPgpId> list;
AuthGPG::getAuthGPG()->getGPGFilteredList(list);
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mPgpFingerprintMap.clear();
std::list<std::string>::iterator it;
std::list<RsPgpId>::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
PGPIdType pgpId(*it);
RsPgpId pgpId(*it);
PGPFingerprintType fp;
AuthGPG::getAuthGPG()->getKeyFingerprint(pgpId, fp);
@ -2525,7 +2541,7 @@ void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, id.c_str(), id.length()); // TO FIX ONE DAY.
SHA1_Update(sha_ctx, id.toStdString().c_str(), id.toStdString().length()); // TO FIX ONE DAY.
SHA1_Update(sha_ctx, pgp.toByteArray(), pgp.SIZE_IN_BYTES);
SHA1_Final(signature, sha_ctx);
hash = GxsIdPgpHash(signature);
@ -2737,7 +2753,7 @@ bool p3IdService::recogn_process()
for(it = tagItems.begin(); it != tagItems.end(); it++)
{
bool isTagPending = false;
bool isTagOk = recogn_checktag(item->meta.mGroupId, item->meta.mGroupName, *it, true, isPending);
bool isTagOk = recogn_checktag(RsGxsId(item->meta.mGroupId.toStdString()), item->meta.mGroupName, *it, true, isPending);
if (isTagOk)
{
tagValidFlags |= i;
@ -2773,7 +2789,7 @@ bool p3IdService::recogn_process()
std::string serviceString = ssdata.save();
setGroupServiceString(dummyToken, item->meta.mGroupId, serviceString);
cache_update_if_cached(item->meta.mGroupId, serviceString);
cache_update_if_cached(RsGxsId(item->meta.mGroupId.toStdString()), serviceString);
delete item;
@ -2962,10 +2978,10 @@ void p3IdService::generateDummy_OwnIds()
/* grab all the gpg ids... and make some ids */
std::string ownId = rsPeers->getGPGOwnId();
RsPgpId ownId = rsPeers->getGPGOwnId();
// generate some ownIds.
int genCount = 0;
//int genCount = 0;
int i;
int nIds = 2 + (RSRandom::random_u32() % 2);
@ -2976,15 +2992,15 @@ void p3IdService::generateDummy_OwnIds()
id.mMeta.mGroupFlags = RSGXSID_GROUPFLAG_REALID;
// HACK FOR DUMMY GENERATION.
id.mMeta.mAuthorId = ownId;
if (rsPeers->getPeerDetails(ownId, details))
{
std::ostringstream out;
out << details.name << "_" << i + 1;
id.mMeta.mGroupName = out.str();
}
// // HACK FOR DUMMY GENERATION.
// id.mMeta.mAuthorId = ownId.toStdString();
// if (rsPeers->getPeerDetails(ownId, details))
// {
// std::ostringstream out;
// out << details.name << "_" << i + 1;
//
// id.mMeta.mGroupName = out.str();
// }
uint32_t dummyToken = 0;
createGroup(dummyToken, id);
@ -2997,8 +3013,8 @@ void p3IdService::generateDummy_FriendPGP()
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
// Now Generate for friends.
std::list<std::string> gpgids;
std::list<std::string>::iterator it;
std::list<RsPgpId> gpgids;
std::list<RsPgpId>::const_iterator it;
rsPeers->getGPGAllList(gpgids);
RsGxsIdGroup id;
@ -3010,10 +3026,10 @@ void p3IdService::generateDummy_FriendPGP()
for(int j = 0; j < idx; j++, it++) ;
// HACK FOR DUMMY GENERATION.
id.mMeta.mAuthorId = *it;
id.mMeta.mAuthorId = it->toStdString();
RsPeerDetails details;
if (rsPeers->getPeerDetails(*it, details))
if (/*rsPeers->getPeerDetails(*it, details)*/false)
{
std::ostringstream out;
out << details.name << "_" << RSRandom::random_u32() % 1000;
@ -3210,6 +3226,616 @@ Processing Algorithm:
*/
bool p3IdService::reputation_start()
{
if (!CacheArbitration(BG_REPUTATION))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::reputation_start() Other Events running... Rescheduling";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* reschedule in a bit */
RsTickEvent::schedule_in(GXSID_EVENT_REPUTATION, REPUTATION_RETRY_PERIOD);
return false;
}
CacheArbitrationDone(BG_REPUTATION);
// SCHEDULE NEXT ONE.
RsTickEvent::schedule_in(GXSID_EVENT_REPUTATION, REPUTATION_PERIOD);
return true;
}
#define ID_BACKGROUND_PERIOD 60
int p3IdService::background_tick()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_tick()";
std::cerr << std::endl;
#endif // DEBUG_IDS
// Run Background Stuff.
background_checkTokenRequest();
/* every minute - run a background check */
time_t now = time(NULL);
bool doCheck = false;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if (now - mLastBgCheck > ID_BACKGROUND_PERIOD)
{
doCheck = true;
mLastBgCheck = now;
}
}
if (doCheck)
{
//addExtraDummyData();
background_requestGroups();
}
// Add in new votes + comments.
return 0;
}
/***** Background Processing ****
*
* Process Each Message - as it arrives.
*
* Update
*
*/
#define ID_BG_IDLE 0
#define ID_BG_REQUEST_GROUPS 1
#define ID_BG_REQUEST_UNPROCESSED 2
#define ID_BG_REQUEST_FULLCALC 3
bool p3IdService::background_checkTokenRequest()
{
uint32_t token = 0;
uint32_t phase = 0;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if (!mBgProcessing)
{
return false;
}
token = mBgToken;
phase = mBgPhase;
}
uint32_t status;
//uint32_t reqtype;
//uint32_t anstype;
time_t ts;
status = RsGenExchange::getTokenService()->requestStatus(token);
//checkRequestStatus(token, status, reqtype, anstype, ts);
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
switch(phase)
{
case ID_BG_REQUEST_GROUPS:
background_requestNewMessages();
break;
case ID_BG_REQUEST_UNPROCESSED:
background_processNewMessages();
break;
case ID_BG_REQUEST_FULLCALC:
background_processFullCalc();
break;
default:
break;
}
}
return true;
}
bool p3IdService::background_requestGroups()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_requestGroups()";
std::cerr << std::endl;
#endif // DEBUG_IDS
// grab all the subscribed groups.
uint32_t token = 0;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if (mBgProcessing)
{
std::cerr << "p3IdService::background_requestGroups() ERROR Already processing, Skip this cycle";
std::cerr << std::endl;
return false;
}
mBgProcessing = true;
mBgPhase = ID_BG_REQUEST_GROUPS;
mBgToken = 0;
}
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
std::list<RsGxsGroupId> groupIds;
/**
TODO
opts.mStatusFilter = RSGXS_GROUP_STATUS_NEWMSG;
opts.mStatusMask = RSGXS_GROUP_STATUS_NEWMSG;
**/
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts, groupIds);
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgToken = token;
}
return true;
}
bool p3IdService::background_requestNewMessages()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_requestNewMessages()";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<RsGroupMetaData> modGroupList;
std::list<RsGroupMetaData>::iterator it;
std::list<RsGxsGroupId> groupIds;
uint32_t token = 0;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
token = mBgToken;
}
if (!getGroupSummary(token, modGroupList))
{
std::cerr << "p3IdService::background_requestNewMessages() ERROR No Group List";
std::cerr << std::endl;
background_cleanup();
return false;
}
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgPhase = ID_BG_REQUEST_UNPROCESSED;
mBgToken = 0;
/* now we process the modGroupList -> a map so we can use it easily later, and create id list too */
for(it = modGroupList.begin(); it != modGroupList.end(); it++)
{
/*** TODO
uint32_t dummyToken = 0;
setGroupStatusFlags(dummyToken, it->mGroupId, 0, RSGXS_GROUP_STATUS_NEWMSG);
***/
mBgGroupMap[it->mGroupId] = *it;
groupIds.push_back(it->mGroupId);
}
}
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
token = 0;
/* TODO
opts.mStatusFilter = RSGXS_MSG_STATUS_UNPROCESSED;
opts.mStatusMask = RSGXS_MSG_STATUS_UNPROCESSED;
*/
RsGenExchange::getTokenService()->requestMsgInfo(token, ansType, opts, groupIds);
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgToken = token;
}
return true;
}
bool p3IdService::background_processNewMessages()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages()";
std::cerr << std::endl;
#endif // DEBUG_IDS
GxsMsgMetaMap newMsgMap;
GxsMsgMetaMap::iterator it;
uint32_t token = 0;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
token = mBgToken;
}
if (!getMsgSummary(token, newMsgMap))
{
std::cerr << "p3IdService::background_processNewMessages() ERROR No New Msgs";
std::cerr << std::endl;
background_cleanup();
return false;
}
/* iterate through the msgs.. update the mBgGroupMap with new data,
* and flag these items as modified - so we rewrite them to the db later.
*
* If a message is not an original -> store groupId for requiring full analysis later.
*/
std::map<RsGxsGroupId, RsGroupMetaData>::iterator mit;
for (it = newMsgMap.begin(); it != newMsgMap.end(); it++)
{
std::vector<RsMsgMetaData>::iterator vit;
for(vit = it->second.begin(); vit != it->second.end(); vit++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() new MsgId: " << vit->mMsgId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* flag each new vote as processed */
/**
TODO
uint32_t dummyToken = 0;
setMsgStatusFlags(dummyToken, it->mMsgId, 0, RSGXS_MSG_STATUS_UNPROCESSED);
**/
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mit = mBgGroupMap.find(it->first);
if (mit == mBgGroupMap.end())
{
std::cerr << "p3IdService::background_processNewMessages() ERROR missing GroupId: ";
std::cerr << vit->mGroupId;
std::cerr << std::endl;
/* error */
continue;
}
if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Group Already marked FULL_CALC";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* already marked */
continue;
}
if (vit->mMsgId != vit->mOrigMsgId)
{
/*
* not original -> hard, redo calc (alt: could substract previous score)
*/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Update, mark for FULL_CALC";
std::cerr << std::endl;
#endif // DEBUG_IDS
mit->second.mGroupStatus |= ID_LOCAL_STATUS_FULL_CALC_FLAG;
}
else
{
/*
* Try incremental calculation.
* - extract parameters from group.
* - increment, & save back.
* - flag group as modified.
*/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() NewOpt, Try Inc Calc";
std::cerr << std::endl;
#endif // DEBUG_IDS
mit->second.mGroupStatus |= ID_LOCAL_STATUS_INC_CALC_FLAG;
SSGxsIdGroup ssdata;
if (!ssdata.load(mit->second.mServiceString))
{
/* error */
std::cerr << "p3IdService::background_processNewMessages() ERROR Extracting";
std::cerr << std::endl;
}
#ifdef DEBUG_IDS
/* do calcs */
std::cerr << "p3IdService::background_processNewMessages() Extracted: ";
std::cerr << std::endl;
/* store it back in */
std::cerr << "p3IdService::background_processNewMessages() Stored: ";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::string serviceString = ssdata.save();
if (0)
{
/* error */
std::cerr << "p3IdService::background_processNewMessages() ERROR Storing";
std::cerr << std::endl;
}
}
}
}
/* now iterate through groups again
* -> update status as we go
* -> record one requiring a full analyssis
*/
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Checking Groups for Calc Type";
std::cerr << std::endl;
#endif // DEBUG_IDS
for(mit = mBgGroupMap.begin(); mit != mBgGroupMap.end(); mit++)
{
if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() FullCalc for: ";
std::cerr << mit->second.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
mBgFullCalcGroups.push_back(mit->second.mGroupId);
}
else if (mit->second.mGroupStatus & ID_LOCAL_STATUS_INC_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() IncCalc done for: ";
std::cerr << mit->second.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* set Cache */
uint32_t dummyToken = 0;
setGroupServiceString(dummyToken, mit->second.mGroupId, mit->second.mServiceString);
}
else
{
/* why is it here? error. */
std::cerr << "p3IdService::background_processNewMessages() ERROR for: ";
std::cerr << mit->second.mGroupId;
std::cerr << std::endl;
}
}
}
return background_FullCalcRequest();
}
bool p3IdService::background_FullCalcRequest()
{
/*
* grab an GroupId from List.
* - If empty, we are finished.
* - request all latest mesgs
*/
std::list<RsGxsGroupId> groupIds;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgPhase = ID_BG_REQUEST_FULLCALC;
mBgToken = 0;
mBgGroupMap.clear();
if (mBgFullCalcGroups.empty())
{
/* finished! */
background_cleanup();
return true;
}
groupIds.push_back(mBgFullCalcGroups.front());
mBgFullCalcGroups.pop_front();
}
/* request the summary info from the parents */
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
uint32_t token = 0;
RsTokReqOptions opts;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
RsGenExchange::getTokenService()->requestMsgInfo(token, ansType, opts, groupIds);
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgToken = token;
}
return true;
}
bool p3IdService::background_processFullCalc()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processFullCalc()";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<RsMsgMetaData> msgList;
std::list<RsMsgMetaData>::iterator it;
bool validmsgs = false;
/* calc variables */
uint32_t opinion_count = 0;
uint32_t opinion_nullcount = 0;
double opinion_sum = 0;
double opinion_sumsq = 0;
uint32_t rep_count = 0;
uint32_t rep_nullcount = 0;
double rep_sum = 0;
double rep_sumsq = 0;
std::vector<RsGxsIdOpinion> opinions;
std::vector<RsGxsIdOpinion>::iterator vit;
if (!getMsgData(mBgToken, opinions))
{
std::cerr << "p3IdService::background_processFullCalc() ERROR Failed to get Opinions";
std::cerr << std::endl;
return false;
}
RsGxsGroupId groupId;
for(vit = opinions.begin(); vit != opinions.end(); vit++)
{
RsGxsIdOpinion &opinion = *vit;
/* These should all be same group - should check for sanity! */
if (groupId.isNull())
{
groupId = opinion.mMeta.mGroupId;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processFullCalc() Msg:";
std::cerr << opinion;
std::cerr << std::endl;
#endif // DEBUG_IDS
validmsgs = true;
/* for each opinion.... extract score, and reputation */
if (opinion.mOpinion != 0)
{
opinion_count++;
opinion_sum += opinion.mOpinion;
opinion_sum += (opinion.mOpinion * opinion.mOpinion);
}
else
{
opinion_nullcount++;
}
/* for each opinion.... extract score, and reputation */
if (opinion.mReputation != 0)
{
rep_nullcount++;
rep_sum += opinion.mReputation;
rep_sum += (opinion.mReputation * opinion.mReputation);
}
else
{
rep_nullcount++;
}
}
double opinion_avg = 0;
double opinion_var = 0;
double opinion_frac = 0;
double rep_avg = 0;
double rep_var = 0;
double rep_frac = 0;
if (opinion_count)
{
opinion_avg = opinion_sum / opinion_count;
opinion_var = (opinion_sumsq - opinion_count * opinion_avg * opinion_avg) / opinion_count;
opinion_frac = opinion_count / ((float) (opinion_count + opinion_nullcount));
}
if (rep_count)
{
rep_avg = rep_sum / rep_count;
rep_var = (rep_sumsq - rep_count * rep_avg * rep_avg) / rep_count;
rep_frac = rep_count / ((float) (rep_count + rep_nullcount));
}
if (validmsgs)
{
SSGxsIdGroup ssdata;
std::string serviceString = ssdata.save();
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_updateVoteCounts() Encoded String: " << serviceString;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* store new result */
uint32_t dummyToken = 0;
setGroupServiceString(dummyToken, groupId, serviceString);
}
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mBgPhase = ID_BG_IDLE;
mBgToken = 0;
}
return background_FullCalcRequest();
}
bool p3IdService::background_cleanup()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_cleanup()";
std::cerr << std::endl;
#endif // DEBUG_IDS
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
// Cleanup.
mBgProcessing = false;
mBgPhase = ID_BG_IDLE;
mBgToken = 0;
mBgGroupMap.clear();
mBgFullCalcGroups.clear();
return true;
}
std::ostream &operator<<(std::ostream &out, const RsGxsIdGroup &grp)
{
out << "RsGxsIdGroup: Meta: " << grp.mMeta;

View file

@ -106,7 +106,7 @@ virtual std::string save() const;
bool idKnown;
time_t lastCheckTs;
uint32_t checkAttempts;
std::string pgpId;
RsPgpId pgpId;
};
class SSGxsIdRecognTags: public SSBit
@ -290,7 +290,7 @@ virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
// get Reputation.
virtual bool haveReputation(const RsGxsId &id);
virtual bool loadReputation(const RsGxsId &id, const std::list<std::string>& peers);
virtual bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
virtual bool getReputation(const RsGxsId &id, GixsReputation &rep);
@ -316,7 +316,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
*/
int cache_tick();
bool cache_request_load(const RsGxsId &id, const std::list<std::string>& peers = std::list<std::string>());
bool cache_request_load(const RsGxsId &id, const std::list<PeerId>& peers = std::list<PeerId>());
bool cache_start_load();
bool cache_load_for_token(uint32_t token);
@ -329,7 +329,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
// Mutex protected.
//std::list<RsGxsId> mCacheLoad_ToCache;
std::map<RsGxsId, std::list<std::string> > mCacheLoad_ToCache, mPendingCache;
std::map<RsGxsId, std::list<RsPeerId> > mCacheLoad_ToCache, mPendingCache;
// Switching to RsMemCache for Key Caching.
RsMemCache<RsGxsId, RsGxsIdCache> mPublicKeyCache;
@ -370,12 +370,12 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
bool pgphash_handlerequest(uint32_t token);
bool pgphash_process();
bool checkId(const RsGxsIdGroup &grp, PGPIdType &pgp_id);
bool checkId(const RsGxsIdGroup &grp, RsPgpId &pgp_id);
void getPgpIdList();
/* MUTEX PROTECTED DATA (mIdMtx - maybe should use a 2nd?) */
std::map<PGPIdType, PGPFingerprintType> mPgpFingerprintMap;
std::map<RsPgpId, PGPFingerprintType> mPgpFingerprintMap;
std::list<RsGxsIdGroup> mGroupsToProcess;
/************************************************************************
@ -461,8 +461,8 @@ std::string genRandomId(int len = 20);
uint32_t mBgToken;
uint32_t mBgPhase;
std::map<std::string, RsGroupMetaData> mBgGroupMap;
std::list<std::string> mBgFullCalcGroups;
std::map<RsGxsGroupId, RsGroupMetaData> mBgGroupMap;
std::list<RsGxsGroupId> mBgFullCalcGroups;
#endif
/************************************************************************
@ -476,7 +476,7 @@ std::string genRandomId(int len = 20);
std::map<uint32_t, std::set<RsGxsGroupId> > mIdsPendingCache;
std::map<uint32_t, std::list<RsGxsGroupId> > mGroupNotPresent;
std::map<RsGxsId, std::list<std::string> > mIdsNotPresent;
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
RsNetworkExchangeService* mNes;
};

View file

@ -90,16 +90,16 @@ 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 RsPgpId& gpg_id = rsPeers->getGPGOwnId() ;
RsPeerDetails d;
rsPeers->getPeerDetails(gpg_id,d) ;
rsPeers->getGPGDetails(gpg_id,d) ;
PGPFingerprintType fingerp( d.fpr ) ;
// Re-hash the SSL id, to make it one way. Will be replaced by proper invitations in the future.
//
GRouterKeyId key ( RsDirUtil::sha1sum( (uint8_t*)own_ssl_id.c_str(),own_ssl_id.length() ).toStdString() ) ;
GRouterKeyId key ( RsDirUtil::sha1sum( own_ssl_id.toByteArray(),own_ssl_id.SIZE_IN_BYTES )) ;
static GRouterServiceId client_id = GROUTER_CLIENT_ID_MESSAGES;
static std::string description = "Test string for debug purpose" ;
@ -167,9 +167,9 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming)
if (notify)
{
if(mi->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId(), mi->subject, mi->message);
notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId().toStdString(), mi->subject, mi->message);
else
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(), mi->subject, mi->message);
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId().toStdString(), mi->subject, mi->message);
std::string out;
rs_sprintf(out, "%lu", mi->msgId);
@ -197,7 +197,7 @@ bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci)
{
// Check is the item is ending an incomplete item.
//
std::map<std::string,RsMsgItem*>::iterator it = _pendingPartialMessages.find(ci->PeerId()) ;
std::map<RsPeerId,RsMsgItem*>::iterator it = _pendingPartialMessages.find(ci->PeerId()) ;
bool ci_is_partial = ci->msgFlags & RS_MSG_FLAGS_PARTIAL ;
@ -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) ;
}
@ -320,7 +340,7 @@ int p3MsgService::checkOutgoingMessages()
std::list<RsMsgItem*> output_queue ;
{
const std::string ownId = mLinkMgr->getOwnId();
const RsPeerId& ownId = mLinkMgr->getOwnId();
std::list<uint32_t>::iterator it;
std::list<uint32_t> toErase;
@ -334,7 +354,7 @@ int p3MsgService::checkOutgoingMessages()
}
/* find the certificate */
std::string pid = mit->second->PeerId();
RsPeerId pid = mit->second->PeerId();
bool tunnel_is_ok = false ;
if(mit->second->msgFlags & RS_MSG_FLAGS_DISTANT)
@ -344,29 +364,29 @@ int p3MsgService::checkOutgoingMessages()
#ifdef GROUTER
tunnel_is_ok = true ;
#else
const std::string& 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" ;
@ -517,7 +525,7 @@ static void getStandardTagTypes(MsgTagType &tags)
void p3MsgService::initStandardTagTypes()
{
bool bChanged = false;
std::string ownId = mLinkMgr->getOwnId();
const RsPeerId& ownId = mLinkMgr->getOwnId();
MsgTagType tags;
getStandardTagTypes(tags);
@ -527,7 +535,7 @@ void p3MsgService::initStandardTagTypes()
std::map<uint32_t, RsMsgTagType*>::iterator mit = mTags.find(tit->first);
if (mit == mTags.end()) {
RsMsgTagType* tagType = new RsMsgTagType();
tagType->PeerId (ownId);
tagType->PeerId (ownId);
tagType->tagId = tit->first;
tagType->text = tit->second.first;
tagType->rgb_color = tit->second.second;
@ -550,13 +558,13 @@ 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;
std::map<uint32_t, RsMsgTagType*>::iterator tagIt;
std::map<uint32_t, std::string> srcIdMsgMap;
std::map<uint32_t, std::string>::iterator srcIt;
std::map<uint32_t, RsPeerId> srcIdMsgMap;
std::map<uint32_t, RsPeerId>::iterator srcIt;
bool distant_messaging_set = false ;
@ -593,17 +601,17 @@ bool p3MsgService::loadList(std::list<RsItem*>& load)
}
else if(NULL != (msi = dynamic_cast<RsMsgSrcId *>(*it)))
{
srcIdMsgMap.insert(std::pair<uint32_t, std::string>(msi->msgId, msi->srcId));
srcIdMsgMap.insert(std::pair<uint32_t, RsPeerId>(msi->msgId, msi->srcId));
mSrcIds.insert(std::pair<uint32_t, RsMsgSrcId*>(msi->msgId, msi)); // does not need to be kept
}
else if(NULL != (msp = dynamic_cast<RsMsgParentId *>(*it)))
{
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 ;
@ -1049,7 +1057,7 @@ int p3MsgService::sendMessage(RsMsgItem *item)
bool p3MsgService::MessageSend(MessageInfo &info)
{
std::list<std::string>::const_iterator pit;
std::list<RsPeerId>::const_iterator pit;
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
{
@ -1082,16 +1090,16 @@ bool p3MsgService::MessageSend(MessageInfo &info)
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
if (msg)
{
std::list<std::string>::iterator it ;
std::list<RsPgpId>::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
@ -1113,7 +1121,7 @@ bool p3MsgService::SystemMessage(const std::string &title, const std::string &me
return false;
}
std::string ownId = mLinkMgr->getOwnId();
const RsPeerId& ownId = mLinkMgr->getOwnId();
RsMsgItem *msg = new RsMsgItem();
@ -1580,10 +1588,10 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
rs_sprintf(mi.msgId, "%lu", msg->msgId);
}
std::list<std::string>::iterator pit;
std::list<RsPeerId>::iterator pit;
for(pit = msg->msgto.ids.begin();
pit != msg->msgto.ids.end(); pit++)
pit != msg->msgto.ids.end(); pit++)
{
mi.msgto.push_back(*pit);
}
@ -1704,7 +1712,7 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
mis.ts = msg->sendTime;
}
RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const std::string &to)
RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const RsPeerId &to)
{
RsMsgItem *msg = new RsMsgItem();
@ -1719,7 +1727,7 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const std::string &to)
msg -> message = info.msg;
std::list<std::string>::iterator pit;
std::list<RsPeerId>::iterator pit;
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
{
msg -> msgto.ids.push_back(*pit);
@ -1774,15 +1782,17 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const std::string &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 RsPgpId& pgp_id,RsMsgItem *item)
{
#ifdef DEBUG_DISTANT_MSG
std::cerr << "Encrypting message with public key " << pgp_id << " in place." << std::endl;
@ -1803,7 +1813,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
#ifdef DEBUG_DISTANT_MSG
std::cerr << " adding own key ID " << AuthGPG::getAuthGPG()->getGPGOwnId() << std::endl;
#endif
memcpy(&data[1], PGPIdType(AuthGPG::getAuthGPG()->getGPGOwnId()).toByteArray(), PGP_KEY_ID_SIZE) ;
memcpy(&data[1], RsPgpId(AuthGPG::getAuthGPG()->getGPGOwnId()).toByteArray(), PGP_KEY_ID_SIZE) ;
// 1 - serialise the whole message item into a binary chunk.
//
@ -1972,7 +1982,7 @@ bool p3MsgService::decryptMessage(const std::string& mId)
return false;
}
PGPIdType senders_id(&decrypted_data[1]) ;
RsPgpId senders_id(&decrypted_data[1]) ;
#ifdef DEBUG_DISTANT_MSG
std::cerr << " Sender's ID: " << senders_id.toStdString() << 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,9 +2037,9 @@ 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 ;
std::string own_pgp_id = AuthGPG::getAuthGPG()->getGPGOwnId();
getDistantMessageHash(own_pgp_id,own_hash) ;
RsPeerId own_id ;
const RsPgpId& own_pgp_id = AuthGPG::getAuthGPG()->getGPGOwnId();
getDistantMessagePeerId(own_pgp_id,own_id) ;
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -2041,11 +2051,14 @@ 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()) ;
DistantMsgPeerId senders_vpid ;
getDistantMessagePeerId(senders_id,senders_vpid) ;
msgi.PeerId(senders_vpid) ;
for(std::list<std::string>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
for(std::list<std::string>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
for(std::list<std::string>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_hash) *it = own_pgp_id ;
//for(std::list<RsPeerId>::iterator it(msgi.msgto.ids.begin());it!=msgi.msgto.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
//for(std::list<RsPeerId>::iterator it(msgi.msgcc.ids.begin());it!=msgi.msgcc.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
//for(std::list<RsPeerId>::iterator it(msgi.msgbcc.ids.begin());it!=msgi.msgbcc.ids.end();++it) if(*it == own_id) *it = own_pgp_id ;
if(signature_present)
{
@ -2065,14 +2078,14 @@ bool p3MsgService::decryptMessage(const std::string& mId)
RsMsgSrcId* msi = new RsMsgSrcId();
msi->msgId = msgi.msgId;
msi->srcId = senders_id.toStdString() ;
msi->srcId = senders_vpid ;
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.toStdString() << std::endl;
it->second->srcId = senders_id.toStdString() ;
std::cerr << "Substituting source name for message id " << msgi.msgId << ": " << it->second->srcId << " -> " << senders_id << std::endl;
it->second->srcId = senders_vpid ;
}
}
delete item ;
@ -2096,21 +2109,22 @@ void p3MsgService::connectToTurtleRouter(p3turtle *pt)
pt->registerTunnelService(this) ;
}
bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,TurtleFileHash& hash)
bool p3MsgService::createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId& peer_id)
{
unsigned char hash_bytes[DISTANT_MSG_HASH_SIZE] ;
RSRandom::random_bytes( hash_bytes, DISTANT_MSG_HASH_SIZE) ;
std::cerr << __PRETTY_FUNCTION__ << ": disabled for now" << std::endl;
hash = Sha1CheckSum(hash_bytes).toStdString(false) ;
DistantMessengingInvite invite ;
invite.time_of_validity = time_of_validity + time(NULL);
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
_messenging_invites[hash] = invite ;
}
IndicateConfigChanged() ;
// peer_id = DistantMsgPeerId::random();
// TurtleFileHash hash = rsdir::sha1sum(peer_id.toByteArray(),DistantMsgPeerId::SIZE_IN_BYTES) ;
//
// DistantMessengingInvite invite ;
// invite.time_of_validity = time_of_validity + time(NULL);
//
//
// {
// RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
// _messenging_invites[hash] = invite ;
// }
// IndicateConfigChanged() ;
return true ;
}
@ -2119,9 +2133,9 @@ void p3MsgService::enableDistantMessaging(bool b)
{
// compute the hash
std::string hash ;
Sha1CheckSum hash ;
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
return ;
bool cchanged = false ;
@ -2132,7 +2146,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,16 +2158,16 @@ 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 RsPgpId& gpg_id = rsPeers->getGPGOwnId() ;
RsPeerDetails d;
rsPeers->getPeerDetails(gpg_id,d) ;
rsPeers->getGPGDetails(gpg_id,d) ;
PGPFingerprintType fingerp( d.fpr ) ;
// Re-hash the SSL id, to make it one way. Will be replaced by proper invitations in the future.
//
GRouterKeyId key ( RsDirUtil::sha1sum( (uint8_t*)own_ssl_id.c_str(),own_ssl_id.length() ).toStdString() ) ;
GRouterKeyId key ( RsDirUtil::sha1sum( own_ssl_id.toByteArray(),own_ssl_id.SIZE_IN_BYTES ) ) ;
static GRouterServiceId client_id = GROUTER_CLIENT_ID_MESSAGES;
static std::string description = "Test string for debug purpose" ;
@ -2178,7 +2192,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 +2200,7 @@ bool p3MsgService::distantMessagingEnabled()
{
// compute the hash
std::string hash ;
Sha1CheckSum hash ;
if(!getDistantMessageHash(AuthGPG::getAuthGPG()->getGPGOwnId(),hash))
return false;
@ -2198,26 +2212,37 @@ bool p3MsgService::distantMessagingEnabled()
}
return res ;
}
bool p3MsgService::getDistantMessageHash(const std::string& pgp_id,std::string& hash)
bool p3MsgService::getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId& peer_id)
{
if(pgp_id.length() != 16)
{
std::cerr << "pgp id \"" << pgp_id << "\" is not valid! Something definitly wrong." << std::endl;
return false;
}
if(!AuthGPG::getAuthGPG()->isKeySupported(pgp_id))
return false ;
hash = RsDirUtil::sha1sum((uint8_t*)pgp_id.c_str(),16).toStdString() ;
unsigned char tmp[RsPeerId::SIZE_IN_BYTES] ;
memset(tmp,0,RsPeerId::SIZE_IN_BYTES) ;
memcpy(tmp,pgp_id.toByteArray(),RsPgpId::SIZE_IN_BYTES) ;
peer_id = RsPeerId(tmp) ;
// Also check that we have the public key.
return AuthGPG::getAuthGPG()->isKeySupported(pgp_id) ;
return true ;
}
bool p3MsgService::getDistantMessageHash(const RsPgpId& pgp_id,Sha1CheckSum& hash)
{
if(!AuthGPG::getAuthGPG()->isKeySupported(pgp_id))
return false ;
hash = RsDirUtil::sha1sum(pgp_id.toByteArray(),RsPgpId::SIZE_IN_BYTES) ;
// Also check that we have the public key.
return true ;
}
bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites)
{
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 ;
@ -2233,11 +2258,11 @@ bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOffline
return true ;
}
bool p3MsgService::handleTunnelRequest(const std::string& hash,const std::string& /*peer_id*/)
bool p3MsgService::handleTunnelRequest(const Sha1CheckSum &hash,const RsPeerId& /*peer_id*/)
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantMessengingInvite>::const_iterator it = _messenging_invites.find(hash) ;
std::map<Sha1CheckSum,DistantMessengingInvite>::const_iterator it = _messenging_invites.find(hash) ;
#ifdef DEBUG_DISTANT_MSG
if(it != _messenging_invites.end())
@ -2263,13 +2288,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 +2302,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 +2378,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.
@ -2383,10 +2408,10 @@ void p3MsgService::sendTurtleData(const std::string& hash,RsMsgItem *msgitem)
// do we have a working tunnel for that hash ?
// If not, put on the contact's waiting list.
std::string virtual_peer_id ;
{
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 +2435,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 +2521,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 +2542,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 +2564,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
}

View file

@ -123,46 +123,48 @@ int checkOutgoingMessages();
struct DistantMessengingContact
{
time_t last_hit_time ;
std::string virtual_peer_id ;
RsPeerId virtual_peer_id ;
uint32_t status ;
bool pending_messages ;
};
bool createDistantOfflineMessengingInvite(time_t time_of_validity,TurtleFileHash& hash) ;
bool createDistantOfflineMessengingInvite(time_t time_of_validity,DistantMsgPeerId &peer_id) ;
bool getDistantOfflineMessengingInvites(std::vector<DistantOfflineMessengingInvite>& invites) ;
void enableDistantMessaging(bool b) ;
bool distantMessagingEnabled() ;
bool getDistantMessageHash(const std::string& pgp_id,std::string& hash) ;
void sendPrivateMsgItem(RsMsgItem *) ;
bool getDistantMessagePeerId(const RsPgpId& pgp_id,DistantMsgPeerId &peer_id) ;
private:
bool getDistantMessageHash(const RsPgpId& pgp_id,Sha1CheckSum &hash) ;
void sendPrivateMsgItem(const Sha1CheckSum& hash,RsMsgItem *) ;
// This maps contains the current invitations to respond to.
//
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.
//
std::map<std::string,DistantMessengingContact> _messenging_contacts ;
// The map is indexed by the hash
std::map<Sha1CheckSum,DistantMessengingContact> _messenging_contacts ;
// Overloaded from RsTurtleClientService
#ifdef GROUTER
virtual void receiveGRouterData(RsGRouterGenericDataItem *item, const GRouterKeyId& key) ;
#endif
virtual bool handleTunnelRequest(const std::string& hash,const std::string& peer_id) ;
virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const std::string& hash,const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ;
void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ;
void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ;
virtual bool handleTunnelRequest(const Sha1CheckSum& hash,const RsPeerId& peer_id) ;
// 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 std::string& pgp_id,RsMsgItem *msg) ;
bool encryptMessage(const RsPgpId& 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 *) ;
@ -181,7 +183,7 @@ bool checkAndRebuildPartialMessage(RsMsgItem*) ;
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
RsMsgItem *initMIRsMsg(MessageInfo &info, const std::string &to);
RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId &to);
void initStandardTagTypes();
@ -197,7 +199,7 @@ void initStandardTagTypes();
/* ones that haven't made it out yet! */
std::map<uint32_t, RsMsgItem *> msgOutgoing;
std::map<std::string, RsMsgItem *> _pendingPartialMessages ;
std::map<RsPeerId, RsMsgItem *> _pendingPartialMessages ;
/* maps for tags types and msg tags */

View file

@ -429,7 +429,7 @@ void p3PostBase::background_loadMsgs(const uint32_t &token, bool unprocessed)
}
/* 3 types expected: PostedPost, Comment and Vote */
if (parentId.empty())
if (parentId.isNull())
{
/* we don't care about top-level (Posts) */
std::cerr << "\tIgnoring TopLevel Item";

View file

@ -168,7 +168,7 @@ void p3rtt::sendPingMeasurements()
/* we ping our peers */
/* who is online? */
std::list<std::string> idList;
std::list<RsPeerId> idList;
mLinkMgr->getOnlineList(idList);
@ -180,7 +180,7 @@ void p3rtt::sendPingMeasurements()
#endif
/* prepare packets */
std::list<std::string>::iterator it;
std::list<RsPeerId>::iterator it;
for(it = idList.begin(); it != idList.end(); it++)
{
#ifdef DEBUG_RTT
@ -309,7 +309,7 @@ int p3rtt::handlePong(RsItem *item)
int p3rtt::storePingAttempt(std::string id, double ts, uint32_t seqno)
int p3rtt::storePingAttempt(const RsPeerId& id, double ts, uint32_t seqno)
{
RsStackMutex stack(mRttMtx); /****** LOCKED MUTEX *******/
@ -332,7 +332,7 @@ int p3rtt::storePingAttempt(std::string id, double ts, uint32_t seqno)
int p3rtt::storePongResult(std::string id, uint32_t counter, double ts, double rtt, double offset)
int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double ts, double rtt, double offset)
{
RsStackMutex stack(mRttMtx); /****** LOCKED MUTEX *******/
@ -363,7 +363,7 @@ int p3rtt::storePongResult(std::string id, uint32_t counter, double ts, double r
}
uint32_t p3rtt::getPongResults(std::string id, int n, std::list<RsRttPongResult> &results)
uint32_t p3rtt::getPongResults(const RsPeerId& id, int n, std::list<RsRttPongResult> &results)
{
RsStackMutex stack(mRttMtx); /****** LOCKED MUTEX *******/
@ -381,9 +381,9 @@ uint32_t p3rtt::getPongResults(std::string id, int n, std::list<RsRttPongResult>
RttPeerInfo *p3rtt::locked_GetPeerInfo(std::string id)
RttPeerInfo *p3rtt::locked_GetPeerInfo(const RsPeerId& id)
{
std::map<std::string, RttPeerInfo>::iterator it;
std::map<RsPeerId, RttPeerInfo>::iterator it;
it = mPeerInfo.find(id);
if (it == mPeerInfo.end())
{
@ -404,7 +404,7 @@ RttPeerInfo *p3rtt::locked_GetPeerInfo(std::string id)
bool RttPeerInfo::initialisePeerInfo(std::string id)
bool RttPeerInfo::initialisePeerInfo(const RsPeerId& id)
{
mId = id;

View file

@ -40,9 +40,9 @@ class RttPeerInfo
{
public:
bool initialisePeerInfo(std::string id);
bool initialisePeerInfo(const RsPeerId& id);
std::string mId;
RsPeerId mId;
double mCurrentPingTS;
double mCurrentPingCounter;
bool mCurrentPongRecvd;
@ -67,7 +67,7 @@ class p3rtt: public RsRtt, public p3FastService
/***** overloaded from rsRtt *****/
virtual uint32_t getPongResults(std::string id, int n, std::list<RsRttPongResult> &results);
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsRttPongResult> &results);
/***** overloaded from p3Service *****/
@ -82,8 +82,8 @@ virtual bool recvItem(RsItem *item); // Overloaded from p3FastService.
int handlePing(RsItem *item);
int handlePong(RsItem *item);
int storePingAttempt(std::string id, double ts, uint32_t mCounter);
int storePongResult(std::string id, uint32_t counter, double ts, double rtt, double offset);
int storePingAttempt(const RsPeerId& id, double ts, uint32_t mCounter);
int storePongResult(const RsPeerId& id, uint32_t counter, double ts, double rtt, double offset);
/*!
@ -104,9 +104,9 @@ virtual bool recvItem(RsItem *item); // Overloaded from p3FastService.
private:
RsMutex mRttMtx;
RttPeerInfo *locked_GetPeerInfo(std::string id);
RttPeerInfo *locked_GetPeerInfo(const RsPeerId& id);
std::map<std::string, RttPeerInfo> mPeerInfo;
std::map<RsPeerId, RttPeerInfo> mPeerInfo;
time_t mSentPingTime;
uint32_t mCounter;

View file

@ -201,16 +201,25 @@ int p3FastService::sendItem(RsItem *si)
std::cerr << "************************************************************" << std::endl;
}
raw->setPriorityLevel(si->priority_level()) ;
}
/* cleanup */
delete si;
#ifdef SERV_DEBUG
std::cerr << "p3Service::send() returning RawItem.";
std::cerr << std::endl;
std::cerr << "p3Service::send() returning RawItem.";
std::cerr << std::endl;
#endif
return pqiService::send(raw);
delete si;
return pqiService::send(raw);
}
else
{
std::cerr << "p3service: item could not be properly serialised. Will be wasted. Item is: "<< std::endl;
si->print(std::cerr,0) ;
/* cleanup */
delete si;
return 0 ;
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -517,12 +517,12 @@ std::string chooseRandomAuthorId()
int i = 0;
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
std::string answer;
RsGxsId answer;
if (it != ownIds.end())
{
answer = *it;
}
return answer;
return answer.toStdString();
}