Merge pull request #1554 from G10h4ck/rsgossipdiscovery

Gossip discovery refinement
This commit is contained in:
csoler 2019-05-06 22:59:34 +02:00 committed by GitHub
commit cc47ee72f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 590 additions and 503 deletions

View File

@ -1,9 +1,10 @@
/******************************************************************************* /*******************************************************************************
* libretroshare/src/rsitems: rsdiscitems.cc * * Gossip discovery service items *
* * * *
* libretroshare: retroshare core library * * 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 * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * 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/>. * * 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/rsbaseserial.h"
#include "serialiser/rstypeserializer.h" #include "serialiser/rstypeserializer.h"
#include "serialiser/rsserializable.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 <iostream> #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) if(service != RS_SERVICE_TYPE_DISC) return nullptr;
return NULL ;
switch(item_subtype) switch(static_cast<RsGossipDiscoveryItemType>(item_subtype))
{ {
case RS_PKT_SUBTYPE_DISC_PGP_LIST : return new RsDiscPgpListItem() ; //= 0x01; case RsGossipDiscoveryItemType::PGP_LIST: return new RsDiscPgpListItem();
case RS_PKT_SUBTYPE_DISC_PGP_CERT : return new RsDiscPgpCertItem() ; //= 0x02; case RsGossipDiscoveryItemType::PGP_CERT: return new RsDiscPgpCertItem();
case RS_PKT_SUBTYPE_DISC_CONTACT_deprecated : return NULL ; //= 0x03; case RsGossipDiscoveryItemType::CONTACT: return new RsDiscContactItem();
#if 0 case RsGossipDiscoveryItemType::IDENTITY_LIST:
case RS_PKT_SUBTYPE_DISC_SERVICES : return new RsDiscServicesItem(); //= 0x04; return new RsDiscIdentityListItem();
#endif case RsGossipDiscoveryItemType::INVITE:
case RS_PKT_SUBTYPE_DISC_CONTACT : return new RsDiscContactItem(); //= 0x05; return new RsGossipDiscoveryInviteItem();
case RS_PKT_SUBTYPE_DISC_IDENTITY_LIST : return new RsDiscIdentityListItem(); //= 0x06; case RsGossipDiscoveryItemType::INVITE_REQUEST:
default: return new RsGossipDiscoveryInviteRequestItem();
return NULL ; }
}
return nullptr;
} }
/*************************************************************************/ /*************************************************************************/
void RsDiscPgpListItem::clear() void RsDiscPgpListItem::clear()
{ {
mode = DISC_PGP_LIST_MODE_NONE; mode = RsGossipDiscoveryPgpListMode::NONE;
pgpIdSet.TlvClear(); 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") ; RS_SERIAL_PROCESS(mode);
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,pgpIdSet,"pgpIdSet") ; RS_SERIAL_PROCESS(pgpIdSet);
} }
void RsDiscPgpCertItem::clear() void RsDiscPgpCertItem::clear()
@ -156,3 +146,17 @@ void RsDiscIdentityListItem::serial_process(RsGenericSerializer::SerializeJob j,
RS_SERIAL_PROCESS(ownIdentityList); 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() {}

View 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;
};

View File

@ -1,10 +1,10 @@
/******************************************************************************* /*******************************************************************************
* libretroshare/src/services: p3discovery2.cc * * RetroShare gossip discovery service implementation *
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2004-2013 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2004-2013 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> * * Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * 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/>. * * 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 "pqi/p3peermgr.h"
#include "retroshare/rsversion.h" #include "retroshare/rsversion.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "util/rsdebug.h"
// Interface pointer.
RsDisc *rsDisc = NULL;
/**** /****
* #define P3DISC_DEBUG 1 * #define P3DISC_DEBUG 1
****/ ****/
/*extern*/ std::shared_ptr<RsGossipDiscovery> rsGossipDiscovery(nullptr);
RsGossipDiscovery::~RsGossipDiscovery() {};
static bool populateContactInfo( const peerState &detail, static bool populateContactInfo( const peerState &detail,
RsDiscContactItem *pkt, RsDiscContactItem *pkt,
bool include_ip_information ) bool include_ip_information )
@ -48,8 +50,8 @@ static bool populateContactInfo( const peerState &detail,
pkt->netMode = detail.netMode; pkt->netMode = detail.netMode;
pkt->vs_disc = detail.vs_disc; pkt->vs_disc = detail.vs_disc;
pkt->vs_dht = detail.vs_dht; pkt->vs_dht = detail.vs_dht;
pkt->lastContact = time(NULL); pkt->lastContact = time(nullptr);
if (detail.hiddenNode) 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) p3discovery2::p3discovery2(
:p3Service(), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr), mServiceCtrl(sc), mGixs(gixs),mDiscMtx("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()); addSerialType(new RsDiscSerialiser());
#ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::p3discovery2()";
std::cerr << std::endl;
#endif
mLastPgpUpdate = 0;
// Add self into PGP FriendList. // Add self into PGP FriendList.
mFriendList[AuthGPG::getAuthGPG()->getGPGOwnId()] = DiscPgpInfo(); 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); DISCOVERY_MIN_MINOR_VERSION);
} }
p3discovery2::~p3discovery2() p3discovery2::~p3discovery2()
{ { rsEvents->unregisterEventsHandler(mRsEventsHandle); }
return;
}
void p3discovery2::addFriend(const SSLID &sslId) void p3discovery2::addFriend(const SSLID &sslId)
{ {
@ -243,7 +235,6 @@ void p3discovery2::removeFriend(const SSLID &sslId)
} }
} }
PGPID p3discovery2::getPGPId(const SSLID &id) PGPID p3discovery2::getPGPId(const SSLID &id)
{ {
PGPID pgpId; PGPID pgpId;
@ -251,7 +242,6 @@ PGPID p3discovery2::getPGPId(const SSLID &id)
return pgpId; return pgpId;
} }
int p3discovery2::tick() int p3discovery2::tick()
{ {
return handleIncoming(); return handleIncoming();
@ -259,62 +249,60 @@ int p3discovery2::tick()
int p3discovery2::handleIncoming() int p3discovery2::handleIncoming()
{ {
RsItem *item = NULL; RsItem* item = nullptr;
int nhandled = 0; int nhandled = 0;
// While messages read // While messages read
while(nullptr != (item = recvItem())) while(nullptr != (item = recvItem()))
{ {
RsDiscPgpListItem *pgplist = nullptr; RsDiscPgpListItem* pgplist = nullptr;
RsDiscPgpCertItem *pgpcert = nullptr; RsDiscPgpCertItem* pgpcert = nullptr;
RsDiscContactItem *contact = nullptr; RsDiscContactItem* contact = nullptr;
RsDiscIdentityListItem *gxsidlst = nullptr; RsDiscIdentityListItem* gxsidlst = nullptr;
nhandled++; RsGossipDiscoveryInviteItem* invite = nullptr;
RsGossipDiscoveryInviteRequestItem* inviteReq = nullptr;
#ifdef P3DISC_DEBUG ++nhandled;
std::cerr << "p3discovery2::handleIncoming() Received Message!" << std::endl;
item -> print(std::cerr);
std::cerr << std::endl;
#endif
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); recvOwnContactInfo(item->PeerId(), contact);
else else processContactInfo(item->PeerId(), contact);
processContactInfo(item->PeerId(), contact);
} }
else if (nullptr != (gxsidlst = dynamic_cast<RsDiscIdentityListItem *> (item))) else if( (gxsidlst = dynamic_cast<RsDiscIdentityListItem *>(item))
{ != nullptr )
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)))
{ {
/* two types */ recvIdentityList(item->PeerId(),gxsidlst->ownIdentityList);
if (pgplist->mode == DISC_PGP_LIST_MODE_FRIENDS) 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); processPGPList(pgplist->PeerId(), pgplist);
else if (pgplist->mode == RsGossipDiscoveryPgpListMode::GETCERT)
}
else if (pgplist->mode == DISC_PGP_LIST_MODE_GETCERT)
{
recvPGPCertificateRequest(pgplist->PeerId(), pgplist); recvPGPCertificateRequest(pgplist->PeerId(), pgplist);
} else delete item;
else }
{ else if( (invite = dynamic_cast<RsGossipDiscoveryInviteItem*>(item))
delete item ; != nullptr )
} recvInvite(std::unique_ptr<RsGossipDiscoveryInviteItem>(invite));
else if( (inviteReq =
dynamic_cast<RsGossipDiscoveryInviteRequestItem*>(item))
!= nullptr )
{
sendInvite(inviteReq->mInviteId, item->PeerId());
delete item;
} }
else else
{ {
#ifdef P3DISC_DEBUG RsWarn() << __PRETTY_FUNCTION__ << " Received unknown item type! "
std::cerr << "p3discovery2::handleIncoming() Unknown Received Message!" << std::endl; << std::endl << item << std::endl;
item -> print(std::cerr);
std::cerr << std::endl;
#endif
delete item; delete item;
} }
} }
@ -322,8 +310,6 @@ int p3discovery2::handleIncoming()
return nhandled; return nhandled;
} }
void p3discovery2::sendOwnContactInfo(const SSLID &sslid) 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) 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) void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
{ {
if (item->isHidden) if (item->isHidden)
@ -512,7 +496,6 @@ void p3discovery2::updatePeerAddressList(const RsDiscContactItem *item)
} }
} }
// Starts the Discovery process. // Starts the Discovery process.
// should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status). // should only be called it DISC2_STATUS_NOT_HIDDEN(OwnInfo.status).
void p3discovery2::sendPGPList(const SSLID &toId) void p3discovery2::sendPGPList(const SSLID &toId)
@ -528,7 +511,7 @@ void p3discovery2::sendPGPList(const SSLID &toId)
RsDiscPgpListItem *pkt = new RsDiscPgpListItem(); RsDiscPgpListItem *pkt = new RsDiscPgpListItem();
pkt->mode = DISC_PGP_LIST_MODE_FRIENDS; pkt->mode = RsGossipDiscoveryPgpListMode::FRIENDS;
std::map<PGPID, DiscPgpInfo>::const_iterator it; std::map<PGPID, DiscPgpInfo>::const_iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); ++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) void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *item)
{ {
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -666,7 +646,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *
#endif #endif
std::map<PGPID, DiscPgpInfo>::iterator it; std::map<PGPID, DiscPgpInfo>::iterator it;
PGPID fromPgpId = getPGPId(fromId); PGPID fromPgpId = getPGPId(fromId);
it = mFriendList.find(fromPgpId); it = mFriendList.find(fromPgpId);
if (it == mFriendList.end()) if (it == mFriendList.end())
{ {
@ -699,7 +679,7 @@ void p3discovery2::processPGPList(const SSLID &fromId, const RsDiscPgpListItem *
if (requestUnknownPgpCerts) 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) for(fit = item->pgpIdSet.ids.begin(); fit != item->pgpIdSet.ids.end(); ++fit)
{ {
if (!AuthGPG::getAuthGPG()->isGPGId(*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) void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toId)
{ {
#ifdef P3DISC_DEBUG #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 p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactItem *item)
{ {
(void) fromId; // remove unused parameter warnings, debug only (void) fromId; // remove unused parameter warnings, debug only
@ -1001,8 +979,6 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt
delete item; delete item;
} }
/* we explictly request certificates, instead of getting them all the time /* we explictly request certificates, instead of getting them all the time
*/ */
void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId) 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(); RsDiscPgpListItem *pkt = new RsDiscPgpListItem();
pkt->mode = DISC_PGP_LIST_MODE_GETCERT; pkt->mode = RsGossipDiscoveryPgpListMode::GETCERT;
pkt->pgpIdSet.ids.insert(aboutId); pkt->pgpIdSet.ids.insert(aboutId);
pkt->PeerId(toId); pkt->PeerId(toId);
@ -1027,93 +1003,46 @@ void p3discovery2::requestPGPCertificate(const PGPID &aboutId, const SSLID &toId
sendItem(pkt); sendItem(pkt);
} }
/* comment */ void p3discovery2::recvPGPCertificateRequest(
void p3discovery2::recvPGPCertificateRequest(const SSLID &fromId, const RsDiscPgpListItem *item) const RsPeerId& fromId, const RsDiscPgpListItem* item )
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::recvPPGPCertificateRequest() from " << fromId; std::cerr << __PRETTY_FUNCTION__ << " from " << fromId << std::endl;
std::cerr << std::endl;
#endif #endif
std::set<RsPgpId>::const_iterator it; RsPgpId ownPgpId = AuthGPG::getAuthGPG()->getGPGOwnId();
for(it = item->pgpIdSet.ids.begin(); it != item->pgpIdSet.ids.end(); ++it) for(const RsPgpId& pgpId : item->pgpIdSet.ids)
{ if (pgpId == ownPgpId || AuthGPG::getAuthGPG()->isGPGAccepted(pgpId))
// NB: This doesn't include own certificates? why not. sendPGPCertificate(pgpId, fromId);
// shouldn't be a real problem. Peer must have own PgpCert already.
if (AuthGPG::getAuthGPG()->isGPGAccepted(*it))
{
sendPGPCertificate(*it, fromId);
}
}
delete item; delete item;
} }
void p3discovery2::sendPGPCertificate(const PGPID &aboutId, const SSLID &toId) void p3discovery2::sendPGPCertificate(const PGPID &aboutId, const SSLID &toId)
{ {
RsDiscPgpCertItem* item = new RsDiscPgpCertItem();
/* 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();
item->pgpId = aboutId; item->pgpId = aboutId;
item->PeerId(toId); 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 ******/ Dbg4() << __PRETTY_FUNCTION__ << " queuing for Cert generation: "
/* queue it! */ << std::endl << *item << std::endl;
mPendingDiscPgpCertOutList.push_back(item); {
RS_STACK_MUTEX(mDiscMtx);
mPendingDiscPgpCertOutList.push_back(item);
}
} }
void p3discovery2::recvPGPCertificate(
void p3discovery2::recvPGPCertificate(const SSLID &/*fromId*/, RsDiscPgpCertItem *item) const SSLID& /*fromId*/, RsDiscPgpCertItem* item )
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3discovery2::recvPGPCertificate() queuing for Cert loading" << std::endl; std::cerr << __PRETTY_FUNCTION__ << " queuing for Cert loading" << std::endl;
std::cerr << std::endl;
#endif #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 */ /* push this back to be processed by pgp when possible */
RS_STACK_MUTEX(mDiscMtx);
mPendingDiscPgpCertInList.push_back(item); mPendingDiscPgpCertInList.push_back(item);
} }
/************* from pqiServiceMonitor *******************/ /************* from pqiServiceMonitor *******************/
void p3discovery2::statusChange(const std::list<pqiServicePeer> &plist) void p3discovery2::statusChange(const std::list<pqiServicePeer> &plist)
@ -1210,8 +1139,45 @@ bool p3discovery2::getWaitingDiscCount(size_t &sendCount, size_t &recvCount)
return true; 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) bool p3discovery2::getDiscPgpFriends(const PGPID &pgp_id, std::list<PGPID> &proxyPgpIds)
{ {
/* find id -> and extract the neighbour_of ids */ /* 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; return true;
} }
bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version) bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version)
{ {
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -1253,8 +1218,7 @@ bool p3discovery2::getPeerVersion(const SSLID &peerId, std::string &version)
version = it->second.mVersion; version = it->second.mVersion;
return true; return true;
} }
bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version) bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &version)
{ {
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -1270,7 +1234,28 @@ bool p3discovery2::setPeerVersion(const SSLID &peerId, const std::string &versio
it->second.mVersion = version; it->second.mVersion = version;
return true; 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 */ /* AuthGPGService */
@ -1344,3 +1329,7 @@ void p3discovery2::setGPGOperation(AuthGPGOperation *operation)
/* ignore other operations */ /* ignore other operations */
} }
RsGossipDiscoveryFriendInviteReceivedEvent::
RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) :
RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED),
mInvite(invite) {}

