-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
860ede5
commit 022daa3
Showing
11 changed files
with
183 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[inbound] | ||
proto = "dokodemo" | ||
local = "127.0.0.1" | ||
port = "3134" | ||
|
||
[outbound] | ||
proto = "dokodemo" | ||
proxy = "127.0.0.1" | ||
port = "3135" |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# proto | ||
|
||
add_lib_batch(vmecs-proto STATIC "*.c" "vmess/*.c" "native/*.c" "relay/*.c" "socks/*.c") | ||
add_lib_batch(vmecs-proto STATIC "*.c" "vmess/*.c" "native/*.c" "relay/*.c" "socks/*.c" "dokodemo/*.c") | ||
|
||
target_link_libraries(vmecs-proto vmecs-crypto vmecs-pub) |
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,42 @@ | ||
#include "pub/socket.h" | ||
|
||
#include "proto/common.h" | ||
#include "proto/native/tcp.h" | ||
|
||
#include "inbound.h" | ||
|
||
static tcp_socket_t * | ||
_dokodemo_tcp_inbound_server(tcp_inbound_t *_inbound) | ||
{ | ||
dokodemo_tcp_inbound_t *inbound = (dokodemo_tcp_inbound_t *)_inbound; | ||
tcp_socket_t *sock = (tcp_socket_t *)native_tcp_socket_new(); | ||
|
||
while (tcp_socket_bind_target(sock, inbound->local)) | ||
sleep(1); | ||
|
||
return sock; | ||
} | ||
|
||
static void | ||
_dokodemo_tcp_inbound_free(tcp_inbound_t *_inbound) | ||
{ | ||
dokodemo_tcp_inbound_t *inbound = (dokodemo_tcp_inbound_t *)_inbound; | ||
|
||
if (inbound) { | ||
target_id_free(inbound->local); | ||
free(inbound); | ||
} | ||
} | ||
|
||
dokodemo_tcp_inbound_t * | ||
dokodemo_tcp_inbound_new(target_id_t *local) | ||
{ | ||
dokodemo_tcp_inbound_t *ret = malloc(sizeof(*ret)); | ||
ASSERT(ret, "out of mem"); | ||
|
||
ret->server_func = _dokodemo_tcp_inbound_server; | ||
ret->free_func = _dokodemo_tcp_inbound_free; | ||
ret->local = target_id_copy(local); | ||
|
||
return ret; | ||
} |
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,16 @@ | ||
#ifndef _PROTO_DOKODEMO_INBOUND_H_ | ||
#define _PROTO_DOKODEMO_INBOUND_H_ | ||
|
||
#include "pub/type.h" | ||
|
||
#include "proto/relay/inbound.h" | ||
|
||
typedef struct { | ||
TCP_INBOUND_HEADER | ||
target_id_t *local; // local bind address | ||
} dokodemo_tcp_inbound_t; | ||
|
||
dokodemo_tcp_inbound_t * | ||
dokodemo_tcp_inbound_new(target_id_t *local); | ||
|
||
#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,43 @@ | ||
#include "proto/native/tcp.h" | ||
|
||
#include "outbound.h" | ||
|
||
static tcp_socket_t * | ||
_dokodemo_tcp_outbound_client(tcp_outbound_t *_outbound, const target_id_t *_) | ||
{ | ||
dokodemo_tcp_outbound_t *outbound = (dokodemo_tcp_outbound_t *)_outbound; | ||
tcp_socket_t *sock = (tcp_socket_t *)native_tcp_socket_new(); | ||
|
||
if (tcp_socket_connect_target(sock, outbound->target)) { | ||
tcp_socket_close(sock); | ||
tcp_socket_free(sock); | ||
return NULL; | ||
} | ||
|
||
return sock; | ||
} | ||
|
||
static void | ||
_dokodemo_tcp_outbound_free(tcp_outbound_t *_outbound) | ||
{ | ||
dokodemo_tcp_outbound_t *outbound = (dokodemo_tcp_outbound_t *)_outbound; | ||
|
||
if (outbound) { | ||
target_id_free(outbound->target); | ||
free(outbound); | ||
} | ||
} | ||
|
||
dokodemo_tcp_outbound_t * | ||
dokodemo_tcp_outbound_new(target_id_t *target) | ||
{ | ||
dokodemo_tcp_outbound_t *ret = malloc(sizeof(*ret)); | ||
ASSERT(ret, "out of mem"); | ||
|
||
ret->client_func = _dokodemo_tcp_outbound_client; | ||
ret->free_func = _dokodemo_tcp_outbound_free; | ||
|
||
ret->target = target_id_copy(target); | ||
|
||
return ret; | ||
} |
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,16 @@ | ||
#ifndef _PROTO_DOKODEMO_OUTBOUND_H_ | ||
#define _PROTO_DOKODEMO_OUTBOUND_H_ | ||
|
||
#include "pub/type.h" | ||
|
||
#include "proto/relay/outbound.h" | ||
|
||
typedef struct { | ||
TCP_OUTBOUND_HEADER | ||
target_id_t *target; | ||
} dokodemo_tcp_outbound_t; | ||
|
||
dokodemo_tcp_outbound_t * | ||
dokodemo_tcp_outbound_new(target_id_t *target); | ||
|
||
#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
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