Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message attachments, encryption #40

Merged
merged 1 commit into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ android {
allWarningsAsErrors = true
}

viewBinding {
enabled = true
buildFeatures {
viewBinding = true
}

packagingOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class TrustChainApplication : Application() {
val randomWalk = RandomWalk.Factory()
val store = PeerChatStore.getInstance(this)
return OverlayConfiguration(
PeerChatCommunity.Factory(store),
PeerChatCommunity.Factory(store, this),
listOf(randomWalk)
)
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_gradle_version"
classpath "com.squareup.sqldelight:gradle-plugin:$sqldelight_version"
Expand Down
4 changes: 2 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ android {
allWarningsAsErrors = true
}

viewBinding {
enabled = true
buildFeatures {
viewBinding = true
}

testOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nl.tudelft.trustchain.common
import io.mockk.*
import nl.tudelft.ipv8.Peer
import nl.tudelft.ipv8.messaging.EndpointAggregator
import nl.tudelft.ipv8.messaging.Serializable
import nl.tudelft.ipv8.peerdiscovery.Network
import nl.tudelft.trustchain.common.messaging.TradePayload
import org.junit.Assert.assertEquals
Expand All @@ -20,12 +19,14 @@ class MarketCommunityTest {
fun broadcast_callsSendOneTimePerPeer() {
val payload = mockk<TradePayload>()
every {
marketCommunity["serializePacket"](
any<Int>(),
any<Serializable>(),
any<Boolean>(),
any<Peer>(),
any<ByteArray>()
marketCommunity.serializePacket(
any(),
any(),
any(),
any(),
any(),
any(),
any()
)
} returns byteArrayOf(0x00)
every { marketCommunity.getPeers() } returns getFakePeers()
Expand Down
6 changes: 4 additions & 2 deletions peerchat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ android {
allWarningsAsErrors = true
}

viewBinding {
enabled = true
buildFeatures {
viewBinding = true
}
}

Expand Down Expand Up @@ -85,6 +85,8 @@ dependencies {
implementation 'com.github.tony19:logback-android:2.0.0'

implementation 'com.mattskala:itemadapter:0.3'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

// Testing
testImplementation 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package nl.tudelft.trustchain.peerchat.community

import nl.tudelft.ipv8.messaging.*

class AttachmentPayload(
val id: String,
val data: ByteArray
) : Serializable {
override fun serialize(): ByteArray {
return serializeVarLen(id.toByteArray()) +
serializeVarLen(data)
}

companion object Deserializer : Deserializable<AttachmentPayload> {
override fun deserialize(buffer: ByteArray, offset: Int): Pair<AttachmentPayload, Int> {
var localOffset = offset
val (id, idSize) = deserializeVarLen(buffer, localOffset)
localOffset += idSize
val (data, dataSize) = deserializeVarLen(buffer, localOffset)
localOffset += dataSize
return Pair(
AttachmentPayload(
id.toString(Charsets.UTF_8),
data
),
localOffset - offset
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package nl.tudelft.trustchain.peerchat.community

import nl.tudelft.ipv8.messaging.*

data class AttachmentRequestPayload(
val id: String
) : Serializable {
override fun serialize(): ByteArray {
return serializeVarLen(id.toByteArray())
}

companion object Deserializer : Deserializable<AttachmentRequestPayload> {
override fun deserialize(buffer: ByteArray, offset: Int): Pair<AttachmentRequestPayload, Int> {
var localOffset = offset
val (id, idSize) = deserializeVarLen(buffer, localOffset)
localOffset += idSize
return Pair(
AttachmentRequestPayload(id.toString(Charsets.UTF_8)),
localOffset - offset
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package nl.tudelft.trustchain.peerchat.community

import nl.tudelft.ipv8.messaging.*

data class MessagePayload(
class MessagePayload constructor(
val id: String,
val message: String
val message: String,
val attachmentType: String,
val attachmentSize: Long,
val attachmentContent: ByteArray
) : Serializable {
override fun serialize(): ByteArray {
return serializeVarLen(id.toByteArray()) +
serializeVarLen(message.toByteArray())
serializeVarLen(message.toByteArray()) +
serializeVarLen(attachmentType.toByteArray()) +
serializeLong(attachmentSize) +
serializeVarLen(attachmentContent)
}

companion object Deserializer : Deserializable<MessagePayload> {
Expand All @@ -18,8 +24,20 @@ data class MessagePayload(
localOffset += idSize
val (message, messageSize) = deserializeVarLen(buffer, localOffset)
localOffset += messageSize
val (attachmentType, attachmentTypeSize) = deserializeVarLen(buffer, localOffset)
localOffset += attachmentTypeSize
val attachmentSize = deserializeLong(buffer, localOffset)
localOffset += SERIALIZED_LONG_SIZE
val (attachmentContent, attachmentContentSize) = deserializeVarLen(buffer, localOffset)
localOffset += attachmentContentSize
return Pair(
MessagePayload(id.toString(Charsets.UTF_8), message.toString(Charsets.UTF_8)),
MessagePayload(
id.toString(Charsets.UTF_8),
message.toString(Charsets.UTF_8),
attachmentType.toString(Charsets.UTF_8),
attachmentSize,
attachmentContent
),
localOffset - offset
)
}
Expand Down
Loading