2019-04-12 02:53:39 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* RetroShare Broadcast Domain Discovery *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2019 Gioacchino Mazzurco <gio@altermundi.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
2019-04-14 12:34:01 +02:00
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
2019-04-12 02:53:39 +02:00
|
|
|
* 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 *
|
2019-04-14 12:34:01 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
2019-04-12 02:53:39 +02:00
|
|
|
* *
|
2019-04-14 12:34:01 +02:00
|
|
|
* 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/>. *
|
2019-04-12 02:53:39 +02:00
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "retroshare/rsids.h"
|
|
|
|
#include "retroshare/rstypes.h"
|
|
|
|
#include "serialiser/rsserializable.h"
|
|
|
|
#include "util/rstime.h"
|
|
|
|
#include "util/rsurl.h"
|
|
|
|
#include "util/rsmemory.h"
|
2019-04-15 00:12:29 +02:00
|
|
|
#include "retroshare/rsevents.h"
|
2019-04-12 02:53:39 +02:00
|
|
|
|
|
|
|
class RsBroadcastDiscovery;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pointer to global instance of RsBroadcastDiscovery service implementation
|
|
|
|
* @jsonapi{development}
|
2019-04-15 10:37:21 +02:00
|
|
|
*
|
|
|
|
* TODO: this should become std::weak_ptr once we have a reasonable services
|
|
|
|
* management.
|
2019-04-12 02:53:39 +02:00
|
|
|
*/
|
2019-09-25 16:33:13 +02:00
|
|
|
extern RsBroadcastDiscovery* rsBroadcastDiscovery;
|
2019-04-12 02:53:39 +02:00
|
|
|
|
2019-04-16 17:10:46 +02:00
|
|
|
|
2019-04-12 02:53:39 +02:00
|
|
|
struct RsBroadcastDiscoveryResult : RsSerializable
|
|
|
|
{
|
2019-09-25 16:33:13 +02:00
|
|
|
RsPgpFingerprint mPgpFingerprint;
|
2019-04-12 02:53:39 +02:00
|
|
|
RsPeerId mSslId;
|
|
|
|
std::string mProfileName;
|
2019-05-17 12:07:52 +02:00
|
|
|
RsUrl mLocator;
|
2019-04-12 02:53:39 +02:00
|
|
|
|
2019-04-15 00:12:29 +02:00
|
|
|
/// @see RsSerializable
|
2019-04-12 02:53:39 +02:00
|
|
|
void serial_process( RsGenericSerializer::SerializeJob j,
|
|
|
|
RsGenericSerializer::SerializeContext& ctx) override
|
|
|
|
{
|
2019-09-25 16:33:13 +02:00
|
|
|
RS_SERIAL_PROCESS(mPgpFingerprint);
|
2019-04-12 02:53:39 +02:00
|
|
|
RS_SERIAL_PROCESS(mSslId);
|
|
|
|
RS_SERIAL_PROCESS(mProfileName);
|
2019-05-17 12:07:52 +02:00
|
|
|
RS_SERIAL_PROCESS(mLocator);
|
2019-04-12 02:53:39 +02:00
|
|
|
}
|
2019-04-16 17:02:03 +02:00
|
|
|
|
|
|
|
RsBroadcastDiscoveryResult() = default;
|
|
|
|
RsBroadcastDiscoveryResult (const RsBroadcastDiscoveryResult&) = default;
|
|
|
|
~RsBroadcastDiscoveryResult() override;
|
2019-04-12 02:53:39 +02:00
|
|
|
};
|
|
|
|
|
2019-04-16 17:10:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Event emitted when a non friend new peer is found in the local network
|
|
|
|
* @see RsEvents
|
|
|
|
*/
|
2019-04-15 00:12:29 +02:00
|
|
|
struct RsBroadcastDiscoveryPeerFoundEvent : RsEvent
|
|
|
|
{
|
|
|
|
RsBroadcastDiscoveryPeerFoundEvent(
|
|
|
|
const RsBroadcastDiscoveryResult& eventData ) :
|
|
|
|
RsEvent(RsEventType::BROADCAST_DISCOVERY_PEER_FOUND), mData(eventData) {}
|
|
|
|
|
|
|
|
RsBroadcastDiscoveryResult mData;
|
|
|
|
|
|
|
|
/// @see RsSerializable
|
|
|
|
void serial_process( RsGenericSerializer::SerializeJob j,
|
|
|
|
RsGenericSerializer::SerializeContext& ctx) override
|
|
|
|
{
|
|
|
|
RsEvent::serial_process(j, ctx);
|
|
|
|
RS_SERIAL_PROCESS(mData);
|
|
|
|
}
|
|
|
|
|
2019-04-16 17:02:03 +02:00
|
|
|
~RsBroadcastDiscoveryPeerFoundEvent() override;
|
2019-04-15 00:12:29 +02:00
|
|
|
};
|
|
|
|
|
2019-04-16 17:10:46 +02:00
|
|
|
|
2019-04-15 00:12:29 +02:00
|
|
|
/**
|
|
|
|
* Announce own RetroShare instace and look friends and peers in own broadcast
|
|
|
|
* domain (aka LAN).
|
|
|
|
* Emit event @see RsBroadcastDiscoveryPeerFoundEvent when a new peer (not
|
|
|
|
* friend yet) is found.
|
|
|
|
*/
|
2019-04-12 02:53:39 +02:00
|
|
|
class RsBroadcastDiscovery
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Get potential peers that have been discovered up until now
|
|
|
|
* @jsonapi{development}
|
|
|
|
* @return vector containing discovered peers, may be empty.
|
|
|
|
*/
|
|
|
|
virtual std::vector<RsBroadcastDiscoveryResult> getDiscoveredPeers() = 0;
|
|
|
|
|
2019-04-15 00:12:29 +02:00
|
|
|
virtual ~RsBroadcastDiscovery();
|
2019-04-12 02:53:39 +02:00
|
|
|
};
|