Commit 32e306ed10

32e306ed109ca473642673779baf1b5a3d596f25

parent: 5d8828a45b

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2020-03-01 18:41 UTC

weechat-matrix: Switch to the new nio/rust-sdk repo.

Layout: unified · split

Cargo.toml +2 −2
@@ -13,10 +13,10 @@ crate-type = ["dylib"]
13libc = "0.2.66" 13libc = "0.2.66"
14url = "2.1.1" 14url = "2.1.1"
15tokio = { version = "0.2.9", features = [ "rt-threaded" ] } 15tokio = { version = "0.2.9", features = [ "rt-threaded" ] }
16async-std = { version = "1.4.0", features = [ "unstable" ] } 16async-std = { version = "1.5.0", features = [ "unstable" ] }
17clap = "2.33.0" 17clap = "2.33.0"
18 18
19matrix-nio = { git = "https://github.com/poljar/nio-rust" } 19matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk" }
20 20
21weechat = { path = "/home/poljar/werk/weechat/rust-weechat/weechat-rs/", features = ["async-executor"] } 21weechat = { path = "/home/poljar/werk/weechat/rust-weechat/weechat-rs/", features = ["async-executor"] }
22weechat-sys = { path = "/home/poljar/werk/weechat/rust-weechat/weechat-sys" } 22weechat-sys = { path = "/home/poljar/werk/weechat/rust-weechat/weechat-sys" }
src/config.rs +16
@@ -1,3 +1,19 @@
1//! Configuration module
2//!
3//! This is the global plugin configuration.
4//!
5//! Configuration options should be split out into different sections:
6//!
7//! * network
8//! * look
9//! * color
10//! * server
11//!
12//! The server config options are added in the server.rs file.
13//!
14//! The config options created here will be alive as long as the plugin is
15//! loaded so they don't need to be freed manually. The drop implementation of
16//! the section will do so.
1use crate::{MatrixServer, Servers}; 17use crate::{MatrixServer, Servers};
2use weechat::config::{ 18use weechat::config::{
3 Conf, ConfigSection, ConfigSectionSettings, OptionChanged, 19 Conf, ConfigSection, ConfigSectionSettings, OptionChanged,
src/server.rs +56 −2
@@ -1,3 +1,55 @@
1//! Matrix server abstraction.
2//!
3//! A MatrixServer is created for every server the user configures.
4//!
5//! It will create a per server config subsection. If options are added to the
6//! server they need to be removed from the server section when the server is
7//! dropped.
8//!
9//! The server will create a tokio runtime which will spawn two tasks, one for
10//! the sync loop and one to send out room messages.
11//!
12//! If will also spawn a task on the Weechat mainloop, this one waits for
13//! responses from the sync loop.
14//!
15//!
16//! Schematically this looks like the following diagram.
17//!
18//! MatrixServer
19//! +--------------------------------------------------------------------+
20//! | |
21//! | Weechat mainloop Tokio runtime |
22//! | +---------------------------+ +------------------------+ |
23//! | | | | | |
24//! | | +--------------------+ | | +----------------+ | |
25//! | | | | | | | | | |
26//! | | | Response receiver +<---------------+ Sync loop | | |
27//! | | | | | | | | | |
28//! | | | | | | | | | |
29//! | | +--------------------+ | | +----------------+ | |
30//! | | | | | |
31//! | | +--------------------+ | | +----------------+ | |
32//! | | | | | | | | | |
33//! | | | Roombuffer input +--------------->+ Send loop | | |
34//! | | | callback +<---------------+ | | |
35//! | | | | | | | | | |
36//! | | +--------------------+ | | +----------------+ | |
37//! | | | | | |
38//! | +---------------------------+ +------------------------+ |
39//! | |
40//! +--------------------------------------------------------------------+
41//!
42//!
43//! The tokio runtime and response receiver task will be alive only if the user
44//! connects to the server while the room buffer input callback will print an
45//! error if the server is disconnected.
46//!
47//! The server holds all the rooms which in turn hold the buffers, users, and
48//! room metadata.
49//!
50//! The response receiver forwards events to the correct room. The response
51//! receiver fetches events individually from a mpsc channel. This makes sure
52//! that processing events will not block the Weechat mainloop for too long.
1use async_std::sync::channel as async_channel; 53use async_std::sync::channel as async_channel;
2use async_std::sync::{Receiver, Sender}; 54use async_std::sync::{Receiver, Sender};
3use std::cell::RefCell; 55use std::cell::RefCell;
@@ -6,9 +58,9 @@ use std::rc::{Rc, Weak};
6use tokio::runtime::Runtime; 58use tokio::runtime::Runtime;
7use url::Url; 59use url::Url;
8 60
9use matrix_nio::api::r0::session::login::Response as LoginResponse; 61use matrix_sdk::api::r0::session::login::Response as LoginResponse;
10 62
11use matrix_nio::{ 63use matrix_sdk::{
12 self, 64 self,
13 events::{ 65 events::{
14 collections::all::{RoomEvent, StateEvent}, 66 collections::all::{RoomEvent, StateEvent},
@@ -66,6 +118,8 @@ pub struct LoginState {
66pub struct Connection { 118pub struct Connection {
67 client_channel: Sender<ServerMessage>, 119 client_channel: Sender<ServerMessage>,
68 response_receiver: JoinHandle<(), ()>, 120 response_receiver: JoinHandle<(), ()>,
121 // TODO move the runtime into the plugin, once we're able to cancel tokio
122 // tasks.
69 runtime: Runtime, 123 runtime: Runtime,
70} 124}
71 125