From 45c7c27d5ebd54790d76dd34d97de35d221c8411 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 17 Sep 2022 18:39:19 +0200 Subject: remove api interface from native lib (breaks rift) --- client-native-lib/src/lib.rs | 11 +++-------- client-native-lib/src/peer.rs | 6 +++--- client-native-lib/src/state.rs | 27 ++++++--------------------- 3 files changed, 12 insertions(+), 32 deletions(-) (limited to 'client-native-lib') diff --git a/client-native-lib/src/lib.rs b/client-native-lib/src/lib.rs index d41fc58..70ec2bd 100644 --- a/client-native-lib/src/lib.rs +++ b/client-native-lib/src/lib.rs @@ -8,8 +8,8 @@ use log::debug; use signaling::signaling_connect; -use state::{HasPeer, PeerInit, State}; -use std::{marker::Sync, sync::Arc}; +use state::State; +use std::sync::Arc; use tokio::sync::{mpsc::unbounded_channel, RwLock}; use webrtc::{ api::{ @@ -31,11 +31,7 @@ pub struct Config { pub secret: String, } -pub async fn connect(config: Config, sup: Arc) -> Arc> -where - I: PeerInit

+ Sync + std::marker::Send + 'static, - P: HasPeer + Sync + std::marker::Send + 'static, -{ +pub async fn connect(config: Config) -> Arc { let (sender, mut recv) = signaling_connect(&config.signaling_host, &config.secret).await; let key = crypto::Key::derive(&config.secret); @@ -58,7 +54,6 @@ where sender, config, relay_tx, - sup, }); { diff --git a/client-native-lib/src/peer.rs b/client-native-lib/src/peer.rs index b682bb7..d2a6fbc 100644 --- a/client-native-lib/src/peer.rs +++ b/client-native-lib/src/peer.rs @@ -5,7 +5,7 @@ */ use crate::{ protocol::{self, RelayMessage, Sdp}, - state::{HasPeer, PeerInit, State}, + state::State, }; use log::info; use std::sync::Arc; @@ -25,8 +25,8 @@ pub struct Peer { } impl Peer { - pub async fn create>( - state: Arc>, + pub async fn create( + state: Arc, signal: UnboundedSender<(usize, RelayMessage)>, id: usize, ) -> Arc { diff --git a/client-native-lib/src/state.rs b/client-native-lib/src/state.rs index af4a05b..6182e66 100644 --- a/client-native-lib/src/state.rs +++ b/client-native-lib/src/state.rs @@ -3,9 +3,7 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2022 metamuffin */ -use std::{collections::HashMap, pin::Pin, sync::Arc}; - -use futures_util::Future; +use std::{collections::HashMap, sync::Arc}; use log::warn; use tokio::sync::{mpsc::UnboundedSender, RwLock}; use webrtc::api::API; @@ -17,27 +15,16 @@ use crate::{ Config, }; -pub trait HasPeer { - fn peer(&self) -> &Arc; -} -pub trait PeerInit

{ - fn add_peer( - &self, - p: Arc, - ) -> Pin> + 'static + Send + Sync>>; -} - -pub struct State> { - pub sup: Arc, +pub struct State { pub config: Config, pub api: API, pub key: Key, pub my_id: RwLock>, pub sender: UnboundedSender, - pub peers: RwLock>>, + pub peers: RwLock>>, pub relay_tx: UnboundedSender<(usize, RelayMessage)>, } -impl> State { +impl State { pub async fn my_id(&self) -> usize { self.my_id.read().await.expect("not initialized yet") } @@ -56,9 +43,7 @@ impl> State { } else { self.peers.write().await.insert( id, - self.sup - .add_peer(Peer::create(self.clone(), self.relay_tx.clone(), id).await) - .await, + Peer::create(self.clone(), self.relay_tx.clone(), id).await, ); } } @@ -75,7 +60,7 @@ impl> State { pub async fn on_relay(&self, sender: usize, p: RelayMessage) { if let Some(peer) = self.peers.read().await.get(&sender).cloned() { - peer.peer().on_relay(p).await + peer.on_relay(p).await } else { warn!("got a packet from a non-existent peer") } -- cgit v1.2.3-70-g09d2