Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update burrow-gtk with new rpc #269

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
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
1,926 changes: 382 additions & 1,544 deletions burrow-gtk/Cargo.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion burrow-gtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
relm4 = { version = "0.6", features = ["libadwaita", "gnome_44"]}
burrow = { version = "*", path = "../burrow/" }
tokio = { version = "1.35.0", features = ["time", "sync"] }
gettext-rs = { version = "0.7.0", features = ["gettext-system"] }
tonic = "0.12"
prost = "0.13"
prost-types = "0.13"
hyper-util = "0.1.6"
tower = "0.4.13"
log = "0.4.22"
colog = "1.3.0"

[build-dependencies]
anyhow = "1.0"
glib-build-tools = "0.18.0"
tonic-build = "0.12"
2 changes: 1 addition & 1 deletion burrow-gtk/build-aux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive

RUN set -eux && \
dnf update -y && \
dnf install -y clang ninja-build cmake meson gtk4-devel glib2-devel libadwaita-devel desktop-file-utils libappstream-glib util-linux wget fuse fuse-libs file sqlite sqlite-devel
dnf install -y clang ninja-build cmake meson gtk4-devel glib2-devel libadwaita-devel desktop-file-utils libappstream-glib util-linux wget fuse fuse-libs file sqlite-devel protobuf-compiler protobuf-devel

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal
ENV PATH="/root/.cargo/bin:${PATH}"
Expand Down
1 change: 1 addition & 0 deletions burrow-gtk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;

fn main() -> Result<()> {
compile_gresources()?;
tonic_build::compile_protos("proto/burrow.proto")?;

Ok(())
}
Expand Down
73 changes: 73 additions & 0 deletions burrow-gtk/proto/burrow.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
syntax = "proto3";
package burrow;

import "google/protobuf/timestamp.proto";

service Tunnel {
rpc TunnelConfiguration (Empty) returns (TunnelConfigurationResponse);
rpc TunnelStart (Empty) returns (Empty);
rpc TunnelStop (Empty) returns (Empty);
rpc TunnelStatus (Empty) returns (stream TunnelStatusResponse);
}

service Networks {
rpc NetworkAdd (Empty) returns (Empty);
rpc NetworkList (Empty) returns (stream NetworkListResponse);
rpc NetworkReorder (NetworkReorderRequest) returns (Empty);
rpc NetworkDelete (NetworkDeleteRequest) returns (Empty);
}

message NetworkReorderRequest {
int32 id = 1;
int32 index = 2;
}

message WireGuardPeer {
string endpoint = 1;
repeated string subnet = 2;
}

message WireGuardNetwork {
string address = 1;
string dns = 2;
repeated WireGuardPeer peer = 3;
}

message NetworkDeleteRequest {
int32 id = 1;
}

message Network {
int32 id = 1;
NetworkType type = 2;
bytes payload = 3;
}

enum NetworkType {
WireGuard = 0;
HackClub = 1;
}

message NetworkListResponse {
repeated Network network = 1;
}

message Empty {

}

enum State {
Stopped = 0;
Running = 1;
}

message TunnelStatusResponse {
State state = 1;
optional google.protobuf.Timestamp start = 2;
}

message TunnelConfigurationResponse {
repeated string addresses = 1;
int32 mtu = 2;
}

68 changes: 47 additions & 21 deletions burrow-gtk/src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use super::*;
use anyhow::Context;
use std::time::Duration;

const RECONNECT_POLL_TIME: Duration = Duration::from_secs(5);
const RECONNECT_POLL_TIME: Duration = Duration::from_secs(3);

