Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
7f73b7b7
Commit
7f73b7b7
authored
Dec 16, 2012
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable quick sort
parent
39c70f65
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
38 deletions
+35
-38
assets/pdnsd.conf
assets/pdnsd.conf
+2
-1
assets/shadowsocks
assets/shadowsocks
+0
-0
jni/Application.mk
jni/Application.mk
+1
-1
jni/shadowsocks/android.h
jni/shadowsocks/android.h
+5
-0
jni/shadowsocks/encrypt.c
jni/shadowsocks/encrypt.c
+13
-18
jni/shadowsocks/encrypt.h
jni/shadowsocks/encrypt.h
+4
-1
jni/shadowsocks/local.c
jni/shadowsocks/local.c
+9
-16
src/com/github/shadowsocks/ShadowsocksService.java
src/com/github/shadowsocks/ShadowsocksService.java
+1
-1
No files found.
assets/pdnsd.conf
View file @
7f73b7b7
...
...
@@ -2,8 +2,9 @@ global {
perm_cache
=
2048
;
cache_dir
=
"/data/data/com.github.shadowsocks"
;
server_ip
=
127
.
0
.
0
.
1
;
server_port
=
8
0
53
;
server_port
=
8
1
53
;
query_method
=
tcp_only
;
run_ipv4
=
on
;
min_ttl
=
15
m
;
max_ttl
=
1
w
;
timeout
=
10
;
...
...
assets/shadowsocks
View file @
7f73b7b7
No preview for this file type
jni/Application.mk
View file @
7f73b7b7
APP_PLATFORM
=
anrdoid-
7
APP_PLATFORM
=
anrdoid-
8
jni/shadowsocks/android.h
0 → 100644
View file @
7f73b7b7
#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__))
jni/shadowsocks/encrypt.c
View file @
7f73b7b7
#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
...
...
jni/shadowsocks/encrypt.h
View file @
7f73b7b7
...
...
@@ -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
;
jni/shadowsocks/local.c
View file @
7f73b7b7
...
...
@@ -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
;
...
...
src/com/github/shadowsocks/ShadowsocksService.java
View file @
7f73b7b7
...
...
@@ -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
=
8
0
53
;
private
final
static
int
DNS_PORT
=
8
1
53
;
private
static
final
Class
<?>[]
mStartForegroundSignature
=
new
Class
[]{
int
.
class
,
Notification
.
class
};
private
static
final
Class
<?>[]
mStopForegroundSignature
=
new
Class
[]{
boolean
.
class
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment