implemented EncryptedSocket
This commit is contained in:
10
src/server/ClientConnection.c
Normal file
10
src/server/ClientConnection.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "server.h"
|
||||
|
||||
void ClientConnection_close(ClientConnection* conn){
|
||||
if(conn == NULL)
|
||||
return;
|
||||
socket_close(conn->system_socket.sock);
|
||||
socket_close(conn->content_socket.sock);
|
||||
free(conn->session_key.data);
|
||||
free(conn);
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "db/idb.h"
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct AcceptedConnection {
|
||||
Socket sock;
|
||||
EndpointIPv4 client_end;
|
||||
} AcceptedConnection;
|
||||
|
||||
static void* handle_connection(void* _args);
|
||||
|
||||
typedef struct ConnectionHandlerArgs {
|
||||
Socket accepted_socket;
|
||||
EndpointIPv4 client_end;
|
||||
} ConnectionHandlerArgs;
|
||||
|
||||
Result(void) server_run(cstr server_endpoint_str){
|
||||
Deferral(32);
|
||||
EndpointIPv4 server_end;
|
||||
@@ -19,8 +19,8 @@ Result(void) server_run(cstr server_endpoint_str){
|
||||
try_void(socket_listen(main_socket, 512));
|
||||
|
||||
while(true){
|
||||
AcceptedConnection* args = malloc(sizeof(AcceptedConnection));
|
||||
try(args->sock, i, socket_accept(main_socket, &args->client_end));
|
||||
ConnectionHandlerArgs* args = (ConnectionHandlerArgs*)malloc(sizeof(ConnectionHandlerArgs));
|
||||
try(args->accepted_socket, i, socket_accept(main_socket, &args->client_end));
|
||||
pthread_t conn_thread = {0};
|
||||
try_stderrcode(pthread_create(&conn_thread, NULL, handle_connection, args));
|
||||
}
|
||||
@@ -30,8 +30,11 @@ Result(void) server_run(cstr server_endpoint_str){
|
||||
|
||||
static void* handle_connection(void* _args){
|
||||
Deferral(64);
|
||||
AcceptedConnection* conn = (AcceptedConnection*)_args;
|
||||
Defer(free(conn));
|
||||
ConnectionHandlerArgs* args = (ConnectionHandlerArgs*)_args;
|
||||
// TODO: receive handshake and session key
|
||||
|
||||
//ClientConnection conn;
|
||||
|
||||
|
||||
Return NULL;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
#pragma once
|
||||
#include "network/socket.h"
|
||||
#include "cryptography/cryptography.h"
|
||||
#include "network/EncryptedSocket.h"
|
||||
|
||||
Result(void) server_run(cstr server_endpoint_str);
|
||||
|
||||
typedef struct ClientConnection {
|
||||
EndpointIPv4 client_end;
|
||||
Array(u8) session_key;
|
||||
EncryptedSocket system_socket;
|
||||
EncryptedSocket content_socket;
|
||||
} ClientConnection;
|
||||
|
||||
Reference in New Issue
Block a user