2016-08-05 18:36:28 -04:00
|
|
|
#define NODE_QUERY_INTERVAL 1000 * 60 * 2 // Query nodelist from nodes evry 2 minutes
|
|
|
|
#define NODE_QUERY_TIMEOUT 1000 * 30 * 1 // Invalidate nodes after 30 seconds without query response
|
|
|
|
#define NODE_INVALID_DELETE 1000 * 60 * 10 // Delete invalidated nodes after 10 minutes
|
2016-08-05 19:47:12 -04:00
|
|
|
#define NODE_FRAME_QUERY_LIMIT 3 // Limit of nodes to be queried per frame
|
2016-08-05 18:36:28 -04:00
|
|
|
#define NODE_FRAME_LOCK 60 // Limit of max frames per second
|
|
|
|
#define NODE_PACKET_LIMIT 111 // Send 111 nodes per synchronization packet
|
|
|
|
#define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute
|
|
|
|
#define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout
|
|
|
|
|
2016-10-09 11:27:37 -04:00
|
|
|
#define NODE_VERSION 3
|
2016-08-05 18:36:28 -04:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Node : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Node();
|
|
|
|
~Node();
|
2016-08-15 10:40:30 -04:00
|
|
|
|
2016-09-16 05:04:28 -04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2016-11-25 07:00:48 -05:00
|
|
|
const char* getName() { return "Node"; };
|
2016-08-15 10:40:30 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
bool unitTest();
|
2016-08-05 18:36:28 -04:00
|
|
|
|
|
|
|
static void SyncNodeList();
|
|
|
|
static void AddNode(Network::Address address);
|
|
|
|
|
|
|
|
static unsigned int GetValidNodeCount();
|
|
|
|
|
2016-11-15 10:40:15 -05:00
|
|
|
static void LoadNodeRemotePreset();
|
|
|
|
|
2016-08-05 18:36:28 -04:00
|
|
|
private:
|
|
|
|
enum EntryState
|
|
|
|
{
|
|
|
|
STATE_UNKNOWN,
|
|
|
|
STATE_NEGOTIATING,
|
|
|
|
STATE_VALID,
|
|
|
|
STATE_INVALID,
|
|
|
|
};
|
|
|
|
|
|
|
|
class NodeEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Network::Address address;
|
|
|
|
std::string challenge;
|
|
|
|
Utils::Cryptography::ECC::Key publicKey;
|
|
|
|
EntryState state;
|
|
|
|
|
|
|
|
bool registered; // Do we consider this node as registered?
|
|
|
|
|
|
|
|
int lastTime; // Last time we heard anything from the server itself
|
|
|
|
int lastHeard; // Last time we heard something of the server at all (refs form other nodes)
|
|
|
|
int lastListQuery; // Last time we got the list of the node
|
|
|
|
|
|
|
|
// This is only relevant for clients
|
|
|
|
bool isDedi;
|
|
|
|
uint32_t protocol;
|
|
|
|
uint32_t version;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClientSession
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Network::Address address;
|
|
|
|
std::string challenge;
|
|
|
|
bool valid;
|
|
|
|
//bool terminated; // Sessions can't explicitly be terminated, they can only timeout
|
|
|
|
int lastTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Utils::Cryptography::ECC::Key SignatureKey;
|
|
|
|
|
2016-09-17 12:51:18 -04:00
|
|
|
static std::mutex NodeMutex;
|
|
|
|
static std::mutex SessionMutex;
|
2016-08-05 18:36:28 -04:00
|
|
|
static std::vector<NodeEntry> Nodes;
|
|
|
|
static std::vector<ClientSession> Sessions;
|
|
|
|
|
|
|
|
static void LoadNodes();
|
|
|
|
static void LoadNodePreset();
|
|
|
|
static void StoreNodes(bool force);
|
|
|
|
|
|
|
|
static void PerformRegistration(Network::Address address);
|
|
|
|
static void SendNodeList(Network::Address address);
|
|
|
|
static NodeEntry* FindNode(Network::Address address);
|
|
|
|
static ClientSession* FindSession(Network::Address address);
|
|
|
|
|
|
|
|
static void DeleteInvalidNodes();
|
|
|
|
static void DeleteInvalidSessions();
|
|
|
|
|
|
|
|
static void FrameHandler();
|
|
|
|
|
|
|
|
static const char* GetStateName(EntryState state);
|
|
|
|
};
|
|
|
|
}
|