@@ -21,15 +21,13 @@ import dev.c0redev.volter.VolterLog
2121import dev.c0redev.volter.VolterVpnService
2222import dev.c0redev.volter.core.CoreBridge
2323import dev.c0redev.volter.data.cloud.CloudConfigRepository
24- import dev.c0redev.volter.data.cloud.TrafficApiClient
2524import dev.c0redev.volter.data.repo.LocalConfigRepository
2625import dev.c0redev.volter.data.servergeo.IpWhoLookup
2726import dev.c0redev.volter.data.servergeo.ServerGeo
2827import dev.c0redev.volter.domain.model.ClientSettings
2928import dev.c0redev.volter.domain.model.Config
3029import dev.c0redev.volter.domain.model.PeerTicket
3130import dev.c0redev.volter.domain.model.AppTrafficEntry
32- import dev.c0redev.volter.domain.model.ServerTraffic
3331import dev.c0redev.volter.domain.model.SessionRecord
3432import dev.c0redev.volter.traffic.TrafficPending
3533import dev.c0redev.volter.traffic.VpnTrafficRecorder
@@ -101,7 +99,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
10199
102100 private var coreHandle = - 1L
103101 private var pollJob: Job ? = null
104- private var trafficPollJob: Job ? = null
105102 private var cloudRefreshJob: Job ? = null
106103 private val cloudRefreshSeq = AtomicInteger (0 )
107104 private var pollGeneration = 0L
@@ -124,8 +121,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
124121 val logs = _logs
125122 private val _connection = MutableStateFlow (ConnectionState ())
126123 val connection = _connection
127- private val _serverTraffic = MutableStateFlow <ServerTraffic ?>(null )
128- val serverTraffic = _serverTraffic .asStateFlow()
129124 private val _vpnPermissionIntent = MutableStateFlow <Intent ?>(null )
130125 val vpnPermissionIntent = _vpnPermissionIntent
131126 private val _clientSettings = MutableStateFlow (localRepo.loadClientSettings())
@@ -260,7 +255,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
260255 val draft = activeMetric
261256 if (draft != null ) finalizeActiveMetric(Instant .now(), handshakeOk = draft.handshakeOk, errorType = classifyErr(normalized))
262257 }
263- stopServerTrafficPolling()
264258 return
265259 }
266260 if (handle <= 0 ) {
@@ -291,7 +285,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
291285 }
292286
293287 override fun onCleared () {
294- stopServerTrafficPolling()
295288 runCatching { appCtx.unregisterReceiver(receiver) }
296289 pollJob?.cancel()
297290 super .onCleared()
@@ -404,10 +397,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
404397 autoFallbackDone = false
405398 activateMetric()
406399 startService(effective.toJson().toString(), settings.toJson().toString())
407- val managed = effective.managed
408- if (managed != null && managed.controlUrl.isNotBlank() && managed.clientId.isNotBlank() && managed.secret.isNotBlank()) {
409- startServerTrafficPolling(managed.controlUrl, managed.clientId, managed.secret)
410- }
411400 }
412401 }
413402
@@ -426,10 +415,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
426415 autoFallbackDone = false
427416 activateMetric()
428417 startService(cfg.toJson().toString(), settings.toJson().toString())
429- val managed = cfg.managed
430- if (managed != null && managed.controlUrl.isNotBlank() && managed.clientId.isNotBlank() && managed.secret.isNotBlank()) {
431- startServerTrafficPolling(managed.controlUrl, managed.clientId, managed.secret)
432- }
433418 }
434419 }
435420
@@ -781,7 +766,6 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
781766 if (clearConnecting) {
782767 _connectingProfileName .value = null
783768 }
784- stopServerTrafficPolling()
785769 pollJob?.cancel()
786770 pollJob = null
787771 ++ pollGeneration
@@ -928,31 +912,4 @@ class ConnectionViewModel(app: Application) : AndroidViewModel(app) {
928912 }
929913 }
930914
931- private fun startServerTrafficPolling (controlUrl : String , clientId : String , secret : String ) {
932- trafficPollJob?.cancel()
933- trafficPollJob = viewModelScope.launch(Dispatchers .IO ) {
934- VolterLog .i(" startServerTrafficPolling url=$controlUrl clientId=$clientId " )
935- var errorCount = 0
936- while (true ) {
937- ensureActive()
938- val traffic = TrafficApiClient .fetch(clientId, secret, controlUrl)
939- if (traffic != null ) {
940- _serverTraffic .value = traffic.copy(updatedAt = System .currentTimeMillis())
941- errorCount = 0
942- } else {
943- errorCount++
944- if (errorCount >= 3 ) {
945- _serverTraffic .value = null
946- }
947- }
948- delay(5000L )
949- }
950- }
951- }
952-
953- private fun stopServerTrafficPolling () {
954- trafficPollJob?.cancel()
955- trafficPollJob = null
956- _serverTraffic .value = null
957- }
958915}
0 commit comments