mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
Notable changes: * Rewritten transport protocols into Dialer and Listener (Nym is TODO) This simplifies using the transports a lot, as can be seen for example in src/rpc, and generally around the p2p library. It also defines features for each transport (all of which are enabled by default). We drop the socks client for Tor and Nym and use first-class support with the Arti Tor library, and nym-sphinx/nym-websockets (to be used with nym-client). * Outbound session healing The outbound session will now poll and try to fill all the requested slots more efficiently, and if needed, will activate peer discovery to find more peers if we can't connect to any known ones. Also if we're unable to connect to any, we shall drop them from our set. Additionally, transport mixing is enabled by default, so when we're allowing transport mixing, and we use Tor, we will also be able to connect to other transports that Tor can connect to (e.g. tcp://). * Unix socket transport dropped We haven't been using this, and it seems we're not going down this path, so the code has been obsoleted and removed. * TLS session verification We fully verify server and client TLS certificates upon connection so we're able to perform TLS1.3 with forward secrecy. * lilith pruning lilith now periodically prunes known peers from its sets if it's unable to connect to them.
67 lines
2.1 KiB
Rust
67 lines
2.1 KiB
Rust
/* This file is part of DarkFi (https://dark.fi)
|
|
*
|
|
* Copyright (C) 2020-2023 Dyne.org foundation
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
use async_std::sync::Arc;
|
|
|
|
use futures::{Future, FutureExt};
|
|
use smol::Executor;
|
|
|
|
pub type StoppableTaskPtr = Arc<StoppableTask>;
|
|
|
|
#[derive(Debug)]
|
|
pub struct StoppableTask {
|
|
stop_send: smol::channel::Sender<()>,
|
|
stop_recv: smol::channel::Receiver<()>,
|
|
}
|
|
|
|
impl StoppableTask {
|
|
pub fn new() -> Arc<Self> {
|
|
let (stop_send, stop_recv) = smol::channel::unbounded();
|
|
Arc::new(Self { stop_send, stop_recv })
|
|
}
|
|
|
|
pub async fn stop(&self) {
|
|
// Ignore any errors from this send
|
|
let _ = self.stop_send.send(()).await;
|
|
}
|
|
|
|
pub fn start<'a, MainFut, StopFut, StopFn, Error>(
|
|
self: Arc<Self>,
|
|
main: MainFut,
|
|
stop_handler: StopFn,
|
|
stop_value: Error,
|
|
executor: Arc<Executor<'a>>,
|
|
) where
|
|
MainFut: Future<Output = std::result::Result<(), Error>> + Send + 'a,
|
|
StopFut: Future<Output = ()> + Send,
|
|
StopFn: FnOnce(std::result::Result<(), Error>) -> StopFut + Send + 'a,
|
|
Error: std::error::Error + Send + 'a,
|
|
{
|
|
executor
|
|
.spawn(async move {
|
|
let result = futures::select! {
|
|
_ = self.stop_recv.recv().fuse() => Err(stop_value),
|
|
result = main.fuse() => result
|
|
};
|
|
|
|
stop_handler(result).await;
|
|
})
|
|
.detach();
|
|
}
|
|
}
|