Skip to content

Commit 759f8c5

Browse files
committed
feat: unify Kotlin hubs into Rust getter via OutsideProvider registration
Route all update requests through the Rust getter's JSON-RPC system by registering Kotlin-implemented hubs (GooglePlay, CoolApk) as OutsideProviders. This eliminates the old hub-specific routing/fallback logic in ClientProxyApi. Flow: Kotlin -> GetterPort (WebSocket JSON-RPC) -> Rust Provider Map -> OutsideProvider -> HTTP JSON-RPC -> KotlinHubRpcServer -> Hub impls Kotlin changes: - Add KotlinHubRpcServer: Ktor CIO HTTP JSON-RPC server exposing hub methods - Rewrite ClientProxyApi to delegate all methods to getterPort (remove hubMap, getHub, NoFunction, fallback logic) - Simplify ServerApi by removing callOrBack/NoFunction patterns - Add registerProvider() and getDownloadInfo() to GetterService/Impl/Port - Start KotlinHubRpcServer in Init.kt and register hubs at startup - Add ktor-server-core and ktor-server-cio dependencies Rust changes (getter submodule): - Add register_provider and get_download JSON-RPC server methods - Add DownloadItemData, RpcRegisterProviderRequest, RpcDownloadInfoRequest - Implement get_download on OutsideProvider via HTTP JSON-RPC callback - Add GetDownload to FunctionType enum with default impl on BaseProvider - Make rpc::data module public for cross-module imports
1 parent b21e322 commit 759f8c5

File tree

10 files changed

+580
-223
lines changed

10 files changed

+580
-223
lines changed

core-getter/rpc/src/main/java/net/xzos/upgradeall/getter/rpc/GetterService.kt

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package net.xzos.upgradeall.getter.rpc
22

33
import net.xzos.upgradeall.websdk.data.json.CloudConfigList
4+
import net.xzos.upgradeall.websdk.data.json.DownloadItem
45
import net.xzos.upgradeall.websdk.data.json.ReleaseGson
56

67
/**
78
* Suspend-based GetterService interface for Rust getter RPC.
8-
*
9+
*
910
* All methods are suspend functions, enabling efficient async/await patterns
1011
* over a persistent WebSocket connection.
1112
*/
@@ -15,7 +16,7 @@ interface GetterService {
1516
suspend fun init(
1617
dataPath: String,
1718
cachePath: String,
18-
globalExpireTime: Long
19+
globalExpireTime: Long,
1920
): Boolean
2021

2122
suspend fun shutdown()
@@ -38,9 +39,27 @@ interface GetterService {
3839
hubData: Map<String, String>,
3940
): List<ReleaseGson>
4041

41-
suspend fun getCloudConfig(
42-
url: String
43-
): CloudConfigList
42+
suspend fun getCloudConfig(url: String): CloudConfigList
43+
44+
// ========================================================================
45+
// Provider Registration
46+
// ========================================================================
47+
48+
suspend fun registerProvider(
49+
hubUuid: String,
50+
url: String,
51+
): Boolean
52+
53+
// ========================================================================
54+
// Download Info
55+
// ========================================================================
56+
57+
suspend fun getDownloadInfo(
58+
hubUuid: String,
59+
appData: Map<String, String>,
60+
hubData: Map<String, String>,
61+
assetIndex: List<Int>,
62+
): List<DownloadItem>
4463

4564
// ========================================================================
4665
// Downloader RPC Methods
@@ -50,29 +69,21 @@ interface GetterService {
5069
url: String,
5170
destPath: String,
5271
headers: Map<String, String>? = null,
53-
cookies: Map<String, String>? = null
72+
cookies: Map<String, String>? = null,
5473
): TaskIdResponse
5574

56-
suspend fun downloadGetStatus(
57-
taskId: String
58-
): TaskInfo
75+
suspend fun downloadGetStatus(taskId: String): TaskInfo
5976

6077
suspend fun downloadWaitForChange(
6178
taskId: String,
62-
timeoutSeconds: Long
79+
timeoutSeconds: Long,
6380
): TaskInfo
6481

65-
suspend fun downloadCancel(
66-
taskId: String
67-
): Boolean
82+
suspend fun downloadCancel(taskId: String): Boolean
6883

69-
suspend fun downloadPause(
70-
taskId: String
71-
): Boolean
84+
suspend fun downloadPause(taskId: String): Boolean
7285

73-
suspend fun downloadResume(
74-
taskId: String
75-
): Boolean
86+
suspend fun downloadResume(taskId: String): Boolean
7687
}
7788

7889
/**

core-getter/rpc/src/main/java/net/xzos/upgradeall/getter/rpc/GetterServiceImpl.kt

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package net.xzos.upgradeall.getter.rpc
22

33
import net.xzos.upgradeall.websdk.data.json.CloudConfigList
4+
import net.xzos.upgradeall.websdk.data.json.DownloadItem
45
import net.xzos.upgradeall.websdk.data.json.ReleaseGson
56

67
/**
78
* WebSocket-based implementation of GetterService.
8-
*
9+
*
910
* Uses RpcClient internally to communicate with the Rust getter server
1011
* over a persistent WebSocket connection.
1112
*/
12-
class GetterServiceImpl(private val client: RpcClient) : GetterService {
13-
14-
override suspend fun ping(): String {
15-
return client.invoke("ping", typeOf<String>())
16-
}
13+
class GetterServiceImpl(
14+
private val client: RpcClient,
15+
) : GetterService {
16+
override suspend fun ping(): String = client.invoke("ping", typeOf<String>())
1717

1818
override suspend fun init(
1919
dataPath: String,
2020
cachePath: String,
21-
globalExpireTime: Long
21+
globalExpireTime: Long,
2222
): Boolean {
23-
val params = mapOf(
24-
"data_path" to dataPath,
25-
"cache_path" to cachePath,
26-
"global_expire_time" to globalExpireTime
27-
)
23+
val params =
24+
mapOf(
25+
"data_path" to dataPath,
26+
"cache_path" to cachePath,
27+
"global_expire_time" to globalExpireTime,
28+
)
2829
return client.invoke("init", params, typeOf<Boolean>())
2930
}
3031

@@ -35,39 +36,42 @@ class GetterServiceImpl(private val client: RpcClient) : GetterService {
3536
override suspend fun checkAppAvailable(
3637
hubUuid: String,
3738
appData: Map<String, String>,
38-
hubData: Map<String, String>
39+
hubData: Map<String, String>,
3940
): Boolean {
40-
val params = mapOf(
41-
"hub_uuid" to hubUuid,
42-
"app_data" to appData,
43-
"hub_data" to hubData
44-
)
41+
val params =
42+
mapOf(
43+
"hub_uuid" to hubUuid,
44+
"app_data" to appData,
45+
"hub_data" to hubData,
46+
)
4547
return client.invoke("check_app_available", params, typeOf<Boolean>())
4648
}
4749

4850
override suspend fun getAppLatestRelease(
4951
hubUuid: String,
5052
appData: Map<String, String>,
51-
hubData: Map<String, String>
53+
hubData: Map<String, String>,
5254
): ReleaseGson {
53-
val params = mapOf(
54-
"hub_uuid" to hubUuid,
55-
"app_data" to appData,
56-
"hub_data" to hubData
57-
)
55+
val params =
56+
mapOf(
57+
"hub_uuid" to hubUuid,
58+
"app_data" to appData,
59+
"hub_data" to hubData,
60+
)
5861
return client.invoke("get_latest_release", params, typeOf<ReleaseGson>())
5962
}
6063

6164
override suspend fun getAppReleases(
6265
hubUuid: String,
6366
appData: Map<String, String>,
64-
hubData: Map<String, String>
67+
hubData: Map<String, String>,
6568
): List<ReleaseGson> {
66-
val params = mapOf(
67-
"hub_uuid" to hubUuid,
68-
"app_data" to appData,
69-
"hub_data" to hubData
70-
)
69+
val params =
70+
mapOf(
71+
"hub_uuid" to hubUuid,
72+
"app_data" to appData,
73+
"hub_data" to hubData,
74+
)
7175
return client.invoke("get_releases", params, typeOf<List<ReleaseGson>>())
7276
}
7377

@@ -76,6 +80,42 @@ class GetterServiceImpl(private val client: RpcClient) : GetterService {
7680
return client.invoke("get_cloud_config", params, typeOf<CloudConfigList>())
7781
}
7882

83+
// ========================================================================
84+
// Provider Registration
85+
// ========================================================================
86+
87+
override suspend fun registerProvider(
88+
hubUuid: String,
89+
url: String,
90+
): Boolean {
91+
val params =
92+
mapOf(
93+
"hub_uuid" to hubUuid,
94+
"url" to url,
95+
)
96+
return client.invoke("register_provider", params, typeOf<Boolean>())
97+
}
98+
99+
// ========================================================================
100+
// Download Info
101+
// ========================================================================
102+
103+
override suspend fun getDownloadInfo(
104+
hubUuid: String,
105+
appData: Map<String, String>,
106+
hubData: Map<String, String>,
107+
assetIndex: List<Int>,
108+
): List<DownloadItem> {
109+
val params =
110+
mapOf(
111+
"hub_uuid" to hubUuid,
112+
"app_data" to appData,
113+
"hub_data" to hubData,
114+
"asset_index" to assetIndex,
115+
)
116+
return client.invoke("get_download", params, typeOf<List<DownloadItem>>())
117+
}
118+
79119
// ========================================================================
80120
// Downloader RPC Methods
81121
// ========================================================================
@@ -84,15 +124,16 @@ class GetterServiceImpl(private val client: RpcClient) : GetterService {
84124
url: String,
85125
destPath: String,
86126
headers: Map<String, String>?,
87-
cookies: Map<String, String>?
127+
cookies: Map<String, String>?,
88128
): TaskIdResponse {
89-
val params = mutableMapOf<String, Any?>(
90-
"url" to url,
91-
"dest_path" to destPath
92-
)
129+
val params =
130+
mutableMapOf<String, Any?>(
131+
"url" to url,
132+
"dest_path" to destPath,
133+
)
93134
if (headers != null) params["headers"] = headers
94135
if (cookies != null) params["cookies"] = cookies
95-
136+
96137
return client.invoke("download_submit", params, typeOf<TaskIdResponse>())
97138
}
98139

@@ -103,12 +144,13 @@ class GetterServiceImpl(private val client: RpcClient) : GetterService {
103144

104145
override suspend fun downloadWaitForChange(
105146
taskId: String,
106-
timeoutSeconds: Long
147+
timeoutSeconds: Long,
107148
): TaskInfo {
108-
val params = mapOf(
109-
"task_id" to taskId,
110-
"timeout_seconds" to timeoutSeconds
111-
)
149+
val params =
150+
mapOf(
151+
"task_id" to taskId,
152+
"timeout_seconds" to timeoutSeconds,
153+
)
112154
// Use longer timeout for long-polling (add 5 seconds buffer)
113155
val rpcTimeout = (timeoutSeconds + 5) * 1000
114156
return client.invoke("download_wait_for_change", params, typeOf<TaskInfo>(), rpcTimeout)
@@ -128,7 +170,7 @@ class GetterServiceImpl(private val client: RpcClient) : GetterService {
128170
val params = mapOf("task_id" to taskId)
129171
return client.invoke("download_resume", params, typeOf<Boolean>())
130172
}
131-
173+
132174
/**
133175
* Close the underlying WebSocket connection
134176
*/

0 commit comments

Comments
 (0)