Skip to content
Snippets Groups Projects
Commit 340a0b20 authored by j.detchart's avatar j.detchart
Browse files

refactor server part

parent 55e8dfc2
No related tags found
No related merge requests found
......@@ -22,14 +22,14 @@ use std::str::FromStr;
use std::time::Duration;
use tracing::{debug, error, info, warn};
use crate::commands::DragoonCommand;
use crate::server::commands::DragoonCommand;
use crate::error::DragoonError::{
BadListener, BootstrapError, DialError, PeerNotFound, ProviderError,
};
use crate::dragoon::behaviour::Behaviour;
use crate::dragoon::DragoonEvent;
use crate::p2p::behaviour::Behaviour;
use crate::p2p::DragoonEvent;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileRequest(String);
......@@ -63,7 +63,7 @@ pub(crate) async fn create_swarm(
)],
request_response::Config::default(),
),
dragoon: Behaviour::new("/dragoon/1.0.0".to_string()),
dragoon: Behaviour::new("/p2p/1.0.0".to_string()),
})?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60 * 60)))
.build();
......
mod app;
mod commands;
mod dragoon;
mod p2p;
mod dragoon_network;
mod error;
mod server;
use axum::routing::get;
use axum::Router;
......@@ -16,6 +16,7 @@ use tokio::signal;
use tracing::info;
use crate::dragoon_network::DragoonNetwork;
use crate::server::{app, commands};
#[tokio::main]
pub(crate) async fn main() -> Result<(), Box<dyn Error>> {
......@@ -39,9 +40,9 @@ pub(crate) async fn main() -> Result<(), Box<dyn Error>> {
.route("/bootstrap", get(commands::bootstrap))
.route("/put-record/:key/:value", get(commands::put_record))
.route("/get-record/:key", get(commands::get_record))
.route("/dragoon/peers", get(commands::dragoon_peers))
.route("/dragoon/send/:peer/:data", get(commands::dragoon_send))
.route("/dragoon/get/:peer/:key", get(commands::dragoon_get));
.route("/p2p/peers", get(commands::dragoon_peers))
.route("/p2p/send/:peer/:data", get(commands::dragoon_send))
.route("/p2p/get/:peer/:key", get(commands::dragoon_get));
#[cfg(feature = "file-sharing")]
let router = router
.route("/get-file/:key", get(commands::get_file))
......
use crate::dragoon::{DragoonEvent, InEvent};
use crate::p2p::{DragoonEvent, InEvent};
use libp2p::core::Endpoint;
use libp2p::swarm::behaviour::ConnectionEstablished;
......@@ -12,7 +12,7 @@ use libp2p::{Multiaddr, PeerId};
use std::collections::{HashMap, HashSet, VecDeque};
use std::task::{Context, Poll};
use crate::dragoon::handler::Handler;
use crate::p2p::handler::Handler;
pub struct Behaviour {
connected_peers: HashSet<PeerId>,
......
......@@ -9,8 +9,8 @@ use std::collections::VecDeque;
use std::task::{Context, Poll};
use std::time::Duration;
use futures::ready;
use crate::dragoon::{DragoonEvent, InEvent};
use crate::dragoon::protocol::{dragoon_receive_data, dragoon_send, DragoonRecvFuture, DragoonSendFuture};
use crate::p2p::{DragoonEvent, InEvent};
use crate::p2p::protocol::{dragoon_receive_data, dragoon_send, DragoonRecvFuture, DragoonSendFuture};
pub struct Handler {
remote_peer_id: PeerId,
......@@ -69,7 +69,7 @@ impl ConnectionHandler for Handler {
type OutboundOpenInfo = ();
fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo> {
SubstreamProtocol::new(ReadyUpgrade::new(StreamProtocol::new("/dragoon/1.0.0")), ())
SubstreamProtocol::new(ReadyUpgrade::new(StreamProtocol::new("/p2p/1.0.0")), ())
}
#[tracing::instrument(level = "trace", name = "ConnectionHandler::poll", skip(self, cx))]
......@@ -141,7 +141,7 @@ impl ConnectionHandler for Handler {
self.events
.push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
protocol: SubstreamProtocol::new(
ReadyUpgrade::new(StreamProtocol::new("/dragoon/1.0.0")),
ReadyUpgrade::new(StreamProtocol::new("/p2p/1.0.0")),
(),
),
});
......@@ -170,7 +170,7 @@ impl ConnectionHandler for Handler {
// self.events
// .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest {
// protocol: SubstreamProtocol::new(
// ReadyUpgrade::new(StreamProtocol::new("/dragoon/1.0.0")),
// ReadyUpgrade::new(StreamProtocol::new("/p2p/1.0.0")),
// (),
// ),
// });
......
File moved
......@@ -5,7 +5,7 @@ use futures_timer::Delay;
use libp2p::Stream;
use std::time::{Duration, Instant};
use std::io;
use crate::dragoon::{Failure, Shard};
use crate::p2p::{Failure, Shard};
pub(crate) type DragoonSendFuture = BoxFuture<'static, Result<(Stream, Duration), Failure>>;
......
......@@ -3,7 +3,7 @@ use futures::channel::mpsc::Receiver;
use futures::channel::mpsc::Sender;
use tokio::sync::Mutex;
use crate::commands::DragoonCommand;
use crate::server::commands::DragoonCommand;
#[cfg(feature = "file-sharing")]
use crate::dragoon_network::DragoonEvent;
......
......@@ -17,7 +17,7 @@ use std::sync::Arc;
use tracing::debug;
use tracing::{error, info};
use crate::app::AppState;
use crate::server::app::AppState;
#[cfg(feature = "file-sharing")]
use crate::dragoon_network::{DragoonEvent, FileResponse};
use crate::error::DragoonError;
......@@ -132,9 +132,9 @@ impl std::fmt::Display for DragoonCommand {
DragoonCommand::AddFile { .. } => write!(f, "add-file"),
DragoonCommand::PutRecord { .. } => write!(f, "put-record"),
DragoonCommand::GetRecord { .. } => write!(f, "get-record"),
DragoonCommand::DragoonPeers { .. } => write!(f, "dragoon-peers"),
DragoonCommand::DragoonSend { .. } => write!(f, "dragoon-send"),
DragoonCommand::DragoonGet { .. } => write!(f, "dragoon-get"),
DragoonCommand::DragoonPeers { .. } => write!(f, "p2p-peers"),
DragoonCommand::DragoonSend { .. } => write!(f, "p2p-send"),
DragoonCommand::DragoonGet { .. } => write!(f, "p2p-get"),
}
}
}
......
pub mod app;
pub mod commands;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment