-
Notifications
You must be signed in to change notification settings - Fork 17
/
reflector.h
109 lines (92 loc) · 3.27 KB
/
reflector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// Created by Jean-Luc Deltombe (LX3JL) on 31/10/2015.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2020,2022 Thomas A. Early, N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of M17Refd.
//
// M17Refd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// M17Refd 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// with this software. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#pragma once
#include <unordered_map>
#include "users.h"
#include "clients.h"
#include "peers.h"
#include "protocol.h"
#include "packetstream.h"
#ifndef NO_DHT
#include "dht-values.h"
#endif
class CReflector
{
public:
// constructor
CReflector();
// destructor
virtual ~CReflector();
// operation
bool Start(const char *cfgfilename);
void Stop(void);
// clients
CClients *GetClients(void) { m_Clients.Lock(); return &m_Clients; }
void ReleaseClients(void) { m_Clients.Unlock(); }
// peers
CPeers *GetPeers(void) { m_Peers.Lock(); return &m_Peers; }
void ReleasePeers(void) { m_Peers.Unlock(); }
// stream opening & closing
std::shared_ptr<CPacketStream> OpenStream(std::unique_ptr<CPacket> &, std::shared_ptr<CClient>);
bool IsStreaming(char);
void CloseStream(std::shared_ptr<CPacketStream>);
// users
CUsers *GetUsers(void) { m_Users.Lock(); return &m_Users; }
void ReleaseUsers(void) { m_Users.Unlock(); }
#ifndef NO_DHT
// Publish DHT
void PutDHTConfig();
void PutDHTPeers();
void PutDHTClients();
void PutDHTUsers();
void GetDHTConfig(const std::string &cs);
#endif
protected:
// threads
void RouterThread(std::shared_ptr<CPacketStream>);
void XmlReportThread(void);
// streams
std::shared_ptr<CPacketStream> GetStream(char);
bool IsStreamOpen(const std::unique_ptr<CPacket> &);
char GetStreamModule(std::shared_ptr<CPacketStream>);
// xml helpers
void WriteXmlFile(std::ofstream &);
protected:
// objects
CUsers m_Users; // sorted list of lastheard stations
CClients m_Clients; // list of linked repeaters/nodes/peers's modules
CPeers m_Peers; // list of linked peers
CProtocol m_Protocol; // the only protocol
// queues
std::unordered_map<char, std::shared_ptr<CPacketStream>> m_Streams;
std::unordered_map<std::shared_ptr<CPacketStream>, char> m_RStreams;
// threads
std::atomic<bool> keep_running;
std::unordered_map<char, std::future<void>> m_ModuleFutures;
std::future<void> m_XmlReportFuture, m_JsonReportFuture;
// Distributed Hash Table
#ifndef NO_DHT
dht::DhtRunner node;
dht::InfoHash refhash;
unsigned int peers_put_count, clients_put_count, users_put_count;
#endif
};