tor_multipath_voip/src/algo_naive.c

58 lines
1.8 KiB
C

#include "proxy.h"
#include "algo_utils.h"
void algo_naive_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap) {
// We do nothing
}
int algo_naive_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
char url[256];
struct evt_core_fdinfo *to_fdinfo = NULL;
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
// 1. Find destination
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);
to_fdinfo = evt_core_get_from_url (ctx, url);
if (to_fdinfo == NULL) {
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
mv_buffer_wtof (app_ctx, fdinfo);
return 1;
}
// 2. Move buffer
mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo);
main_on_udp_write(ctx, to_fdinfo);
return 0;
}
int algo_naive_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
struct evt_core_fdinfo *to_fdinfo = NULL;
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
// 1. A whole packet has been read, we will find someone to write it
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
to_fdinfo = g_array_index(cat->socklist, struct evt_core_fdinfo*, 0);
if (to_fdinfo == NULL) {
fprintf(stderr, "No fd for cat %s in udp-read. Dropping packet :( \n", cat->name);
mv_buffer_wtof (app_ctx, fdinfo);
return 1;
}
//printf("Pass packet from %s to %s\n", fdinfo->url, url);
// 2. We move the buffer and notify the target
mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo);
main_on_tcp_write(ctx, to_fdinfo);
return 0;
}
int algo_naive_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
// We do nothing
return 0;
}
int algo_naive_on_err(struct evt_core_ctx *ctx, struct evt_core_fdinfo *fdinfo) {
// We do nothing
return 1;
}