View File

@ -1,9 +1,10 @@
/******************************************************************************* /*******************************************************************************
* libretroshare/src/services: p3discovery2.h * * RetroShare gossip discovery service implementation *
* * * *
* libretroshare: retroshare core library * * 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 * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * 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/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef MRK_SERVICES_DISCOVERY2_H #pragma once
#define MRK_SERVICES_DISCOVERY2_H
// Discovery2: Improved discovery service. #include <memory>
#include "retroshare/rsdisc.h"
#include "retroshare/rsgossipdiscovery.h"
#include "pqi/p3peermgr.h" #include "pqi/p3peermgr.h"
#include "pqi/p3linkmgr.h" #include "pqi/p3linkmgr.h"
#include "pqi/p3netmgr.h" #include "pqi/p3netmgr.h"
#include "pqi/pqiservicemonitor.h" #include "pqi/pqiservicemonitor.h"
#include "rsitems/rsdiscovery2items.h" #include "gossipdiscovery/gossipdiscoveryitems.h"
#include "services/p3service.h" #include "services/p3service.h"
#include "pqi/authgpg.h" #include "pqi/authgpg.h"
#include "gxs/rsgixs.h" #include "gxs/rsgixs.h"
class p3ServiceControl; class p3ServiceControl;
using PGPID RS_DEPRECATED_FOR(RsPgpId) = RsPgpId;
using SSLID RS_DEPRECATED_FOR(RsPeerId) = RsPeerId;
typedef RsPgpId PGPID; struct DiscSslInfo
typedef RsPeerId SSLID;
class DiscSslInfo
{ {
public: DiscSslInfo() : mDiscStatus(0) {}
DiscSslInfo() { mDiscStatus = 0; }
uint16_t mDiscStatus; uint16_t mDiscStatus;
}; };
class DiscPeerInfo struct DiscPeerInfo
{ {
public:
DiscPeerInfo() {} DiscPeerInfo() {}
std::string mVersion; std::string mVersion;
//uint32_t mStatus;
}; };
class DiscPgpInfo struct DiscPgpInfo
{ {
public:
DiscPgpInfo() {} DiscPgpInfo() {}
void mergeFriendList(const std::set<PGPID> &friends); void mergeFriendList(const std::set<PGPID> &friends);
//PGPID mPgpId;
std::set<PGPID> mFriendSet; std::set<PGPID> mFriendSet;
std::map<SSLID, DiscSslInfo> mSslIds; std::map<SSLID, DiscSslInfo> mSslIds;
}; };
class p3discovery2 :
class p3discovery2: public RsDisc, public p3Service, public pqiServiceMonitor, public AuthGPGService public RsGossipDiscovery, public p3Service, public pqiServiceMonitor,
public AuthGPGService
{ {
public: public:
p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr, p3ServiceControl *sc,RsGixs *gixs); p3discovery2( p3PeerMgr* peerMgr, p3LinkMgr* linkMgr, p3NetMgr* netMgr,
virtual ~p3discovery2(); p3ServiceControl* sc, RsGixs* gixs );
virtual ~p3discovery2();
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
@ -92,12 +86,25 @@ virtual RsServiceInfo getServiceInfo();
bool getDiscPgpFriends(const RsPgpId &pgpid, std::list<RsPgpId> &gpg_friends); bool getDiscPgpFriends(const RsPgpId &pgpid, std::list<RsPgpId> &gpg_friends);
bool getPeerVersion(const RsPeerId &id, std::string &version); bool getPeerVersion(const RsPeerId &id, std::string &version);
bool getWaitingDiscCount(size_t &sendCount, size_t &recvCount); 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 ****************/ /************* from AuthGPService ****************/
virtual AuthGPGOperation *getGPGOperation(); virtual AuthGPGOperation *getGPGOperation();
virtual void setGPGOperation(AuthGPGOperation *operation); virtual void setGPGOperation(AuthGPGOperation *operation);
private: private:
PGPID getPGPId(const SSLID &id); PGPID getPGPId(const SSLID &id);
@ -119,20 +126,27 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info); void processContactInfo(const SSLID &fromId, const RsDiscContactItem *info);
void requestPGPCertificate(const PGPID &aboutId, const SSLID &toId); 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 sendPGPCertificate(const PGPID &aboutId, const SSLID &toId);
void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item); void recvPGPCertificate(const SSLID &fromId, RsDiscPgpCertItem *item);
void recvIdentityList(const RsPeerId& pid,const std::list<RsGxsId>& ids); void recvIdentityList(const RsPeerId& pid,const std::list<RsGxsId>& ids);
bool setPeerVersion(const SSLID &peerId, const std::string &version); 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; p3PeerMgr *mPeerMgr;
p3LinkMgr *mLinkMgr; p3LinkMgr *mLinkMgr;
p3NetMgr *mNetMgr; p3NetMgr *mNetMgr;
p3ServiceControl *mServiceCtrl; p3ServiceControl *mServiceCtrl;
RsGixs *mGixs ; RsGixs* mGixs;
/* data */ /* data */
RsMutex mDiscMtx; RsMutex mDiscMtx;
@ -147,7 +161,7 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertInList; std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertInList;
std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertOutList; std::list<RsDiscPgpCertItem *> mPendingDiscPgpCertOutList;
protected:
RS_SET_CONTEXT_DEBUG_LEVEL(1)
}; };
#endif // MRK_SERVICES_DISCOVERY2_H

