tor_multipath_voip/src/algo_skel.h
2019-02-14 11:16:38 +01:00

72 lines
1.3 KiB
C

#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "evt_core.h"
#include "utils.h"
/*
* man 7 udp about receive operation on UDP sockets:
*
* > All receive operations return only one packet. When the packet is smaller than the passed
* > buffer, only that much data is returned; when it is bigger, the packet is truncated and the
* > MSG_TRUNC flag is set. MSG_WAITALL is not supported.
*/
enum FD_STATE {
FDS_READY,
FDS_AGAIN,
FDS_ERR
};
enum BP_MODE {
BP_READING,
BP_WRITING
};
union abstract_packet {
char raw;
struct {
uint16_t size;
char payload;
} str;
};
struct internet_packet {
union abstract_packet ap;
char rest[1499]; // MTU = 1500, 1 byte in the union
};
struct buffer_packet {
uint8_t mode;
uint16_t aread;
uint16_t awrite;
struct internet_packet ip;
};
struct algo_skel {
struct evt_core_cat on_udp_read;
struct evt_core_cat on_tcp_read;
struct evt_core_cat on_udp_write;
struct evt_core_cat on_tcp_write;
struct evt_core_cat on_tcp_co;
};
typedef void (*algo_init)(struct algo_skel* as);
void init_algo(struct algo_skel* as, char* name);
void algo_naive(struct algo_skel* as);
struct algo_desc {
algo_init init;
char* name;
};
static struct algo_desc available_algo[] = {
{
.init = algo_naive,
.name = "naive"
}
};