dnomd343
2 years ago
22 changed files with 214 additions and 327 deletions
@ -1,29 +1,16 @@ |
|||
#ifndef _COMMON_H_ |
|||
#define _COMMON_H_ |
|||
|
|||
#define VERSION "0.9.1" |
|||
#define VERSION "0.9.2" |
|||
|
|||
#define RANDOM_PORT_START 41952 |
|||
#define RANDOM_PORT_END 65535 |
|||
|
|||
typedef struct { |
|||
int is_udp_proxy; |
|||
char *server_addr, *client_addr; |
|||
char *server_port, *client_port; |
|||
char *password; |
|||
char *method; |
|||
char *timeout; |
|||
int fastopen; |
|||
char *plugin; |
|||
char *plugin_opts; |
|||
char *shadowsocks; |
|||
char **shadowsocks_opts; |
|||
} bootstrap_info; |
|||
|
|||
char* int_to_string(int num); |
|||
char* new_string(char *str); |
|||
char* int_to_string(int num); |
|||
char* read_file(char *file_name); |
|||
void params_load(char *ss_default, bootstrap_info *info); |
|||
void args_decode(int argc, char **argv, bootstrap_info *info); |
|||
char** string_list_append(char **string_list, char *data); |
|||
|
|||
void init(int argc, char **argv, char *help_msg); |
|||
|
|||
#endif |
|||
|
@ -1,9 +0,0 @@ |
|||
#ifndef _HELP_H_ |
|||
#define _HELP_H_ |
|||
|
|||
extern char *local_help_msg; |
|||
extern char *server_help_msg; |
|||
|
|||
void is_show_help(int argc, char **argv, char *help_msg); |
|||
|
|||
#endif |
@ -1,6 +1,20 @@ |
|||
#ifndef _LOAD_H_ |
|||
#define _LOAD_H_ |
|||
|
|||
void load_info(int argc, char **argv); |
|||
typedef struct { |
|||
int is_udp_proxy; |
|||
char *server_addr, *client_addr; |
|||
char *server_port, *client_port; |
|||
char *password; |
|||
char *method; |
|||
char *timeout; |
|||
int fastopen; |
|||
char *plugin; |
|||
char *plugin_opts; |
|||
char *shadowsocks; |
|||
char **shadowsocks_opts; |
|||
} boot_info; |
|||
|
|||
boot_info* load_info(int argc, char **argv); |
|||
|
|||
#endif |
|||
|
@ -0,0 +1,7 @@ |
|||
#ifndef _SIP003_H_ |
|||
#define _SIP003_H_ |
|||
|
|||
//void params_load(char *ss_default, bootstrap_info *info);
|
|||
//void args_decode(int argc, char **argv, bootstrap_info *info);
|
|||
|
|||
#endif |
@ -1,19 +1,12 @@ |
|||
cmake_minimum_required(VERSION 2.8.12) |
|||
|
|||
include_directories(${PROJECT_SOURCE_DIR}/include) |
|||
include_directories(/usr/lib/i386-linux-gnu/glib-2.0/include) |
|||
include_directories(/usr/lib/x86_64-linux-gnu/glib-2.0/include) |
|||
include_directories(/usr/lib/aarch64-linux-gnu/glib-2.0/include) |
|||
include_directories(/usr/lib64/glib-2.0/include) |
|||
include_directories(/usr/lib/glib-2.0/include) |
|||
include_directories(/usr/include/glib-2.0) |
|||
include_directories(${PROJECT_SOURCE_DIR}/include/utils) |
|||
|
|||
aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC) |
|||
list(REMOVE_ITEM SRC ${PROJECT_SOURCE_DIR}/src/local.c) |
|||
list(REMOVE_ITEM SRC ${PROJECT_SOURCE_DIR}/src/server.c) |
|||
add_subdirectory(utils) |
|||
|
|||
add_executable(ss-bootstrap-local local.c ${SRC}) |
|||
target_link_libraries(ss-bootstrap-local glib-2.0 pthread) |
|||
add_executable(ss-bootstrap-local local.c common.c load.c) |
|||
target_link_libraries(ss-bootstrap-local utils pthread) |
|||
|
|||
add_executable(ss-bootstrap-server server.c ${SRC}) |
|||
target_link_libraries(ss-bootstrap-server glib-2.0 pthread) |
|||
add_executable(ss-bootstrap-server local.c common.c load.c) |
|||
target_link_libraries(ss-bootstrap-server utils pthread) |
|||
|
@ -1,66 +0,0 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include "help.h" |
|||
|
|||
char *server_help_msg = "\n\
|
|||
ss-bootstrap-server\n\ |
|||
\n\ |
|||
A simple program to make the original shadowsocks support SIP003 plugins.\n\ |
|||
\n\ |
|||
-s <server_host> Host name or IP address of your remote server.\n\ |
|||
-p <server_port> Port number of your remote server.\n\ |
|||
-b <local_address> Local address to bind.\n\ |
|||
-l <local_port> Port number of your local server.\n\ |
|||
\n\ |
|||
-c <config_file> Path to JSON config file.\n\ |
|||
-k <password> Password of your remote server.\n\ |
|||
-m <method> Encrypt method.\n\ |
|||
-t <timeout> Socket timeout in seconds.\n\ |
|||
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\ |
|||
--plugin <name> Enable SIP003 plugin.\n\ |
|||
--plugin-opts <options> Set SIP003 plugin options.\n\ |
|||
--shadowsocks <ssservre> Set shadowsocks server program.\n\ |
|||
--no-udp Do not use UDP proxy.\n\ |
|||
-h, --help Print this message.\n\ |
|||
\n\ |
|||
"; |
|||
|
|||
char *local_help_msg = "\n\
|
|||
ss-bootstrap-local\n\ |
|||
\n\ |
|||
A simple program to make the original shadowsocks support SIP003 plugins.\n\ |
|||
\n\ |
|||
-s <server_host> Host name or IP address of your remote server.\n\ |
|||
-p <server_port> Port number of your remote server.\n\ |
|||
-b <local_address> Local address to bind.\n\ |
|||
-l <local_port> Port number of your local server.\n\ |
|||
\n\ |
|||
-c <config_file> Path to JSON config file.\n\ |
|||
-k <password> Password of your remote server.\n\ |
|||
-m <method> Encrypt method.\n\ |
|||
-t <timeout> Socket timeout in seconds.\n\ |
|||
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\ |
|||
--plugin <name> Enable SIP003 plugin.\n\ |
|||
--plugin-opts <options> Set SIP003 plugin options.\n\ |
|||
--shadowsocks <sslocal> Set shadowsocks local program.\n\ |
|||
--no-udp Do not use UDP proxy.\n\ |
|||
-h, --help Print this message.\n\ |
|||
\n\ |
|||
"; |
|||
|
|||
void show_help(char *help_msg) { |
|||
printf("%s", help_msg); |
|||
exit(0); // exit normally
|
|||
} |
|||
|
|||
void is_show_help(int argc, char **argv, char *help_msg) { // output help when necessary
|
|||
if (argc <= 1) { // with only one argument
|
|||
show_help(help_msg); |
|||
} |
|||
for (int i = 0; i < argc; ++i) { |
|||
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { // include `-h` or `--help`
|
|||
show_help(help_msg); |
|||
} |
|||
} |
|||
} |
@ -1,20 +1,38 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include "load.h" |
|||
#include "logger.h" |
|||
#include "common.h" |
|||
#include "process.h" |
|||
#include "help.h" |
|||
#include "logger.h" |
|||
#include "load.h" |
|||
|
|||
char *help_msg = "\n\
|
|||
ss-bootstrap-local\n\ |
|||
\n\ |
|||
A simple program to make the original shadowsocks support SIP003 plugins.\n\ |
|||
\n\ |
|||
-s <server_host> Host name or IP address of your remote server.\n\ |
|||
-p <server_port> Port number of your remote server.\n\ |
|||
-b <local_address> Local address to bind.\n\ |
|||
-l <local_port> Port number of your local server.\n\ |
|||
\n\ |
|||
-c <config_file> Path to JSON config file.\n\ |
|||
-k <password> Password of your remote server.\n\ |
|||
-m <method> Encrypt method.\n\ |
|||
-t <timeout> Socket timeout in seconds.\n\ |
|||
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\ |
|||
--plugin <name> Enable SIP003 plugin.\n\ |
|||
--plugin-opts <options> Set SIP003 plugin options.\n\ |
|||
--shadowsocks <sslocal> Set shadowsocks local program.\n\ |
|||
--no-udp Do not use UDP proxy.\n\ |
|||
-h, --help Print this message.\n\ |
|||
\n\ |
|||
"; |
|||
|
|||
int main(int argc, char *argv[]) { |
|||
is_show_help(argc, argv, local_help_msg); |
|||
init(argc, argv, help_msg); |
|||
log_info("Shadowsocks bootstrap local (%s)", VERSION); |
|||
boot_info *info = load_info(argc, argv); |
|||
|
|||
// set log level
|
|||
// bootstrap_info info;
|
|||
load_info(argc, argv); |
|||
// params_load("sslocal"); // default file name
|
|||
// start_bootstrap("sslocal", is_udp_proxy); // local or server mode
|
|||
|
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,60 @@ |
|||
#include "sip003.h" |
|||
#include "load.h" |
|||
|
|||
void params_load(char *ss_default, boot_info *info) { // load shadowsocks and plugin params
|
|||
if (info->shadowsocks == NULL) { |
|||
info->shadowsocks = ss_default; |
|||
} |
|||
info->shadowsocks_opts[0] = info->shadowsocks; // fill with file name
|
|||
if (info->plugin != NULL) { // with plugin
|
|||
char *rand_port = int_to_string(get_available_port(RANDOM_PORT_START, RANDOM_PORT_END)); |
|||
SS_REMOTE_HOST = info->server_addr; |
|||
SS_REMOTE_PORT = info->server_port; |
|||
SS_LOCAL_HOST = "127.0.0.1"; |
|||
SS_LOCAL_PORT = rand_port; |
|||
info->server_addr = SS_LOCAL_HOST; |
|||
info->server_port = SS_LOCAL_PORT; |
|||
SS_PLUGIN_OPTIONS = info->plugin_opts; |
|||
} |
|||
pack_shadowsocks_params(info); |
|||
shadowsocks_args = info->shadowsocks_opts; |
|||
if (info->plugin == NULL) { |
|||
plugin_file = NULL; |
|||
} else { |
|||
plugin_file = info->plugin; |
|||
} |
|||
} |
|||
|
|||
void pack_shadowsocks_params(boot_info *info) { // packaging shadowsocks parameters
|
|||
if (info->server_addr != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-s"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->server_addr); |
|||
} |
|||
if (info->client_addr != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-b"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->client_addr); |
|||
} |
|||
if (info->server_port != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-p"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->server_port); |
|||
} |
|||
if (info->client_port != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-l"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->client_port); |
|||
} |
|||
if (info->password != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-k"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->password); |
|||
} |
|||
if (info->method != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-m"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->method); |
|||
} |
|||
if (info->timeout != NULL) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "-t"); |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, info->timeout); |
|||
} |
|||
if (info->fastopen) { |
|||
info->shadowsocks_opts = string_list_append(info->shadowsocks_opts, "--fast-open"); |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
aux_source_directory(. utils_src) |
|||
add_library(utils ${utils_src}) |
Loading…
Reference in new issue