Add rsidentity API call to request specific identity to the network

This commit is contained in:
Gioacchino Mazzurco 2019-06-12 19:01:19 +02:00
parent cea88f0c6c
commit 08604774d3
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
4 changed files with 62 additions and 10 deletions

View File

@ -244,14 +244,22 @@ struct RsIdentityUsage : RsSerializable
CIRCLE_MEMBERSHIP_CHECK = 0x13
} ;
RS_DEPRECATED
RsIdentityUsage( uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid = RsGxsGroupId(),
const RsGxsMessageId& mid = RsGxsMessageId(),
uint64_t additional_id=0,
const std::string& comment = std::string() );
RsIdentityUsage( RsServiceType service,
RsIdentityUsage::UsageCode code,
const RsGxsGroupId& gid = RsGxsGroupId(),
const RsGxsMessageId& mid = RsGxsMessageId(),
uint64_t additional_id=0,
const std::string& comment = std::string() );
/// Id of the service using that identity, as understood by rsServiceControl
uint16_t mServiceId;
RsServiceType mServiceId;
/** Specific code to use. Will allow forming the correct translated message
* in the GUI if necessary. */
@ -504,6 +512,14 @@ struct RsIdentity : RsGxsIfaceHelper
*/
virtual void setDeleteBannedNodesThreshold(uint32_t days) = 0;
/**
* @brief request details of a not yet known identity to the network
* @jsonapi{development}
* @param[in] id id of the identity to request
* @return false on error, true otherwise
*/
virtual bool requestIdentity(const RsGxsId& id) = 0;
RS_DEPRECATED
virtual bool getGroupSerializedData(

View File

@ -1153,6 +1153,16 @@ static void mergeIds(std::map<RsGxsId,std::list<RsPeerId> >& idmap,const RsGxsId
old_peers.push_back(*it) ;
}
bool p3IdService::requestIdentity(const RsGxsId& id)
{
RsIdentityUsage usageInfo( RsServiceType::GXSID,
RsIdentityUsage::IDENTITY_DATA_UPDATE );
std::list<RsPeerId> onlinePeers;
return rsPeers && rsPeers->getOnlineList(onlinePeers)
&& requestKey(id, onlinePeers, usageInfo);
}
bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers,const RsIdentityUsage& use_info)
{
if(id.isNull())
@ -4680,12 +4690,34 @@ void RsGxsIdGroup::serial_process(
RS_SERIAL_PROCESS(mReputation);
}
RsIdentityUsage::RsIdentityUsage(
RsServiceType service, RsIdentityUsage::UsageCode code,
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
uint64_t additional_id, const std::string& comment ) :
mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),
mAdditionalId(additional_id), mComment(comment)
{
/* This is a hack, since it will hash also mHash, but because it is
* initialized to 0, and only computed in the constructor here, it should
* be ok. */
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1);
hs << static_cast<uint32_t>(service); // G10h4ck: Why uint32 if it's 16 bits?
hs << static_cast<uint8_t>(code);
hs << gid;
hs << mid;
hs << static_cast<uint64_t>(additional_id);
hs << comment;
mHash = hs.hash();
}
RsIdentityUsage::RsIdentityUsage(
uint16_t service, const RsIdentityUsage::UsageCode& code,
const RsGxsGroupId& gid, const RsGxsMessageId& mid,
uint64_t additional_id,const std::string& comment ) :
mServiceId(service), mUsageCode(code), mGrpId(gid), mMsgId(mid),
mAdditionalId(additional_id), mComment(comment)
mServiceId(static_cast<RsServiceType>(service)), mUsageCode(code),
mGrpId(gid), mMsgId(mid), mAdditionalId(additional_id), mComment(comment)
{
#ifdef DEBUG_IDS
std::cerr << "New identity usage: " << std::endl;
@ -4702,7 +4734,7 @@ RsIdentityUsage::RsIdentityUsage(
* be ok. */
librs::crypto::HashStream hs(librs::crypto::HashStream::SHA1) ;
hs << (uint32_t)service ;
hs << (uint32_t)service ; // G10h4ck: Why uint32 if it's 16 bits?
hs << (uint8_t)code ;
hs << gid ;
hs << mid ;
@ -4717,4 +4749,5 @@ RsIdentityUsage::RsIdentityUsage(
}
RsIdentityUsage::RsIdentityUsage() :
mServiceId(0), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0) {}
mServiceId(RsServiceType::NONE), mUsageCode(UNKNOWN_USAGE), mAdditionalId(0)
{}

View File

@ -370,6 +370,9 @@ public:
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string,
RsGxsId* id = nullptr);
/// @see RsIdentity
bool requestIdentity(const RsGxsId& id) override;
/**************** RsGixsReputation Implementation ****************/
// get Reputation.

View File

@ -1987,11 +1987,11 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
RetroShareLink::enumType service_type = RetroShareLink::TYPE_UNKNOWN;
switch(u.mServiceId)
{
case RS_SERVICE_GXS_TYPE_CHANNELS: service_name = tr("Channels") ;service_type = RetroShareLink::TYPE_CHANNEL ; break ;
case RS_SERVICE_GXS_TYPE_FORUMS: service_name = tr("Forums") ; service_type = RetroShareLink::TYPE_FORUM ; break ;
case RS_SERVICE_GXS_TYPE_POSTED: service_name = tr("Posted") ; service_type = RetroShareLink::TYPE_POSTED ; break ;
case RS_SERVICE_TYPE_CHAT: service_name = tr("Chat") ; service_type = RetroShareLink::TYPE_CHAT_ROOM ; break ;
{
case RsServiceType::CHANNELS: service_name = tr("Channels") ;service_type = RetroShareLink::TYPE_CHANNEL ; break ;
case RsServiceType::FORUMS: service_name = tr("Forums") ; service_type = RetroShareLink::TYPE_FORUM ; break ;
case RsServiceType::POSTED: service_name = tr("Posted") ; service_type = RetroShareLink::TYPE_POSTED ; break ;
case RsServiceType::CHAT: service_name = tr("Chat") ; service_type = RetroShareLink::TYPE_CHAT_ROOM ; break ;
default:
service_name = tr("Unknown"); service_type = RetroShareLink::TYPE_UNKNOWN ;
}