mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added response system from friend server
This commit is contained in:
parent
6b6d556e98
commit
0191072326
@ -123,15 +123,18 @@ public:
|
||||
|
||||
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(nonce);
|
||||
RS_SERIAL_PROCESS(friend_invites);
|
||||
}
|
||||
|
||||
virtual void clear() override
|
||||
{
|
||||
friend_invites.clear();
|
||||
nonce = 0;
|
||||
}
|
||||
// specific members for that item
|
||||
|
||||
uint64_t nonce;
|
||||
std::map<std::string,bool> friend_invites;
|
||||
};
|
||||
|
||||
|
@ -1926,7 +1926,10 @@ bool PGPHandler::locked_syncPublicKeyring()
|
||||
#else
|
||||
if(-1 == stat64(_pubring_path.c_str(), &buf))
|
||||
#endif
|
||||
{
|
||||
std::cerr << "PGPHandler::syncDatabase(): can't stat file " << _pubring_path << ". Can't sync public keyring." << std::endl;
|
||||
buf.st_mtime = 0;
|
||||
}
|
||||
|
||||
if(_pubring_last_update_time < buf.st_mtime)
|
||||
{
|
||||
@ -1968,12 +1971,13 @@ bool PGPHandler::locked_syncTrustDatabase()
|
||||
librs::util::ConvertUtf8ToUtf16(_trustdb_path, wfullname);
|
||||
if(-1 == _wstati64(wfullname.c_str(), &buf))
|
||||
#else
|
||||
if(-1 == stat64(_trustdb_path.c_str(), &buf))
|
||||
if(-1 == stat64(_trustdb_path.c_str(), &buf))
|
||||
#endif
|
||||
{
|
||||
std::cerr << "PGPHandler::syncDatabase(): can't stat file " << _trustdb_path << ". Will force write it." << std::endl;
|
||||
_trustdb_changed = true ; // we force write of trust database if it does not exist.
|
||||
}
|
||||
{
|
||||
std::cerr << "PGPHandler::syncDatabase(): can't stat file " << _trustdb_path << ". Will force write it." << std::endl;
|
||||
_trustdb_changed = true ; // we force write of trust database if it does not exist.
|
||||
buf.st_mtime = 0;
|
||||
}
|
||||
|
||||
if(_trustdb_last_update_time < buf.st_mtime)
|
||||
{
|
||||
|
@ -70,12 +70,21 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
|
||||
RsDbg() << *item ;
|
||||
|
||||
// First of all, read PGP key and short invites, parse them, and check that they contain the same information
|
||||
RsPeerId pid;
|
||||
RsPgpFingerprint fpr;
|
||||
|
||||
FriendServer::handleIncomingClientData(item->pgp_public_key_b64,item->short_invite);
|
||||
std::map<RsPeerId,PeerInfo>::iterator pi = handleIncomingClientData(item->pgp_public_key_b64,item->short_invite);
|
||||
|
||||
// No need to test for it==mCurrentClients.end() because it will be directly caught by the exception handling below even before.
|
||||
// Respond with a list of potential friends
|
||||
|
||||
RsFriendServerServerResponseItem *sr_item = new RsFriendServerServerResponseItem;
|
||||
|
||||
sr_item->nonce = pi->second.last_nonce;
|
||||
sr_item->friend_invites = computeListOfFriendInvites(item->n_requested_friends,pi->first,pi->second.pgp_fingerprint);
|
||||
sr_item->PeerId(item->PeerId());
|
||||
|
||||
mni->SendItem(sr_item);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@ -89,7 +98,27 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it
|
||||
mni->closeConnection(item->PeerId());
|
||||
}
|
||||
|
||||
bool FriendServer::handleIncomingClientData(const std::string& pgp_public_key_b64,const std::string& short_invite_b64)
|
||||
std::map<std::string, bool> FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, const RsPgpFingerprint &fpr)
|
||||
{
|
||||
// For now, returns the first nb_reqs_invites from the currently known peer, that would not be the peer who's asking
|
||||
|
||||
std::map<std::string,bool> res;
|
||||
|
||||
for(auto it:mCurrentClientPeers)
|
||||
{
|
||||
if(it.first == pid)
|
||||
continue;
|
||||
|
||||
res.insert(std::make_pair(it.second.short_certificate,false)); // for now we say that peers havn't been warned already
|
||||
|
||||
if(res.size() >= nb_reqs_invites)
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::map<RsPeerId,PeerInfo>::iterator FriendServer::handleIncomingClientData(const std::string& pgp_public_key_b64,const std::string& short_invite_b64)
|
||||
{
|
||||
RsDbg() << " Checking item data...";
|
||||
|
||||
@ -146,9 +175,11 @@ bool FriendServer::handleIncomingClientData(const std::string& pgp_public_key_b6
|
||||
|
||||
pi.short_certificate = short_invite_b64;
|
||||
pi.last_connection_TS = time(nullptr);
|
||||
pi.last_nonce = RsRandom::random_u64();
|
||||
|
||||
return true;
|
||||
while(pi.last_nonce == 0) // reuse the same identifier (so it's not really a nonce, but it's kept secret whatsoever).
|
||||
pi.last_nonce = RsRandom::random_u64();
|
||||
|
||||
return mCurrentClientPeers.find(shortInviteDetails.id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +32,7 @@ class RsFriendServerClientPublishItem;
|
||||
|
||||
struct PeerInfo
|
||||
{
|
||||
RsPgpFingerprint pgp_fingerprint;
|
||||
std::string short_certificate;
|
||||
rstime_t last_connection_TS;
|
||||
uint64_t last_nonce;
|
||||
@ -53,7 +54,11 @@ private:
|
||||
void handleClientRemove(const RsFriendServerClientRemoveItem *item);
|
||||
void handleClientPublish(const RsFriendServerClientPublishItem *item);
|
||||
|
||||
bool handleIncomingClientData(const std::string& pgp_public_key_b64,const std::string& short_invite_b64);
|
||||
// Adds the incoming peer data to the list of current clients and returns the
|
||||
std::map<RsPeerId,PeerInfo>::iterator handleIncomingClientData(const std::string& pgp_public_key_b64,const std::string& short_invite_b64);
|
||||
|
||||
// Computes the appropriate list of short invites to send to a given peer.
|
||||
std::map<std::string,bool> computeListOfFriendInvites(uint32_t nb_reqs_invites,const RsPeerId& pid,const RsPgpFingerprint& fpr);
|
||||
|
||||
void autoWash();
|
||||
void debugPrint();
|
||||
|
Loading…
Reference in New Issue
Block a user