the new core and its future
Benjamin Kampmann
@gnunicorn:matrix.org
2022-08-27, Matrix Summit Berlin
rust SDK
It'se me, Ben
formerly
Freelance Dev since 2011
Rust Dev since 2015 (before Python, JS, etc)
prev. Core Dev @ Parity on Substrate (blockchain dev framework); App-SDK Dev @ MaidSafe
Co-Host RustFest 2016 & 2017
more about me on gnunicorn.org
What the rust?
obligatory rust-intro slides
Systems-Lang
Fast
as fast & sometimes faster than c/c++; no garbage collector
Safe
typed; without segfaults; checked at compile time
Yes, WASM
LLVM backend
Portable
Lovely People
Great Tooling
Massive Docs
What rust looks like
use rand::Rng;
struct CustomType {
inner: String
}
impl CustomType {
pub fn new(inner: String) -> Self {
CustomType { inner }
}
}
fn main() {
let mut rng = rand::thread_rng();
let num = rng.gen::<u8>();
let conv = match num {
0 => Some(CustomType::new("Zero".to_owned())),
5 => Some(CustomType::new("Zero".to_owned())),
_ => None,
};
if let Some(t) = conv {
println!("{}", t.inner);
} else {
println!("{}", num)
}
}
But why are we talking about this?
there are issues...
well,...
Spec and the ecosystem are thriving
But
- The main crypto library is C
- which is not very portable and hard to maintain for users
- which means a lot of clients don't ever bother implementing e2ee
And
- A lot has changed since the first clients have been developed
- a lot has been learned, but not necessarily been translated into cross-plattform code
- Old code-base also means it is harder to experiment with new features
Which overall means
Matrix Clients are all over the place; developing one is hard and most lack a core aspect end-to-end-encryption because of a lack of well supported libraries. This slows down development of matrix as a whole.
Rust
hence..
The Matrix Rust SDK
mission
multi-platform
Matrix Development Toolkit with crypto built-in
Key Features
- Sync state, rooms, events, devices & ephemeral events
- handle end-2-end-encryption transparently for you
- verify device(s), exchange keys
- fetch attachments, avatars
and if enabled, resize images for you - compute and manage common state
e.g. rooms member list, display_name -
pluggable persistent storage layers for state
with sled on native, indexeddb for wasm/web - various bindings
with uniffi for Swift; crypto for NodeJS, Python
Server / Bot
Mobile
Web (wasm)
Example
// from `examples/getting_started/src/main.rs:152`
async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
// First, we need to unpack the message: We only want messages from rooms we are
// still in and that are regular text messages - ignoring everything else.
if let Room::Joined(room) = room {
let msg_body = match event.content.msgtype {
MessageType::Text(TextMessageEventContent { body, .. }) => body,
_ => return,
};
// here comes the actual "logic": when the bot see's a `!party` in the message,
// it responds
if msg_body.contains("!party") {
let content = RoomMessageEventContent::text_plain("🎉🎊🥳 let's PARTY!! 🥳🎊🎉");
println!("sending");
// send our message to the room we found the "!party" command in
// the last parameter is an optional transaction id which we don't
// care about.
room.send(content, None).await.unwrap();
println!("message sent");
}
}
}
// ...
Join the matrix SDK workshop here @2pm
rust SDK
future
already in the works:
and beyond
- Extended Timeline State machines
- Encrypted Appservices
- Async over FFI
- More storage backends
Want more vision and future? Join my closing talk today @ 5pm in mainhall
Questions?
Thanks!
Matrix Rust SDK
By Benjamin Kampmann
Matrix Rust SDK
- 441