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
4674139d
Commit
4674139d
authored
Mar 25, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only update RemoteConfig if it is used
parent
68490279
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
18 deletions
+31
-18
build.gradle
build.gradle
+1
-1
core/build.gradle
core/build.gradle
+2
-2
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
+0
-5
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
.../src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
+7
-1
core/src/main/java/com/github/shadowsocks/bg/RemoteConfig.kt
core/src/main/java/com/github/shadowsocks/bg/RemoteConfig.kt
+20
-8
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+1
-1
No files found.
build.gradle
View file @
4674139d
...
@@ -31,7 +31,7 @@ buildscript {
...
@@ -31,7 +31,7 @@ buildscript {
classpath
'com.github.ben-manes:gradle-versions-plugin:0.21.0'
classpath
'com.github.ben-manes:gradle-versions-plugin:0.21.0'
classpath
'com.google.gms:google-services:4.2.0'
classpath
'com.google.gms:google-services:4.2.0'
classpath
'com.vanniktech:gradle-maven-publish-plugin:0.8.0'
classpath
'com.vanniktech:gradle-maven-publish-plugin:0.8.0'
classpath
'io.fabric.tools:gradle:1.2
7
.1'
classpath
'io.fabric.tools:gradle:1.2
8
.1'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
}
}
...
...
core/build.gradle
View file @
4674139d
...
@@ -54,8 +54,8 @@ dependencies {
...
@@ -54,8 +54,8 @@ dependencies {
api
'androidx.preference:preference:1.0.0'
api
'androidx.preference:preference:1.0.0'
api
"androidx.room:room-runtime:$roomVersion"
api
"androidx.room:room-runtime:$roomVersion"
api
'com.crashlytics.sdk.android:crashlytics:2.9.9'
api
'com.crashlytics.sdk.android:crashlytics:2.9.9'
api
'com.google.firebase:firebase-config:16.
1.3
'
api
'com.google.firebase:firebase-config:16.
4.1
'
api
'com.google.firebase:firebase-core:16.0.
7
'
api
'com.google.firebase:firebase-core:16.0.
8
'
api
"com.takisoft.preferencex:preferencex:$preferencexVersion"
api
"com.takisoft.preferencex:preferencex:$preferencexVersion"
api
'dnsjava:dnsjava:2.1.8'
api
'dnsjava:dnsjava:2.1.8'
api
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
api
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
...
...
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
View file @
4674139d
...
@@ -90,10 +90,6 @@ object BaseService {
...
@@ -90,10 +90,6 @@ object BaseService {
binder
.
stateChanged
(
s
,
msg
)
binder
.
stateChanged
(
s
,
msg
)
state
=
s
state
=
s
}
}
init
{
RemoteConfig
.
fetch
()
}
}
}
class
Binder
(
private
var
data
:
Data
?
=
null
)
:
IShadowsocksService
.
Stub
(),
AutoCloseable
{
class
Binder
(
private
var
data
:
Data
?
=
null
)
:
IShadowsocksService
.
Stub
(),
AutoCloseable
{
...
@@ -341,7 +337,6 @@ object BaseService {
...
@@ -341,7 +337,6 @@ object BaseService {
proxy
.
scheduleUpdate
()
proxy
.
scheduleUpdate
()
data
.
udpFallback
?.
scheduleUpdate
()
data
.
udpFallback
?.
scheduleUpdate
()
RemoteConfig
.
fetch
()
data
.
changeState
(
State
.
Connected
)
data
.
changeState
(
State
.
Connected
)
}
catch
(
_
:
CancellationException
)
{
}
catch
(
_
:
CancellationException
)
{
...
...
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
View file @
4674139d
...
@@ -40,6 +40,7 @@ import kotlinx.coroutines.*
...
@@ -40,6 +40,7 @@ import kotlinx.coroutines.*
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.io.IOException
import
java.net.HttpURLConnection
import
java.net.HttpURLConnection
import
java.net.URL
import
java.net.UnknownHostException
import
java.net.UnknownHostException
import
java.security.MessageDigest
import
java.security.MessageDigest
...
@@ -51,12 +52,16 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -51,12 +52,16 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
var
trafficMonitor
:
TrafficMonitor
?
=
null
var
trafficMonitor
:
TrafficMonitor
?
=
null
private
val
plugin
=
PluginConfiguration
(
profile
.
plugin
?:
""
).
selectedOptions
private
val
plugin
=
PluginConfiguration
(
profile
.
plugin
?:
""
).
selectedOptions
val
pluginPath
by
lazy
{
PluginManager
.
init
(
plugin
)
}
val
pluginPath
by
lazy
{
PluginManager
.
init
(
plugin
)
}
private
var
scheduleConfigUpdate
=
false
suspend
fun
init
(
service
:
BaseService
.
Interface
)
{
suspend
fun
init
(
service
:
BaseService
.
Interface
)
{
if
(
profile
.
host
==
"198.199.101.152"
)
{
if
(
profile
.
host
==
"198.199.101.152"
)
{
scheduleConfigUpdate
=
true
val
mdg
=
MessageDigest
.
getInstance
(
"SHA-1"
)
val
mdg
=
MessageDigest
.
getInstance
(
"SHA-1"
)
mdg
.
update
(
Core
.
packageInfo
.
signaturesCompat
.
first
().
toByteArray
())
mdg
.
update
(
Core
.
packageInfo
.
signaturesCompat
.
first
().
toByteArray
())
val
conn
=
service
.
openConnection
(
RemoteConfig
.
proxyUrl
)
as
HttpURLConnection
val
(
config
,
success
)
=
RemoteConfig
.
fetch
()
scheduleConfigUpdate
=
!
success
val
conn
=
service
.
openConnection
(
URL
(
config
.
getString
(
"proxy_url"
)))
as
HttpURLConnection
conn
.
requestMethod
=
"POST"
conn
.
requestMethod
=
"POST"
conn
.
doOutput
=
true
conn
.
doOutput
=
true
...
@@ -134,6 +139,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -134,6 +139,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
fun
scheduleUpdate
()
{
fun
scheduleUpdate
()
{
if
(
route
!
in
arrayOf
(
Acl
.
ALL
,
Acl
.
CUSTOM_RULES
))
AclSyncer
.
schedule
(
route
)
if
(
route
!
in
arrayOf
(
Acl
.
ALL
,
Acl
.
CUSTOM_RULES
))
AclSyncer
.
schedule
(
route
)
if
(
scheduleConfigUpdate
)
RemoteConfig
.
scheduleFetch
()
}
}
fun
shutdown
(
scope
:
CoroutineScope
)
{
fun
shutdown
(
scope
:
CoroutineScope
)
{
...
...
core/src/main/java/com/github/shadowsocks/bg/RemoteConfig.kt
View file @
4674139d
...
@@ -25,18 +25,30 @@ import androidx.core.os.bundleOf
...
@@ -25,18 +25,30 @@ import androidx.core.os.bundleOf
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.core.R
import
com.github.shadowsocks.core.R
import
com.google.firebase.remoteconfig.FirebaseRemoteConfig
import
com.google.firebase.remoteconfig.FirebaseRemoteConfig
import
java.net.URL
import
kotlinx.coroutines.suspendCancellableCoroutine
import
kotlin.coroutines.resume
object
RemoteConfig
{
object
RemoteConfig
{
private
val
config
=
FirebaseRemoteConfig
.
getInstance
().
apply
{
setDefaults
(
R
.
xml
.
default_configs
)
}
private
val
config
by
lazy
{
FirebaseRemoteConfig
.
getInstance
().
apply
{
setDefaults
(
R
.
xml
.
default_configs
)
}
}
val
proxyUrl
get
()
=
URL
(
config
.
getString
(
"proxy_url"
))
private
fun
Exception
.
log
()
{
Log
.
w
(
"RemoteConfig"
,
this
)
Core
.
analytics
.
logEvent
(
"femote_config_failure"
,
bundleOf
(
Pair
(
javaClass
.
simpleName
,
message
)))
}
fun
scheduleFetch
()
=
config
.
fetch
().
addOnCompleteListener
{
if
(
it
.
isSuccessful
)
config
.
activateFetched
()
else
it
.
exception
?.
log
()
}
fun
fetch
()
=
config
.
fetch
().
addOnCompleteListener
{
suspend
fun
fetch
()
=
suspendCancellableCoroutine
<
Pair
<
FirebaseRemoteConfig
,
Boolean
>>
{
cont
->
if
(
it
.
isSuccessful
)
config
.
activateFetched
()
else
{
config
.
fetch
().
addOnCompleteListener
{
val
e
=
it
.
exception
?:
return
@addOnCompleteListener
if
(
it
.
isSuccessful
)
{
Log
.
w
(
"RemoteConfig"
,
e
)
config
.
activateFetched
()
Core
.
analytics
.
logEvent
(
"femote_config_failure"
,
bundleOf
(
Pair
(
e
.
javaClass
.
simpleName
,
e
.
message
)))
cont
.
resume
(
config
to
true
)
}
else
{
it
.
exception
?.
log
()
cont
.
resume
(
config
to
false
)
}
}
}
}
}
}
}
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
4674139d
...
@@ -76,7 +76,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
...
@@ -76,7 +76,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private
val
job
=
SupervisorJob
()
private
val
job
=
SupervisorJob
()
override
val
coroutineContext
=
job
+
CoroutineExceptionHandler
{
_
,
t
->
printLog
(
t
)
}
override
val
coroutineContext
=
job
+
CoroutineExceptionHandler
{
_
,
t
->
printLog
(
t
)
}
suspend
fun
start
(
listen
:
SocketAddress
)
=
DatagramChannel
.
open
().
apply
{
suspend
fun
start
(
listen
:
SocketAddress
)
=
DatagramChannel
.
open
().
run
{
configureBlocking
(
false
)
configureBlocking
(
false
)
socket
().
bind
(
listen
)
socket
().
bind
(
listen
)
monitor
.
register
(
this
,
SelectionKey
.
OP_READ
)
{
handlePacket
(
this
)
}
monitor
.
register
(
this
,
SelectionKey
.
OP_READ
)
{
handlePacket
(
this
)
}
...
...
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