server.cpp File Reference

#include <pthread.h>
#include <semaphore.h>
#include <event.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <netinet/tcp.h>
#include <sys/timeb.h>
#include <string.h>
#include <time.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "Protocol.h"
#include "LocalDB.hpp"
#include "config_reader.hpp"
#include "hashtable.hpp"
#include "types.hpp"
#include "common_functions.hpp"
#include "dst_config.hpp"
#include "config_store.hpp"
#include <list>
#include <set>
#include <sys/stat.h>
#include <fcntl.h>
#include "daemonize.hpp"
#include "file_tokenizer.hpp"
#include "diff_process.hpp"
#include "extern.hpp"
#include <limits>

Typedefs

typedef thread_s thread_t

Functions

void read_cb (int fd, short event_type, void *arg)
 Reads data from socket and cuts them into packets.
void close_con (client_t *cli)
 Frees connection. Should be used every time there is some error with it. Also, removes all callbacks and events.
void register_proxy (limit_server_register_t *data, client_t *cli)
 Registers proxy server. It will be added to proxy list or updated if already present.
void send_data_cb (int fd, short event_type, void *arg)
 Callback run every time there is something to send in output buffer. It attempts to send next buffer from cli->packets_to_send.
void enqueue_packet (client_s *cli, const buf_el &packet)
 Enqueues packet to be send to client. Also, sets write events if necessary.
void send_packet_to_all_servers (buf_el packet)
 Enqueues packet to all connected servers.
void protocol_limit_server_protocol_register (client_s *cli, char *input_buffer, uint32_t packet_size)
void protocol_limit_server_update_diff (client_s *cli, char *input_buffer, uint32_t packet_size)
void protocol_limit_server_update_dest_host_send_diff (client_s *cli, char *input_buffer, uint32_t packet_size)
void protocol_limit_server_request_uid (client_s *cli, char *input_buffer, uint32_t packet_size)
uint32_t protocol_core (client_s *cli, char *input_buffer, uint32_t size)
 Main function to parse the received data and call proper procedure.
void do_accept (int listener_socket, short event_type, void *arg)
 Callback run every time there is new connection.
void update_cb (int fd, short event_type, void *arg)
 Callback run by timer. It starts diff process. Also, changes current mouth variable.
void pipe_cb (int fd, short event_type, void *arg)
 Called each time there is event to add.
void * worker (void *arg)
 Worker thread. Enters libevent loop, and should never leave it.
void insert_to_config (const std::pair< std::string, config_destination_entry > &new_entry)
 Inserts rule entry to server configuration. Creates underlying classes and loads database from disk if necessary.
void init_config ()
 Used at server startup. Fetches entire configuration using parse_config(rules_file), then calls insert_to_config() for each row.
void reload_config ()
 Reloads configuration. Called if SIGUSR1 was received. Will call parse_config(rules_file) to fetch new configuration, then
.
void handler (int signal)
 Parses signals. Two signals are handled: SIGINT will close server saving anything, SIGUSR1 will reload configuration.
void init ()
 Main initialization. Sets signals handler, creates socket and worker thread.
void read_local_config (const char *conf_file_name)
 Parses config.txt file.
int main (int argc, char **argv)

Variables

struct timeval tv
struct event_base * thread_loops [RECV_THREAD_AMOUNT]
pthread_t thread_ids [RECV_THREAD_AMOUNT]
int thread_usage [RECV_THREAD_AMOUNT]
pthread_mutex_t thread_usage_guard = PTHREAD_MUTEX_INITIALIZER
pthread_mutex_t mutex_queue [RECV_THREAD_AMOUNT]
int pipe_queue [RECV_THREAD_AMOUNT][2]
int last_thread = 0
pthread_mutex_t parse_synchronization = PTHREAD_MUTEX_INITIALIZER
const char * NOTIFY = "1"
int curr_month = 0
std::list< t_uiddest_list
HashMap< t_uid,dest_config * > local_config (hashFunction)
std::list< proxy_server * > proxies
std::list< client_t * > queue [RECV_THREAD_AMOUNT]
char rules_file [1024]
char db_prefix [1024]
int update_interval
int main_server_port
int daemonize
char log_error [1024]
char log_common [1024]
bool pending_reload = false
int listener_socket

Typedef Documentation

typedef thread_s thread_t


Function Documentation

void close_con ( client_t cli  ) 

Frees connection. Should be used every time there is some error with it. Also, removes all callbacks and events.

Parameters:
[in] cli Client to be closed and freed.

void do_accept ( int  listener_socket,
short  event_type,
void *  arg 
)

Callback run every time there is new connection.