View File

@ -134,6 +134,7 @@ SOURCES += tcponudp/udppeer.cc \
PUBLIC_HEADERS = retroshare/rsdisc.h \ PUBLIC_HEADERS = retroshare/rsdisc.h \
retroshare/rsgossipdiscovery \
retroshare/rsevents.h \ retroshare/rsevents.h \
retroshare/rsexpr.h \ retroshare/rsexpr.h \
retroshare/rsfiles.h \ retroshare/rsfiles.h \
@ -452,7 +453,7 @@ HEADERS += rsitems/rsitem.h \
serialiser/rstlvbanlist.h \ serialiser/rstlvbanlist.h \
rsitems/rsbanlistitems.h \ rsitems/rsbanlistitems.h \
rsitems/rsbwctrlitems.h \ rsitems/rsbwctrlitems.h \
rsitems/rsdiscovery2items.h \ gossipdiscovery/gossipdiscoveryitems.h \
rsitems/rsheartbeatitems.h \ rsitems/rsheartbeatitems.h \
rsitems/rsrttitems.h \ rsitems/rsrttitems.h \
rsitems/rsgxsrecognitems.h \ rsitems/rsgxsrecognitems.h \
@ -466,8 +467,8 @@ HEADERS += services/autoproxy/p3i2pbob.h \
services/p3service.h \ services/p3service.h \
services/p3statusservice.h \ services/p3statusservice.h \
services/p3banlist.h \ services/p3banlist.h \
services/p3bwctrl.h \ services/p3bwctrl.h \
services/p3discovery2.h \ gossipdiscovery/p3gossipdiscovery.h \
services/p3heartbeat.h \ services/p3heartbeat.h \
services/p3rtt.h \ services/p3rtt.h \
services/p3serviceinfo.h \ services/p3serviceinfo.h \
@ -603,7 +604,7 @@ SOURCES += serialiser/rsbaseserial.cc \
serialiser/rstlvbanlist.cc \ serialiser/rstlvbanlist.cc \
rsitems/rsbanlistitems.cc \ rsitems/rsbanlistitems.cc \
rsitems/rsbwctrlitems.cc \ rsitems/rsbwctrlitems.cc \
rsitems/rsdiscovery2items.cc \ gossipdiscovery/gossipdiscoveryitems.cc \
rsitems/rsrttitems.cc \ rsitems/rsrttitems.cc \
rsitems/rsgxsrecognitems.cc \ rsitems/rsgxsrecognitems.cc \
rsitems/rsgxsupdateitems.cc \ rsitems/rsgxsupdateitems.cc \
@ -618,7 +619,7 @@ SOURCES += services/autoproxy/rsautoproxymonitor.cc \
services/p3statusservice.cc \ services/p3statusservice.cc \
services/p3banlist.cc \ services/p3banlist.cc \
services/p3bwctrl.cc \ services/p3bwctrl.cc \
services/p3discovery2.cc \ gossipdiscovery/p3gossipdiscovery.cc \
services/p3heartbeat.cc \ services/p3heartbeat.cc \
services/p3rtt.cc \ services/p3rtt.cc \
services/p3serviceinfo.cc \ services/p3serviceinfo.cc \

View File

@ -1,9 +1,9 @@
/******************************************************************************* /*******************************************************************************
* libretroshare/src/retroshare: rsdht.h * * RetroShare gossip discovery - discovery2 retro-compatibility include *
* * * *
* libretroshare: retroshare core library * * 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 * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * 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/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef RETROSHARE_DISC_GUI_INTERFACE_H #pragma once
#define RETROSHARE_DISC_GUI_INTERFACE_H
#include <inttypes.h> #include "retroshare/rsgossipdiscovery.h"
#include <string> #include "util/rsdeprecate.h"
#include <list>
#include <map>
#include <retroshare/rstypes.h>
/* The Main Interface Class - for information about your Peers */ #warning "Including retroshare/rsdisc.h is deprecated, \
class RsDisc; use retroshare/rsgossipdiscovery.h instead"
/** using RsDisc RS_DEPRECATED_FOR("RsGossipDiscovery") = RsGossipDiscovery;
* Pointer to global instance of RsDisc service implementation
* @jsonapi{development}
*/
extern RsDisc *rsDisc;
class RsDisc #define rsDisc rsGossipDiscovery.get()
{
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

View File

@ -52,7 +52,7 @@ enum class RsEventType : uint32_t
BROADCAST_DISCOVERY_PEER_FOUND = 1, BROADCAST_DISCOVERY_PEER_FOUND = 1,
/// @see RsDiscPendingPgpReceivedEvent /// @see RsDiscPendingPgpReceivedEvent
GOSSIP_DISCOVERY_PENDIG_PGP_CERT_RECEIVED = 2, GOSSIP_DISCOVERY_INVITE_RECEIVED = 2,
/// @see AuthSSL /// @see AuthSSL
AUTHSSL_CONNECTION_AUTENTICATION = 3, AUTHSSL_CONNECTION_AUTENTICATION = 3,

View 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();
};

