Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Aug 24, 2023
1 parent 2af4534 commit a1ac3c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 46 deletions.
8 changes: 1 addition & 7 deletions src/endpoint/locality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ impl LocalitySet {
Entry::Occupied(entry) => {
let (key, original_locality) = entry.remove_entry();
let mut value = value.clone();
let new_set_addresses = value
.endpoints
.iter()
.map(|endpoint| endpoint.address.clone())
.collect::<BTreeSet<_>>();

if tracing::enabled!(tracing::Level::INFO) {
for endpoint in value.endpoints.iter() {
Expand All @@ -326,8 +321,7 @@ impl LocalitySet {
.endpoints
.into_iter()
.partition(|endpoint| {
!new_set_addresses.contains(&endpoint.address)
&& endpoint.sessions.load(std::sync::atomic::Ordering::SeqCst) != 0
endpoint.sessions.load(std::sync::atomic::Ordering::SeqCst) != 0
});

if tracing::enabled!(tracing::Level::INFO) {
Expand Down
14 changes: 1 addition & 13 deletions src/maxmind_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,7 @@ impl MaxmindDb {
};

match mmdb.lookup::<IpNetEntry>(ip) {
Ok(asn) => {
tracing::info!(
number = asn.r#as,
organization = asn.as_name,
country_code = asn.as_cc,
prefix = asn.prefix,
prefix_entity = asn.prefix_entity,
prefix_name = asn.prefix_name,
"maxmind information"
);

Some(asn)
}
Ok(asn) => Some(asn),
Err(error) => {
tracing::warn!(%ip, %error, "ip not found in maxmind database");
None
Expand Down
50 changes: 24 additions & 26 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,31 @@ impl DownstreamReceiveWorkerConfig {
"Awaiting packet"
);

tokio::select! {
result = socket.recv_from(&mut buf) => {
match result {
Ok((size, source)) => {
let packet = DownstreamPacket {
received_at: chrono::Utc::now().timestamp_nanos(),
asn_info: crate::maxmind_db::MaxmindDb::lookup(source.ip()),
contents: buf[..size].to_vec(),
source,
};

if let Some(last_received_at) = last_received_at {
crate::metrics::packet_jitter(
crate::metrics::READ,
packet.asn_info.as_ref(),
)
.set(packet.received_at - last_received_at);
}
last_received_at = Some(packet.received_at);

Self::spawn_process_task(packet, source, worker_id, &socket, &config, &sessions)
}
Err(error) => {
tracing::error!(%error, "error receiving packet");
return;
}
match socket.recv_from(&mut buf).await {
Ok((size, source)) => {
let packet = DownstreamPacket {
received_at: chrono::Utc::now().timestamp_nanos(),
asn_info: crate::maxmind_db::MaxmindDb::lookup(source.ip()),
contents: buf[..size].to_vec(),
source,
};

if let Some(last_received_at) = last_received_at {
crate::metrics::packet_jitter(
crate::metrics::READ,
packet.asn_info.as_ref(),
)
.set(packet.received_at - last_received_at);
}
last_received_at = Some(packet.received_at);

Self::spawn_process_task(
packet, source, worker_id, &socket, &config, &sessions,
)
}
Err(error) => {
tracing::error!(%error, "error receiving packet");
return;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/proxy/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ impl Session {
};

tracing::debug!(source = %s.source, dest = ?s.dest, "Session created");
if let Some(asn) = &s.asn_info {
tracing::info!(
number = asn.r#as,
organization = asn.as_name,
country_code = asn.as_cc,
prefix = asn.prefix,
prefix_entity = asn.prefix_entity,
prefix_name = asn.prefix_name,
"maxmind information"
);
}

self::metrics::total_sessions().inc();
s.active_session_metric().inc();
Expand Down

0 comments on commit a1ac3c5

Please sign in to comment.