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
88bff42c
Commit
88bff42c
authored
Dec 19, 2018
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert
856f726d
parent
1ec3a30b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
42 deletions
+36
-42
core/src/main/java/com/github/shadowsocks/JniHelper.java
core/src/main/java/com/github/shadowsocks/JniHelper.java
+1
-13
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
+10
-7
core/src/main/jni/jni-helper.cpp
core/src/main/jni/jni-helper.cpp
+25
-22
No files found.
core/src/main/java/com/github/shadowsocks/JniHelper.java
View file @
88bff42c
...
...
@@ -48,19 +48,7 @@ public class JniHelper {
System
.
loadLibrary
(
"jni-helper"
);
}
public
static
void
sendFd
(
int
fd
,
@NonNull
String
path
)
throws
ErrnoException
{
int
[]
ret
=
sendFdInternal
(
fd
,
path
);
if
(
ret
!=
null
)
{
if
(
ret
[
0
]
==
-
1
)
throw
new
ErrnoException
(
"socket"
,
ret
[
1
]);
else
if
(
ret
[
0
]
==
-
2
)
throw
new
ErrnoException
(
"connect"
,
ret
[
1
]);
else
if
(
ret
[
0
]
==
-
3
)
throw
new
ErrnoException
(
"ancil_send_fd"
,
ret
[
1
]);
}
}
public
static
native
int
[]
sendFdInternal
(
int
fd
,
@NonNull
String
path
)
throws
ErrnoException
;
public
static
native
void
sendFd
(
int
fd
,
@NonNull
String
path
)
throws
ErrnoException
;
@Nullable
public
static
native
byte
[]
parseNumericAddress
(
@NonNull
String
str
);
}
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
View file @
88bff42c
...
...
@@ -169,9 +169,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
super
.
startNativeProcesses
()
val
fd
=
startVpn
()
sendFd
(
fd
)
sendFd
(
startVpn
())
}
override
fun
buildAdditionalArguments
(
cmd
:
ArrayList
<
String
>):
ArrayList
<
String
>
{
...
...
@@ -248,8 +246,13 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
cmd
+=
"--dnsgw"
cmd
+=
"127.0.0.1:${DataStore.portLocalDns}"
}
data
.
processes
.
start
(
cmd
)
data
.
processes
.
start
(
cmd
)
{
try
{
sendFd
(
fd
)
}
catch
(
e
:
ErrnoException
)
{
stopRunner
(
true
,
e
.
message
)
}
}
return
fd
}
...
...
@@ -258,11 +261,11 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
var
tries
=
0
val
path
=
File
(
Core
.
deviceStorage
.
noBackupFilesDir
,
"sock_path"
).
absolutePath
while
(
true
)
try
{
Thread
.
sleep
(
50
0L
shl
tries
)
Thread
.
sleep
(
3
0L
shl
tries
)
JniHelper
.
sendFd
(
fd
,
path
)
return
}
catch
(
e
:
ErrnoException
)
{
if
(
tries
>=
3
)
throw
e
if
(
tries
>=
10
)
throw
e
tries
+=
1
}
}
...
...
core/src/main/jni/jni-helper.cpp
View file @
88bff42c
...
...
@@ -10,26 +10,35 @@
using
namespace
std
;
// return -1 for socket error
// return -2 for connect error
// return -3 for ancil_send_fd error
// Based on: https://android.googlesource.com/platform/libcore/+/564c7e8/luni/src/main/native/libcore_io_Linux.cpp#256
static
void
throwException
(
JNIEnv
*
env
,
jclass
exceptionClass
,
jmethodID
ctor2
,
const
char
*
functionName
,
int
error
)
{
jstring
detailMessage
=
env
->
NewStringUTF
(
functionName
);
if
(
detailMessage
==
NULL
)
{
// Not really much we can do here. We're probably dead in the water,
// but let's try to stumble on...
env
->
ExceptionClear
();
}
env
->
Throw
(
reinterpret_cast
<
jthrowable
>
(
env
->
NewObject
(
exceptionClass
,
ctor2
,
detailMessage
,
error
)));
env
->
DeleteLocalRef
(
detailMessage
);
}
static
void
throwErrnoException
(
JNIEnv
*
env
,
const
char
*
functionName
)
{
int
error
=
errno
;
static
jclass
ErrnoException
=
env
->
FindClass
(
"android/system/ErrnoException"
);
static
jmethodID
ctor2
=
env
->
GetMethodID
(
ErrnoException
,
"<init>"
,
"(Ljava/lang/String;I)V"
);
throwException
(
env
,
ErrnoException
,
ctor2
,
functionName
,
error
);
}
#pragma clang diagnostic ignored "-Wunused-parameter"
extern
"C"
{
JNIEXPORT
jintArray
JNICALL
Java_com_github_shadowsocks_JniHelper_sendFdInternal
(
JNIEnv
*
env
,
jobject
thiz
,
jint
tun_fd
,
jstring
path
)
{
JNIEXPORT
void
JNICALL
Java_com_github_shadowsocks_JniHelper_sendFd
(
JNIEnv
*
env
,
jobject
thiz
,
jint
tun_fd
,
jstring
path
)
{
int
fd
;
struct
sockaddr_un
addr
;
const
char
*
sock_str
=
env
->
GetStringUTFChars
(
path
,
0
);
jint
info
[
2
]
=
{
0
};
jintArray
ret
=
env
->
NewIntArray
(
2
);
if
(
ret
==
nullptr
)
{
goto
quit3
;
}
if
((
fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
))
==
-
1
)
{
info
[
0
]
=
-
1
;
info
[
1
]
=
errno
;
throwErrnoException
(
env
,
"socket"
);
goto
quit2
;
}
...
...
@@ -38,23 +47,17 @@ Java_com_github_shadowsocks_JniHelper_sendFdInternal(JNIEnv *env, jobject thiz,
strncpy
(
addr
.
sun_path
,
sock_str
,
sizeof
(
addr
.
sun_path
)
-
1
);
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
-
1
)
{
info
[
0
]
=
-
2
;
info
[
1
]
=
errno
;
throwErrnoException
(
env
,
"connect"
);
goto
quit
;
}
if
(
ancil_send_fd
(
fd
,
tun_fd
))
{
info
[
0
]
=
-
3
;
info
[
1
]
=
errno
;
}
if
(
ancil_send_fd
(
fd
,
tun_fd
))
throwErrnoException
(
env
,
"ancil_send_fd"
);
quit:
close
(
fd
);
quit2:
env
->
ReleaseStringUTFChars
(
path
,
sock_str
);
env
->
SetIntArrayRegion
(
ret
,
0
,
2
,
info
);
quit3:
return
ret
;
return
;
}
JNIEXPORT
jbyteArray
JNICALL
...
...
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