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-02-18 20:55:53 +00:00
|
|
|
|
2019-04-24 14:23:41 +00:00
|
|
|
// 1. Find destination
|
2019-02-18 16:51:13 +00:00
|
|
|
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);
|
|
|
|
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-03-20 14:13:16 +00:00
|
|
|
mv_buffer_wtof (app_ctx, 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-04-24 14:23:41 +00:00
|
|
|
// 2. Move buffer
|
2019-03-20 14:13:16 +00:00
|
|
|
mv_buffer_rtow (app_ctx, 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");
|
|
|
|
to_fdinfo = g_array_index(cat->socklist, struct evt_core_fdinfo*, 0);
|
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-03-20 14:13:16 +00:00
|
|
|
mv_buffer_wtof (app_ctx, 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-03-20 14:13:16 +00:00
|
|
|
mv_buffer_rtow (app_ctx, 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_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|
|
|
// We do nothing
|
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
|
|
|
}
|