View File

@ -30,6 +30,7 @@
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
#include "retroshare/rsversion.h" #include "retroshare/rsversion.h"
#include "util/rsinitedptr.h" #include "util/rsinitedptr.h"
#include "retroshare/rsdisc.h"
class RsPluginHandler ; class RsPluginHandler ;
extern RsPluginHandler *rsPlugins ; extern RsPluginHandler *rsPlugins ;
@ -40,7 +41,6 @@ class RsReputations ;
class RsTurtle ; class RsTurtle ;
class RsGxsTunnelService ; class RsGxsTunnelService ;
class RsDht ; class RsDht ;
class RsDisc ;
class RsMsgs ; class RsMsgs ;
class RsGxsForums; class RsGxsForums;
class RsGxsChannels; class RsGxsChannels;

View File

@ -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

View File

@ -745,7 +745,7 @@ RsGRouter *rsGRouter = NULL ;
#include "services/p3gxsreputation.h" #include "services/p3gxsreputation.h"
#include "services/p3serviceinfo.h" #include "services/p3serviceinfo.h"
#include "services/p3heartbeat.h" #include "services/p3heartbeat.h"
#include "services/p3discovery2.h" #include "gossipdiscovery/p3gossipdiscovery.h"
#include "services/p3msgservice.h" #include "services/p3msgservice.h"
#include "services/p3statusservice.h" #include "services/p3statusservice.h"
@ -1484,7 +1484,7 @@ int RsServer::StartupRetroShare()
mGxsNetTunnel->connectToTurtleRouter(tr) ; mGxsNetTunnel->connectToTurtleRouter(tr) ;
rsDisc = mDisc; rsGossipDiscovery.reset(mDisc);
rsMsgs = new p3Msgs(msgSrv, chatSrv); rsMsgs = new p3Msgs(msgSrv, chatSrv);
// connect components to turtle router. // connect components to turtle router.