getting everything to a stable base, just for development
This commit is contained in:
2
.github/workflows/rust.yml
vendored
2
.github/workflows/rust.yml
vendored
@@ -14,6 +14,6 @@ jobs:
|
||||
- name: Build Irssi
|
||||
run: git clone https://github.com/irssi/irssi && cd irssi && ./autogen.sh && ./configure && make && cd ..
|
||||
- name: Build irssi-wire
|
||||
run: IRSSI_INCLUDE=irssi cargo build --verbose
|
||||
run: REBUILD_PROTOBUF=1 REBUILD_BINDGEN=1 IRSSI_INCLUDE=irssi cargo build -vv
|
||||
- name: Run tests
|
||||
run: IRSSI_INCLUDE=irssi cargo test --verbose
|
||||
|
||||
19
build.rs
19
build.rs
@@ -6,19 +6,20 @@ use std::fs::File;
|
||||
use protoc_rust::Customize;
|
||||
|
||||
fn main() {
|
||||
if env::var("REBUILD_BINDGEN").is_ok() {
|
||||
// C bindings
|
||||
eprintln!("Generating C bindings to irssi");
|
||||
let server_rec = "
|
||||
typedef struct _WireServerRec {
|
||||
int x;
|
||||
} WireServerRec;
|
||||
|
||||
#define STRUCT_SERVER_REC WireServerRec".to_string();
|
||||
|
||||
let mut recs = File::create("recs.h").unwrap();
|
||||
recs.write_all(server_rec.as_bytes()).unwrap();
|
||||
|
||||
|
||||
// Generate bindings for headers.h
|
||||
eprintln!("Generating C bindings");
|
||||
let mut irssi_path = "-I".to_string();
|
||||
irssi_path.push_str(env::var("IRSSI_INCLUDE").unwrap().as_str());
|
||||
let bindings = bindgen::Builder::default()
|
||||
@@ -29,13 +30,17 @@ typedef struct _WireServerRec {
|
||||
.generate()
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.write_to_file("src/irssi/bindgen_output.rs")
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
||||
else {
|
||||
eprintln!("Skipping C binding generation");
|
||||
}
|
||||
|
||||
eprintln!("Generating protobuf code");
|
||||
// Protobuffer code generation
|
||||
if env::var("REBUILD_PROTOBUF").is_ok() {
|
||||
eprintln!("Generating protobuf code");
|
||||
protoc_rust::run(protoc_rust::Args {
|
||||
out_dir: "src/net/protos",
|
||||
input: &["wire-api.proto"],
|
||||
@@ -44,4 +49,8 @@ typedef struct _WireServerRec {
|
||||
..Default::default()
|
||||
},
|
||||
}).expect("Couln't generate code from protobuffers for wire api");
|
||||
}
|
||||
else {
|
||||
eprintln!("Skipping protobuf generation");
|
||||
}
|
||||
}
|
||||
|
||||
27964
src/irssi/bindgen_output.rs
Normal file
27964
src/irssi/bindgen_output.rs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,5 +2,6 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
include!("bindgen_output.rs");
|
||||
|
||||
11
src/lib.rs
11
src/lib.rs
@@ -1,11 +1,8 @@
|
||||
use std::os::raw::c_int;
|
||||
use std::ffi::CString;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
mod irssi;
|
||||
mod net;
|
||||
mod storage;
|
||||
|
||||
use irssi::bindings::*;
|
||||
|
||||
@@ -22,14 +19,6 @@ pub extern fn wire_core_init() {
|
||||
unsafe {
|
||||
module_register_full(CString::new("wire").unwrap().as_ptr(), CString::new("core").unwrap().as_ptr(), CString::new("wire/core").unwrap().as_ptr());
|
||||
}
|
||||
thread::spawn(|| {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(10));
|
||||
println!("{} iteration", i);
|
||||
i += 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
pub(crate) mod protos;
|
||||
pub(crate) mod model;
|
||||
pub mod protos;
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::net::model::prekeys::{PreKey, LastPreKey};
|
||||
// Client
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Client {
|
||||
pub id: String,
|
||||
pub class: Option<Class>,
|
||||
pub time: Option<DateTime<Utc>>,
|
||||
pub r#type: Option<ClientType>,
|
||||
pub cookie_label: Option<String>,
|
||||
pub label: Option<String>,
|
||||
pub model: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
|
||||
pub enum Class {
|
||||
phone,
|
||||
tablet,
|
||||
desktop
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
|
||||
pub enum ClientType {
|
||||
permanent,
|
||||
temporary
|
||||
}
|
||||
|
||||
// PubClientView
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PubClientView {
|
||||
pub id: String,
|
||||
pub class: Class
|
||||
}
|
||||
|
||||
// SignalingKeys
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct SignalingKeys {
|
||||
#[serde(serialize_with = "b64_encode", deserialize_with = "b64_decode")]
|
||||
pub enc: Vec<u8>,
|
||||
#[serde(serialize_with = "b64_encode", deserialize_with = "b64_decode")]
|
||||
pub mac: Vec<u8>
|
||||
}
|
||||
|
||||
fn b64_encode<'a, S>(bytes: &'a Vec<u8>, serialzer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
serialzer.serialize_str(&base64::encode(&bytes))
|
||||
}
|
||||
|
||||
fn b64_decode<'de, D>(deserialzer: D) -> Result<Vec<u8>, D::Error>
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
use serde::de::Error;
|
||||
|
||||
String::deserialize(deserialzer)
|
||||
.and_then(|string|
|
||||
base64::decode(&string)
|
||||
.map_err(|e| Error::custom(e.to_string()))
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct User2Clients {
|
||||
pub value: HashMap<Uuid, HashSet<String>>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientMismatch {
|
||||
pub time: DateTime<Utc>,
|
||||
pub redundant: User2Clients,
|
||||
pub missing: User2Clients,
|
||||
pub deleted: User2Clients
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct RegisterParams{
|
||||
pub prekeys: Vec<PreKey>,
|
||||
pub last_prekey: LastPreKey,
|
||||
pub sig_keys: SignalingKeys,
|
||||
pub ctype: ClientType,
|
||||
pub class: Class,
|
||||
pub cookie_label: String,
|
||||
pub label: Option<String>,
|
||||
pub password: Option<String>,
|
||||
pub model: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
struct DeleteParams {
|
||||
password: String
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
pub mod client;
|
||||
pub mod prekeys;
|
||||
@@ -1,63 +0,0 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use proteus::keys::{IdentityKey, PreKeyBundle};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PreKeyMap {
|
||||
pub value: HashMap<Uuid, HashMap<String, Option<PreKey>>>
|
||||
}
|
||||
|
||||
impl PreKeyMap {
|
||||
pub fn new() -> PreKeyMap {
|
||||
PreKeyMap {
|
||||
value: HashMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, id: &Uuid) -> Option<&HashMap<String, Option<PreKey>>> {
|
||||
self.value.get(id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PreKey {
|
||||
pub key: PreKeyBundle
|
||||
}
|
||||
|
||||
impl PreKey {
|
||||
pub fn last_resort(k: &IdentityKey) -> LastPreKey {
|
||||
let pk = proteus::PreKey::last_resort();
|
||||
LastPreKey(PreKey { key: PreKeyBundle::new(k.clone(), &pk) })
|
||||
}
|
||||
|
||||
pub fn from_str(s: &str) -> Option<PreKey> {
|
||||
base64::decode(s).ok().and_then(|xs| {
|
||||
PreKeyBundle::deserialise(xs.as_slice()).ok().map(|k| PreKey { key: k })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct LastPreKey(PreKey);
|
||||
|
||||
impl LastPreKey {
|
||||
pub fn new(p: PreKey) -> Option<LastPreKey> {
|
||||
if p.key.prekey_id == proteus::MAX_PREKEY_ID {
|
||||
Some(LastPreKey(p))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientPreKey {
|
||||
pub id: String,
|
||||
pub key: PreKey
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientPreKeys(Vec<ClientPreKey>);
|
||||
Reference in New Issue
Block a user