Skip to content
Open
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
383 changes: 378 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"backup-shard",
"btp",
"ql-api",
"ql-fsm",
"ql-rpc",
"ql-runtime",
Expand Down
20 changes: 20 additions & 0 deletions ql-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "ql-api"
version = "0.1.0"
edition = "2021"
description = "KeyOS QLv2 RPC protocol"
license = "Proprietary"


[dependencies]
ql-rpc = { workspace = true }
bytes = { workspace = true }
ciborium = "0.2.2"
flutter_rust_bridge = { version = "=2.11.1", optional = true }
serde = { version = "1.0", features = ["derive"] }

[features]
frb = ["flutter_rust_bridge"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] }
72 changes: 72 additions & 0 deletions ql-api/src/app_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use ql_rpc::{Download, Request};

use crate::{route, Error};

rpc! {
#[derive(Copy)]
pub struct AppVersion(pub u32, pub u32, pub u32);
}

//
// LIST APPS
//

rpc! {
pub struct ListAppsRequest {
//
}
}

rpc! {
pub struct ListAppsResponse {
pub apps: Vec<AppDetails>,
}
}

rpc! {
pub struct AppDetails {
pub name: String,
pub icon: String, // SVG?
pub developer_id: Vec<u8>,
pub app_id: Vec<u8>,
}
}

impl Request for route::ListApps {
type Error = Error;
type Request = ListAppsRequest;
type Response = ListAppsResponse;
}

//
// APP DOWNLOAD
//
// download a single tar file that contains:
// - app.elf
// - manifest.json

rpc! {
pub struct AppDownloadRequest {
pub version: Option<String>,
}
}

rpc! {
pub struct AppDownloadHeader {
pub version: String,
}
}

rpc! {
pub struct AppDownloadPartHeader {}
}

impl Download for route::AppDownload {
type Error = Error;

type Request = AppDownloadRequest;

type ResponseHeader = AppDownloadHeader;

type PartHeader = AppDownloadPartHeader;
}
167 changes: 167 additions & 0 deletions ql-api/src/backup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
use ql_rpc::{Download, Notification, Request, Upload};

use crate::{route, Error};

rpc! {
pub struct Shard(pub Vec<u8>);
}

rpc! {
pub struct SeedFingerprint(pub [u8; 32]);
}

rpc! {
pub struct BackupShardRequest {
pub shard: Shard,
}
}

rpc! {
pub enum BackupShardResponse {
Success,
Error { error: String },
}
}

impl Request for route::BackupShard {
type Error = Error;
type Request = BackupShardRequest;
type Response = BackupShardResponse;
}

rpc! {
pub struct RestoreShardRequest {
pub seed_fingerprint: SeedFingerprint,
pub timestamp: Option<u32>,
}
}

rpc! {
pub enum RestoreShardResponse {
Success { shard: Shard },
Error { error: String },
NotFound,
}
}

impl Request for route::RestoreShard {
type Error = Error;
type Request = RestoreShardRequest;
type Response = RestoreShardResponse;
}

rpc! {
pub struct EnvoyMagicBackupEnabledRequest {}
}

rpc! {
pub struct EnvoyMagicBackupEnabledResponse {
pub enabled: bool,
}
}

impl Request for route::EnvoyMagicBackupEnabled {
type Error = Error;
type Request = EnvoyMagicBackupEnabledRequest;
type Response = EnvoyMagicBackupEnabledResponse;
}

rpc! {
pub struct PassportMagicBackupEnabledPayload {
pub enabled: bool,
pub seed_fingerprint: SeedFingerprint,
}
}

impl Notification for route::PassportMagicBackupEnabled {
type Error = Error;
type Payload = PassportMagicBackupEnabledPayload;
}

rpc! {
pub struct PassportMagicBackupStatusRequest {
pub seed_fingerprint: SeedFingerprint,
pub timestamp: Option<u32>,
}
}

rpc! {
pub struct PassportMagicBackupStatusResponse {
pub shard_backup_found: bool,
}
}

impl Request for route::PassportMagicBackupStatus {
type Error = Error;
type Request = PassportMagicBackupStatusRequest;
type Response = PassportMagicBackupStatusResponse;
}

rpc! {
pub struct UploadMagicBackupRequest {
pub seed_fingerprint: SeedFingerprint,
pub total_size: Option<u64>,
pub hash: [u8; 32],
}
}

rpc! {
pub enum UploadMagicBackupResult {
Success,
Error { error: String },
}
}

rpc! {
pub struct UploadMagicBackupPartHeader {}
}

impl Upload for route::UploadMagicBackup {
type Error = Error;
type Request = UploadMagicBackupRequest;
type PartHeader = UploadMagicBackupPartHeader;
type Response = UploadMagicBackupResult;
}

rpc! {
pub struct DownloadMagicBackupRequest {
pub seed_fingerprint: SeedFingerprint,
}
}

rpc! {
pub enum DownloadMagicBackupHeader {
Found(BackupMetadata),
NotFound,
Error { error: String },
}
}

rpc! {
pub struct BackupMetadata {
pub total_size: Option<u64>,
}
}

rpc! {
pub struct DownloadMagicBackupPartHeader {}
}

impl Download for route::DownloadMagicBackup {
type Error = Error;
type Request = DownloadMagicBackupRequest;
type ResponseHeader = DownloadMagicBackupHeader;
type PartHeader = DownloadMagicBackupPartHeader;
}

rpc! {
pub enum RestoreMagicBackupResult {
Success,
Error { error: String },
}
}

impl Notification for route::RestoreMagicBackupComplete {
type Error = Error;
type Payload = RestoreMagicBackupResult;
}
65 changes: 65 additions & 0 deletions ql-api/src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use ql_rpc::{request::Request, Download, Subscription};

use crate::{route, Error};

// Echo request-response benchmark
impl Request for route::Echo {
type Error = Error;
type Request = EchoRequest;
type Response = EchoResponse;
}

rpc! {
pub struct EchoRequest {
pub message: String,
}
}

rpc! {
pub struct EchoResponse {
pub message: String,
}
}

// Byte-stream subscription benchmark
impl Subscription for route::BytesBenchmark {
type Error = Error;
type Event = BenchmarkEvent;
type Request = BenchmarkRequest;
}

rpc! {
pub struct BenchmarkRequest {
pub length: u32,
}
}

rpc! {
pub struct BenchmarkEvent {
pub bytes: Vec<u8>,
}
}

// Raw-body download benchmark
impl Download for route::DownloadBenchmark {
type Error = Error;
type Request = DownloadBenchmarkRequest;
type ResponseHeader = DownloadBenchmarkHeader;
type PartHeader = DownloadBenchmarkPartHeader;
}

rpc! {
pub struct DownloadBenchmarkRequest {
pub length: u64,
}
}

rpc! {
pub struct DownloadBenchmarkHeader {
pub hash: Vec<u8>,
}
}

rpc! {
pub struct DownloadBenchmarkPartHeader {}
}
Loading