mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-08 20:09:54 +00:00
Update the processor for the previous commit
This commit is contained in:
parent
6cc8ce840e
commit
a1599df126
2 changed files with 8 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::{marker::Send, collections::HashMap};
|
use std::{marker::Send, io::Cursor, collections::HashMap};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -17,7 +17,7 @@ pub enum NetworkError {}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Network: Send {
|
pub trait Network: Send {
|
||||||
async fn round(&mut self, data: Vec<u8>) -> Result<HashMap<u16, Vec<u8>>, NetworkError>;
|
async fn round(&mut self, data: Vec<u8>) -> Result<HashMap<u16, Cursor<Vec<u8>>>, NetworkError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Error, Debug)]
|
#[derive(Clone, Error, Debug)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{sync::{Arc, RwLock}, collections::HashMap};
|
use std::{io::Cursor, sync::{Arc, RwLock}, collections::HashMap};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ struct LocalNetwork {
|
||||||
i: u16,
|
i: u16,
|
||||||
size: u16,
|
size: u16,
|
||||||
round: usize,
|
round: usize,
|
||||||
rounds: Arc<RwLock<Vec<HashMap<u16, Vec<u8>>>>>
|
rounds: Arc<RwLock<Vec<HashMap<u16, Cursor<Vec<u8>>>>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalNetwork {
|
impl LocalNetwork {
|
||||||
|
@ -27,13 +27,13 @@ impl LocalNetwork {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Network for LocalNetwork {
|
impl Network for LocalNetwork {
|
||||||
async fn round(&mut self, data: Vec<u8>) -> Result<HashMap<u16, Vec<u8>>, NetworkError> {
|
async fn round(&mut self, data: Vec<u8>) -> Result<HashMap<u16, Cursor<Vec<u8>>>, NetworkError> {
|
||||||
{
|
{
|
||||||
let mut rounds = self.rounds.write().unwrap();
|
let mut rounds = self.rounds.write().unwrap();
|
||||||
if rounds.len() == self.round {
|
if rounds.len() == self.round {
|
||||||
rounds.push(HashMap::new());
|
rounds.push(HashMap::new());
|
||||||
}
|
}
|
||||||
rounds[self.round].insert(self.i, data);
|
rounds[self.round].insert(self.i, Cursor::new(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
while {
|
while {
|
||||||
|
@ -43,7 +43,8 @@ impl Network for LocalNetwork {
|
||||||
tokio::task::yield_now().await;
|
tokio::task::yield_now().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = self.rounds.try_read().unwrap()[self.round].clone();
|
let mut res = self.rounds.try_read().unwrap()[self.round].clone();
|
||||||
|
res.remove(&self.i);
|
||||||
self.round += 1;
|
self.round += 1;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue