Skip to content

Commit 66e9f6e

Browse files
committed
Move provide_requested_content into spawned task
1 parent 37f1bd7 commit 66e9f6e

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- cargo-{{ checksum "Cargo.lock" }}-v1
6868
- run:
6969
name: Install rustup
70-
command: choco install rustup.install
70+
command: choco install rustup.install --ignore-checksums
7171
- run:
7272
name: Install clang
7373
command: choco install llvm

trin-core/src/portalnet/overlay_service.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -1224,17 +1224,35 @@ where
12241224
self.utp_listener_tx
12251225
.send(utp_request).map_err(|err| anyhow!("Unable to send Connect request to UtpListener when processing ACCEPT message: {err}"))?;
12261226

1227-
let content_items = self.provide_requested_content(&response, content_keys_offered)?;
1228-
1229-
let content_payload = ContentPayloadList::new(content_items)
1230-
.map_err(|err| anyhow!("Unable to build content payload: {err:?}"))?;
1227+
let storage = Arc::clone(&self.storage);
1228+
let response_clone = response.clone();
12311229

12321230
tokio::spawn(async move {
12331231
let mut conn = rx.await.unwrap();
12341232
// Handle STATE packet for SYN
12351233
let mut buf = [0; BUF_SIZE];
12361234
conn.recv(&mut buf).await.unwrap();
12371235

1236+
let content_items = match Self::provide_requested_content(
1237+
storage,
1238+
&response_clone,
1239+
content_keys_offered,
1240+
) {
1241+
Ok(val) => val,
1242+
Err(msg) => {
1243+
warn!("Unable to provide requested content for acceptor: {msg:?}");
1244+
return;
1245+
}
1246+
};
1247+
1248+
let content_payload = match ContentPayloadList::new(content_items) {
1249+
Ok(val) => val,
1250+
Err(msg) => {
1251+
warn!("Unable to build content payload: {msg:?}");
1252+
return;
1253+
}
1254+
};
1255+
12381256
// send the content to the acceptor over a uTP stream
12391257
if let Err(err) = conn.send_to(&content_payload.as_ssz_bytes()).await {
12401258
warn!("Error sending content {err}");
@@ -1456,7 +1474,7 @@ where
14561474

14571475
/// Provide the requested content key and content value for the acceptor
14581476
fn provide_requested_content(
1459-
&self,
1477+
storage: Arc<RwLock<PortalStorage>>,
14601478
accept_message: &Accept,
14611479
content_keys_offered: Vec<TContentKey>,
14621480
) -> anyhow::Result<Vec<ByteList>> {
@@ -1469,7 +1487,7 @@ where
14691487
.zip(content_keys_offered.iter())
14701488
{
14711489
if i == true {
1472-
match self.storage.read().get(key) {
1490+
match storage.read().get(key) {
14731491
Ok(content) => match content {
14741492
Some(content) => content_items.push(content.into()),
14751493
None => return Err(anyhow!("Unable to read offered content!")),

0 commit comments

Comments
 (0)