2016-02-09 16:13:49 -05: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
|
|
|
|
#define NODE_FRAME_QUERY_LIMIT 1 // Limit of nodes to be queried per frame
|
2016-03-06 10:42:58 -05:00
|
|
|
#define NODE_FRAME_LOCK 30 // Limit of max frames per second
|
2016-02-09 16:13:49 -05:00
|
|
|
#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-02-06 18:48:39 -05:00
|
|
|
|
2016-01-28 10:19:43 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Node : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Node();
|
|
|
|
~Node();
|
|
|
|
const char* GetName() { return "Node"; };
|
2016-02-09 16:13:49 -05:00
|
|
|
bool UnitTest();
|
2016-01-28 15:37:48 -05:00
|
|
|
|
2016-02-12 21:18:49 -05:00
|
|
|
static void SyncNodeList();
|
2016-02-12 16:23:41 -05:00
|
|
|
static void AddNode(Network::Address address);
|
2016-02-03 14:10:54 -05:00
|
|
|
|
2016-03-09 14:16:38 -05:00
|
|
|
static unsigned int GetValidNodeCount();
|
|
|
|
|
2016-01-28 10:19:43 -05:00
|
|
|
private:
|
|
|
|
enum EntryState
|
|
|
|
{
|
|
|
|
STATE_UNKNOWN,
|
2016-02-09 16:13:49 -05:00
|
|
|
STATE_NEGOTIATING,
|
2016-01-28 10:19:43 -05:00
|
|
|
STATE_VALID,
|
2016-02-01 15:59:45 -05:00
|
|
|
STATE_INVALID,
|
2016-01-28 10:19:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeEntry
|
|
|
|
{
|
|
|
|
Network::Address address;
|
2016-02-09 16:13:49 -05:00
|
|
|
std::string challenge;
|
2016-02-08 12:43:31 -05:00
|
|
|
Utils::Cryptography::ECDSA::Key publicKey;
|
2016-01-28 10:19:43 -05:00
|
|
|
EntryState state;
|
2016-02-09 16:13:49 -05:00
|
|
|
|
|
|
|
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;
|
2016-01-28 10:19:43 -05:00
|
|
|
};
|
|
|
|
|
2016-02-09 16:13:49 -05:00
|
|
|
struct ClientSession
|
2016-01-28 10:19:43 -05:00
|
|
|
{
|
|
|
|
Network::Address address;
|
2016-01-28 15:37:48 -05:00
|
|
|
std::string challenge;
|
2016-02-09 16:13:49 -05:00
|
|
|
bool valid;
|
2016-02-09 19:22:00 -05:00
|
|
|
//bool terminated; // Sessions can't explicitly be terminated, they can only timeout
|
2016-01-28 21:49:51 -05:00
|
|
|
int lastTime;
|
2016-01-28 10:19:43 -05:00
|
|
|
};
|
|
|
|
|
2016-02-08 12:43:31 -05:00
|
|
|
static Utils::Cryptography::ECDSA::Key SignatureKey;
|
|
|
|
|
2016-01-28 10:19:43 -05:00
|
|
|
static std::vector<NodeEntry> Nodes;
|
2016-02-09 16:13:49 -05:00
|
|
|
static std::vector<ClientSession> Sessions;
|
2016-01-28 10:19:43 -05:00
|
|
|
|
|
|
|
static void LoadNodes();
|
2016-02-15 13:40:11 -05:00
|
|
|
static void LoadNodePreset();
|
2016-02-06 18:48:39 -05:00
|
|
|
static void StoreNodes(bool force);
|
2016-01-28 10:19:43 -05:00
|
|
|
|
2016-02-13 09:01:34 -05:00
|
|
|
static void PerformRegistration(Network::Address address);
|
2016-02-09 16:13:49 -05:00
|
|
|
static void SendNodeList(Network::Address address);
|
|
|
|
static NodeEntry* FindNode(Network::Address address);
|
|
|
|
static ClientSession* FindSession(Network::Address address);
|
2016-01-28 17:36:57 -05:00
|
|
|
|
|
|
|
static void DeleteInvalidNodes();
|
2016-02-09 16:13:49 -05:00
|
|
|
static void DeleteInvalidSessions();
|
2016-02-03 14:10:54 -05:00
|
|
|
|
|
|
|
static void FrameHandler();
|
|
|
|
|
|
|
|
static const char* GetStateName(EntryState state);
|
2016-01-28 10:19:43 -05:00
|
|
|
};
|
|
|
|
}
|