bless
This commit is contained in:
parent
c9925e02d1
commit
79bc2958ef
@ -8,7 +8,6 @@ pub mod node {
|
|||||||
pub mod blockchain;
|
pub mod blockchain;
|
||||||
pub use blockchain::*;
|
pub use blockchain::*;
|
||||||
|
|
||||||
pub mod ws_server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
@ -65,7 +64,7 @@ pub mod watcher {
|
|||||||
pub use command::*;
|
pub use command::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod protocol {
|
pub mod network {
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub use message::*;
|
pub use message::*;
|
||||||
|
|
||||||
@ -74,6 +73,8 @@ pub mod protocol {
|
|||||||
|
|
||||||
pub mod connector;
|
pub mod connector;
|
||||||
pub use connector::*;
|
pub use connector::*;
|
||||||
|
|
||||||
|
pub mod ws_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod seeds_constants;
|
pub mod seeds_constants;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use crate::executor::ExecutorCommand;
|
use crate::executor::ExecutorCommand;
|
||||||
use crate::log;
|
use crate::log;
|
||||||
use crate::node::node;
|
use crate::node::node;
|
||||||
use crate::protocol::ProtocolMessage;
|
use super::ProtocolMessage;
|
||||||
use tokio::net;
|
use tokio::net;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ use crate::bus::*;
|
|||||||
use crate::executor::ExecutorCommand;
|
use crate::executor::ExecutorCommand;
|
||||||
use crate::node::node;
|
use crate::node::node;
|
||||||
use crate::node::{NetworkError, error};
|
use crate::node::{NetworkError, error};
|
||||||
use crate::protocol::ProtocolMessage;
|
use super::ProtocolMessage;
|
||||||
|
|
||||||
pub enum ConnectorCommand {
|
pub enum ConnectorCommand {
|
||||||
ConnectToTcpPeer(SocketAddr),
|
ConnectToTcpPeer(SocketAddr),
|
||||||
@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
use tokio::sync::mpsc::{self, Receiver, Sender};
|
use tokio::sync::mpsc::{self, Receiver, Sender};
|
||||||
@ -116,19 +117,24 @@ impl WsServer {
|
|||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
con_res = listener.accept() => {
|
con_res = listener.accept() => {
|
||||||
match con_res {
|
match con_res {
|
||||||
Ok((stream, addr)) => {
|
Ok((mut stream, addr)) => {
|
||||||
log(msg!(DEBUG, "Received Connection Attempt from {}", addr));
|
log(msg!(DEBUG, "Received Connection Attempt from {}", addr));
|
||||||
let (tx, rx) = mpsc::channel::<WsClientResponse>(100);
|
if self.clients.len() < 5 {
|
||||||
self.clients.insert(addr, tx);
|
let (tx, rx) = mpsc::channel::<WsClientResponse>(100);
|
||||||
let tx = self.tx.clone();
|
self.clients.insert(addr, tx);
|
||||||
let task_handle = tokio::spawn(async move {
|
let tx = self.tx.clone();
|
||||||
if let Err(e) = ws_connection(stream, rx, tx).await {
|
let task_handle = tokio::spawn(async move {
|
||||||
log(msg!(ERROR, "{e}"));
|
if let Err(e) = ws_connection(stream, rx, tx).await {
|
||||||
}
|
log(msg!(ERROR, "{e}"));
|
||||||
});
|
}
|
||||||
tasks.push(task_handle);
|
});
|
||||||
|
tasks.push(task_handle);
|
||||||
|
} else {
|
||||||
|
stream.shutdown().await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log(msg!(ERROR, "{e}"));
|
log(msg!(ERROR, "{e}"));
|
||||||
@ -3,11 +3,11 @@ use shared::core::{self, ChainData};
|
|||||||
use shared::print_error_chain;
|
use shared::print_error_chain;
|
||||||
use crate::executor::ExecutorCommand;
|
use crate::executor::ExecutorCommand;
|
||||||
use crate::log;
|
use crate::log;
|
||||||
use crate::protocol::ProtocolMessage;
|
use crate::network::ProtocolMessage;
|
||||||
use crate::protocol::{Connector, ConnectorCommand};
|
use crate::network::{Connector, ConnectorCommand};
|
||||||
use crate::seeds_constants::SEED_NODES;
|
use crate::seeds_constants::SEED_NODES;
|
||||||
use crate::watcher::{WatcherCommand, WatcherMode};
|
use crate::watcher::{WatcherCommand, WatcherMode};
|
||||||
use super::ws_server::{WsCommand, WsServer};
|
use crate::network::ws_server::{WsCommand, WsServer};
|
||||||
use super::{ Blockchain, BlockchainError, ValidationError };
|
use super::{ Blockchain, BlockchainError, ValidationError };
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user