Extra Systems

CYPHERNET

central server


The central server of the Extra Systems Cypher Net system is the point of forwarding traffic between subscribers. It accepts TCP connections from clients, receives fingerprint files from them (thus identifying the legitimacy of subscribers), and then ensures that they agree on a session key using the prologue procedure. (In the case of a hacker attack, if the fingerprint turns out to be fake, the connection is, of course, immediately broken.)

typedef struct thread_data
{
	int thread_id;
	int thread_socket;
	PEERID client_id;
	PEERID server_id;
	int server_thread;
	char *buffer_to_send;
	int buf_size;
	int prolog_size;
	unsigned char client_mode;
} THREADDATA;

THREADDATA thread_pool[THREAD_POOL_SIZE];

void run_main_loop(int main_socket) {
	int new_socket, addr_size, i, pooled;
	struct sockaddr_in client_addr;
	while (1)
	{
		addr_size = sizeof(client_addr);
		new_socket = accept(main_socket, (struct sockaddr *) &client_addr, &addr_size);
		if (new_socket < 0) break;
		pooled = 0;
		while (!pooled) {
			for (i = 0; (i < THREAD_POOL_SIZE) && (!pooled); i++) {
				if (thread_pool[i].thread_id == 0) {
					thread_pool[i].thread_socket = new_socket;
					thread_pool[i].thread_id = esthread_create(dispatch_call, &thread_pool[i]);
					pooled = 1;
				}
			}
			if (!pooled) es_sleep(100);
		}
	}
}

int main(void)
{
	int my_socket;
	init_hash();
	init_hard_hash();
	load_rsa_keys("public_0", "private_0");
	sockets_startup();
	my_socket = create_server_socket(main_server_port);
	memset(thread_pool, 0, sizeof(thread_pool));
	run_main_loop(my_socket);
	sockets_cleanup();
	return 0;
}

As can be seen from the code, immediately after startup, the server loads its private key from a local file via the load_rsa_keys procedure, which it will use to decrypt the fingerprint files received from subscribers via RSA (in the check_finger_print procedure). Then the run_main_loop procedure is launched, which listens to the port and accepts TCP connections. Calls accepted by the server are placed in a queue for servicing - a static array thread_pool. Direct servicing of calls is performed by the dispatch_call procedure, which is launched for each call in a separate thread (it is passed an instance of the thread_data structure corresponding to the given connection as a parameter).

The content of this page is also available in French, German, Ukrainian and Russian.


© Extra Systems, 2024 Extra Web Top