chat_join: модуль join-протокола, invite-ссылки v2, синхронизация мемберов

This commit is contained in:
evgeny committed 2026-09-14 19:57:27 +03:00
1 parent a01a4ddba4
commit 75e39d2fee
41 files changed
+2206 -471

No files matched your search

@@ -223,7 +223,7 @@ class MainActivity : ComponentActivity() {
},
onConnect = { data: InviteData ->
val addrs = data.serializeAddrs()
NativeLib.joinChannel(data.channelId, data.nodeId, data.pubkey, addrs, data.addrs.size)
NativeLib.joinChannel(data.channelId, data.nodeId, data.joinKey, data.pubkey, addrs, data.addrs.size)
showJoinDialog = false
},
onDismiss = { showJoinDialog = false }
@@ -386,8 +386,8 @@ class ChatRepository {
NativeLib.photoSend(channelId, filePath, width, height)
fun createChannel(name: String, channelId: String) = NativeLib.createChannel(name, channelId)
fun connectNode(address: String, port: Int, pubkeyHex: String) = NativeLib.connectNode(address, port, pubkeyHex)
fun joinChannel(channelId: Long, nodeId: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) =
NativeLib.joinChannel(channelId, nodeId, pubkey, addrs, addrCount)
fun joinChannel(channelId: Long, nodeId: Long, joinKey: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) =
NativeLib.joinChannel(channelId, nodeId, joinKey, pubkey, addrs, addrCount)
fun connectChannel(channelId: String) = NativeLib.connectChannel(channelId)
fun connectMemberNode(channelId: String, nodeId: Long) = NativeLib.connectMemberNode(channelId, nodeId)
fun isReady() = NativeLib.isReady()
@@ -29,6 +29,7 @@ data class InviteAddr(
data class InviteData(
val channelId: Long,
val joinKey: Long,
val pubkey: ByteArray,
val nodeId: Long,
val addrs: List<InviteAddr>
@@ -98,7 +99,14 @@ object InviteLink {
}
off += 8
LogManager.addLog("DEBUG", "INVITE", "decode: chId=0x%016x".format(chId))
var joinKey = 0L
for (i in 0 until 8) {
if (off + i >= raw.size) return null
joinKey = (joinKey shl 8) or (raw[off + i].toLong() and 0xFF)
}
off += 8
LogManager.addLog("DEBUG", "INVITE", "decode: chId=0x%016x joinKey=0x%016x".format(chId, joinKey))
var pubkey: ByteArray? = null
val addrs = mutableListOf<InviteAddr>()
@@ -135,7 +143,7 @@ object InviteLink {
val pkHex = pubkey.take(8).joinToString("") { "%02x".format(it) }
LogManager.addLog("INFO", "INVITE", "decode: ch=0x%016x node=0x%016x pk=%s... addrs=%d".format(
chId, nodeId, pkHex, addrs.size))
return InviteData(channelId = chId, pubkey = pubkey, nodeId = nodeId, addrs = addrs)
return InviteData(channelId = chId, joinKey = joinKey, pubkey = pubkey, nodeId = nodeId, addrs = addrs)
}
fun addrToString(addr: InviteAddr): String {
@@ -68,9 +68,9 @@ object NativeLib {
fun sendMessage(channelId: String, text: String) { nativeSendMessage(channelId, text) }
fun createChannel(name: String, channelId: String) { nativeCreateChannel(name, channelId) }
fun connectNode(address: String, port: Int, pubkeyHex: String) { nativeConnectNode(address, port, pubkeyHex) }
fun joinChannel(channelId: Long, nodeId: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) {
fun joinChannel(channelId: Long, nodeId: Long, joinKey: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) {
LogManager.addLog("INFO", "JNI", "joinChannel: calling native")
nativeJoinChannel(channelId, nodeId, pubkey, addrs, addrCount)
nativeJoinChannel(channelId, nodeId, joinKey, pubkey, addrs, addrCount)
LogManager.addLog("INFO", "JNI", "joinChannel: native returned")
}
fun deriveNodeId(pubkey: ByteArray): Long = nativeDeriveNodeId(pubkey)
@@ -147,7 +147,7 @@ object NativeLib {
private external fun nativeSendMessage(channelId: String, text: String)
private external fun nativeCreateChannel(name: String, channelId: String)
private external fun nativeConnectNode(address: String, port: Int, pubkeyHex: String)
private external fun nativeJoinChannel(channelId: Long, nodeId: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int)
private external fun nativeJoinChannel(channelId: Long, nodeId: Long, joinKey: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int)
private external fun nativeDeriveNodeId(pubkey: ByteArray): Long
private external fun nativeConnectChannel(channelId: String)
private external fun nativeConnectMemberNode(channelId: String, nodeId: Long)
@@ -589,11 +589,11 @@ class ChatViewModel : ViewModel() {
r.connectNode(address, port, pubkeyHex)
}
fun joinChannel(channelId: Long, nodeId: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) {
fun joinChannel(channelId: Long, nodeId: Long, joinKey: Long, pubkey: ByteArray, addrs: ByteArray, addrCount: Int) {
val r = repo
if (r == null) { LogManager.addLog("ERROR", "VM", "joinChannel: repo is NULL"); return }
LogManager.addLog("INFO", "VM", "joinChannel: ch=0x%016x node=0x%016x".format(channelId, nodeId))
r.joinChannel(channelId, nodeId, pubkey, addrs, addrCount)
r.joinChannel(channelId, nodeId, joinKey, pubkey, addrs, addrCount)
}
fun startVoiceRecording() {