pub struct App {
daemon_client: Arc<Mutex<Option<DaemonClient>>>,
daemon_client: Arc<Mutex<Option<Channel>>>,
settings_screen: Controller<settings_screen::SettingsScreen>,
switch_screen: AsyncController<switch_screen::SwitchScreen>,
main_screen: AsyncController<main_screen::MainScreen>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -49,7 +49,7 @@ impl AsyncComponent for App {
view! {
adw::Window {
set_title: Some("Burrow"),
set_default_size: (640, 480),
set_default_size: (640, 800),
}
}

Expand All @@ -58,10 +58,19 @@ impl AsyncComponent for App {
root: Self::Root,
sender: AsyncComponentSender<Self>,
) -> AsyncComponentParts<Self> {
let daemon_client = Arc::new(Mutex::new(DaemonClient::new().await.ok()));

let switch_screen = switch_screen::SwitchScreen::builder()
.launch(switch_screen::SwitchScreenInit {
// TODO: RPC REFACTOR (Handle Error)
let mut daemon_client_connected = false;
let daemon_client = Arc::new(Mutex::new(
daemon::daemon_connect()
.await
.inspect(|_| {
daemon_client_connected = true;
})
.ok(),
));

let main_screen = main_screen::MainScreen::builder()
.launch(main_screen::MainScreenInit {
daemon_client: Arc::clone(&daemon_client),
})
.forward(sender.input_sender(), |_| AppMsg::None);
Expand All @@ -72,10 +81,21 @@ impl AsyncComponent for App {
})
.forward(sender.input_sender(), |_| AppMsg::None);

if !daemon_client_connected {
main_screen
.sender()
.send(main_screen::MainScreenMsg::DaemonDisconnect)
.unwrap();
settings_screen
.sender()
.send(settings_screen::SettingsScreenMsg::DaemonStateChange)
.unwrap();
}

let widgets = view_output!();

let view_stack = adw::ViewStack::new();
view_stack.add_titled(switch_screen.widget(), None, "Switch");
view_stack.add_titled(main_screen.widget(), None, "Burrow");
view_stack.add_titled(settings_screen.widget(), None, "Settings");

let view_switcher_bar = adw::ViewSwitcherBar::builder().stack(&view_stack).build();
Expand Down Expand Up @@ -108,7 +128,7 @@ impl AsyncComponent for App {

let model = App {
daemon_client,
switch_screen,
main_screen,
settings_screen,
};

Expand All @@ -122,27 +142,32 @@ impl AsyncComponent for App {
_root: &Self::Root,
) {
loop {
tokio::time::sleep(RECONNECT_POLL_TIME).await;
{
let mut daemon_client = self.daemon_client.lock().await;
let mut disconnected_daemon_client = false;

if let Some(daemon_client) = daemon_client.as_mut() {
if let Err(_e) = daemon_client.send_command(DaemonCommand::ServerInfo).await {
disconnected_daemon_client = true;
self.switch_screen
.emit(switch_screen::SwitchScreenMsg::DaemonDisconnect);
self.settings_screen
.emit(settings_screen::SettingsScreenMsg::DaemonStateChange)
if let Some(client) = daemon_client.as_mut() {
let mut client = tunnel_client::TunnelClient::new(client);

if let Ok(mut res) = client.tunnel_status(burrow_rpc::Empty {}).await {
let stream = res.get_mut();
while let Ok(Some(_)) = stream.message().await {}
}

*daemon_client = None;
disconnected_daemon_client = true;
self.main_screen
.emit(main_screen::MainScreenMsg::DaemonDisconnect);
self.settings_screen
.emit(settings_screen::SettingsScreenMsg::DaemonStateChange)
}

if disconnected_daemon_client || daemon_client.is_none() {
match DaemonClient::new().await {
match daemon::daemon_connect().await {
Ok(new_daemon_client) => {
*daemon_client = Some(new_daemon_client);
self.switch_screen
.emit(switch_screen::SwitchScreenMsg::DaemonReconnect);
self.main_screen
.emit(main_screen::MainScreenMsg::DaemonReconnect);
self.settings_screen
.emit(settings_screen::SettingsScreenMsg::DaemonStateChange)
}
Expand All @@ -152,6 +177,7 @@ impl AsyncComponent for App {
}
}
}
tokio::time::sleep(RECONNECT_POLL_TIME).await;
}
}
}
9 changes: 9 additions & 0 deletions burrow-gtk/src/components/main/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use super::*;

mod network_card;
mod networks;
mod switch;

pub use network_card::{NetworkCard, NetworkCardInit};
pub use networks::{Networks, NetworksInit};
pub use switch::{Switch, SwitchInit};
Loading
Loading