27using namespace swarm_protocol;
29class SwarmManager :
public std::enable_shared_from_this<SwarmManager>
31 using ChannelCb = std::function<
bool(
const std::shared_ptr<dhtnet::ChannelSocketInterface>&)>;
32 using NeedSocketCb = std::function<
void(
const std::string&, ChannelCb&&)>;
33 using ToConnectCb = std::function<
bool(
const NodeId&)>;
34 using OnConnectionChanged = std::function<
void(
bool ok)>;
67 void addChannel(
const std::shared_ptr<dhtnet::ChannelSocketInterface>& channel);
124 JAMI_DEBUG(
"SwarmManager {:s} has {:d} nodes in table [P = {}]",
130 for (
auto& node :
bucket.getNodes()) {
131 JAMI_DEBUG(
"Node {:s}", node.first.toString());
179 bool addKnownNode(
const NodeId& nodeId);
185 void addMobileNodes(
const NodeId& nodeId);
194 void sendRequest(
const std::shared_ptr<dhtnet::ChannelSocketInterface>& socket,
204 void sendAnswer(
const std::shared_ptr<dhtnet::ChannelSocketInterface>& socket,
const Message&
msg_);
210 void receiveMessage(
const std::shared_ptr<dhtnet::ChannelSocketInterface>& socket);
218 void resetNodeExpiry(
const asio::error_code&
ec,
219 const std::shared_ptr<dhtnet::ChannelSocketInterface>& socket,
226 void tryConnect(
const NodeId& nodeId);
232 void removeNodeInternal(
const NodeId& nodeId);
235 bool isMobile_ {
false};
237 mutable std::mutex mutex;
238 RoutingTable routing_table;
240 std::atomic_bool isShutdown_ {
false};
242 OnConnectionChanged onConnectionChanged_ {};
244 ToConnectCb toConnectCb_;
static constexpr int BUCKET_MAX_SIZE
unsigned getRoutingTableNodeCount() const
Returns number of total nodes in routing table.
std::list< Bucket > & getBuckets()
Returns buckets in routing table.
void onConnectionChanged(OnConnectionChanged cb)
bool isMobile() const
Get mobility of swarm manager.
NeedSocketCb needSocketCb_
std::list< Bucket > & getBuckets()
Get buckets of routing table.
bool isConnectedWith(const NodeId &deviceId)
Check if we're connected with a specific device.
void removeNode(const NodeId &nodeId)
Remove channel from routing table.
void deleteNode(std::vector< NodeId > nodes)
Delete nodes from the different tables in bucket.
void shutdown()
Shutdown swarm manager.
bool isShutdown()
Check if swarm manager is shutdown.
void changeMobility(const NodeId &nodeId, bool isMobile)
Change mobility of specific node.
void maintainBuckets(const std::set< NodeId > &toConnect={})
Maintain/Update buckets.
void setMobileNodes(const std::vector< NodeId > &mobile_nodes)
Set list of nodes to the routing table mobile_nodes.
const NodeId & getId() const
Get swarm manager id.
void restart()
Restart the swarm manager.
bool setKnownNodes(const std::vector< NodeId > &known_nodes)
Set list of nodes to the routing table known_nodes.
std::vector< NodeId > getAllNodes() const
get all nodes from the different tables in bucket
void setMobility(bool isMobile)
Set mobility of swarm manager.
void addChannel(const std::shared_ptr< dhtnet::ChannelSocketInterface > &channel)
Add channel to routing table.
std::weak_ptr< SwarmManager > weak()
void display()
Display swarm manager info.
RoutingTable & getRoutingTable()
Get routing table.
#define JAMI_DEBUG(formatstr,...)
void emitSignal(Args... args)