mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 16:45:20 +00:00
better
This commit is contained in:
@@ -29,7 +29,7 @@ class BluetoothGattServerManager(
|
||||
companion object {
|
||||
private const val TAG = "BluetoothGattServerManager"
|
||||
// Use exact same UUIDs as iOS version
|
||||
private val SERVICE_UUID = UUID.fromString("F47B5E2D-4A9E-4C5A-9B3F-8E1D2C3A4B5C")
|
||||
private val SERVICE_UUID = UUID.fromString("F47B5E2D-4A9E-4C5A-9B3F-8E1D2C3A4B5B")
|
||||
private val CHARACTERISTIC_UUID = UUID.fromString("A1B2C3D4-E5F6-4A5B-8C9D-0E1F2A3B4C5D")
|
||||
private val DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
|
||||
}
|
||||
|
||||
@@ -37,17 +37,17 @@ class BluetoothMeshService(private val context: Context) {
|
||||
}
|
||||
|
||||
// My peer identification - same format as iOS
|
||||
val myPeerID: ByteArray = generateCompatiblePeerID()
|
||||
val myPeerID: String = generateCompatiblePeerID()
|
||||
|
||||
// Core components - each handling specific responsibilities
|
||||
private val encryptionService = EncryptionService(context)
|
||||
private val peerManager = PeerManager()
|
||||
private val fragmentManager = FragmentManager()
|
||||
private val securityManager = SecurityManager(encryptionService, myPeerID.toHexString())
|
||||
private val securityManager = SecurityManager(encryptionService, myPeerID)
|
||||
private val storeForwardManager = StoreForwardManager()
|
||||
private val messageHandler = MessageHandler(myPeerID.toHexString())
|
||||
internal val connectionManager = BluetoothConnectionManager(context, myPeerID.toHexString(), fragmentManager) // Made internal for access
|
||||
private val packetProcessor = PacketProcessor(myPeerID.toHexString())
|
||||
private val messageHandler = MessageHandler(myPeerID)
|
||||
internal val connectionManager = BluetoothConnectionManager(context, myPeerID, fragmentManager) // Made internal for access
|
||||
private val packetProcessor = PacketProcessor(myPeerID)
|
||||
|
||||
// Service state management
|
||||
private var isActive = false
|
||||
@@ -419,6 +419,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
val signature = securityManager.signPacket(messageData)
|
||||
|
||||
val packet = BitchatPacket(
|
||||
version = 1u,
|
||||
type = MessageType.MESSAGE.value,
|
||||
senderID = myPeerID.toByteArray(),
|
||||
recipientID = SpecialRecipients.BROADCAST,
|
||||
@@ -467,6 +468,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
val signature = securityManager.signPacket(encryptedPayload)
|
||||
|
||||
val packet = BitchatPacket(
|
||||
version = 1u,
|
||||
type = MessageType.MESSAGE.value,
|
||||
senderID = myPeerID.toByteArray(),
|
||||
recipientID = recipientPeerID.toByteArray(),
|
||||
@@ -626,10 +628,10 @@ class BluetoothMeshService(private val context: Context) {
|
||||
/**
|
||||
* Generate peer ID compatible with iOS
|
||||
*/
|
||||
private fun generateCompatiblePeerID(): ByteArray {
|
||||
private fun generateCompatiblePeerID(): String {
|
||||
val randomBytes = ByteArray(4)
|
||||
Random.nextBytes(randomBytes)
|
||||
return randomBytes
|
||||
return randomBytes.joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,6 @@ data class BitchatPacket(
|
||||
var ttl: UByte
|
||||
) : Parcelable {
|
||||
|
||||
// Secondary constructor removed to enforce ByteArray usage for peerIDs
|
||||
/*
|
||||
constructor(
|
||||
type: UByte,
|
||||
ttl: UByte,
|
||||
@@ -97,7 +95,6 @@ data class BitchatPacket(
|
||||
signature = null,
|
||||
ttl = ttl
|
||||
)
|
||||
*/
|
||||
|
||||
fun toBinaryData(): ByteArray? {
|
||||
return BinaryProtocol.encode(this)
|
||||
|
||||
Reference in New Issue
Block a user