mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
Merge pull request #1554 from G10h4ck/rsgossipdiscovery
Gossip discovery refinement
This commit is contained in:
commit
cc47ee72f5
@ -1,9 +1,10 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/rsitems: rsdiscitems.cc *
|
||||
* Gossip discovery service items *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2007-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2007-2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -19,60 +20,49 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#include "rsitems/rsdiscovery2items.h"
|
||||
|
||||
#include "gossipdiscovery/gossipdiscoveryitems.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#include "serialiser/rstypeserializer.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#include "rsitems/rsserviceids.h"
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#endif
|
||||
|
||||
/***
|
||||
* #define RSSERIAL_DEBUG 1
|
||||
* #define RSSERIAL_ERROR_DEBUG 1
|
||||
***/
|
||||
|
||||
#define RSSERIAL_ERROR_DEBUG 1
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
RsItem *RsDiscSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
|
||||
RsItem *RsDiscSerialiser::create_item(
|
||||
uint16_t service, uint8_t item_subtype ) const
|
||||
{
|
||||
if(service != RS_SERVICE_TYPE_DISC)
|
||||
return NULL ;
|
||||
if(service != RS_SERVICE_TYPE_DISC) return nullptr;
|
||||
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_DISC_PGP_LIST : return new RsDiscPgpListItem() ; //= 0x01;
|
||||
case RS_PKT_SUBTYPE_DISC_PGP_CERT : return new RsDiscPgpCertItem() ; //= 0x02;
|
||||
case RS_PKT_SUBTYPE_DISC_CONTACT_deprecated : return NULL ; //= 0x03;
|
||||
#if 0
|
||||
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 ;
|
||||
}
|
||||
switch(static_cast<RsGossipDiscoveryItemType>(item_subtype))
|
||||
{
|
||||
case RsGossipDiscoveryItemType::PGP_LIST: return new RsDiscPgpListItem();
|
||||
case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem();
|
||||
case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem();
|
||||
case RsGossipDiscoveryItemType::IDENTITY_LIST:
|
||||
return new RsDiscIdentityListItem();
|
||||
case RsGossipDiscoveryItemType::INVITE:
|
||||
return new RsGossipDiscoveryInviteItem();
|
||||
case RsGossipDiscoveryItemType::INVITE_REQUEST:
|
||||
return new RsGossipDiscoveryInviteRequestItem();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsDiscPgpListItem::clear()
|
||||
void RsDiscPgpListItem::clear()
|
||||
{
|
||||
mode = DISC_PGP_LIST_MODE_NONE;
|
||||
mode = RsGossipDiscoveryPgpListMode::NONE;
|
||||
pgpIdSet.TlvClear();
|
||||
}
|
||||
|
||||
void RsDiscPgpListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
|
||||
void RsDiscPgpListItem::serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,mode,"mode") ;
|
||||
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ;
|
||||
RS_SERIAL_PROCESS(mode);
|
||||
RS_SERIAL_PROCESS(pgpIdSet);
|
||||
}
|
||||
|
||||
void RsDiscPgpCertItem::clear()
|
||||
@ -156,3 +146,17 @@ void RsDiscIdentityListItem::serial_process(RsGenericSerializer::SerializeJob j,
|
||||
RS_SERIAL_PROCESS(ownIdentityList);
|
||||
}
|
||||
|
||||
|
||||
RsGossipDiscoveryInviteItem::RsGossipDiscoveryInviteItem() :
|
||||
RsDiscItem(RsGossipDiscoveryItemType::INVITE)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_ASK_INFO); }
|
||||
|
||||
RsGossipDiscoveryInviteRequestItem::RsGossipDiscoveryInviteRequestItem() :
|
||||
RsDiscItem(RsGossipDiscoveryItemType::INVITE_REQUEST)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_REPLY); }
|
||||
|
||||
RsDiscItem::RsDiscItem(RsGossipDiscoveryItemType subtype) :
|
||||
RsItem( RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC,
|
||||
static_cast<uint8_t>(subtype) ) {}
|
||||
|
||||
RsDiscItem::~RsDiscItem() {}
|
192
libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h
Normal file
192
libretroshare/src/gossipdiscovery/gossipdiscoveryitems.h
Normal file
@ -0,0 +1,192 @@
|
||||
/*******************************************************************************
|
||||
* Gossip discovery service items *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2004-2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
enum class RsGossipDiscoveryItemType : uint8_t
|
||||
{
|
||||
PGP_LIST = 0x1,
|
||||
PGP_CERT = 0x2,
|
||||
CONTACT = 0x5,
|
||||
IDENTITY_LIST = 0x6,
|
||||
INVITE = 0x7,
|
||||
INVITE_REQUEST = 0x8
|
||||
};
|
||||
|
||||
class RsDiscItem: public RsItem
|
||||
{
|
||||
protected:
|
||||
RsDiscItem(RsGossipDiscoveryItemType subtype);
|
||||
|
||||
public:
|
||||
RsDiscItem() = delete;
|
||||
virtual ~RsDiscItem();
|
||||
};
|
||||
|
||||
/**
|
||||
* This enum is underlined by uint32_t for historical reasons.
|
||||
* We are conscious that uint32_t is an overkill for so few possible values but,
|
||||
* changing here it at this point would break binary serialized item
|
||||
* retro-compatibility.
|
||||
*/
|
||||
enum class RsGossipDiscoveryPgpListMode : uint32_t
|
||||
{
|
||||
NONE = 0x0,
|
||||
FRIENDS = 0x1,
|
||||
GETCERT = 0x2
|
||||
};
|
||||
|
||||
class RsDiscPgpListItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpListItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_LIST)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_LIST); }
|
||||
|
||||
void clear() override;
|
||||
void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override;
|
||||
|
||||
RsGossipDiscoveryPgpListMode mode;
|
||||
RsTlvPgpIdSet pgpIdSet;
|
||||
};
|
||||
|
||||
class RsDiscPgpCertItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpCertItem() : RsDiscItem(RsGossipDiscoveryItemType::PGP_CERT)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT); }
|
||||
|
||||
void clear() override;
|
||||
void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override;
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpCert;
|
||||
};
|
||||
|
||||
class RsDiscContactItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscContactItem() : RsDiscItem(RsGossipDiscoveryItemType::CONTACT)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT); }
|
||||
|
||||
void clear() override;
|
||||
void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override;
|
||||
|
||||
RsPgpId pgpId;
|
||||
RsPeerId sslId;
|
||||
|
||||
// COMMON
|
||||
std::string location;
|
||||
std::string version;
|
||||
|
||||
uint32_t netMode; /* Mandatory */
|
||||
uint16_t vs_disc; /* Mandatory */
|
||||
uint16_t vs_dht; /* Mandatory */
|
||||
uint32_t lastContact;
|
||||
|
||||
bool isHidden; /* not serialised */
|
||||
|
||||
// HIDDEN.
|
||||
std::string hiddenAddr;
|
||||
uint16_t hiddenPort;
|
||||
|
||||
// STANDARD.
|
||||
|
||||
RsTlvIpAddress currentConnectAddress ; // used to check!
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
RsTlvIpAddrSet extAddrList;
|
||||
};
|
||||
|
||||
class RsDiscIdentityListItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscIdentityListItem() :
|
||||
RsDiscItem(RsGossipDiscoveryItemType::IDENTITY_LIST)
|
||||
{ setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT); }
|
||||
|
||||
void clear() override { ownIdentityList.clear(); }
|
||||
void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx) override;
|
||||
|
||||
std::list<RsGxsId> ownIdentityList;
|
||||
};
|
||||
|
||||
struct RsGossipDiscoveryInviteItem : RsDiscItem
|
||||
{
|
||||
RsGossipDiscoveryInviteItem();
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{ RS_SERIAL_PROCESS(mInvite); }
|
||||
void clear() override { mInvite.clear(); }
|
||||
|
||||
std::string mInvite;
|
||||
};
|
||||
|
||||
struct RsGossipDiscoveryInviteRequestItem : RsDiscItem
|
||||
{
|
||||
RsGossipDiscoveryInviteRequestItem();
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{ RS_SERIAL_PROCESS(mInviteId); }
|
||||
void clear() override { mInviteId.clear(); }
|
||||
|
||||
RsPeerId mInviteId;
|
||||
};
|
||||
|
||||
class RsDiscSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsDiscSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_DISC) {}
|
||||
virtual ~RsDiscSerialiser() {}
|
||||
|
||||
RsItem* create_item(uint16_t service, uint8_t item_subtype) const;
|
||||
};
|
@ -1,10 +1,10 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/services: p3discovery2.cc *
|
||||
* RetroShare gossip discovery service implementation *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2004-2013 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2004-2013 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -20,21 +20,23 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#include "services/p3discovery2.h"
|
||||
|
||||
#include "gossipdiscovery/p3gossipdiscovery.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "retroshare/rsversion.h"
|
||||
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "rsserver/p3face.h"
|
||||
|
||||
|
||||
// Interface pointer.
|
||||
RsDisc *rsDisc = NULL;
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
/****
|
||||
* #define P3DISC_DEBUG 1
|
||||
****/
|
||||
|
||||
/*extern*/ std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery(nullptr);
|
||||
|
||||
RsGossipDiscovery::~RsGossipDiscovery() {};
|
||||
|
||||
|
||||
static bool populateContactInfo( const peerState &detail,
|
||||
RsDiscContactItem *pkt,
|
||||
bool include_ip_information )
|
||||
@ -48,8 +50,8 @@ static bool populateContactInfo( const peerState &detail,
|
||||
pkt->netMode = detail.netMode;
|
||||
pkt->vs_disc = detail.vs_disc;
|
||||
pkt->vs_dht = detail.vs_dht;
|
||||
|
||||
pkt->lastContact = time(NULL);
|
||||
|
||||
pkt->lastContact = time(nullptr);
|
||||
|
||||
if (detail.hiddenNode)
|
||||
{
|
||||
@ -94,24 +96,23 @@ void DiscPgpInfo::mergeFriendList(const std::set<PGPID> &friends)
|
||||
}
|
||||
|
||||
|
||||
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")
|
||||
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"), mLastPgpUpdate(0)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
Dbg3() << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
RS_STACK_MUTEX(mDiscMtx);
|
||||
addSerialType(new RsDiscSerialiser());
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::p3discovery2()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mLastPgpUpdate = 0;
|
||||
|
||||
// Add self into PGP FriendList.
|
||||
mFriendList[AuthGPG::getAuthGPG()->getGPGOwnId()] = DiscPgpInfo();
|
||||
|
||||
return;
|
||||
|
||||
rsEvents->registerEventsHandler(
|
||||
[this](const RsEvent& event){ rsEventsHandler(event); },
|
||||
mRsEventsHandle );
|
||||
}
|
||||
|
||||
|
||||
@ -131,17 +132,8 @@ RsServiceInfo p3discovery2::getServiceInfo()
|
||||
DISCOVERY_MIN_MINOR_VERSION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
p3discovery2::~p3discovery2()
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
{ rsEvents->unregisterEventsHandler(mRsEventsHandle); }
|
||||
|
||||
void p3discovery2::addFriend(const SSLID &sslId)
|
||||
{
|
||||
@ -243,7 +235,6 @@ void p3discovery2::removeFriend(const SSLID &sslId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PGPID p3discovery2::getPGPId(const SSLID &id)
|
||||
{
|
||||
PGPID pgpId;
|
||||
@ -251,7 +242,6 @@ PGPID p3discovery2::getPGPId(const SSLID &id)
|
||||
return pgpId;
|
||||
}
|
||||
|
||||
|
||||
int p3discovery2::tick()
|
||||
{
|
||||
return handleIncoming();
|
||||
@ -259,62 +249,60 @@ int p3discovery2::tick()
|
||||
|
||||
int p3discovery2::handleIncoming()
|
||||
{
|
||||
RsItem *item = NULL;
|
||||
RsItem* item = nullptr;
|
||||
|
||||
int nhandled = 0;
|
||||
// While messages read
|
||||
while(nullptr != (item = recvItem()))
|
||||
{
|
||||
RsDiscPgpListItem *pgplist = nullptr;
|
||||
RsDiscPgpCertItem *pgpcert = nullptr;
|
||||
RsDiscContactItem *contact = nullptr;
|
||||
RsDiscIdentityListItem *gxsidlst = nullptr;
|
||||
nhandled++;
|
||||
RsDiscPgpListItem* pgplist = nullptr;
|
||||
RsDiscPgpCertItem* pgpcert = nullptr;
|
||||
RsDiscContactItem* contact = nullptr;
|
||||
RsDiscIdentityListItem* gxsidlst = nullptr;
|
||||
RsGossipDiscoveryInviteItem* invite = nullptr;
|
||||
RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr;
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::handleIncoming() Received Message!" << std::endl;
|
||||
item -> print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
++nhandled;
|
||||
|
||||
if (nullptr != (contact = dynamic_cast<RsDiscContactItem *> (item)))
|
||||
Dbg4() << __PRETTY_FUNCTION__ << " Received item: " << std::endl
|
||||
<< *item << std::endl;
|
||||
|
||||
if((contact = dynamic_cast<RsDiscContactItem *>(item)) != nullptr)
|
||||
{
|
||||
if (item->PeerId() == contact->sslId) /* self describing */
|
||||
if (item->PeerId() == contact->sslId)
|
||||
recvOwnContactInfo(item->PeerId(), contact);
|
||||
else
|
||||
processContactInfo(item->PeerId(), contact);
|
||||
else processContactInfo(item->PeerId(), contact);
|
||||
}
|
||||
else if (nullptr != (gxsidlst = dynamic_cast<RsDiscIdentityListItem *> (item)))
|
||||
{
|
||||
recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList) ;
|
||||
delete item;
|
||||
}
|
||||
else if (nullptr != (pgpcert = dynamic_cast<RsDiscPgpCertItem *> (item)))
|
||||
recvPGPCertificate(item->PeerId(), pgpcert);
|
||||
else if (nullptr != (pgplist = dynamic_cast<RsDiscPgpListItem *> (item)))
|
||||
else if( (gxsidlst = dynamic_cast<RsDiscIdentityListItem *>(item))
|
||||
!= nullptr )
|
||||
{
|
||||
/* two types */
|
||||
if (pgplist->mode == DISC_PGP_LIST_MODE_FRIENDS)
|
||||
{
|
||||
recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList);
|
||||
delete item;
|
||||
}
|
||||
else if((pgpcert = dynamic_cast<RsDiscPgpCertItem *>(item)) != nullptr)
|
||||
recvPGPCertificate(item->PeerId(), pgpcert);
|
||||
else if((pgplist = dynamic_cast<RsDiscPgpListItem *>(item)) != nullptr)
|
||||
{
|
||||
if (pgplist->mode == RsGossipDiscoveryPgpListMode::FRIENDS)
|
||||
processPGPList(pgplist->PeerId(), pgplist);
|
||||
|
||||
}
|
||||
else if (pgplist->mode == DISC_PGP_LIST_MODE_GETCERT)
|
||||
{
|
||||
else if (pgplist->mode == RsGossipDiscoveryPgpListMode::GETCERT)
|
||||
recvPGPCertificateRequest(pgplist->PeerId(), pgplist);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete item ;
|
||||
}
|
||||
else delete item;
|
||||
}
|
||||
else if( (invite = dynamic_cast<RsGossipDiscoveryInviteItem*>(item))
|
||||
!= nullptr )
|
||||
recvInvite(std::unique_ptr<RsGossipDiscoveryInviteItem>(invite));
|
||||
else if( (inviteReq =
|
||||
dynamic_cast<RsGossipDiscoveryInviteRequestItem*>(item))
|
||||
!= nullptr )
|
||||
{
|
||||
sendInvite(inviteReq->mInviteId, item->PeerId());
|
||||
delete item;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::handleIncoming() Unknown Received Message!" << std::endl;
|
||||
item -> print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type! "
|
||||
<< std::endl << item << std::endl;
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
@ -322,8 +310,6 @@ int p3discovery2::handleIncoming()
|
||||
return nhandled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3discovery2::sendOwnContactInfo(const SSLID &sslid)
|
||||
{
|
||||
|
||||
@ -372,7 +358,6 @@ void p3discovery2::sendOwnContactInfo(const SSLID &sslid)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::recvOwnContactInfo(const SSLID &fromId, const RsDiscContactItem *item)
|
||||
{
|
||||
|
||||
@ -477,7 +462,6 @@ void p3discovery2::updatePeerAddresses(const RsDiscContactItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
|
||||
{
|
||||
if (item->isHidden)
|
||||
@ -512,7 +496,6 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Starts the Discovery process.
|
||||
// should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status).
|
||||
void p3discovery2::sendPGPList(const SSLID &toId)
|
||||
@ -528,7 +511,7 @@ void p3discovery2::sendPGPList(const SSLID &toId)
|
||||
|
||||
RsDiscPgpListItem *pkt = new RsDiscPgpListItem();
|
||||
|
||||
pkt->mode = DISC_PGP_LIST_MODE_FRIENDS;
|
||||
pkt->mode = RsGossipDiscoveryPgpListMode::FRIENDS;
|
||||
|
||||
std::map<PGPID, DiscPgpInfo>::const_iterator it;
|
||||
for(it = mFriendList.begin(); it != mFriendList.end(); ++it)
|
||||
@ -653,9 +636,6 @@ void p3discovery2::updatePgpFriendList()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -666,7 +646,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *
|
||||
#endif
|
||||
|
||||
std::map<PGPID, DiscPgpInfo>::iterator it;
|
||||
PGPID fromPgpId = getPGPId(fromId);
|
||||
PGPID fromPgpId = getPGPId(fromId);
|
||||
it = mFriendList.find(fromPgpId);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
@ -699,7 +679,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *
|
||||
|
||||
if (requestUnknownPgpCerts)
|
||||
{
|
||||
std::set<PGPID>::const_iterator fit;
|
||||
std::set<PGPID>::const_iterator fit;
|
||||
for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit)
|
||||
{
|
||||
if (!AuthGPG::getAuthGPG()->isGPGId(*fit))
|
||||
@ -825,7 +805,6 @@ void p3discovery2::updatePeers_locked(const SSLID &aboutId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
@ -906,7 +885,6 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactItem *item)
|
||||
{
|
||||
(void) fromId; // remove unused parameter warnings, debug only
|
||||
@ -1001,8 +979,6 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* we explictly request certificates, instead of getting them all the time
|
||||
*/
|
||||
void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId)
|
||||
@ -1014,7 +990,7 @@ void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId
|
||||
|
||||
RsDiscPgpListItem *pkt = new RsDiscPgpListItem();
|
||||
|
||||
pkt->mode = DISC_PGP_LIST_MODE_GETCERT;
|
||||
pkt->mode = RsGossipDiscoveryPgpListMode::GETCERT;
|
||||
pkt->pgpIdSet.ids.insert(aboutId);
|
||||
pkt->PeerId(toId);
|
||||
|
||||
@ -1027,93 +1003,46 @@ void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId
|
||||
sendItem(pkt);
|
||||
}
|
||||
|
||||
/* comment */
|
||||
void p3discovery2::recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item)
|
||||
void p3discovery2::recvPGPCertificateRequest(
|
||||
const RsPeerId& fromId, const RsDiscPgpListItem* item )
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::recvPPGPCertificateRequest() from " << fromId;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " from " << fromId << std::endl;
|
||||
#endif
|
||||
|
||||
std::set<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.
|
||||
// shouldn't be a real problem. Peer must have own PgpCert already.
|
||||
if (AuthGPG::getAuthGPG()->isGPGAccepted(*it))
|
||||
{
|
||||
sendPGPCertificate(*it, fromId);
|
||||
}
|
||||
}
|
||||
RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId();
|
||||
for(const RsPgpId& pgpId : item->pgpIdSet.ids)
|
||||
if (pgpId == ownPgpId || AuthGPG::getAuthGPG()->isGPGAccepted(pgpId))
|
||||
sendPGPCertificate(pgpId, fromId);
|
||||
delete item;
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::sendPGPCertificate(const PGPID &aboutId, const SSLID &toId)
|
||||
{
|
||||
|
||||
/* for Relay Connections (and other slow ones) we don't want to
|
||||
* to waste bandwidth sending certificates. So don't add it.
|
||||
*/
|
||||
|
||||
uint32_t linkType = mLinkMgr->getLinkType(toId);
|
||||
if ((linkType & RS_NET_CONN_SPEED_TRICKLE) ||
|
||||
(linkType & RS_NET_CONN_SPEED_LOW))
|
||||
{
|
||||
std::cerr << "p3discovery2::sendPGPCertificate() Not sending Certificates to: " << toId;
|
||||
std::cerr << " (low bandwidth)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
RsDiscPgpCertItem *item = new RsDiscPgpCertItem();
|
||||
RsDiscPgpCertItem* item = new RsDiscPgpCertItem();
|
||||
item->pgpId = aboutId;
|
||||
item->PeerId(toId);
|
||||
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::sendPGPCertificate() queuing for Cert generation:" << std::endl;
|
||||
item->print(std::cerr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
/* queue it! */
|
||||
|
||||
mPendingDiscPgpCertOutList.push_back(item);
|
||||
Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: "
|
||||
<< std::endl << *item << std::endl;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mDiscMtx);
|
||||
mPendingDiscPgpCertOutList.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::recvPGPCertificate(const SSLID &/*fromId*/, RsDiscPgpCertItem *item)
|
||||
void p3discovery2::recvPGPCertificate(
|
||||
const SSLID& /*fromId*/, RsDiscPgpCertItem* item )
|
||||
{
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::recvPGPCertificate() queuing for Cert loading" << std::endl;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " queuing for Cert loading" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
/* should only happen if in FULL Mode */
|
||||
peerState pstate;
|
||||
mPeerMgr->getOwnNetStatus(pstate);
|
||||
if (pstate.vs_disc != RS_VS_DISC_FULL)
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::recvPGPCertificate() Not Loading Certificates as in MINIMAL MODE";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
delete item;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
/* push this back to be processed by pgp when possible */
|
||||
|
||||
RS_STACK_MUTEX(mDiscMtx);
|
||||
mPendingDiscPgpCertInList.push_back(item);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************* from pqiServiceMonitor *******************/
|
||||
void p3discovery2::statusChange(const std::list<pqiServicePeer> &plist)
|
||||
@ -1210,8 +1139,45 @@ bool p3discovery2::getWaitingDiscCount(size_t &sendCount, size_t &recvCount)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3discovery2::sendInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& errorMsg )
|
||||
{
|
||||
RsPeers& mPeers = *rsPeers;
|
||||
|
||||
std::string&& invite = mPeers.GetRetroshareInvite(inviteId);
|
||||
|
||||
if(invite.empty())
|
||||
{
|
||||
errorMsg = "Failure generating invite for peer: " +
|
||||
inviteId.toStdString() + " are you sure is a friend?";
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMsg << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsGossipDiscoveryInviteItem* item = new RsGossipDiscoveryInviteItem;
|
||||
item->PeerId(toSslId);
|
||||
item->mInvite = mPeers.GetRetroshareInvite(inviteId, true, true);
|
||||
|
||||
return sendItem(item);
|
||||
}
|
||||
|
||||
bool p3discovery2::requestInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& /*errorMsg*/ )
|
||||
{
|
||||
Dbg2() << __PRETTY_FUNCTION__ << " inviteId: " << inviteId
|
||||
<< " toSslId: " << toSslId << std::endl;
|
||||
|
||||
RsGossipDiscoveryInviteRequestItem* item =
|
||||
new RsGossipDiscoveryInviteRequestItem;
|
||||
item->PeerId(toSslId);
|
||||
item->mInviteId = inviteId;
|
||||
|
||||
return sendItem(item);
|
||||
}
|
||||
|
||||
bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list<PGPID> &proxyPgpIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
@ -1236,8 +1202,7 @@ bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list<PGPID> &prox
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -1253,8 +1218,7 @@ bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version)
|
||||
version = it->second.mVersion;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
@ -1270,7 +1234,28 @@ bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &versio
|
||||
it->second.mVersion = version;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void p3discovery2::recvInvite(
|
||||
std::unique_ptr<RsGossipDiscoveryInviteItem> inviteItem )
|
||||
{
|
||||
typedef RsGossipDiscoveryFriendInviteReceivedEvent Evt_t;
|
||||
|
||||
// Ensure rsEvents is not deleted while we use it
|
||||
std::shared_ptr<RsEvents> lockedRsEvents = rsEvents;
|
||||
if(lockedRsEvents)
|
||||
lockedRsEvents->postEvent(
|
||||
std::unique_ptr<Evt_t>(new Evt_t(inviteItem->mInvite)) );
|
||||
}
|
||||
|
||||
void p3discovery2::rsEventsHandler(const RsEvent& event)
|
||||
{
|
||||
switch(event.mType)
|
||||
{
|
||||
// TODO: When an SSL-only friend become online requestInvite(...)
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************************/
|
||||
/* AuthGPGService */
|
||||
@ -1344,3 +1329,7 @@ void p3discovery2::setGPGOperation(AuthGPGOperation *operation)
|
||||
/* ignore other operations */
|
||||
}
|
||||
|
||||
RsGossipDiscoveryFriendInviteReceivedEvent::
|
||||
RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) :
|
||||
RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED),
|
||||
mInvite(invite) {}
|
@ -1,9 +1,10 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/services: p3discovery2.h *
|
||||
* RetroShare gossip discovery service implementation *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2004-2013 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2004-2013 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -19,65 +20,58 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef MRK_SERVICES_DISCOVERY2_H
|
||||
#define MRK_SERVICES_DISCOVERY2_H
|
||||
#pragma once
|
||||
|
||||
// Discovery2: Improved discovery service.
|
||||
|
||||
#include "retroshare/rsdisc.h"
|
||||
#include <memory>
|
||||
|
||||
#include "retroshare/rsgossipdiscovery.h"
|
||||
#include "pqi/p3peermgr.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
|
||||
#include "pqi/pqiservicemonitor.h"
|
||||
#include "rsitems/rsdiscovery2items.h"
|
||||
#include "gossipdiscovery/gossipdiscoveryitems.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/authgpg.h"
|
||||
#include "gxs/rsgixs.h"
|
||||
|
||||
class p3ServiceControl;
|
||||
|
||||
using PGPID RS_DEPRECATED_FOR(RsPgpId) = RsPgpId;
|
||||
using SSLID RS_DEPRECATED_FOR(RsPeerId) = RsPeerId;
|
||||
|
||||
typedef RsPgpId PGPID;
|
||||
typedef RsPeerId SSLID;
|
||||
|
||||
class DiscSslInfo
|
||||
struct DiscSslInfo
|
||||
{
|
||||
public:
|
||||
DiscSslInfo() { mDiscStatus = 0; }
|
||||
DiscSslInfo() : mDiscStatus(0) {}
|
||||
uint16_t mDiscStatus;
|
||||
};
|
||||
|
||||
class DiscPeerInfo
|
||||
struct DiscPeerInfo
|
||||
{
|
||||
public:
|
||||
DiscPeerInfo() {}
|
||||
|
||||
std::string mVersion;
|
||||
//uint32_t mStatus;
|
||||
};
|
||||
|
||||
class DiscPgpInfo
|
||||
struct DiscPgpInfo
|
||||
{
|
||||
public:
|
||||
DiscPgpInfo() {}
|
||||
|
||||
void mergeFriendList(const std::set<PGPID> &friends);
|
||||
void mergeFriendList(const std::set<PGPID> &friends);
|
||||
|
||||
//PGPID mPgpId;
|
||||
std::set<PGPID> mFriendSet;
|
||||
std::map<SSLID, DiscSslInfo> mSslIds;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class p3discovery2: public RsDisc, public p3Service, public pqiServiceMonitor, public AuthGPGService
|
||||
class p3discovery2 :
|
||||
public RsGossipDiscovery, public p3Service, public pqiServiceMonitor,
|
||||
public AuthGPGService
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc,RsGixs *gixs);
|
||||
virtual ~p3discovery2();
|
||||
p3discovery2( p3PeerMgr* peerMgr, p3LinkMgr* linkMgr, p3NetMgr* netMgr,
|
||||
p3ServiceControl* sc, RsGixs* gixs );
|
||||
virtual ~p3discovery2();
|
||||
|
||||
virtual RsServiceInfo getServiceInfo();
|
||||
|
||||
@ -92,12 +86,25 @@ virtual RsServiceInfo getServiceInfo();
|
||||
bool getDiscPgpFriends(const RsPgpId &pgpid, std::list<RsPgpId> &gpg_friends);
|
||||
bool getPeerVersion(const RsPeerId &id, std::string &version);
|
||||
bool getWaitingDiscCount(size_t &sendCount, size_t &recvCount);
|
||||
|
||||
/// @see RsGossipDiscovery
|
||||
bool sendInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsGossipDiscovery
|
||||
bool requestInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& errorMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/************* from AuthGPService ****************/
|
||||
virtual AuthGPGOperation *getGPGOperation();
|
||||
virtual void setGPGOperation(AuthGPGOperation *operation);
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
PGPID getPGPId(const SSLID &id);
|
||||
|
||||
@ -119,20 +126,27 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
|
||||
void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info);
|
||||
|
||||
void requestPGPCertificate(const PGPID &aboutId, const SSLID &toId);
|
||||
void recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item);
|
||||
|
||||
void recvPGPCertificateRequest(
|
||||
const RsPeerId& 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);
|
||||
|
||||
private:
|
||||
void recvInvite(std::unique_ptr<RsGossipDiscoveryInviteItem> inviteItem);
|
||||
|
||||
void rsEventsHandler(const RsEvent& event);
|
||||
RsEventsHandlerId_t mRsEventsHandle;
|
||||
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
p3LinkMgr *mLinkMgr;
|
||||
p3NetMgr *mNetMgr;
|
||||
p3ServiceControl *mServiceCtrl;
|
||||
RsGixs *mGixs ;
|
||||
RsGixs* mGixs;
|
||||
|
||||
/* data */
|
||||
RsMutex mDiscMtx;
|
||||
@ -147,7 +161,7 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
|
||||
|
||||
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertInList;
|
||||
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertOutList;
|
||||
|
||||
protected:
|
||||
RS_SET_CONTEXT_DEBUG_LEVEL(1)
|
||||
};
|
||||
|
||||
|
||||
#endif // MRK_SERVICES_DISCOVERY2_H
|
@ -134,6 +134,7 @@ SOURCES += tcponudp/udppeer.cc \
|
||||
|
||||
|
||||
PUBLIC_HEADERS = retroshare/rsdisc.h \
|
||||
retroshare/rsgossipdiscovery \
|
||||
retroshare/rsevents.h \
|
||||
retroshare/rsexpr.h \
|
||||
retroshare/rsfiles.h \
|
||||
@ -452,7 +453,7 @@ HEADERS += rsitems/rsitem.h \
|
||||
serialiser/rstlvbanlist.h \
|
||||
rsitems/rsbanlistitems.h \
|
||||
rsitems/rsbwctrlitems.h \
|
||||
rsitems/rsdiscovery2items.h \
|
||||
gossipdiscovery/gossipdiscoveryitems.h \
|
||||
rsitems/rsheartbeatitems.h \
|
||||
rsitems/rsrttitems.h \
|
||||
rsitems/rsgxsrecognitems.h \
|
||||
@ -466,8 +467,8 @@ HEADERS += services/autoproxy/p3i2pbob.h \
|
||||
services/p3service.h \
|
||||
services/p3statusservice.h \
|
||||
services/p3banlist.h \
|
||||
services/p3bwctrl.h \
|
||||
services/p3discovery2.h \
|
||||
services/p3bwctrl.h \
|
||||
gossipdiscovery/p3gossipdiscovery.h \
|
||||
services/p3heartbeat.h \
|
||||
services/p3rtt.h \
|
||||
services/p3serviceinfo.h \
|
||||
@ -603,7 +604,7 @@ SOURCES += serialiser/rsbaseserial.cc \
|
||||
serialiser/rstlvbanlist.cc \
|
||||
rsitems/rsbanlistitems.cc \
|
||||
rsitems/rsbwctrlitems.cc \
|
||||
rsitems/rsdiscovery2items.cc \
|
||||
gossipdiscovery/gossipdiscoveryitems.cc \
|
||||
rsitems/rsrttitems.cc \
|
||||
rsitems/rsgxsrecognitems.cc \
|
||||
rsitems/rsgxsupdateitems.cc \
|
||||
@ -618,7 +619,7 @@ SOURCES += services/autoproxy/rsautoproxymonitor.cc \
|
||||
services/p3statusservice.cc \
|
||||
services/p3banlist.cc \
|
||||
services/p3bwctrl.cc \
|
||||
services/p3discovery2.cc \
|
||||
gossipdiscovery/p3gossipdiscovery.cc \
|
||||
services/p3heartbeat.cc \
|
||||
services/p3rtt.cc \
|
||||
services/p3serviceinfo.cc \
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsdht.h *
|
||||
* RetroShare gossip discovery - discovery2 retro-compatibility include *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2008-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -19,66 +19,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
#define RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <retroshare/rstypes.h>
|
||||
#include "retroshare/rsgossipdiscovery.h"
|
||||
#include "util/rsdeprecate.h"
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsDisc;
|
||||
#warning "Including retroshare/rsdisc.h is deprecated, \
|
||||
use retroshare/rsgossipdiscovery.h instead"
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsDisc service implementation
|
||||
* @jsonapi{development}
|
||||
*/
|
||||
extern RsDisc *rsDisc;
|
||||
using RsDisc RS_DEPRECATED_FOR("RsGossipDiscovery") = RsGossipDiscovery;
|
||||
|
||||
class RsDisc
|
||||
{
|
||||
public:
|
||||
|
||||
RsDisc() {}
|
||||
virtual ~RsDisc() {}
|
||||
|
||||
/**
|
||||
* @brief getDiscFriends get a list with all friends (ssl id) to a given friend (ssl id)
|
||||
* @jsonapi{development}
|
||||
* @param[in] id peer to get the friends of
|
||||
* @param[out] friends list of friends (ssl id)
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getDiscFriends(const RsPeerId &id, std::list<RsPeerId>& friends) = 0;
|
||||
|
||||
/**
|
||||
* @brief getDiscPgpFriends get a list with all friends (pgp id) to a given friend (pgp id)
|
||||
* @jsonapi{development}
|
||||
* @param[in] pgpid peer to get the friends of
|
||||
* @param[out] gpg_friends list of friends (gpg id)
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getDiscPgpFriends(const RsPgpId &pgpid, std::list<RsPgpId>& gpg_friends) = 0;
|
||||
|
||||
/**
|
||||
* @brief getPeerVersion get the version string of a peer.
|
||||
* @jsonapi{development}
|
||||
* @param[in] id peer to get the version string of
|
||||
* @param[out] versions version string sent by the peer
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getPeerVersion(const RsPeerId &id, std::string &versions) = 0;
|
||||
|
||||
/**
|
||||
* @brief getWaitingDiscCount get the number of queued discovery packets.
|
||||
* @jsonapi{development}
|
||||
* @param[out] sendCount number of queued outgoing packets
|
||||
* @param[out] recvCount number of queued incoming packets
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getWaitingDiscCount(size_t &sendCount, size_t &recvCount) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
#define rsDisc rsGossipDiscovery.get()
|
||||
|
@ -52,7 +52,7 @@ enum class RsEventType : uint32_t
|
||||
BROADCAST_DISCOVERY_PEER_FOUND = 1,
|
||||
|
||||
/// @see RsDiscPendingPgpReceivedEvent
|
||||
GOSSIP_DISCOVERY_PENDIG_PGP_CERT_RECEIVED = 2,
|
||||
GOSSIP_DISCOVERY_INVITE_RECEIVED = 2,
|
||||
|
||||
/// @see AuthSSL
|
||||
AUTHSSL_CONNECTION_AUTENTICATION = 3,
|
||||
|
134
libretroshare/src/retroshare/rsgossipdiscovery.h
Normal file
134
libretroshare/src/retroshare/rsgossipdiscovery.h
Normal file
@ -0,0 +1,134 @@
|
||||
/*******************************************************************************
|
||||
* RetroShare remote peers gossip discovery *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2008 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "retroshare/rsevents.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
class RsGossipDiscovery;
|
||||
|
||||
/**
|
||||
* Pointer to global instance of RsGossipDiscovery service implementation
|
||||
* @jsonapi{development}
|
||||
*
|
||||
* TODO: this should become std::weak_ptr once we have a reasonable services
|
||||
* management.
|
||||
*/
|
||||
extern std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery;
|
||||
|
||||
/**
|
||||
* @brief Emitted when a pending PGP certificate is received
|
||||
*/
|
||||
struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent
|
||||
{
|
||||
RsGossipDiscoveryFriendInviteReceivedEvent(
|
||||
const std::string& invite );
|
||||
|
||||
std::string mInvite;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{
|
||||
RsEvent::serial_process(j,ctx);
|
||||
RS_SERIAL_PROCESS(mInvite);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGossipDiscovery
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief getDiscFriends get a list of all friends of a given friend
|
||||
* @jsonapi{development}
|
||||
* @param[in] id peer to get the friends of
|
||||
* @param[out] friends list of friends (ssl id)
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getDiscFriends( const RsPeerId& id,
|
||||
std::list<RsPeerId>& friends ) = 0;
|
||||
|
||||
/**
|
||||
* @brief getDiscPgpFriends get a list of all friends of a given friend
|
||||
* @jsonapi{development}
|
||||
* @param[in] pgpid peer to get the friends of
|
||||
* @param[out] gpg_friends list of friends (gpg id)
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getDiscPgpFriends(
|
||||
const RsPgpId& pgpid, std::list<RsPgpId>& gpg_friends ) = 0;
|
||||
|
||||
/**
|
||||
* @brief getPeerVersion get the version string of a peer.
|
||||
* @jsonapi{development}
|
||||
* @param[in] id peer to get the version string of
|
||||
* @param[out] version version string sent by the peer
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getPeerVersion(const RsPeerId& id, std::string& version) = 0;
|
||||
|
||||
/**
|
||||
* @brief getWaitingDiscCount get the number of queued discovery packets.
|
||||
* @jsonapi{development}
|
||||
* @param[out] sendCount number of queued outgoing packets
|
||||
* @param[out] recvCount number of queued incoming packets
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getWaitingDiscCount(size_t& sendCount, size_t& recvCount) = 0;
|
||||
|
||||
/**
|
||||
* @brief Send RetroShare invite to given peer
|
||||
* @jsonapi{development}
|
||||
* @param[in] inviteId id of peer of which send the invite
|
||||
* @param[in] toSslId ssl id of the destination peer
|
||||
* @param[out] errorMessage Optional storage for the error message,
|
||||
* meaningful only on failure.
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool sendInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Request RetroShare certificate to given peer
|
||||
* @jsonapi{development}
|
||||
* @param[in] inviteId id of the peer of which request the invite
|
||||
* @param[in] toSslId id of the destination of the request
|
||||
* @param[out] errorMessage Optional storage for the error message,
|
||||
* meaningful only on failure.
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool requestInvite(
|
||||
const RsPeerId& inviteId, const RsPeerId& toSslId,
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
virtual ~RsGossipDiscovery();
|
||||
};
|
@ -30,6 +30,7 @@
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "retroshare/rsversion.h"
|
||||
#include "util/rsinitedptr.h"
|
||||
#include "retroshare/rsdisc.h"
|
||||
|
||||
class RsPluginHandler ;
|
||||
extern RsPluginHandler *rsPlugins ;
|
||||
@ -40,7 +41,6 @@ class RsReputations ;
|
||||
class RsTurtle ;
|
||||
class RsGxsTunnelService ;
|
||||
class RsDht ;
|
||||
class RsDisc ;
|
||||
class RsMsgs ;
|
||||
class RsGxsForums;
|
||||
class RsGxsChannels;
|
||||
|
@ -1,195 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/rsitems: rsdiscitems.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2004-2008 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RS_DISC_ITEMS_H
|
||||
#define RS_DISC_ITEMS_H
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rstlvaddrs.h"
|
||||
#include "rsitems/rsserviceids.h"
|
||||
#include "rsitems/rsitem.h"
|
||||
#include "rsitems/itempriorities.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01;
|
||||
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
|
||||
{
|
||||
protected:
|
||||
RsDiscItem(uint8_t subtype) :RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DISC, subtype) {}
|
||||
};
|
||||
|
||||
|
||||
#define DISC_PGP_LIST_MODE_NONE 0x00
|
||||
#define DISC_PGP_LIST_MODE_FRIENDS 0x01
|
||||
#define DISC_PGP_LIST_MODE_GETCERT 0x02
|
||||
|
||||
class RsDiscPgpListItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpListItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_LIST)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_LIST);
|
||||
}
|
||||
|
||||
virtual ~RsDiscPgpListItem(){}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
uint32_t mode;
|
||||
RsTlvPgpIdSet pgpIdSet;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsDiscPgpCertItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscPgpCertItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_PGP_CERT)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_PGP_CERT);
|
||||
}
|
||||
|
||||
virtual ~RsDiscPgpCertItem(){}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
std::string pgpCert;
|
||||
};
|
||||
|
||||
|
||||
class RsDiscContactItem: public RsDiscItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscContactItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_CONTACT)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_CONTACT);
|
||||
}
|
||||
|
||||
virtual ~RsDiscContactItem() {}
|
||||
|
||||
virtual void clear();
|
||||
virtual void serial_process(RsGenericSerializer::SerializeJob /* j */,RsGenericSerializer::SerializeContext& /* ctx */);
|
||||
|
||||
RsPgpId pgpId;
|
||||
RsPeerId sslId;
|
||||
|
||||
// COMMON
|
||||
std::string location;
|
||||
std::string version;
|
||||
|
||||
uint32_t netMode; /* Mandatory */
|
||||
uint16_t vs_disc; /* Mandatory */
|
||||
uint16_t vs_dht; /* Mandatory */
|
||||
uint32_t lastContact;
|
||||
|
||||
bool isHidden; /* not serialised */
|
||||
|
||||
// HIDDEN.
|
||||
std::string hiddenAddr;
|
||||
uint16_t hiddenPort;
|
||||
|
||||
// STANDARD.
|
||||
|
||||
RsTlvIpAddress currentConnectAddress ; // used to check!
|
||||
|
||||
RsTlvIpAddress localAddrV4; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV4; /* Mandatory */
|
||||
|
||||
RsTlvIpAddress localAddrV6; /* Mandatory */
|
||||
RsTlvIpAddress extAddrV6; /* Mandatory */
|
||||
|
||||
std::string dyndns;
|
||||
|
||||
RsTlvIpAddrSet localAddrList;
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
||||
RsDiscServicesItem()
|
||||
:RsDiscItem(RS_PKT_SUBTYPE_DISC_SERVICES)
|
||||
{
|
||||
setPriorityLevel(QOS_PRIORITY_RS_DISC_SERVICES);
|
||||
}
|
||||
|
||||
virtual ~RsDiscServicesItem();
|
||||
|
||||
virtual void clear();
|
||||
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
std::string version;
|
||||
RsTlvServiceIdMap mServiceIdMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
class RsDiscSerialiser: public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
RsDiscSerialiser() :RsServiceSerializer(RS_SERVICE_TYPE_DISC) {}
|
||||
|
||||
virtual ~RsDiscSerialiser() {}
|
||||
|
||||
RsItem *create_item(uint16_t service,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
|
||||
#endif // RS_DISC_ITEMS_H
|
||||
|
@ -745,7 +745,7 @@ RsGRouter *rsGRouter = NULL ;
|
||||
#include "services/p3gxsreputation.h"
|
||||
#include "services/p3serviceinfo.h"
|
||||
#include "services/p3heartbeat.h"
|
||||
#include "services/p3discovery2.h"
|
||||
#include "gossipdiscovery/p3gossipdiscovery.h"
|
||||
#include "services/p3msgservice.h"
|
||||
#include "services/p3statusservice.h"
|
||||
|
||||
@ -1484,7 +1484,7 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
mGxsNetTunnel->connectToTurtleRouter(tr) ;
|
||||
|
||||
rsDisc = mDisc;
|
||||
rsGossipDiscovery.reset(mDisc);
|
||||
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
||||
|
||||
// connect components to turtle router.
|
||||
|
Loading…
Reference in New Issue
Block a user