2018-10-09 04:53:15 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
|
|
|
|
|
|
|
|
#ifdef NODE_LOG_MESSAGES
|
|
|
|
#define NODE_LOG(x, ...) Logger::Print(x, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define NODE_LOG(x, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Node : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Data
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
uint64_t protocol;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Entry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Network::Address address;
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
std::optional<Utils::Time::Point> lastRequest;
|
|
|
|
std::optional<Utils::Time::Point> lastResponse;
|
|
|
|
|
|
|
|
bool isValid();
|
|
|
|
bool isDead();
|
|
|
|
|
|
|
|
bool requiresRequest();
|
|
|
|
void sendRequest();
|
|
|
|
|
|
|
|
void reset();
|
2018-12-03 15:48:12 -05:00
|
|
|
json11::Json to_json() const;
|
2018-10-09 04:53:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Node();
|
|
|
|
~Node();
|
|
|
|
|
|
|
|
static void Add(Network::Address address);
|
2018-12-02 12:17:45 -05:00
|
|
|
static std::vector<Entry> GetNodes();
|
2018-10-09 04:53:15 -04:00
|
|
|
static void RunFrame();
|
|
|
|
static void Synchronize();
|
|
|
|
|
|
|
|
static void LoadNodeRemotePreset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static std::recursive_mutex Mutex;
|
|
|
|
static std::vector<Entry> Nodes;
|
|
|
|
static bool wasIngame;
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
static void HandleResponse(Network::Address address, const std::string& data);
|
2018-10-09 04:53:15 -04:00
|
|
|
|
|
|
|
static void SendList(Network::Address address);
|
|
|
|
|
|
|
|
static void LoadNodePreset();
|
|
|
|
static void LoadNodes();
|
|
|
|
static void StoreNodes(bool force);
|
|
|
|
|
|
|
|
static unsigned short GetPort();
|
|
|
|
};
|
|
|
|
}
|