Browse Source

Merge pull request #23 from madeye/multi-port-config

Multi port config
pull/24/head
Max Lv 11 years ago
parent
commit
ad19aad076
11 changed files with 79 additions and 35 deletions
  1. 5
      README.md
  2. 20
      configure
  3. 2
      configure.ac
  4. 7
      debian/changelog
  5. 26
      src/jconf.c
  6. 8
      src/jconf.h
  7. 21
      src/local.c
  8. 3
      src/local.h
  9. 17
      src/redir.c
  10. 3
      src/redir.h
  11. 2
      src/server.c

5
README.md

@ -16,6 +16,11 @@ Current version: 1.4.0 | [![Build Status](https://travis-ci.org/madeye/shadowsoc
Changelog
---------
1.4.1 -- Tue, 12 Nov 2013 03:57:21 +0000
* Add multi-port support.
* Add PolarSSL support by @linusyang.
1.4.0 -- Sun, 08 Sep 2013 02:20:40 +0000
* Add standard socks5 udp support.

20
configure

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.68 for shadowsocks 1.4.0.
# Generated by GNU Autoconf 2.68 for shadowsocks 1.4.1.
#
# Report bugs to <max.c.lv@gmail.com>.
#
@ -570,8 +570,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='shadowsocks'
PACKAGE_TARNAME='shadowsocks'
PACKAGE_VERSION='1.4.0'
PACKAGE_STRING='shadowsocks 1.4.0'
PACKAGE_VERSION='1.4.1'
PACKAGE_STRING='shadowsocks 1.4.1'
PACKAGE_BUGREPORT='max.c.lv@gmail.com'
PACKAGE_URL=''
@ -1306,7 +1306,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures shadowsocks 1.4.0 to adapt to many kinds of systems.
\`configure' configures shadowsocks 1.4.1 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1376,7 +1376,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of shadowsocks 1.4.0:";;
short | recursive ) echo "Configuration of shadowsocks 1.4.1:";;
esac
cat <<\_ACEOF
@ -1492,7 +1492,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
shadowsocks configure 1.4.0
shadowsocks configure 1.4.1
generated by GNU Autoconf 2.68
Copyright (C) 2010 Free Software Foundation, Inc.
@ -2014,7 +2014,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by shadowsocks $as_me 1.4.0, which was
It was created by shadowsocks $as_me 1.4.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ $0 $@
@ -2834,7 +2834,7 @@ fi
# Define the identity of the package.
PACKAGE='shadowsocks'
VERSION='1.4.0'
VERSION='1.4.1'
cat >>confdefs.h <<_ACEOF
@ -15457,7 +15457,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by shadowsocks $as_me 1.4.0, which was
This file was extended by shadowsocks $as_me 1.4.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -15523,7 +15523,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
shadowsocks config.status 1.4.0
shadowsocks config.status 1.4.1
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"

2
configure.ac

@ -2,7 +2,7 @@ dnl -*- Autoconf -*-
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([shadowsocks], [1.4.0], [max.c.lv@gmail.com])
AC_INIT([shadowsocks], [1.4.1], [max.c.lv@gmail.com])
AC_CONFIG_SRCDIR([src/encrypt.c])
AC_CONFIG_HEADERS([config.h])

7
debian/changelog

@ -1,3 +1,10 @@
shadowsocks (1.4.1-1) unstable; urgency=low
* Add multi-port support.
* Add PolarSSL support by @linusyang.
-- Max Lv <max.c.lv@gmail.com> Tue, 12 Nov 2013 03:57:21 +0000
shadowsocks (1.4.0-1) unstable; urgency=low
* Add standard socks5 udp support.

26
src/jconf.c

@ -52,6 +52,27 @@ static int to_int(const json_value *value)
return 0;
}
static void parse_addr(const char *str, remote_addr_t *addr) {
int ret = -1;
char *pch;
pch = strchr(str, ':');
while (pch != NULL)
{
ret = pch - str;
pch = strchr(pch + 1, ':');
}
if (ret == -1)
{
addr->host = str;
addr->port = NULL;
}
else
{
addr->host = ss_strndup(str, ret);
addr->port = str + ret + 1;
}
}
jconf_t *read_jconf(const char* file)
{
@ -101,13 +122,14 @@ jconf_t *read_jconf(const char* file)
{
if (j >= MAX_REMOTE_NUM) break;
json_value *v = value->u.array.values[j];
conf.remote_host[j] = to_string(v);
parse_addr(to_string(v), conf.remote_addr + j);
conf.remote_num = j + 1;
}
}
else if (value->type == json_string)
{
conf.remote_host[0] = to_string(value);
conf.remote_addr[0].host = to_string(value);
conf.remote_addr[0].port = NULL;
conf.remote_num = 1;
}
}

8
src/jconf.h

@ -6,10 +6,16 @@
#define DNS_THREAD_NUM 4
#define MAX_UDP_CONN_NUM 4096
typedef struct
{
char *host;
char *port;
} remote_addr_t;
typedef struct
{
int remote_num;
char *remote_host[MAX_REMOTE_NUM];
remote_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port;
char *local_port;
char *password;

21
src/local.c

@ -751,7 +751,11 @@ static void accept_cb (EV_P_ ev_io *w, int revents)
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int index = rand() % listener->remote_num;
int err = getaddrinfo(listener->remote_host[index], listener->remote_port, &hints, &res);
if (verbose)
{
LOGD("connect to %s:%s", listener->remote_addr[index].host, listener->remote_addr[index].port);
}
int err = getaddrinfo(listener->remote_addr[index].host, listener->remote_addr[index].port, &hints, &res);
if (err)
{
ERROR("getaddrinfo");
@ -804,7 +808,7 @@ int main (int argc, char **argv)
char *iface = NULL;
int remote_num = 0;
char *remote_host[MAX_REMOTE_NUM];
remote_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
opterr = 0;
@ -814,7 +818,8 @@ int main (int argc, char **argv)
switch (c)
{
case 's':
remote_host[remote_num++] = optarg;
remote_addr[remote_num].host = optarg;
remote_addr[remote_num++].port = NULL;
break;
case 'p':
remote_port = optarg;
@ -867,7 +872,7 @@ int main (int argc, char **argv)
remote_num = conf->remote_num;
for (i = 0; i < remote_num; i++)
{
remote_host[i] = conf->remote_host[i];
remote_addr[i] = conf->remote_addr[i];
}
}
if (remote_port == NULL) remote_port = conf->remote_port;
@ -922,13 +927,13 @@ int main (int argc, char **argv)
// Setup proxy context
struct listen_ctx listen_ctx;
listen_ctx.remote_num = remote_num;
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
listen_ctx.remote_addr = malloc(sizeof(remote_addr_t) * remote_num);
while (remote_num > 0)
{
int index = --remote_num;
listen_ctx.remote_host[index] = remote_host[index];
if (remote_addr[index].port == NULL) remote_addr[index].port = remote_port;
listen_ctx.remote_addr[index] = remote_addr[index];
}
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
listen_ctx.iface = iface;
@ -946,7 +951,7 @@ int main (int argc, char **argv)
if (udprelay)
{
LOGD("udprelay enabled.");
udprelay_init(local_addr, local_port, remote_host[0], remote_port, m, iface);
udprelay_init(local_addr, local_port, remote_addr[0].host, remote_addr[0].port, m, iface);
}
ev_run (loop, 0);

3
src/local.h

@ -8,8 +8,7 @@
struct listen_ctx
{
ev_io io;
char **remote_host;
char *remote_port;
remote_addr_t *remote_addr;
char *iface;
int remote_num;
int method;

17
src/redir.c

@ -619,7 +619,7 @@ static void accept_cb (EV_P_ ev_io *w, int revents)
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int index = rand() % listener->remote_num;
err = getaddrinfo(listener->remote_host[index], listener->remote_port, &hints, &res);
err = getaddrinfo(listener->remote_addr[index].host, listener->remote_addr[index].port, &hints, &res);
if (err)
{
ERROR("getaddrinfo");
@ -670,7 +670,7 @@ int main (int argc, char **argv)
char *conf_path = NULL;
int remote_num = 0;
char *remote_host[MAX_REMOTE_NUM];
remote_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
opterr = 0;
@ -680,7 +680,8 @@ int main (int argc, char **argv)
switch (c)
{
case 's':
remote_host[remote_num++] = optarg;
remote_addr[remote_num].host = optarg;
remote_addr[remote_num++].port = NULL;
break;
case 'p':
remote_port = optarg;
@ -724,7 +725,7 @@ int main (int argc, char **argv)
remote_num = conf->remote_num;
for (i = 0; i < remote_num; i++)
{
remote_host[i] = conf->remote_host[i];
remote_addr[i] = conf->remote_addr[i];
}
}
if (remote_port == NULL) remote_port = conf->remote_port;
@ -755,7 +756,7 @@ int main (int argc, char **argv)
signal(SIGABRT, SIG_IGN);
// Setup keys
LOGD("calculating ciphers...");
LOGD("initialize ciphers... %s", method);
int m = enc_init(password, method);
// Setup socket
@ -775,13 +776,13 @@ int main (int argc, char **argv)
// Setup proxy context
struct listen_ctx listen_ctx;
listen_ctx.remote_num = remote_num;
listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
listen_ctx.remote_addr = malloc(sizeof(remote_addr_t) * remote_num);
while (remote_num > 0)
{
int index = --remote_num;
listen_ctx.remote_host[index] = remote_host[index];
if (remote_addr[index].port == NULL) remote_addr[index].port = remote_port;
listen_ctx.remote_addr[index] = remote_addr[index];
}
listen_ctx.remote_port = remote_port;
listen_ctx.timeout = atoi(timeout);
listen_ctx.fd = listenfd;
listen_ctx.method = m;

3
src/redir.h

@ -8,8 +8,7 @@
struct listen_ctx
{
ev_io io;
char **remote_host;
char *remote_port;
remote_addr_t *remote_addr;
int remote_num;
int timeout;
int fd;

2
src/server.c

@ -969,7 +969,7 @@ int main (int argc, char **argv)
server_num = conf->remote_num;
for (i = 0; i < server_num; i++)
{
server_host[i] = conf->remote_host[i];
server_host[i] = conf->remote_addr[i].host;
}
}
if (server_port == NULL) server_port = conf->remote_port;

Loading…
Cancel
Save