-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
211 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ cacert.pem | |
|
||
/core/texts | ||
/cmake | ||
/.cache | ||
|
||
.env.local | ||
.env.*.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
|
||
add_library(Listener STATIC | ||
listener.c | ||
|
||
) | ||
|
||
# target_include_directories(Listener PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
#ww api | ||
target_include_directories(Listener PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../ww) | ||
target_link_libraries(Listener ww) | ||
# add dependencies | ||
include(${CMAKE_BINARY_DIR}/cmake/CPM.cmake) | ||
|
||
target_compile_definitions(Listener PRIVATE Listener_VERSION=0.1) | ||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
target_compile_definitions(Listener PRIVATE DEBUG=1) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "listener.h" | ||
#include "loggers/network_logger.h" | ||
#include "managers/node_manager.h" | ||
#include "utils/stringutils.h" | ||
|
||
typedef struct listener_state_s | ||
{ | ||
tunnel_t *tcp_listener; | ||
tunnel_t *udp_listener; | ||
|
||
} listener_state_t; | ||
|
||
typedef struct listener_con_state_s | ||
{ | ||
|
||
} listener_con_state_t; | ||
|
||
static void upStream(tunnel_t *self, context_t *c) | ||
{ | ||
self->up->upStream(self->up, c); | ||
} | ||
static void downStream(tunnel_t *self, context_t *c) | ||
{ | ||
listener_state_t *state = STATE(self); | ||
|
||
switch ((c->line->src_ctx.address_protocol)) | ||
{ | ||
default: | ||
case kSapTcp: | ||
state->tcp_listener->downStream(state->tcp_listener, c); | ||
break; | ||
|
||
case kSapUdp: | ||
state->udp_listener->downStream(state->udp_listener, c); | ||
break; | ||
} | ||
} | ||
|
||
tunnel_t *newListener(node_instance_context_t *instance_info) | ||
{ | ||
listener_state_t *state = malloc(sizeof(listener_state_t)); | ||
memset(state, 0, sizeof(listener_state_t)); | ||
cJSON *settings = instance_info->node_settings_json; | ||
|
||
if (! (cJSON_IsObject(settings) && settings->child != NULL)) | ||
{ | ||
LOGF("JSON Error: Listener->settings (object field) : The object was empty or invalid"); | ||
return NULL; | ||
} | ||
node_t *tcp_outbound_node = newNode(); | ||
node_t *udp_outbound_node = newNode(); | ||
tcp_outbound_node->name = concat(instance_info->node->name, "_tcp_inbound"); | ||
tcp_outbound_node->type = "TcpListener"; | ||
tcp_outbound_node->version = instance_info->node->version; | ||
udp_outbound_node->name = concat(instance_info->node->name, "_tcp_inbound"); | ||
udp_outbound_node->type = "UdpListener"; | ||
udp_outbound_node->version = instance_info->node->version; | ||
registerNode(tcp_outbound_node, settings); | ||
registerNode(udp_outbound_node, settings); | ||
runNode(tcp_outbound_node, instance_info->chain_index); | ||
runNode(udp_outbound_node, instance_info->chain_index); | ||
state->tcp_listener = tcp_outbound_node->instance; | ||
state->udp_listener = udp_outbound_node->instance; | ||
|
||
tunnel_t *t = newTunnel(); | ||
t->state = state; | ||
t->upStream = &upStream; | ||
t->downStream = &downStream; | ||
|
||
chainDown(t, state->tcp_listener); | ||
chainDown(t, state->udp_listener); | ||
|
||
atomic_thread_fence(memory_order_release); | ||
return t; | ||
} | ||
api_result_t apiListener(tunnel_t *self, const char *msg) | ||
{ | ||
(void) (self); | ||
(void) (msg); | ||
return (api_result_t){0}; | ||
} | ||
tunnel_t *destroyListener(tunnel_t *self) | ||
{ | ||
(void) (self); | ||
return NULL; | ||
} | ||
tunnel_metadata_t getMetadataListener() | ||
{ | ||
return (tunnel_metadata_t){.version = 0001, .flags = 0x0}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#include "api.h" | ||
|
||
// user <-----\ /-----> (Tcp|Udp) listener | ||
// user <------> Listener <------> (Tcp|Udp) listener | ||
// user <-----/ \-----> (Tcp|Udp) listener | ||
// | ||
|
||
tunnel_t * newListener(node_instance_context_t *instance_info); | ||
api_result_t apiListener(tunnel_t *self, const char *msg); | ||
tunnel_t * destroyListener(tunnel_t *self); | ||
tunnel_metadata_t getMetadataListener(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.