Parameters:
[in] listener_socket 
[in] event_type 
[in] arg 
Returns:

void enqueue_packet ( client_s cli,
const buf_el packet 
)

Enqueues packet to be send to client. Also, sets write events if necessary.

Parameters:
[in] cli Client to which data shall be send
[in] packet packet that will be send

void handler ( int  signal  ) 

Parses signals. Two signals are handled: SIGINT will close server saving anything, SIGUSR1 will reload configuration.

void init (  ) 

Main initialization. Sets signals handler, creates socket and worker thread.

void init_config (  ) 

Used at server startup. Fetches entire configuration using parse_config(rules_file), then calls insert_to_config() for each row.

void insert_to_config ( const std::pair< std::string, config_destination_entry > &  new_entry  ) 

Inserts rule entry to server configuration. Creates underlying classes and loads database from disk if necessary.

Parameters:
[in] new_entry std::pair<> of host name and it's settings

int main ( int  argc,
char **  argv 
)

void pipe_cb ( int  fd,
short  event_type,
void *  arg 
)

Called each time there is event to add.

uint32_t protocol_core ( client_s cli,
char *  input_buffer,
uint32_t  size 
)

Main function to parse the received data and call proper procedure.

Parameters:
[in] cli client who received something
[in] input_buffer buffer pointer
[in] size total buffer length
Returns:
amount of data parsed (less or equal to size)

void protocol_limit_server_protocol_register ( client_s cli,
char *  input_buffer,
uint32_t  packet_size 
)

void protocol_limit_server_request_uid ( client_s cli,
char *  input_buffer,
uint32_t  packet_size 
)

void protocol_limit_server_update_dest_host_send_diff ( client_s cli,
char *  input_buffer,
uint32_t  packet_size 
)

void protocol_limit_server_update_diff ( client_s cli,
char *  input_buffer,
uint32_t  packet_size 
)

void read_cb ( int  fd,
short  event_type,
void *  arg 
)

Reads data from socket and cuts them into packets.

Parameters:
[in] fd fd from which data are avialable
[in] event_type unused
[in] arg client related with this event
Returns:

void read_local_config ( const char *  conf_file_name  ) 

Parses config.txt file.

void register_proxy ( limit_server_register_t data,
client_t cli 
)

Registers proxy server. It will be added to proxy list or updated if already present.

Parameters:
[in] data Packet, containing server name used to distinguish servers.
[in] cli Client context used by this proxy server.

void reload_config (  ) 

Reloads configuration. Called if SIGUSR1 was received. Will call parse_config(rules_file) to fetch new configuration, then
.

  • for new entries, will call insert_to_config()
  • for deleted entires, will call destructors
  • for other, will override old configuration

void send_data_cb ( int  fd,
short  event_type,
void *  arg 
)

Callback run every time there is something to send in output buffer. It attempts to send next buffer from cli->packets_to_send.

Parameters:
[in] fd File descriptor on which event occured.
[in] event_type unused
[in] arg Client context used by fd (as void*)

void send_packet_to_all_servers ( buf_el  packet  ) 

Enqueues packet to all connected servers.

Parameters:
[in] packet packet that will be send

void update_cb ( int  fd,
short  event_type,
void *  arg 
)

Callback run by timer. It starts diff process. Also, changes current mouth variable.

Parameters:
[in] listener_socket 
[in] event_type 
[in] arg 

void* worker ( void *  arg  ) 

Worker thread. Enters libevent loop, and should never leave it.

Parameters:
[in] arg thread Index (converted to pointer type)


Variable Documentation

int curr_month = 0

Variable identifying current month (1-12)

int daemonize

char db_prefix[1024]

std::list<t_uid> dest_list

int last_thread = 0

char log_common[1024]

char log_error[1024]

pthread_mutex_t mutex_queue[RECV_THREAD_AMOUNT]

const char* NOTIFY = "1"

pthread_mutex_t parse_synchronization = PTHREAD_MUTEX_INITIALIZER

bool pending_reload = false

int pipe_queue[RECV_THREAD_AMOUNT][2]

std::list<proxy_server*> proxies

std::list<client_t *> queue[RECV_THREAD_AMOUNT]

char rules_file[1024]

pthread_t thread_ids[RECV_THREAD_AMOUNT]

struct event_base* thread_loops[RECV_THREAD_AMOUNT]

int thread_usage[RECV_THREAD_AMOUNT]

pthread_mutex_t thread_usage_guard = PTHREAD_MUTEX_INITIALIZER

struct timeval tv


Generated on Thu Oct 22 16:30:59 2009 for Main server by  doxygen 1.5.6