Skip to content

Commit

Permalink
progerss on udp/ general things
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 30, 2024
1 parent 37d2b35 commit e919891
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 300 deletions.
2 changes: 1 addition & 1 deletion core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(void)

// libhv has a separate logger, we attach it to the core logger
logger_set_level_by_str(hv_default_logger(), getCoreSettings()->core_log_level);
logger_set_handler(hv_default_logger(), getCoreLoggerHandle(getCoreSettings()->core_log_console));
logger_set_handler(hv_default_logger(), getCoreLoggerHandle());

LOGI("Starting Waterwall version %s", TOSTRING(WATERWALL_VERSION));
LOGI("Parsing core file complete");
Expand Down
14 changes: 5 additions & 9 deletions tunnels/adapters/bridge/bridge.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "bridge.h"
#include "loggers/network_logger.h"
#include "managers/node_manager.h"

#include "utils/jsonutils.h"

typedef struct bridge_state_s
{
bool mode_upside; // if this node is last node of upstream
node_t * pair_node;
node_t *pair_node;
tunnel_t *pair;

} bridge_state_t;
Expand All @@ -16,7 +16,6 @@ typedef struct bridge_con_state_s

} bridge_con_state_t;


static void upStream(tunnel_t *self, context_t *c)
{
bridge_state_t *state = STATE(self);
Expand All @@ -39,9 +38,7 @@ static void upStream(tunnel_t *self, context_t *c)
// }
// self->upStream(self, c);


state->pair->dw->downStream(state->pair->dw,c);

state->pair->dw->downStream(state->pair->dw, c);
}

static inline void downStream(tunnel_t *self, context_t *c)
Expand All @@ -67,14 +64,13 @@ static inline void downStream(tunnel_t *self, context_t *c)
// }
// self->downStream(self, c);


state->pair->up->upStream(state->pair->up,c);
state->pair->up->upStream(state->pair->up, c);
}

