2019-04-24 14:23:41 +00:00
|
|
|
#include "proxy.h"
|
2019-03-07 15:57:02 +00:00
|
|
|
#include "algo_utils.h"
|
2019-02-11 21:40:00 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
void algo_naive_init(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx, struct algo_params* ap) {
|
|
|
|
// We do nothing
|
2019-02-11 21:40:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
int algo_naive_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
|
|
|
char url[256];
|
2019-02-18 16:51:13 +00:00
|
|
|
struct evt_core_fdinfo *to_fdinfo = NULL;
|
2019-03-07 15:57:02 +00:00
|
|
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
2019-08-09 15:01:28 +00:00
|
|
|
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
2019-02-18 20:55:53 +00:00
|
|
|
|
2019-08-12 14:24:20 +00:00
|
|
|
if (ctx->verbose > 1) fprintf(stderr, " [algo_naive] 1/2 Find destination\n");
|
2019-08-09 15:01:28 +00:00
|
|
|
sprintf(url, "udp:write:127.0.0.1:%d", ap->fmt.content.udp_encapsulated.port);
|
2019-02-18 16:51:13 +00:00
|
|
|
to_fdinfo = evt_core_get_from_url (ctx, url);
|
2019-02-19 18:31:26 +00:00
|
|
|
if (to_fdinfo == NULL) {
|
|
|
|
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
2019-05-27 15:32:00 +00:00
|
|
|
mv_buffer_wtof (&app_ctx->br, fdinfo);
|
2019-02-20 16:46:58 +00:00
|
|
|
return 1;
|
2019-02-19 18:31:26 +00:00
|
|
|
}
|
2019-02-18 16:51:13 +00:00
|
|
|
|
2019-08-12 14:24:20 +00:00
|
|
|
if (ctx->verbose > 1) fprintf(stderr, " [algo_naive] 2/2 Move buffer\n");
|
2019-05-27 15:32:00 +00:00
|
|
|
mv_buffer_rtow (&app_ctx->br, fdinfo, to_fdinfo);
|
2019-04-24 14:23:41 +00:00
|
|
|
main_on_udp_write(ctx, to_fdinfo);
|
2019-02-18 16:51:13 +00:00
|
|
|
|
2019-02-20 16:46:58 +00:00
|
|
|
return 0;
|
2019-02-18 16:51:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
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;
|
2019-03-07 15:57:02 +00:00
|
|
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
2019-02-14 10:16:38 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
// 1. A whole packet has been read, we will find someone to write it
|
2019-05-06 13:03:53 +00:00
|
|
|
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
|
2019-05-06 15:17:45 +00:00
|
|
|
to_fdinfo = cat->socklist->len > 0 ? g_array_index(cat->socklist, struct evt_core_fdinfo*, 0) : NULL;
|
2019-02-19 18:31:26 +00:00
|
|
|
if (to_fdinfo == NULL) {
|
2019-05-06 13:03:53 +00:00
|
|
|
fprintf(stderr, "No fd for cat %s in udp-read. Dropping packet :( \n", cat->name);
|
2019-08-12 14:24:20 +00:00
|
|
|
mv_buffer_wtof(&app_ctx->br, fdinfo);
|
2019-02-20 16:46:58 +00:00
|
|
|
return 1;
|
2019-02-19 18:31:26 +00:00
|
|
|
}
|
2019-02-20 08:34:10 +00:00
|
|
|
//printf("Pass packet from %s to %s\n", fdinfo->url, url);
|
2019-02-18 20:55:53 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
// 2. We move the buffer and notify the target
|
2019-05-27 15:32:00 +00:00
|
|
|
mv_buffer_rtow (&app_ctx->br, fdinfo, to_fdinfo);
|
2019-04-24 14:23:41 +00:00
|
|
|
main_on_tcp_write(ctx, to_fdinfo);
|
2019-02-11 21:40:00 +00:00
|
|
|
|
2019-02-20 16:46:58 +00:00
|
|
|
return 0;
|
2019-02-11 21:40:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
int algo_naive_on_err(struct evt_core_ctx *ctx, struct evt_core_fdinfo *fdinfo) {
|
|
|
|
// We do nothing
|
|
|
|
return 1;
|
2019-02-11 21:40:00 +00:00
|
|
|
}
|