mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-14 01:23:13 -04:00
Expose RsPeers JSON API
Added also new method for better usability via the API that allow to add friend directly for RetroShare invitation (supports also URL) without having to call to mulptiple metods to set IP etc. RsPeers::acceptInvite /rsPeers/acceptInvite
This commit is contained in:
parent
a8ddec03fc
commit
cc6f0b1f05
3 changed files with 311 additions and 55 deletions
libretroshare/src/rsserver
|
@ -34,6 +34,7 @@
|
|||
#include "pqi/authgpg.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "util/rsurl.h"
|
||||
|
||||
#include "pgp/rscertificate.h"
|
||||
|
||||
|
@ -200,6 +201,15 @@ bool p3Peers::getFriendList(std::list<RsPeerId> &ids)
|
|||
// return true;
|
||||
//}
|
||||
|
||||
bool p3Peers::getPeersCount(
|
||||
uint32_t& peersCount, uint32_t& onlinePeersCount,
|
||||
bool countLocations )
|
||||
{
|
||||
peersCount = mPeerMgr->getFriendCount(countLocations, false);
|
||||
onlinePeersCount = mPeerMgr->getFriendCount(countLocations, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
@ -1099,6 +1109,72 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const RsPgpId& gpg_id,
|
|||
return true ;
|
||||
}
|
||||
|
||||
bool p3Peers::acceptInvite( const std::string& invite,
|
||||
ServicePermissionFlags flags )
|
||||
{
|
||||
if(invite.empty()) return false;
|
||||
|
||||
const std::string* radixPtr(&invite);
|
||||
|
||||
RsUrl url(invite);
|
||||
std::map<std::string, std::string> query(url.query());
|
||||
|
||||
if(query.find("radix") != query.end())
|
||||
radixPtr = &query["radix"];
|
||||
|
||||
const std::string& radix(*radixPtr);
|
||||
if(radix.empty()) return false;
|
||||
|
||||
RsPgpId pgpId;
|
||||
RsPeerId sslId;
|
||||
std::string errorString;
|
||||
|
||||
if(!loadCertificateFromString(radix, sslId, pgpId, errorString))
|
||||
return false;
|
||||
|
||||
RsPeerDetails peerDetails;
|
||||
uint32_t errorCode;
|
||||
|
||||
if(!loadDetailsFromStringCert(radix, peerDetails, errorCode))
|
||||
return false;
|
||||
|
||||
if(peerDetails.gpg_id.isNull())
|
||||
return false;
|
||||
|
||||
addFriend(peerDetails.id, peerDetails.gpg_id, flags);
|
||||
|
||||
if (!peerDetails.location.empty())
|
||||
setLocation(peerDetails.id, peerDetails.location);
|
||||
|
||||
// Update new address even the peer already existed.
|
||||
if (peerDetails.isHiddenNode)
|
||||
{
|
||||
setHiddenNode( peerDetails.id,
|
||||
peerDetails.hiddenNodeAddress,
|
||||
peerDetails.hiddenNodePort );
|
||||
}
|
||||
else
|
||||
{
|
||||
//let's check if there is ip adresses in the certificate.
|
||||
if (!peerDetails.extAddr.empty() && peerDetails.extPort)
|
||||
setExtAddress( peerDetails.id,
|
||||
peerDetails.extAddr,
|
||||
peerDetails.extPort );
|
||||
if (!peerDetails.localAddr.empty() && peerDetails.localPort)
|
||||
setLocalAddress( peerDetails.id,
|
||||
peerDetails.localAddr,
|
||||
peerDetails.localPort );
|
||||
if (!peerDetails.dyndns.empty())
|
||||
setDynDNS(peerDetails.id, peerDetails.dyndns);
|
||||
for(auto&& ipr : peerDetails.ipAddressList)
|
||||
addPeerLocator(
|
||||
peerDetails.id,
|
||||
RsUrl(ipr.substr(0, ipr.find(' '))) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string p3Peers::GetRetroshareInvite(
|
||||
const RsPeerId& ssl_id, bool include_signatures,
|
||||
bool includeExtraLocators )
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "util/rsurl.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
class p3LinkMgr;
|
||||
class p3PeerMgr;
|
||||
|
@ -56,6 +57,11 @@ public:
|
|||
|
||||
virtual bool getOnlineList(std::list<RsPeerId> &ids);
|
||||
virtual bool getFriendList(std::list<RsPeerId> &ids);
|
||||
virtual bool getPeersCount(
|
||||
uint32_t& peersCount, uint32_t& onlinePeersCount,
|
||||
bool countLocations );
|
||||
|
||||
RS_DEPRECATED
|
||||
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
|
||||
|
||||
virtual bool isOnline(const RsPeerId &id);
|
||||
|
@ -121,6 +127,11 @@ public:
|
|||
bool includeExtraLocators = true );
|
||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum);
|
||||
|
||||
/// @see RsPeers::acceptInvite
|
||||
virtual bool acceptInvite(
|
||||
const std::string& invite,
|
||||
ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT );
|
||||
|
||||
virtual bool hasExportMinimal();
|
||||
|
||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue