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

Upgrade Dependencies #84

Merged
merged 7 commits into from
Feb 19, 2024
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
6 changes: 4 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

# ktlint
disabled_rules=no-wildcard-imports,import-ordering,max-line-length
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_import-ordering = disabled
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
java-package: jdk

- name: Grant execute permission for gradlew
Expand Down
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.7.10'
ext.ktlint_version = '0.44.0'
ext.kotlin_version = '1.9.22'
ext.coroutines_version = '1.6.4'
ext.ktlint_gradle_version = '11.0.0'
// https://github.com/cashapp/sqldelight/issues/1574
ext.sqldelight_version = '1.5.2'
ext.nav_version = "2.5.3"
ext.fragment_version = "1.5.4"
ext.lifecycle_version = "2.5.1"
ext.dokka_version = "0.10.1"
ext.ktlint_version = '1.1.1'
ext.ktlint_gradle_version = '12.1.0'
ext.sqldelight_version = '2.0.1'
ext.nav_version = '2.5.3'
ext.fragment_version = '1.5.4'
ext.lifecycle_version = '2.5.1'
ext.dokka_version = '0.10.1'
ext.mockk_version = '1.13.9'
repositories {
google()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:8.2.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"
classpath "app.cash.sqldelight:gradle-plugin:$sqldelight_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
// NOTE: Do not place your application dependencies here; they belong
Expand Down Expand Up @@ -50,7 +50,7 @@ task clean(type: Delete) {

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.freeCompilerArgs += [
"-opt-in=kotlin.Experimental,kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.RequiresOptIn"
]
}
29 changes: 15 additions & 14 deletions demo-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 33

defaultConfig {
applicationId "nl.tudelft.ipv8.demo"
minSdkVersion 22
targetSdkVersion 33
versionCode 1
versionName "0.1"
compileSdk 34
versionCode 2
versionName "0.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -25,21 +27,20 @@ android {
// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
jvmTarget = JavaVersion.VERSION_17.toString()
allWarningsAsErrors = true
}

viewBinding {
enabled = true
}

packagingOptions {
exclude 'META-INF/kotlinx-coroutines-core.kotlin_module'
resources {
excludes += ['META-INF/kotlinx-coroutines-core.kotlin_module']
}
}

namespace 'nl.tudelft.trustchain.demo'
}

