Skip to content

Commit

Permalink
Refactor, added kotlin build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-baumann committed Feb 15, 2024
1 parent 32d0505 commit 41351ed
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 230 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ jobs:
- name: Build
run: cargo build --verbose

publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3

# - name: Publish package
# uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
# with:
# arguments: publish
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd bindings/kotlin
./gradlew clean build publish
test:
name: Run Tests
runs-on: ${{ matrix.os }}
Expand Down
9 changes: 1 addition & 8 deletions bindings/kotlin/DataRCT/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'idea'
id "org.mozilla.rust-android-gradle.rust-android"
id "maven-publish"
}

android {
Expand Down Expand Up @@ -59,14 +60,6 @@ tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.configureEach {
it.dependsOn("cargoBuild")
}

//tasks.configureEach {
// if ((this.name == "mergeDebugJniLibFolders" || this.name == "mergeReleaseJniLibFolders")) {
// this.dependsOn("cargoBuild")
// // fix mergeDebugJniLibFolders UP-TO-DATE
// this.inputs.dir(buildDir.resolve("rustJniLibs/android"))
// }
//}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import android.content.pm.PackageManager
import android.os.ParcelUuid
import android.util.Log
import androidx.core.app.ActivityCompat
import com.julian_baumann.data_rct.BleServerImplementationDelegate
import com.julian_baumann.data_rct.BluetoothLeConnectionInfo
import com.julian_baumann.data_rct.InternalNearbyServer
import com.julian_baumann.data_rct.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.*


class BlePermissionNotGrantedException : Exception()
val discoveryServiceUUID: UUID = UUID.fromString("68D60EB2-8AAA-4D72-8851-BD6D64E169B7")
val discoveryCharacteristicUUID: UUID = UUID.fromString("0BEBF3FE-9A5E-4ED1-8157-76281B3F0DA5")
val discoveryServiceUUID: UUID = UUID.fromString(getBleServiceUuid())
val discoveryCharacteristicUUID: UUID = UUID.fromString(getBleCharacteristicUuid())

internal class BLEPeripheralManager(private val context: Context, private val internalNearbyServer: InternalNearbyServer) : BleServerImplementationDelegate {
private val bluetoothManager: BluetoothManager by lazy {
Expand Down
23 changes: 23 additions & 0 deletions bindings/kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ plugins {
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id 'com.android.library' version '8.2.0' apply false
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3" apply false
id 'maven-publish'
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/julian-baumann/data-rct")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}

publications {
gpr(MavenPublication) {
groupId = "com.julian_baumann.data_rct" as Publication
artifactId = "DataRCT" as Publication
version = System.getenv("VERSION") as Publication
artifact("$buildDir/outputs/aar/DataRCT-release.aar")
}
}
}
1 change: 1 addition & 0 deletions bindings/kotlin/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pluginManagement {
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

repositories {
google()
mavenCentral()
Expand Down
5 changes: 2 additions & 3 deletions src/data_rct/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name = "data_rct"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
protocol = { path = "../protocol" }
crossbeam-channel = "0.5"
Expand All @@ -21,6 +19,7 @@ bytes = "1.5.0"
futures = "0.3"
tokio = { version = "1.35.1", features = ["net", "io-util", "time"] }
async-prost = "0.4.0"
gethostname = "0.4.3"
local-ip-address = { git = "https://github.com/julian-baumann/local-ip-address.git", branch = "main" }
prost-stream = "0.1.2"
android_logger = "0.13.3"
log = "0.4.20"
10 changes: 0 additions & 10 deletions src/data_rct/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ pub async fn initiate_sender_communication<T>(mut stream: T) -> Result<Encrypted
public_key: public_key.as_bytes().to_vec()
};

println!("initiating prost stream");
let mut prost_stream = Stream::new(&mut stream);
let _ = prost_stream.send(&encryption_request);
println!("sent request");

println!("receiving response");
let encryption_response: EncryptionResponse = match prost_stream.recv::<EncryptionResponse>() {
Ok(message) => message,
Err(error) => return Err(Box::new(error))
};
println!("received response");

let public_key: [u8; 32] = encryption_response.public_key.try_into().expect("Vec length is not 32");
let foreign_public_key = PublicKey::from(public_key);
Expand All @@ -33,9 +29,7 @@ pub async fn initiate_sender_communication<T>(mut stream: T) -> Result<Encrypted

let iv: [u8; 24] = encryption_response.iv.try_into().expect("Vec length is not 24");

println!("encrypting stream");
let encrypted_stream = EncryptedStream::new(shared_secret.to_bytes(), iv, stream);
println!("encrypted stream");

return Ok(encrypted_stream);
}
Expand All @@ -46,16 +40,13 @@ pub fn initiate_receiver_communication<T>(mut stream: T) -> Result<EncryptedStre

let iv = generate_iv();

println!("initiating prost stream");
let mut prost_stream = Stream::new(&mut stream);

println!("Receiving request");
let encryption_request = match prost_stream.recv::<EncryptionRequest>() {
Ok(message) => message,
Err(error) => return Err(Box::new(error))
};

println!("Sending response");
let _ = prost_stream.send(
&EncryptionResponse {
public_key: public_key.as_bytes().to_vec(),
Expand All @@ -68,7 +59,6 @@ pub fn initiate_receiver_communication<T>(mut stream: T) -> Result<EncryptedStre

let shared_secret = secret.diffie_hellman(&foreign_public_key);

println!("Encrypting stream");
let encrypted_stream = EncryptedStream::new(shared_secret.to_bytes(), iv, stream);

return Ok(encrypted_stream);
Expand Down
2 changes: 0 additions & 2 deletions src/data_rct/src/connection_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl ConnectionRequest {
let path = path.join(&file_transfer.file_name.unwrap_or_else(|| "temp.zip".to_string()));
let path = path.into_os_string();

println!("Creating file at {:?}", path);
let mut file = File::create(path).expect("Failed to create file");

let mut buffer = [0; 1024];
Expand All @@ -136,7 +135,6 @@ impl ConnectionRequest {
.expect("Failed to write file to disk");

let progress = all_read / file_transfer.file_size as f64;

self.update_progress(ReceiveProgressState::Receiving { progress });
}

Expand Down
3 changes: 3 additions & 0 deletions src/data_rct/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use protocol::discovery::{DeviceConnectionInfo, DeviceDiscoveryMessage, Device};
use protocol::discovery::device_discovery_message::Content;
use protocol::prost::Message;
use crate::errors::DiscoverySetupError;
use crate::init_logger;

pub trait BleDiscoveryImplementationDelegate: Send + Sync + Debug {
fn start_scanning(&self);
Expand All @@ -21,6 +22,8 @@ pub struct Discovery {

impl Discovery {
pub fn new(delegate: Option<Box<dyn DiscoveryDelegate>>) -> Result<Self, DiscoverySetupError> {
init_logger();

DISCOVERED_DEVICES.get_or_init(|| RwLock::new(HashMap::new()));

let callback_arc = match delegate {
Expand Down
175 changes: 0 additions & 175 deletions src/data_rct/src/discovery/mdns_sd.rs

This file was deleted.

Loading

0 comments on commit 41351ed

Please sign in to comment.