Atrinik Server  4.0
Macros | Functions | Variables
metaserver.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <toolkit/curl.h>
#include <toolkit/socket_crypto.h>
#include <player.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/err.h>

Go to the source code of this file.

Macros

#define METASERVER_KEY_FILE   "metaserver_key"
 

Functions

static bool metaserver_enabled (void)
 
void metaserver_init (void)
 
void metaserver_deinit (void)
 
static bool metaserver_request_process_error (curl_request_t *request)
 
static void metaserver_update_request (curl_request_t *request, void *user_data)
 
static bool metaserver_get_key (char *key, size_t key_size, const char *otp, const char *cotp)
 
static void metaserver_otp_request (curl_request_t *request, void *user_data)
 
void metaserver_info_update (void)
 
void metaserver_stats (char *buf, size_t size)
 

Variables

struct {
   uint64_t   num
 Number of successful updates.
 
   uint64_t   num_failed
 Number of failed updates.
 
   time_t   last
 Last successful update.
 
   time_t   last_failed
 Last failed update.
 
stats
 
static pthread_mutex_t stats_lock
 
static curl_request_t * current_request = NULL
 
static pthread_mutex_t request_lock
 
static char * request_players = NULL
 
static uint32_t request_num_players = 0
 
static bool key_is_new = false
 

Detailed Description

Metaserver updating related code.

Definition in file metaserver.c.

Macro Definition Documentation

#define METASERVER_KEY_FILE   "metaserver_key"

Where the metaserver key file is located.

Definition at line 55 of file metaserver.c.

Function Documentation

void metaserver_deinit ( void  )

Deinitialize the metaserver.

Definition at line 122 of file metaserver.c.

static bool metaserver_enabled ( void  )
static

Figure out whether the meta-server is enabled or not.

Returns
True if the meta-server is enabled, false otherwise.

Definition at line 90 of file metaserver.c.

static bool metaserver_get_key ( char *  key,
size_t  key_size,
const char *  otp,
const char *  cotp 
)
static

Acquires the key to use for metaserver authentication.

Parameters
[out]keyWill contain the key on success.
key_sizeSize of the 'key' buffer.
otpOTP from the metaserver.
cotpGenerated COTP.
Returns
True on success, false on failure.

Definition at line 252 of file metaserver.c.

void metaserver_info_update ( void  )

Updates the metaserver information.

Definition at line 588 of file metaserver.c.

void metaserver_init ( void  )

Initialize the metaserver.

Definition at line 107 of file metaserver.c.

static void metaserver_otp_request ( curl_request_t *  request,
void *  user_data 
)
static

Process the OTP GET request reply.

Parameters
requestcURL request.
user_dataNULL.

Definition at line 455 of file metaserver.c.

static bool metaserver_request_process_error ( curl_request_t *  request)
static

Check if the specified cURL request resulted in an error.

Parameters
requestRequest to check.
Returns
True if an error was processed, false otherwise.

Definition at line 171 of file metaserver.c.

void metaserver_stats ( char *  buf,
size_t  size 
)

Construct metaserver statistics.

Parameters
[out]bufBuffer to use for writing. Must end with a NUL.
sizeSize of 'buf'.

Definition at line 643 of file metaserver.c.

static void metaserver_update_request ( curl_request_t *  request,
void *  user_data 
)
static

Callback received for publishing a metaserver update.

Parameters
requestcURL request.
user_dataNULL.

Definition at line 204 of file metaserver.c.

Variable Documentation

curl_request_t* current_request = NULL
static

cURL request structure.

Definition at line 65 of file metaserver.c.

bool key_is_new = false
static

Keeps track of whether the generate metaserver key is new or not.

Definition at line 81 of file metaserver.c.

pthread_mutex_t request_lock
static

Mutex for the current request pointer.

Definition at line 69 of file metaserver.c.

uint32_t request_num_players = 0
static

Number of players.

Definition at line 77 of file metaserver.c.

char* request_players = NULL
static

Temporary string used to send a list of players to the metaserver.

Definition at line 73 of file metaserver.c.

struct { ... } stats

Used to hold metaserver statistics.

pthread_mutex_t stats_lock
static

Mutex for the metaserver stats.

Definition at line 60 of file metaserver.c.