56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
#pragma once
|
|
#include <pthread.h>
|
|
#include "tlibc/collections/HashMap.h"
|
|
#include "tlibc/collections/List.h"
|
|
#include "tcp-chat/server.h"
|
|
#include "cryptography/AES.h"
|
|
#include "cryptography/RSA.h"
|
|
#include "network/encrypted_sockets.h"
|
|
#include "db/idb.h"
|
|
#include "server/db_tables.h"
|
|
|
|
typedef struct ClientConnection ClientConnection;
|
|
|
|
typedef struct Server {
|
|
/* from constructor */
|
|
void* logger;
|
|
LogFunction_t log_func;
|
|
|
|
/* from config */
|
|
str name;
|
|
str description;
|
|
u64 landing_channel_id;
|
|
EndpointIPv4 local_end;
|
|
br_rsa_private_key rsa_sk;
|
|
br_rsa_public_key rsa_pk;
|
|
|
|
/* database and cache */
|
|
IncrementalDB* db;
|
|
Table* db_users_table;
|
|
pthread_mutex_t users_cache_mutex;
|
|
List(User) users_cache_list; // index is id
|
|
HashMap(u64) users_name_id_map; //key is user name
|
|
} Server;
|
|
|
|
|
|
typedef struct ClientConnection {
|
|
u64 session_id;
|
|
EndpointIPv4 client_end;
|
|
Array(u8) session_key;
|
|
EncryptedSocketTCP sock;
|
|
bool authorized;
|
|
} ClientConnection;
|
|
|
|
typedef struct ConnectionHandlerArgs {
|
|
Server* server;
|
|
Socket accepted_socket_tcp;
|
|
EndpointIPv4 client_end;
|
|
u64 session_id;
|
|
} ConnectionHandlerArgs;
|
|
|
|
Result(ClientConnection*) ClientConnection_accept(ConnectionHandlerArgs* args);
|
|
|
|
void ClientConnection_close(ClientConnection* conn);
|
|
|
|
|