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
7fdcee61
Commit
7fdcee61
authored
May 05, 2020
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Suppress write errors to protect_path
parent
fdff88e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
27 deletions
+30
-27
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
+30
-22
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
+0
-5
No files found.
core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
View file @
7fdcee61
...
...
@@ -29,6 +29,7 @@ import android.net.Network
import
android.os.Build
import
android.os.ParcelFileDescriptor
import
android.system.ErrnoException
import
android.system.Os
import
android.system.OsConstants
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.VpnRequestActivity
...
...
@@ -40,7 +41,6 @@ import com.github.shadowsocks.net.DnsResolverCompat
import
com.github.shadowsocks.net.Subnet
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.utils.closeQuietly
import
com.github.shadowsocks.utils.int
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.delay
...
...
@@ -59,34 +59,42 @@ class VpnService : BaseVpnService(), BaseService.Interface {
private
const
val
PRIVATE_VLAN4_ROUTER
=
"172.19.0.2"
private
const
val
PRIVATE_VLAN6_CLIENT
=
"fdfe:dcba:9876::1"
private
const
val
PRIVATE_VLAN6_ROUTER
=
"fdfe:dcba:9876::2"
private
fun
<
T
>
FileDescriptor
.
use
(
block
:
(
FileDescriptor
)
->
T
)
=
try
{
block
(
this
)
}
finally
{
try
{
Os
.
close
(
this
)
}
catch
(
_
:
ErrnoException
)
{
}
}
}
private
inner
class
ProtectWorker
:
ConcurrentLocalSocketListener
(
"ShadowsocksVpnThread"
,
File
(
Core
.
deviceStorage
.
noBackupFilesDir
,
"protect_path"
))
{
override
fun
acceptInternal
(
socket
:
LocalSocket
)
{
socket
.
inputStream
.
read
()
val
fd
=
socket
.
ancillaryFileDescriptors
!!
.
single
()
!!
try
{
socket
.
outputStream
.
write
(
if
(
underlyingNetwork
.
let
{
network
->
if
(
network
!=
null
)
try
{
DnsResolverCompat
.
bindSocket
(
network
,
fd
)
return
@let
true
}
catch
(
e
:
IOException
)
{
when
((
e
.
cause
as
?
ErrnoException
)
?.
errno
)
{
// also suppress ENONET (Machine is not on the network)
OsConstants
.
EPERM
,
64
->
Timber
.
d
(
e
)
else
->
Timber
.
w
(
e
)
}
return
@let
false
}
catch
(
e
:
ReflectiveOperationException
)
{
check
(
Build
.
VERSION
.
SDK_INT
<
23
)
Timber
.
w
(
e
)
}
protect
(
fd
.
int
)
})
0
else
1
)
}
finally
{
fd
.
closeQuietly
()
val
success
=
socket
.
ancillaryFileDescriptors
!!
.
single
()
!!
.
use
{
fd
->
underlyingNetwork
.
let
{
network
->
if
(
network
!=
null
)
try
{
DnsResolverCompat
.
bindSocket
(
network
,
fd
)
return
@let
true
}
catch
(
e
:
IOException
)
{
when
((
e
.
cause
as
?
ErrnoException
)
?.
errno
)
{
// also suppress ENONET (Machine is not on the network)
OsConstants
.
EPERM
,
64
->
Timber
.
d
(
e
)
else
->
Timber
.
w
(
e
)
}
return
@let
false
}
catch
(
e
:
ReflectiveOperationException
)
{
check
(
Build
.
VERSION
.
SDK_INT
<
23
)
Timber
.
w
(
e
)
}
protect
(
fd
.
int
)
}
}
try
{
socket
.
outputStream
.
write
(
if
(
success
)
0
else
1
)
}
catch
(
_
:
IOException
)
{
}
// ignore connection early close
}
}
...
...
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
View file @
7fdcee61
...
...
@@ -28,7 +28,6 @@ import android.graphics.BitmapFactory
import
android.graphics.ImageDecoder
import
android.net.Uri
import
android.os.Build
import
android.system.ErrnoException
import
android.system.Os
import
android.system.OsConstants
import
android.util.TypedValue
...
...
@@ -66,10 +65,6 @@ val Throwable.readableMessage get() = localizedMessage ?: javaClass.name
private
val
getInt
=
FileDescriptor
::
class
.
java
.
getDeclaredMethod
(
"getInt$"
)
val
FileDescriptor
.
int
get
()
=
getInt
.
invoke
(
this
)
as
Int
fun
FileDescriptor
.
closeQuietly
()
=
try
{
Os
.
close
(
this
)
}
catch
(
_
:
ErrnoException
)
{
}
private
val
parseNumericAddress
by
lazy
@SuppressLint
(
"SoonBlockedPrivateApi"
)
{
InetAddress
::
class
.
java
.
getDeclaredMethod
(
"parseNumericAddress"
,
String
::
class
.
java
).
apply
{
isAccessible
=
true
...
...
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