enable quick sort
This commit is contained in:
+2
-1
@@ -2,8 +2,9 @@ global {
|
||||
perm_cache = 2048;
|
||||
cache_dir = "/data/data/com.github.shadowsocks";
|
||||
server_ip = 127.0.0.1;
|
||||
server_port = 8053;
|
||||
server_port = 8153;
|
||||
query_method = tcp_only;
|
||||
run_ipv4 = on;
|
||||
min_ttl = 15m;
|
||||
max_ttl = 1w;
|
||||
timeout = 10;
|
||||
|
||||
Binary file not shown.
+1
-1
@@ -1 +1 @@
|
||||
APP_PLATFORM = anrdoid-7
|
||||
APP_PLATFORM = anrdoid-8
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", __VA_ARGS__))
|
||||
|
||||
+13
-18
@@ -1,4 +1,5 @@
|
||||
#include "encrypt.h"
|
||||
#include "android.h"
|
||||
|
||||
#include <openssl/md5.h>
|
||||
|
||||
@@ -33,37 +34,31 @@ int recv_decrypt(int sock, char *buf, int len, int flags) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int random_compare(unsigned char x, unsigned char y, unsigned int i, unsigned long long a) {
|
||||
static int random_compare(const void *_x, const void *_y) {
|
||||
unsigned int i = _i;
|
||||
unsigned long long a = _a;
|
||||
unsigned char x = *((unsigned char*) _x);
|
||||
unsigned char y = *((unsigned char*) _y);
|
||||
return (a % (x + i) - a % (y + i));
|
||||
}
|
||||
|
||||
void get_table(const unsigned char* key) {
|
||||
void get_table(const char* key) {
|
||||
unsigned char *table = encrypt_table;
|
||||
unsigned char *tmp_hash;
|
||||
tmp_hash = MD5((const unsigned char*)key, strlen((const char*)key), NULL);
|
||||
unsigned long long a;
|
||||
a = *(unsigned long long *)tmp_hash;
|
||||
tmp_hash = MD5((const unsigned char*)key, strlen(key), NULL);
|
||||
_a = *(unsigned long long *)tmp_hash;
|
||||
unsigned int i;
|
||||
|
||||
LOGD("key hash: %lld", _a);
|
||||
|
||||
for(i = 0; i < 256; ++i) {
|
||||
table[i] = i;
|
||||
}
|
||||
for(i = 1; i < 1024; ++i) {
|
||||
// use bubble sort in order to keep the array stable as in Python
|
||||
int k,j;
|
||||
unsigned char t;
|
||||
for(k = 256 - 2; k >= 0; --k)
|
||||
{
|
||||
for(j = 0;j <= k; ++j)
|
||||
{
|
||||
if(random_compare(table[j], table[j + 1], i, a) > 0)
|
||||
{
|
||||
t=table[j];
|
||||
table[j]=table[j + 1];
|
||||
table[j + 1]=t;
|
||||
}
|
||||
}
|
||||
}
|
||||
_i = i;
|
||||
qsort(table, 256, sizeof(unsigned char), random_compare);
|
||||
}
|
||||
for(i = 0; i < 256; ++i) {
|
||||
// gen decrypt table from encrypt table
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
|
||||
unsigned char encrypt_table[256];
|
||||
unsigned char decrypt_table[256];
|
||||
void get_table(const unsigned char* key);
|
||||
void get_table(const char* key);
|
||||
void encrypt(char *buf, int len);
|
||||
void decrypt(char *buf, int len);
|
||||
int send_encrypt(int sock, char *buf, int len, int flags);
|
||||
int recv_decrypt(int sock, char *buf, int len, int flags);
|
||||
|
||||
unsigned int _i;
|
||||
unsigned long long _a;
|
||||
|
||||
|
||||
+9
-16
@@ -17,13 +17,10 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/limits.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "local.h"
|
||||
#include "encrypt.h"
|
||||
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", __VA_ARGS__))
|
||||
#include "android.h"
|
||||
|
||||
#define REPLY "HTTP/1.1 200 OK\n\nhello"
|
||||
|
||||
@@ -60,7 +57,7 @@ int create_and_bind(const char *port) {
|
||||
|
||||
s = getaddrinfo("0.0.0.0", port, &hints, &result);
|
||||
if (s != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
LOGD("getaddrinfo: %s", gai_strerror(s));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -83,7 +80,7 @@ int create_and_bind(const char *port) {
|
||||
}
|
||||
|
||||
if (rp == NULL) {
|
||||
fprintf(stderr, "Could not bind\n");
|
||||
LOGE("Could not bind");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -171,8 +168,8 @@ static void server_send_cb (EV_P_ ev_io *w, int revents) {
|
||||
return;
|
||||
}
|
||||
if (r < server->buf_len) {
|
||||
// printf("r=%d\n", r);
|
||||
// printf("server->buf_len=%d\n", server->buf_len);
|
||||
LOGD("r=%d\n", r);
|
||||
LOGD("server->buf_len=%d\n", server->buf_len);
|
||||
// partly sent, move memory, wait for the next time to send
|
||||
char *pt;
|
||||
for (pt = server->buf; pt < pt + min(r, BUF_SIZE); pt++) {
|
||||
@@ -204,7 +201,7 @@ static void remote_recv_cb (EV_P_ ev_io *w, int revents) {
|
||||
}
|
||||
while (1) {
|
||||
ssize_t r = recv(remote->fd, server->buf, BUF_SIZE, 0);
|
||||
// printf("after recv: r=%d\n", r);
|
||||
/*LOGD("after recv: r=%d\n", r);*/
|
||||
if (r == 0) {
|
||||
// connection closed
|
||||
server->buf_len = 0;
|
||||
@@ -227,7 +224,7 @@ static void remote_recv_cb (EV_P_ ev_io *w, int revents) {
|
||||
}
|
||||
decrypt(server->buf, r);
|
||||
int w = send(server->fd, server->buf, r, MSG_NOSIGNAL);
|
||||
// printf("after send: w=%d\n", w);
|
||||
/*LOGD("after send: w=%d\n", w);*/
|
||||
if(w == -1) {
|
||||
perror("send");
|
||||
if (errno == EAGAIN) {
|
||||
@@ -329,7 +326,6 @@ struct remote* new_remote(int fd) {
|
||||
remote->recv_ctx->connected = 0;
|
||||
remote->send_ctx->remote = remote;
|
||||
remote->send_ctx->connected = 0;
|
||||
fprintf(stderr, "new remote\n");
|
||||
return remote;
|
||||
}
|
||||
void free_remote(struct remote *remote) {
|
||||
@@ -340,7 +336,6 @@ void free_remote(struct remote *remote) {
|
||||
free(remote->recv_ctx);
|
||||
free(remote->send_ctx);
|
||||
free(remote);
|
||||
fprintf(stderr, "free remote\n");
|
||||
}
|
||||
}
|
||||
void close_and_free_remote(EV_P_ struct remote *remote) {
|
||||
@@ -363,7 +358,6 @@ struct server* new_server(int fd) {
|
||||
server->recv_ctx->connected = 0;
|
||||
server->send_ctx->server = server;
|
||||
server->send_ctx->connected = 0;
|
||||
fprintf(stderr, "new server\n");
|
||||
return server;
|
||||
}
|
||||
void free_server(struct server *server) {
|
||||
@@ -374,7 +368,6 @@ void free_server(struct server *server) {
|
||||
free(server->recv_ctx);
|
||||
free(server->send_ctx);
|
||||
free(server);
|
||||
fprintf(stderr, "free server\n");
|
||||
}
|
||||
}
|
||||
void close_and_free_server(EV_P_ struct server *server) {
|
||||
@@ -432,7 +425,7 @@ int main (int argc, char **argv)
|
||||
const char *server = argv[1];
|
||||
const char *remote_port = argv[2];
|
||||
const char *port = argv[3];
|
||||
const char *key = argv[4];
|
||||
const char *key = argv[4];
|
||||
|
||||
/* Our process ID and Session ID */
|
||||
pid_t pid, sid;
|
||||
@@ -478,7 +471,7 @@ int main (int argc, char **argv)
|
||||
_server = strdup(server);
|
||||
_remote_port = strdup(remote_port);
|
||||
|
||||
fprintf(stderr, "calculating ciphers\n");
|
||||
LOGD("calculating ciphers");
|
||||
get_table(key);
|
||||
|
||||
int listenfd;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ShadowsocksService extends Service {
|
||||
private static final int MSG_HOST_CHANGE = 4;
|
||||
private static final int MSG_STOP_SELF = 5;
|
||||
private static final String TAG = "ShadowsocksService";
|
||||
private final static int DNS_PORT = 8053;
|
||||
private final static int DNS_PORT = 8153;
|
||||
private static final Class<?>[] mStartForegroundSignature = new Class[]{
|
||||
int.class, Notification.class};
|
||||
private static final Class<?>[] mStopForegroundSignature = new Class[]{boolean.class};
|
||||
|
||||
Reference in New Issue
Block a user