srctree

Robin Linden parent f688cec4 6f0d85ab
Improve logging

  • * Don't log contacts full public keys.
  • * Stop logging contacts loaded.
  • * Fix a lot of not-errors being logged as errors.
inlinesplit
atox/src/main/kotlin/ui/chat/ChatViewModel.kt added: 36, removed: 32, total 4
@@ -57,15 +57,15 @@ class ChatViewModel @Inject constructor(
fileTransferManager.deleteAll(publicKey)
}
 
fun setActiveChat(pubKey: PublicKey) {
if (pubKey.string().isEmpty()) {
fun setActiveChat(pk: PublicKey) {
if (pk.string().isEmpty()) {
Log.i(TAG, "Clearing active chat")
setTyping(false)
} else {
Log.i(TAG, "Setting active chat ${pubKey.string().take(8)}")
Log.i(TAG, "Setting active chat ${pk.fingerprint()}")
}
 
publicKey = pubKey
publicKey = pk
notificationHelper.dismissNotifications(publicKey)
chatManager.activeChat = publicKey.string()
}
 
domain/src/main/kotlin/tox/Tox.kt added: 36, removed: 32, total 4
@@ -105,14 +105,14 @@ class Tox @Inject constructor(
save()
}
 
fun startFileTransfer(publicKey: PublicKey, fileNumber: Int) = launch {
Log.e(TAG, "Starting file transfer $fileNumber from $publicKey")
tox.startFileTransfer(publicKey, fileNumber)
fun startFileTransfer(pk: PublicKey, fileNumber: Int) = launch {
Log.i(TAG, "Starting file transfer $fileNumber from ${pk.fingerprint()}")
tox.startFileTransfer(pk, fileNumber)
}
 
fun stopFileTransfer(publicKey: PublicKey, fileNumber: Int) = launch {
Log.e(TAG, "Stopping file transfer $fileNumber from $publicKey")
tox.stopFileTransfer(publicKey, fileNumber)
fun stopFileTransfer(pk: PublicKey, fileNumber: Int) = launch {
Log.i(TAG, "Stopping file transfer $fileNumber from ${pk.fingerprint()}")
tox.stopFileTransfer(pk, fileNumber)
}
 
fun sendFile(pk: PublicKey, fileKind: FileKind, fileSize: Long, fileName: String) = async {
 
domain/src/main/kotlin/tox/ToxTypes.kt added: 36, removed: 32, total 4
@@ -3,6 +3,10 @@ package ltd.evilcorp.domain.tox
inline class PublicKey(private val value: String) {
fun bytes() = value.hexToBytes()
fun string() = value
fun fingerprint(): String {
val shortId = value.take(8)
return "%s %s".format(shortId.take(4), shortId.takeLast(4))
}
 
companion object {
fun fromBytes(publicKey: ByteArray) = PublicKey(publicKey.bytesToHex())
 
domain/src/main/kotlin/tox/ToxWrapper.kt added: 36, removed: 32, total 4
@@ -32,8 +32,9 @@ class ToxWrapper(
}
 
private fun updateContactMapping() {
eventListener.contactMapping = getContacts()
avEventListener.contactMapping = getContacts()
val contacts = getContacts()
eventListener.contactMapping = contacts
avEventListener.contactMapping = contacts
}
 
fun bootstrap(address: String, port: Int, publicKey: ByteArray) {
@@ -71,9 +72,9 @@ class ToxWrapper(
updateContactMapping()
}
 
fun deleteContact(publicKey: PublicKey) {
Log.e(TAG, "Deleting $publicKey")
tox.friendList.find { PublicKey.fromBytes(tox.getFriendPublicKey(it)) == publicKey }?.let { friend ->
fun deleteContact(pk: PublicKey) {
Log.i(TAG, "Deleting ${pk.fingerprint()}")
tox.friendList.find { PublicKey.fromBytes(tox.getFriendPublicKey(it)) == pk }?.let { friend ->
tox.deleteFriend(friend)
} ?: Log.e(
TAG, "Tried to delete nonexistent contact, this can happen if the database is out of sync with the Tox save"
@@ -86,7 +87,6 @@ class ToxWrapper(
val friendNumbers = tox.friendList
Log.i(TAG, "Loading ${friendNumbers.size} friends")
return List(friendNumbers.size) {
Log.i(TAG, "${friendNumbers[it]}: ${tox.getFriendPublicKey(friendNumbers[it]).bytesToHex()}")
Pair(PublicKey.fromBytes(tox.getFriendPublicKey(friendNumbers[it])), friendNumbers[it])
}
}
@@ -98,35 +98,35 @@ class ToxWrapper(
message.toByteArray()
)
 
fun acceptFriendRequest(publicKey: PublicKey) = try {
tox.addFriendNorequest(publicKey.bytes())
fun acceptFriendRequest(pk: PublicKey) = try {
tox.addFriendNorequest(pk.bytes())
updateContactMapping()
} catch (e: ToxFriendAddException) {
Log.e(TAG, "Exception while accepting friend request $publicKey: $e")
Log.e(TAG, "Exception while accepting friend request $pk: $e")
}
 
fun startFileTransfer(publicKey: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(publicKey), fileNumber, ToxFileControl.RESUME)
fun startFileTransfer(pk: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(pk), fileNumber, ToxFileControl.RESUME)
} catch (e: ToxFileControlException) {
Log.e(TAG, "Error starting ft ${publicKey.string().take(8)} $fileNumber\n$e")
Log.e(TAG, "Error starting ft ${pk.fingerprint()} $fileNumber\n$e")
}
 
fun stopFileTransfer(publicKey: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(publicKey), fileNumber, ToxFileControl.CANCEL)
fun stopFileTransfer(pk: PublicKey, fileNumber: Int) = try {
tox.fileControl(contactByKey(pk), fileNumber, ToxFileControl.CANCEL)
} catch (e: ToxFileControlException) {
Log.e(TAG, "Error stopping ft ${publicKey.string().take(8)} $fileNumber\n$e")
Log.e(TAG, "Error stopping ft ${pk.fingerprint()} $fileNumber\n$e")
}
 
fun sendFile(pk: PublicKey, fileKind: FileKind, fileSize: Long, fileName: String) = try {
tox.fileSend(contactByKey(pk), fileKind.toToxtype(), fileSize, Random.nextBytes(32), fileName.toByteArray())
} catch (e: ToxFileControlException) {
Log.e(TAG, "Error sending ft $fileName ${pk.string().take(8)}\n$e")
Log.e(TAG, "Error sending ft $fileName ${pk.fingerprint()}\n$e")
}
 
fun sendFileChunk(pk: PublicKey, fileNo: Int, pos: Long, data: ByteArray) = try {
tox.fileSendChunk(contactByKey(pk), fileNo, pos, data)
} catch (e: ToxFileSendChunkException) {
Log.e(TAG, "Error sending chunk $pos:${data.size} to ${pk.string().take(8)} $fileNo\n$e")
Log.e(TAG, "Error sending chunk $pos:${data.size} to ${pk.fingerprint()} $fileNo\n$e")
}
 
fun setTyping(publicKey: PublicKey, typing: Boolean) = tox.setTyping(contactByKey(publicKey), typing)
@@ -136,7 +136,7 @@ class ToxWrapper(
tox.status = status.toToxType()
}
 
private fun contactByKey(publicKey: PublicKey): Int = tox.friendByPublicKey(publicKey.bytes())
private fun contactByKey(pk: PublicKey): Int = tox.friendByPublicKey(pk.bytes())
 
// ToxAv, probably move these.
fun startCall(pk: PublicKey) = av.call(contactByKey(pk), 128, 0)