WIP algo
This commit is contained in:
parent
a603a5762c
commit
577408a050
1 changed files with 41 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "proxy.h"
|
#include "proxy.h"
|
||||||
#include "algo_utils.h"
|
#include "algo_utils.h"
|
||||||
|
#include "packet.h"
|
||||||
|
|
||||||
struct dup2_ctx {
|
struct dup2_ctx {
|
||||||
uint16_t recv_id;
|
uint16_t recv_id;
|
||||||
|
@ -19,30 +20,50 @@ int algo_dup2_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
|
||||||
char url[256];
|
char url[256];
|
||||||
struct evt_core_fdinfo *to_fdinfo = NULL;
|
struct evt_core_fdinfo *to_fdinfo = NULL;
|
||||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||||
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
union abstract_packet *ap = (union abstract_packet*) &bp->ip, *ap_prev = NULL;
|
||||||
|
|
||||||
// Check that we didn't already received the packet
|
|
||||||
struct dup2_ctx* dup2c = app_ctx->misc;
|
struct dup2_ctx* dup2c = app_ctx->misc;
|
||||||
if (ring_ge(dup2c->recv_id, ap->fmt.content.clear.id)) {
|
uint16_t id = 0;
|
||||||
|
|
||||||
|
switch (ap->fmt.headers.cmd) {
|
||||||
|
case CMD_UDP_METADATA_THUNDER:
|
||||||
|
id = ap->fmt.content.udp_metadata_thunder.id;
|
||||||
mv_buffer_rtof(&app_ctx->br, fdinfo);
|
mv_buffer_rtof(&app_ctx->br, fdinfo);
|
||||||
|
|
||||||
|
// Check that received identifier has not been delivered
|
||||||
|
if (ring_ge(dup2c->recv_id, id)) {
|
||||||
|
mv_buffer_atof(&app_ctx->br, fdinfo);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dup2c->recv_id = bp->ip.ap.fmt.content.clear.id;
|
// Update delivered identifier
|
||||||
|
dup2c->recv_id = id;
|
||||||
|
|
||||||
// 1. Find destination
|
// 1. Find destination
|
||||||
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.fmt.content.clear.port);
|
ap_prev = (union abstract_packet*) get_app_buffer(&app_ctx->br, fdinfo)->ip;
|
||||||
|
sprintf(url, "udp:write:127.0.0.1:%d", ap_prev->fmt.content.udp_encapsulated.port);
|
||||||
to_fdinfo = evt_core_get_from_url (ctx, url);
|
to_fdinfo = evt_core_get_from_url (ctx, url);
|
||||||
if (to_fdinfo == NULL) {
|
if (to_fdinfo == NULL) {
|
||||||
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
||||||
mv_buffer_wtof (&app_ctx->br, fdinfo);
|
mv_buffer_atof (&app_ctx->br, fdinfo);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Move buffer
|
// 2. Move buffer
|
||||||
mv_buffer_rtow (&app_ctx->br, fdinfo, to_fdinfo);
|
mv_buffer_atow (&app_ctx->br, fdinfo, to_fdinfo);
|
||||||
main_on_udp_write(ctx, to_fdinfo);
|
main_on_udp_write(ctx, to_fdinfo);
|
||||||
return 0;
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_UDP_ENCAPSULATED:
|
||||||
|
mv_buffer_rtoa(&app_ctx->br, fdinfo, fdinfo);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Unknown packet type\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int algo_dup2_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
int algo_dup2_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||||
|
|
Loading…
Reference in a new issue