Expand Down Expand Up @@ -89,7 +90,7 @@ dependencies {

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.freeCompilerArgs += [
"-opt-in=kotlin.Experimental,kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.RequiresOptIn"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.os.Build
import android.util.Log
import androidx.core.content.getSystemService
import androidx.preference.PreferenceManager
import com.squareup.sqldelight.android.AndroidSqliteDriver
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import nl.tudelft.ipv8.IPv8Configuration
import nl.tudelft.ipv8.Overlay
import nl.tudelft.ipv8.OverlayConfiguration
Expand All @@ -21,7 +21,6 @@ import nl.tudelft.ipv8.attestation.trustchain.validation.TransactionValidator
import nl.tudelft.ipv8.attestation.trustchain.validation.ValidationResult
import nl.tudelft.ipv8.keyvault.PrivateKey
import nl.tudelft.ipv8.keyvault.defaultCryptoProvider
import nl.tudelft.ipv8.messaging.tftp.TFTPCommunity
import nl.tudelft.ipv8.peerdiscovery.DiscoveryCommunity
import nl.tudelft.ipv8.peerdiscovery.strategy.PeriodicSimilarity
import nl.tudelft.ipv8.peerdiscovery.strategy.RandomChurn
Expand All @@ -34,24 +33,20 @@ import nl.tudelft.trustchain.demo.service.TrustChainService
class DemoApplication : Application() {
override fun onCreate() {
super.onCreate()

defaultCryptoProvider = AndroidCryptoProvider

initIPv8()
}

private fun initIPv8() {
val config = IPv8Configuration(overlays = listOf(
createDiscoveryCommunity(),
createTrustChainCommunity(),
createDemoCommunity()
), walkerInterval = 5.0)

IPv8Android.Factory(this)
.setConfiguration(config)
.setPrivateKey(getPrivateKey())
.setServiceClass(TrustChainService::class.java)
.init()
val config = IPv8Configuration(
overlays = listOf(
createDiscoveryCommunity(), createTrustChainCommunity(), createDemoCommunity()
), walkerInterval = 5.0
)

IPv8Android.Factory(this).setConfiguration(config).setPrivateKey(getPrivateKey())
.setServiceClass(TrustChainService::class.java).init()

initTrustChain()
}
Expand All @@ -62,8 +57,7 @@ class DemoApplication : Application() {

trustchain.registerTransactionValidator(BLOCK_TYPE, object : TransactionValidator {
override fun validate(
block: TrustChainBlock,
database: TrustChainStore
block: TrustChainBlock, database: TrustChainStore
): ValidationResult {
if (block.transaction["message"] != null || block.isAgreement) {
return ValidationResult.Valid
Expand Down Expand Up @@ -92,8 +86,8 @@ class DemoApplication : Application() {
val periodicSimilarity = PeriodicSimilarity.Factory()

val nsd = NetworkServiceDiscovery.Factory(getSystemService()!!)
val bluetoothManager = getSystemService<BluetoothManager>()
?: throw IllegalStateException("BluetoothManager not available")
val bluetoothManager =
getSystemService<BluetoothManager>() ?: throw IllegalStateException("BluetoothManager not available")
val strategies = mutableListOf(
randomWalk, randomChurn, periodicSimilarity, nsd
)
Expand All @@ -103,8 +97,7 @@ class DemoApplication : Application() {
}

return OverlayConfiguration(
DiscoveryCommunity.Factory(),
strategies
DiscoveryCommunity.Factory(), strategies
)
}

Expand All @@ -114,16 +107,14 @@ class DemoApplication : Application() {
val store = TrustChainSQLiteStore(Database(driver))
val randomWalk = RandomWalk.Factory()
return OverlayConfiguration(
TrustChainCommunity.Factory(settings, store),
listOf(randomWalk)
TrustChainCommunity.Factory(settings, store), listOf(randomWalk)
)
}

private fun createDemoCommunity(): OverlayConfiguration<DemoCommunity> {
val randomWalk = RandomWalk.Factory()
return OverlayConfiguration(
Overlay.Factory(DemoCommunity::class.java),
listOf(randomWalk)
Overlay.Factory(DemoCommunity::class.java), listOf(randomWalk)
)
}

Expand All @@ -134,9 +125,7 @@ class DemoApplication : Application() {
return if (privateKey == null) {
// Generate a new key on the first launch
val newKey = AndroidCryptoProvider.generateKey()
prefs.edit()
.putString(PREF_PRIVATE_KEY, newKey.keyToBin().toHex())
.apply()
prefs.edit().putString(PREF_PRIVATE_KEY, newKey.keyToBin().toHex()).apply()
newKey
} else {
AndroidCryptoProvider.keyFromPrivateBin(privateKey.hexToBytes())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package nl.tudelft.trustchain.demo

import nl.tudelft.ipv8.IPv4Address
import nl.tudelft.ipv8.Community
import nl.tudelft.ipv8.IPv4Address
import nl.tudelft.ipv8.Peer
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.attestation.trustchain.TrustChainCommunity
import nl.tudelft.ipv8.messaging.*
import nl.tudelft.ipv8.messaging.payload.IntroductionResponsePayload
import nl.tudelft.ipv8.messaging.payload.PuncturePayload
import java.util.*

class DemoCommunity : Community() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import nl.tudelft.trustchain.demo.ui.DemoActivity
class TrustChainService : IPv8Service() {
override fun createNotification(): NotificationCompat.Builder {
val trustChainExplorerIntent = Intent(this, DemoActivity::class.java)
val pendingIntent = TaskStackBuilder.create(this)
.addNextIntentWithParentStack(trustChainExplorerIntent)
val pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(trustChainExplorerIntent)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)

return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_CONNECTION)
.setContentTitle("IPv8 Demo")
.setContentText("Running")
.setSmallIcon(R.drawable.ic_insert_link_black_24dp)
return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_CONNECTION).setContentTitle("IPv8 Demo")
.setContentText("Running").setSmallIcon(R.drawable.ic_insert_link_black_24dp)
.setContentIntent(pendingIntent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.mattskala.itemadapter.ItemAdapter
import kotlinx.android.synthetic.main.fragment_peers.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.trustchain.demo.DemoCommunity
import nl.tudelft.trustchain.demo.R
import nl.tudelft.trustchain.demo.databinding.FragmentPeersBinding
import nl.tudelft.trustchain.demo.ui.peers.AddressItem
import nl.tudelft.trustchain.demo.ui.peers.AddressItemRenderer
import nl.tudelft.trustchain.demo.ui.peers.PeerItem
import nl.tudelft.trustchain.demo.ui.peers.PeerItemRenderer

class DemoActivity : AppCompatActivity() {
private lateinit var binding: FragmentPeersBinding
private val adapter = ItemAdapter()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.fragment_peers)
binding = FragmentPeersBinding.inflate(layoutInflater)
setContentView(binding.root)

adapter.registerRenderer(PeerItemRenderer {
// NOOP
Expand All @@ -36,9 +37,9 @@ class DemoActivity : AppCompatActivity() {
// NOOP
})

recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))
binding.recyclerView.adapter = adapter
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))

loadNetworkInfo()
}
Expand All @@ -49,12 +50,10 @@ class DemoActivity : AppCompatActivity() {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network
.getWalkableAddresses(demoCommunity.serviceId)
val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses = demoCommunity.network
.getNewBluetoothPeerCandidates()
.map { it.address }
val discoveredBluetoothAddresses =
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }

val peerItems = peers.map {
PeerItem(
Expand All @@ -65,29 +64,25 @@ class DemoActivity : AppCompatActivity() {
val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address,
null,
contacted
address, null, contacted
)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address,
null,
null
address, null, null
)
}

val items = peerItems + bluetoothAddressItems + addressItems

adapter.updateItems(items)
txtCommunityName.text = demoCommunity.javaClass.simpleName
txtPeerCount.text = "${peers.size} peers"
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
binding.txtPeerCount.text = "${peers.size} peers"
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
txtPeerCount.setTextColor(textColor)
imgEmpty.isVisible = items.isEmpty()
binding.txtPeerCount.setTextColor(textColor)
binding.imgEmpty.isVisible = items.isEmpty()

delay(1000)
}
Expand Down
Loading
Loading