tunnel_t *newBridge(node_instance_context_t *instance_info)
{
const cJSON *settings = instance_info->node_settings_json;
char * pair_node_name = NULL;
char *pair_node_name = NULL;
if (! getStringFromJsonObject(&pair_node_name, settings, "pair"))
{
LOGF("Bridge: \"pair\" is not provided in json");
Expand Down
4 changes: 2 additions & 2 deletions tunnels/adapters/connector/udp/udp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static void cleanup(udp_connector_con_state_t *cstate)
udp_connector_state_t *state = STATE(cstate->tunnel);
free(cstate);
}
static void onRecv(hio_t *io, shift_buffer_t *buf)
static void onRecvFrom(hio_t *io, shift_buffer_t *buf)
{
udp_connector_con_state_t *cstate = (udp_connector_con_state_t *) (hevent_userdata(io));
if (cstate == NULL)
Expand Down Expand Up @@ -120,7 +120,7 @@ static void upStream(tunnel_t *self, context_t *c)

cstate->io = upstream_io;
hevent_set_userdata(upstream_io, cstate);
hio_setcb_read(upstream_io, onRecv);
hio_setcb_read(upstream_io, onRecvFrom);
hio_read(upstream_io);

socket_context_t *dest_ctx = &(c->line->dest_ctx);
Expand Down
2 changes: 2 additions & 0 deletions tunnels/client/header/header_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "buffer_stream.h"
#include "hsocket.h"
#include "loggers/network_logger.h"
#include "utils/jsonutils.h"


enum header_dynamic_value_status
{
Expand Down
19 changes: 10 additions & 9 deletions tunnels/client/preconnect/preconnect_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "loggers/network_logger.h"
#include "managers/node_manager.h"
#include "types.h"
#include "utils/jsonutils.h"

static inline void upStream(tunnel_t *self, context_t *c)
{
Expand Down Expand Up @@ -47,7 +48,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
ucon->mode = kConnectedPair;
CSTATE_MUT(c) = ucon;
self->dw->downStream(self->dw, newEstContext(c->line));
initiateConnect(self,false);
initiateConnect(self, false);
}
else
{
Expand Down Expand Up @@ -121,7 +122,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
else
{
const unsigned int tid = c->line->tid;
thread_box_t * this_tb = &(state->workers[tid]);
thread_box_t *this_tb = &(state->workers[tid]);
preconnect_client_con_state_t *ucon = CSTATE(c);

if (c->fin)
Expand All @@ -134,7 +135,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
atomic_fetch_add_explicit(&(state->active_cons), -1, memory_order_relaxed);
destroyCstate(ucon);
self->dw->downStream(self->dw, c);
initiateConnect(self,true);
initiateConnect(self, true);

break;

Expand All @@ -144,7 +145,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
(ucon->d->chains_state)[self->chain_index] = NULL;
destroyCstate(ucon);
self->dw->downStream(self->dw, switchLine(c, d_line));
initiateConnect(self,false);
initiateConnect(self, false);

break;

Expand All @@ -157,7 +158,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
}
destroyCstate(ucon);
destroyContext(c);
initiateConnect(self,true);
initiateConnect(self, true);

break;

Expand All @@ -177,7 +178,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
destroyContext(c);
unsigned int unused = atomic_fetch_add_explicit(&(state->unused_cons), 1, memory_order_relaxed);
LOGI("PreConnectClient: connected, unused: %d active: %d", unused + 1, state->active_cons);
initiateConnect(self,false);
initiateConnect(self, false);
}
else
{
Expand All @@ -189,15 +190,15 @@ static inline void downStream(tunnel_t *self, context_t *c)

static void startPreconnect(htimer_t *timer)
{
tunnel_t * self = hevent_userdata(timer);
tunnel_t *self = hevent_userdata(timer);
preconnect_client_state_t *state = STATE(self);

for (int i = 0; i < workers_count; i++)
{
const int cpt = state->connection_per_thread;
const size_t cpt = state->connection_per_thread;
for (size_t ci = 0; ci < cpt; ci++)
{
initiateConnect(self,true);
initiateConnect(self, true);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tunnels/client/reverse/reverse_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "helpers.h"
#include "loggers/network_logger.h"
#include "types.h"
#include "utils/jsonutils.h"

static inline void upStream(tunnel_t *self, context_t *c)
{
Expand Down Expand Up @@ -157,7 +158,7 @@ static inline void downStream(tunnel_t *self, context_t *c)

static void startReverseCelint(htimer_t *timer)
{
tunnel_t * self = hevent_userdata(timer);
tunnel_t *self = hevent_userdata(timer);
reverse_client_state_t *state = STATE(self);
for (int i = 0; i < workers_count; i++)
{
Expand Down
1 change: 1 addition & 0 deletions tunnels/server/header/header_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "buffer_stream.h"
#include "hsocket.h"
#include "loggers/network_logger.h"
#include "utils/jsonutils.h"

enum header_dynamic_value_status
{
Expand Down
7 changes: 5 additions & 2 deletions tunnels/server/trojan/auth/trojan_auth_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
#include "managers/node_manager.h"
#include "utils/stringutils.h"
#include "utils/userutils.h"
#include "utils/jsonutils.h"

#define i_type hmap_users_t // NOLINT
#define i_key hash_t // NOLINT
#define i_val trojan_user_t * // NOLINT

#define VEC_CAP 100
#define CRLF_LEN 2
enum {
VEC_CAP = 100,
CRLF_LEN = 2
};

#include "stc/hmap.h"

Expand Down
2 changes: 1 addition & 1 deletion ww/buffer_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
This is the most memory consuming part of the program, and also the preallocation length really
depends on where you want to use this program, on a phone or on a 16 core server?
so there are possible choose able memory profiles in the .c file which you can select the best for your needs
so there are possible choices for memory profiles in the .c file which you can select the best for your needs
todo (runtime selection) its better that the memory profile be a runtime selection than compile time
Expand Down
1 change: 0 additions & 1 deletion ww/context_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@ void contextQueueNotifyIoRemoved(context_queue_t *self, hio_t *io)
{
(*i.ref)->src_io = NULL;
}
destroyContext((*i.ref));
}
}
Loading

0 comments on commit e919891

Please sign in to comment.