Merge pull request #1334 from csoler/v0.6-GxsFix

auto send of own signed GXS ids to friends in discovery
This commit is contained in:
csoler 2018-09-10 20:39:29 +02:00 committed by GitHub
commit c17b821ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 100 additions and 168 deletions

View File

@ -127,7 +127,7 @@ public:
const RsGxsId& encryption_key_id,
uint32_t& encryption_error, bool force_load) = 0 ;
virtual bool getOwnIds(std::list<RsGxsId>& ids) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false)=0;
virtual bool isOwnId(const RsGxsId& key_id) = 0 ;
virtual void timeStampKey(const RsGxsId& key_id,const RsIdentityUsage& reason) = 0 ;

View File

@ -356,7 +356,7 @@ struct RsIdentity : RsGxsIfaceHelper
virtual bool getIdDetails(const RsGxsId &id, RsIdentityDetails &details) = 0;
// Fills up list of all own ids. Returns false if ids are not yet loaded.
virtual bool getOwnIds(std::list<RsGxsId> &ownIds) = 0;
virtual bool getOwnIds(std::list<RsGxsId> &ownIds,bool only_signed_ids = false) = 0;
virtual bool isOwnId(const RsGxsId& id) = 0;
//

View File

@ -55,6 +55,7 @@ RsItem *RsDiscSerialiser::create_item(uint16_t service,uint8_t item_subtype) con
case RS_PKT_SUBTYPE_DISC_SERVICES : return new RsDiscServicesItem(); //= 0x04;
#endif
case RS_PKT_SUBTYPE_DISC_CONTACT : return new RsDiscContactItem(); //= 0x05;
case RS_PKT_SUBTYPE_DISC_IDENTITY_LIST : return new RsDiscIdentityListItem(); //= 0x06;
default:
return NULL ;
}
@ -150,139 +151,8 @@ void RsDiscContactItem::serial_process(RsGenericSerializer::SerializeJob j,RsGen
}
}
/*************************************************************************/
#if 0
RsDiscServicesItem::~RsDiscServicesItem()
void RsDiscIdentityListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
return;
RS_SERIAL_PROCESS(ownIdentityList);
}
void RsDiscServicesItem::clear()
{
version.clear();
mServiceIdMap.TlvClear();
}
std::ostream &RsDiscServicesItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsDiscServicesItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "version: " << version << std::endl;
mServiceIdMap.print(out, int_Indent);
printRsItemEnd(out, "RsDiscServicesItem", indent);
return out;
}
uint32_t RsDiscSerialiser::sizeServices(RsDiscServicesItem *item)
{
uint32_t s = 8; /* header */
s += GetTlvStringSize(item->version); /* version */
s += item->mServiceIdMap.TlvSize();
return s;
}
/* serialise the data to the buffer */
bool RsDiscSerialiser::serialiseServices(RsDiscServicesItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeServices(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsDiscSerialiser::serialiseServices() Header: " << ok << std::endl;
std::cerr << "RsDiscSerialiser::serialiseServices() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VERSION, item->version);
ok &= item->mServiceIdMap.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize) {
ok = false;
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::serialiseServices() Size Error! " << std::endl;
#endif
}
return ok;
}
RsDiscServicesItem *RsDiscSerialiser::deserialiseServices(void *data, uint32_t *pktsize) {
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_DISC != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_DISC_PGP_LIST != getRsItemSubType(rstype)))
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseServices() Wrong Type" << std::endl;
#endif
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
{
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseServices() Not Enough Space" << std::endl;
#endif
return NULL; /* not enough data */
}
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsDiscServicesItem *item = new RsDiscServicesItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_VERSION, item->version);
ok &= item->mServiceIdMap.GetTlv(data, rssize, &offset);
if (offset != rssize) {
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseServices() offset != rssize" << std::endl;
#endif
/* error */
delete item;
return NULL;
}
if (!ok) {
#ifdef RSSERIAL_ERROR_DEBUG
std::cerr << "RsDiscSerialiser::deserialiseServices() ok = false" << std::endl;
#endif
delete item;
return NULL;
}
return item;
}
#endif

View File

@ -36,6 +36,7 @@ const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02;
const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT_deprecated = 0x03;
const uint8_t RS_PKT_SUBTYPE_DISC_SERVICES = 0x04;
const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT = 0x05;
const uint8_t RS_PKT_SUBTYPE_DISC_IDENTITY_LIST = 0x06;
class RsDiscItem: public RsItem
{
@ -138,6 +139,23 @@ public:
RsTlvIpAddrSet extAddrList;
};
class RsDiscIdentityListItem: public RsDiscItem
{
public:
RsDiscIdentityListItem()
:RsDiscItem(RS_PKT_SUBTYPE_DISC_IDENTITY_LIST)
{
setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT);
}
virtual ~RsDiscIdentityListItem() {}
virtual void clear() { ownIdentityList.clear() ; }
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
std::list<RsGxsId> ownIdentityList ;
};
#if 0
class RsDiscServicesItem: public RsDiscItem
{

View File

@ -1475,7 +1475,7 @@ int RsServer::StartupRetroShare()
/* create Services */
p3ServiceInfo *serviceInfo = new p3ServiceInfo(serviceCtrl);
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr, serviceCtrl);
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr, serviceCtrl,mGxsIdService);
mHeart = new p3heartbeat(serviceCtrl, pqih);
msgSrv = new p3MsgService( serviceCtrl, mGxsIdService, *mGxsTrans );
chatSrv = new p3ChatService( serviceCtrl,mGxsIdService, mLinkMgr,

View File

@ -34,6 +34,7 @@ RsDisc *rsDisc = NULL;
/****
* #define P3DISC_DEBUG 1
****/
#define P3DISC_DEBUG 1
static bool populateContactInfo( const peerState &detail,
RsDiscContactItem *pkt,
@ -94,9 +95,8 @@ void DiscPgpInfo::mergeFriendList(const std::set<PGPID> &friends)
}
p3discovery2::p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc)
:p3Service(), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), mServiceCtrl(sc),
mDiscMtx("p3discovery2")
p3discovery2::p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc, RsGixs *gixs)
:p3Service(), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), mServiceCtrl(sc), mGixs(gixs),mDiscMtx("p3discovery2")
{
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -262,17 +262,14 @@ int p3discovery2::handleIncoming()
{
RsItem *item = NULL;
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::handleIncoming()" << std::endl;
#endif
int nhandled = 0;
// While messages read
while(NULL != (item = recvItem()))
while(nullptr != (item = recvItem()))
{
RsDiscPgpListItem *pgplist = NULL;
RsDiscPgpCertItem *pgpcert = NULL;
RsDiscContactItem *contact = NULL;
RsDiscPgpListItem *pgplist = nullptr;
RsDiscPgpCertItem *pgpcert = nullptr;
RsDiscContactItem *contact = nullptr;
RsDiscIdentityListItem *gxsidlst = nullptr;
nhandled++;
#ifdef P3DISC_DEBUG
@ -281,21 +278,21 @@ int p3discovery2::handleIncoming()
std::cerr << std::endl;
#endif
if (NULL != (contact = dynamic_cast<RsDiscContactItem *> (item)))
if (nullptr != (contact = dynamic_cast<RsDiscContactItem *> (item)))
{
if (item->PeerId() == contact->sslId) /* self describing */
recvOwnContactInfo(item->PeerId(), contact);
else
processContactInfo(item->PeerId(), contact);
continue;
}
if (NULL != (pgpcert = dynamic_cast<RsDiscPgpCertItem *> (item)))
else if (nullptr != (gxsidlst = dynamic_cast<RsDiscIdentityListItem *> (item)))
{
recvPGPCertificate(item->PeerId(), pgpcert);
recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList) ;
delete item;
}
else if (NULL != (pgplist = dynamic_cast<RsDiscPgpListItem *> (item)))
else if (nullptr != (pgpcert = dynamic_cast<RsDiscPgpCertItem *> (item)))
recvPGPCertificate(item->PeerId(), pgpcert);
else if (nullptr != (pgplist = dynamic_cast<RsDiscPgpListItem *> (item)))
{
/* two types */
if (pgplist->mode == DISC_PGP_LIST_MODE_FRIENDS)
@ -323,10 +320,6 @@ int p3discovery2::handleIncoming()
}
}
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::handleIncoming() finished." << std::endl;
#endif
return nhandled;
}
@ -355,6 +348,7 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid)
* difficult for average user, that moreover whould have no way to
* revert an hardcoded policy. */
//populateContactInfo(detail, pkt, true);
pkt->version = RsUtil::retroshareVersion();
pkt->PeerId(sslid);
@ -364,6 +358,18 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid)
std::cerr << std::endl;
#endif
sendItem(pkt);
RsDiscIdentityListItem *pkt2 = new RsDiscIdentityListItem();
rsIdentity->getOwnIds(pkt2->ownIdentityList,true);
pkt2->PeerId(sslid) ;
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::sendOwnContactInfo() sending own signed identity list:" << std::endl;
for(auto it(pkt2->ownIdentityList.begin());it!=pkt2->ownIdentityList.end();++it)
std::cerr << " identity: " << (*it).toStdString() << std::endl;
#endif
sendItem(pkt2);
}
}
@ -440,6 +446,26 @@ void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactIt
delete item;
}
void p3discovery2::recvIdentityList(const RsPeerId& pid,const std::list<RsGxsId>& ids)
{
std::list<RsPeerId> peers;
peers.push_back(pid);
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::recvIdentityList(): from peer " << pid << ": " << ids.size() << " identities" << std::endl;
#endif
RsIdentityUsage use_info(RS_SERVICE_TYPE_DISC,RsIdentityUsage::IDENTITY_DATA_UPDATE);
for(auto it(ids.begin());it!=ids.end();++it)
{
#ifdef P3DISC_DEBUG
std::cerr << " identity: " << (*it).toStdString() << std::endl;
#endif
mGixs->requestKey(*it,peers,use_info) ;
}
}
void p3discovery2::updatePeerAddresses(const RsDiscContactItem *item)
{
if (item->isHidden)
@ -1319,4 +1345,3 @@ void p3discovery2::setGPGOperation(AuthGPGOperation *operation)
/* ignore other operations */
}

View File

@ -34,6 +34,7 @@
#include "rsitems/rsdiscovery2items.h"
#include "services/p3service.h"
#include "pqi/authgpg.h"
#include "gxs/rsgixs.h"
class p3ServiceControl;
@ -75,7 +76,7 @@ class p3discovery2: public RsDisc, public p3Service, public pqiServiceMonitor, p
{
public:
p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc);
p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc,RsGixs *gixs);
virtual ~p3discovery2();
virtual RsServiceInfo getServiceInfo();
@ -121,6 +122,7 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
void recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item);
void sendPGPCertificate(const PGPID &aboutId, const SSLID &toId);
void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item);
void recvIdentityList(const RsPeerId& pid,const std::list<RsGxsId>& ids);
bool setPeerVersion(const SSLID &peerId, const std::string &version);
@ -130,6 +132,7 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
p3LinkMgr *mLinkMgr;
p3NetMgr *mNetMgr;
p3ServiceControl *mServiceCtrl;
RsGixs *mGixs ;
/* data */
RsMutex mDiscMtx;

View File

@ -684,7 +684,7 @@ bool p3IdService::isOwnId(const RsGxsId& id)
return std::find(mOwnIds.begin(),mOwnIds.end(),id) != mOwnIds.end() ;
}
bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds,bool signed_only)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -694,7 +694,8 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
return false ;
}
ownIds = mOwnIds;
ownIds = signed_only ? mOwnSignedIds : mOwnIds;
return true ;
}
@ -2825,6 +2826,18 @@ bool p3IdService::cache_load_ownids(uint32_t token)
{
mOwnIds.push_back(RsGxsId(item->meta.mGroupId));
SSGxsIdGroup ssdata;
std::cerr << "Adding own ID " << item->meta.mGroupId << " mGroupFlags=" << std::hex << item->meta.mGroupFlags << std::dec;
if (ssdata.load(item->meta.mServiceString) && ssdata.pgp.validatedSignature) // (cyril) note: we cannot use if(item->meta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
{ // or we need to cmbine it with the deprecated value that overlaps with GXS_SERV::FLAG_PRIVACY_PRIVATE
std::cerr << " signed = YES" << std::endl; // see comments line 799 in ::createIdentity();
mOwnSignedIds.push_back(RsGxsId(item->meta.mGroupId));
}
else
std::cerr << " signed = NO" << std::endl;
// This prevents automatic deletion to get rid of them.
// In other words, own ids are always used.
@ -2833,6 +2846,8 @@ bool p3IdService::cache_load_ownids(uint32_t token)
delete item ;
}
mOwnIdsLoaded = true ;
std::cerr << mOwnIds.size() << " own Ids loaded, " << mOwnSignedIds.size() << " of which are signed" << std::endl;
}
// No need to cache these items...

View File

@ -285,7 +285,7 @@ public:
/**************** RsGixs Implementation ***************/
virtual bool getOwnIds(std::list<RsGxsId> &ownIds);
virtual bool getOwnIds(std::list<RsGxsId> &ownIds, bool signed_only = false);
//virtual bool getPublicKey(const RsGxsId &id, RsTlvSecurityKey &key) ;
//virtual void networkRequestPublicKey(const RsGxsId& key_id,const std::list<RsPeerId>& peer_ids) ;
@ -423,6 +423,7 @@ private:
bool cache_load_ownids(uint32_t token);
std::list<RsGxsId> mOwnIds;
std::list<RsGxsId> mOwnSignedIds;
/************************************************************************
* Test fns for Caching.