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
7cd4ecc7
Commit
7cd4ecc7
authored
Jan 20, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always write something on protect failure
parent
c9550442
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
21 deletions
+18
-21
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
+18
-21
No files found.
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
View file @
7cd4ecc7
...
...
@@ -39,6 +39,7 @@ import com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.utils.Subnet
import
com.github.shadowsocks.utils.parseNumericAddress
import
com.github.shadowsocks.utils.printLog
import
java.io.Closeable
import
java.io.File
import
java.io.FileDescriptor
import
java.io.IOException
...
...
@@ -74,34 +75,30 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
.
build
()
}
class
CloseableFd
(
val
fd
:
FileDescriptor
)
:
Closeable
{
override
fun
close
()
=
Os
.
close
(
fd
)
}
private
inner
class
ProtectWorker
:
LocalSocketListener
(
"ShadowsocksVpnThread"
)
{
override
val
socketFile
:
File
=
File
(
Core
.
deviceStorage
.
noBackupFilesDir
,
"protect_path"
)
override
fun
accept
(
socket
:
LocalSocket
)
{
try
{
socket
.
inputStream
.
read
()
val
fd
=
socket
.
ancillaryFileDescriptors
!!
.
single
()
!!
socket
.
outputStream
.
write
(
if
(
try
{
val
network
=
underlyingNetwork
if
(
network
!=
null
&&
Build
.
VERSION
.
SDK_INT
>=
23
)
{
try
{
network
.
bindSocket
(
fd
)
}
catch
(
e
:
SocketException
)
{
// silently ignore ENONET (Machine is not on the network)
if
((
e
.
cause
as
?
ErrnoException
)
?.
errno
==
64
)
e
.
printStackTrace
()
else
throw
e
}
override
fun
accept
(
socket
:
LocalSocket
)
=
try
{
socket
.
inputStream
.
read
()
val
fd
=
socket
.
ancillaryFileDescriptors
!!
.
single
()
!!
CloseableFd
(
fd
).
use
{
socket
.
outputStream
.
write
(
if
(
underlyingNetwork
.
let
{
network
->
if
(
network
!=
null
&&
Build
.
VERSION
.
SDK_INT
>=
23
)
try
{
network
.
bindSocket
(
fd
)
true
}
catch
(
e
:
IOException
)
{
// suppress ENONET (Machine is not on the network)
if
((
e
.
cause
as
?
ErrnoException
)
?.
errno
!=
64
)
printLog
(
e
)
false
}
else
protect
(
getInt
.
invoke
(
fd
)
as
Int
)
}
finally
{
try
{
Os
.
close
(
fd
)
}
catch
(
e
:
ErrnoException
)
{
printLog
(
e
)
}
})
0
else
1
)
}
catch
(
e
:
IOException
)
{
printLog
(
e
)
}
}
catch
(
e
:
IOException
)
{
printLog
(
e
)
}
}
inner
class
NullConnectionException
:
NullPointerException
()
{
...
...
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