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
b161ab81
Commit
b161ab81
authored
Feb 23, 2022
by
chenhuaqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug
parent
5b98f8d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
26 deletions
+19
-26
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
+17
-24
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
+1
-1
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
.../src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
+1
-1
No files found.
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
View file @
b161ab81
...
...
@@ -2,19 +2,16 @@ package com.github.shadowsocks.bg
import
android.os.Build
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.http.HttpConfig
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.http.FreshToken
import
com.github.shadowsocks.http.HttpConfig
import
com.github.shadowsocks.http.LineConfig
import
com.google.gson.Gson
import
com.google.gson.JsonStreamParser
import
com.google.gson.reflect.TypeToken
import
com.tencent.mmkv.MMKV
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
okhttp3.MediaType.Companion.toMediaTypeOrNull
import
okhttp3.OkHttpClient
...
...
@@ -80,18 +77,16 @@ object AuthManager {
MMKV
.
defaultMMKV
().
putLong
(
"ACC_TIME"
,
acc_time
)
}
suspend
fun
initAuthProfile
()
{
suspend
fun
initAuthProfile
(
profile
:
Profile
)
{
withContext
(
Dispatchers
.
IO
)
{
getLineConfig
()
?.
let
{
if
(
it
.
code
!=
200
)
{
return
@withContext
}
val
profileId
=
1L
val
profile
=
ProfileManager
.
getProfile
(
profileId
)
?:
Profile
()
profile
.
host
=
it
.
data
.
host
profile
.
token
=
it
.
data
.
token
profile
.
remotePort
=
it
.
data
.
port
Timber
.
d
(
"start vpn with games: ${profile.individual}"
)
Timber
.
d
(
"start vpn with games: ${profile.individual}
, profileId: ${profile.id}, route: ${profile.route}
"
)
ProfileManager
.
updateProfile
(
profile
)
}
}
...
...
@@ -101,7 +96,7 @@ object AuthManager {
if
(
data
.
state
!=
BaseService
.
State
.
Connected
)
{
return
}
scheduleAtFixedRate
?.
cancel
(
false
)
scheduleAtFixedRate
=
executor
.
scheduleAtFixedRate
({
val
context
=
if
(
Build
.
VERSION
.
SDK_INT
<
24
||
Core
.
user
.
isUserUnlocked
)
Core
.
app
else
Core
.
deviceStorage
...
...
@@ -110,13 +105,15 @@ object AuthManager {
.
single
().
asJsonObject
if
(
data
.
state
==
BaseService
.
State
.
Connected
)
{
getToken
()
?.
let
{
if
(
it
.
code
==
200
)
{
configJson
.
addProperty
(
"token"
,
it
.
data
.
token
)
configFile
.
writeText
(
configJson
.
toString
())
}
else
{
Core
.
stopService
()
data
.
proxy
?.
let
{
proxyInstance
->
getToken
(
proxyInstance
.
profile
.
token
?:
""
)
?.
let
{
if
(
it
.
code
==
200
)
{
proxyInstance
.
profile
.
token
=
it
.
data
.
token
configJson
.
addProperty
(
"token"
,
it
.
data
.
token
)
configFile
.
writeText
(
configJson
.
toString
())
}
else
{
Core
.
stopService
()
}
}
}
}
...
...
@@ -124,19 +121,15 @@ object AuthManager {
},
1
,
1
,
TimeUnit
.
MINUTES
)
}
fun
getToken
():
FreshToken
?
{
ProfileManager
.
getProfile
(
1L
)
?.
let
{
val
map
=
mutableMapOf
<
String
,
String
>()
it
.
token
?.
let
{
it1
->
map
.
put
(
"token"
,
it1
)
}
return
postSync
<
FreshToken
>(
"/api/acc/line/refresh"
,
map
)
}
return
null
fun
getToken
(
token
:
String
):
FreshToken
?
{
val
map
=
mapOf
(
Pair
(
"token"
,
token
))
return
postSync
<
FreshToken
>(
"/api/acc/line/refresh"
,
map
)
}
val
jsonType
get
()
=
"application/json; charset=utf-8"
.
toMediaTypeOrNull
()
fun
getLineConfig
(
private
fun
getLineConfig
(
):
LineConfig
?
{
val
map
=
mutableMapOf
<
String
,
String
>()
area
?.
let
{
map
.
put
(
"area"
,
it
)
}
...
...
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
View file @
b161ab81
...
...
@@ -348,7 +348,7 @@ object BaseService {
try
{
Executable
.
killAll
()
// clean up old processes
preInit
()
AuthManager
.
initAuthProfile
()
AuthManager
.
initAuthProfile
(
profile
)
if
(
profile
.
route
==
Acl
.
CUSTOM_RULES
)
try
{
withContext
(
Dispatchers
.
IO
)
{
Acl
.
customRules
.
flatten
(
10
,
this
@Interface
::
openConnection
).
also
{
...
...
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
View file @
b161ab81
...
...
@@ -129,7 +129,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
}
fun
scheduleUpdate
()
{
if
(
route
!
in
arrayOf
(
Acl
.
ALL
,
Acl
.
CUSTOM_RULES
))
AclSyncer
.
schedule
(
route
)
if
(
route
!
in
arrayOf
(
Acl
.
ALL
,
Acl
.
CUSTOM_RULES
,
Acl
.
BYPASS_LAN
))
AclSyncer
.
schedule
(
route
)
}
fun
shutdown
(
scope
:
CoroutineScope
)
{
...
...
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