Skip to content

Commit

Permalink
updated stream connection
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKitsune committed Feb 1, 2024
1 parent 87cdafc commit 075bcc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions bin/mpc_participant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::net::{SocketAddr, SocketAddrV4};
use std::path::PathBuf;

use clap::Parser;
use mpc::participant::Participant;
use telemetry_batteries::metrics::batteries::StatsdBattery;
use telemetry_batteries::tracing::batteries::DatadogBattery;
use tracing_subscriber::layer::SubscriberExt;
Expand Down Expand Up @@ -59,5 +61,11 @@ async fn main() -> eyre::Result<()> {
.add_source(config::Environment::with_prefix("MPC").separator("__"))
.build()?;

let participant =
Participant::new("127.0.0.1:8080".parse::<SocketAddr>()?, 20_000)
.await?;

participant.spawn().await?;

Ok(())
}
16 changes: 10 additions & 6 deletions src/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ use crate::distance::{self, DistanceEngine, EncodedBits};

pub struct Participant {
listener: tokio::net::TcpListener,
batch_size: usize,
}

impl Participant {
pub async fn new(socket_address: SocketAddr) -> eyre::Result<Self> {
pub async fn new(
socket_address: SocketAddr,
batch_size: usize,
) -> eyre::Result<Self> {
Ok(Self {
listener: tokio::net::TcpListener::bind(socket_address).await?,
batch_size,
})
}

pub async fn spawn(&self) -> eyre::Result<()> {
let (stream, _) = self.listener.accept().await?;
let mut stream = tokio::io::BufWriter::new(stream);

let mut stream =
tokio::io::BufWriter::new(self.listener.accept().await?.0);
let shares = Arc::new(self.initialize_shares().await?);
let batch_size = self.batch_size;

loop {
// TODO: Sync from database
Expand All @@ -39,8 +44,7 @@ impl Participant {
bytemuck::cast_slice(&shares_ref);
let engine = DistanceEngine::new(&distance::encode(&template));

//TODO: make batch size configurable
for chunk in patterns.chunks(20_000) {
for chunk in patterns.chunks(batch_size) {
let mut result = vec![
0_u8;
chunk.len()
Expand Down

0 comments on commit 075bcc3

Please sign in to comment.