Skip to content

Commit

Permalink
rust: crossbeam dependency removed
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto committed Nov 17, 2024
1 parent ad0bf6d commit a672ce4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 1 addition & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
resolver = "2"

[workspace.dependencies]
thiserror = "1.0"
thiserror = "2.0"
anyhow = "1.0"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["std"] }
Expand All @@ -16,8 +16,6 @@ clap = { version = "4.5", default-features = false, features = ["std", "cargo",
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
log = { version = "0.4", default-features = false, features = ["std"] }
env_logger = { version = "0.11", default-features = false, features = ["humantime"]}
crossbeam = "0.8"
crossbeam-channel = "0.5"
rand = { version = "0.8" }
path-absolutize = "3.1"
directories = "5.0"
Expand Down
10 changes: 7 additions & 3 deletions rust/bear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ path-absolutize.workspace = true
shell-words.workspace = true
nom.workspace = true
regex.workspace = true
crossbeam.workspace = true
crossbeam-channel.workspace = true
rand.workspace = true
tempfile.workspace = true
tempfile.workspace = true

[profile.release]
strip = true
lto = true
opt-level = 3
codegen-units = 1
2 changes: 1 addition & 1 deletion rust/bear/src/intercept/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::net::{SocketAddr, TcpListener, TcpStream};

use crossbeam::channel::Sender;
use std::sync::mpsc::Sender;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

Expand Down
8 changes: 4 additions & 4 deletions rust/bear/src/modes/intercept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::intercept::collector::{EventCollector, EventCollectorOnTcp};
use crate::intercept::{Envelope, KEY_DESTINATION, KEY_PRELOAD_PATH};
use crate::{args, config};
use crossbeam_channel::{bounded, Receiver};
use std::sync::mpsc::Receiver;
use std::sync::mpsc::channel;
use std::path::{Path, PathBuf};
use std::process::{Command, ExitCode};
use std::sync::Arc;
Expand Down Expand Up @@ -36,17 +37,16 @@ impl InterceptService {
{
let collector = EventCollectorOnTcp::new()?;
let collector_arc = Arc::new(collector);
let (sender, receiver) = bounded(32);
let (sender, receiver) = channel();

let collector_in_thread = collector_arc.clone();
let collector_thread = thread::spawn(move || {
// TODO: log failures
collector_in_thread.collect(sender).unwrap();
});
let receiver_in_thread = receiver.clone();
let output_thread = thread::spawn(move || {
// TODO: log failures
consumer(receiver_in_thread).unwrap();
consumer(receiver).unwrap();
});

// TODO: log the address of the service
Expand Down
5 changes: 2 additions & 3 deletions rust/bear/src/modes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::intercept::Envelope;
use crate::output::OutputWriter;
use crate::{args, config};
use anyhow::Context;
use crossbeam_channel::Receiver;
use intercept::{InterceptEnvironment, InterceptService};
use recognition::Recognition;
use std::io::BufWriter;
Expand Down Expand Up @@ -61,12 +60,12 @@ impl Intercept {
/// Write the envelopes into the output file.
fn write_to_file(
output_file_name: String,
envelopes: Receiver<Envelope>,
envelopes: impl IntoIterator<Item=Envelope>,
) -> anyhow::Result<()> {
let mut writer = std::fs::File::create(&output_file_name)
.map(BufWriter::new)
.with_context(|| format!("Failed to create output file: {:?}", &output_file_name))?;
for envelope in envelopes.iter() {
for envelope in envelopes {
envelope
.write_into(&mut writer)
.with_context(|| "Failed to write the envelope")?;
Expand Down
4 changes: 2 additions & 2 deletions rust/bear/tests/intercept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bear::intercept::*;

mod test {
use super::*;
use crossbeam_channel::bounded;
use std::sync::mpsc::channel;
use std::collections::HashMap;
use std::io::Cursor;
use std::path::PathBuf;
Expand All @@ -31,7 +31,7 @@ mod test {
let main_collector = thread_collector.clone();

// Start the collector in a separate thread.
let (input, output) = bounded(EVENTS.len());
let (input, output) = channel();
let receiver_thread = thread::spawn(move || {
thread_collector.collect(input).unwrap();
});
Expand Down

0 comments on commit a672ce4

Please sign in to comment.