Skip to content

Commit f303b9a

Browse files
committed
Add RawContentKey type
1 parent 8debf1f commit f303b9a

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

trin-core/src/jsonrpc/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use validator::{Validate, ValidationError};
1010
use crate::{
1111
jsonrpc::endpoints::{HistoryEndpoint, StateEndpoint, TrinEndpoint},
1212
portalnet::types::{
13-
content_key::OverlayContentKey,
13+
content_key::{OverlayContentKey, RawContentKey},
1414
messages::{ByteList, CustomPayload, SszEnr},
1515
},
1616
};
@@ -274,7 +274,7 @@ impl TryFrom<[&Value; 2]> for OfferParams {
274274
.collect();
275275

276276
if let Ok(content_keys) = content_keys {
277-
let content_keys: Result<Vec<Vec<u8>>, _> =
277+
let content_keys: Result<Vec<RawContentKey>, _> =
278278
content_keys.iter().map(hex::decode).collect();
279279

280280
if let Ok(content_keys) = content_keys {

trin-core/src/portalnet/overlay.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ use crate::portalnet::{
1515
},
1616
};
1717

18-
use crate::utp::{
19-
stream::{UtpListenerRequest, UtpSocket, BUF_SIZE},
20-
trin_helpers::{UtpAccept, UtpMessage},
18+
use crate::{
19+
portalnet::types::content_key::RawContentKey,
20+
utp::{
21+
stream::{UtpListenerRequest, UtpSocket, BUF_SIZE},
22+
trin_helpers::{UtpAccept, UtpMessage},
23+
},
2124
};
2225
use discv5::{
2326
enr::NodeId,
@@ -331,7 +334,7 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
331334
/// Offer is also sent to nodes after FindContent (POKE)
332335
pub async fn send_offer(
333336
&self,
334-
content_keys: Vec<Vec<u8>>,
337+
content_keys: Vec<RawContentKey>,
335338
enr: Enr,
336339
) -> Result<Accept, OverlayRequestError> {
337340
// Construct the request.

trin-core/src/portalnet/overlay_service.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use crate::{
1919
utp::stream::UtpListenerRequest,
2020
};
2121

22-
use crate::utp::{stream::UtpPayload, trin_helpers::UtpStreamId};
22+
use crate::{
23+
portalnet::types::content_key::RawContentKey,
24+
utp::{stream::UtpPayload, trin_helpers::UtpStreamId},
25+
};
2326
use delay_map::HashSetDelay;
2427
use discv5::{
2528
enr::NodeId,
@@ -776,7 +779,7 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
776779
}
777780

778781
/// Process accepted uTP payload of the OFFER?ACCEPT stream
779-
fn process_accept_utp_payload(&self, content_keys: Vec<Vec<u8>>, payload: UtpPayload) {
782+
fn process_accept_utp_payload(&self, content_keys: Vec<RawContentKey>, payload: UtpPayload) {
780783
// TODO: Verify the payload, store the content and propagate gossip.
781784
debug!("DEBUG: Processing content keys: {content_keys:?}, with payload: {payload:?}");
782785
}

trin-core/src/portalnet/types/content_key.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use ssz::{self, Decode, Encode};
66
use ssz_derive::{Decode, Encode};
77
use ssz_types::{typenum, FixedVector, VariableList};
88

9+
/// SSZ encoded overlay content key as bytes
10+
pub type RawContentKey = Vec<u8>;
11+
912
/// Types whose values represent keys to lookup content items in an overlay network.
1013
/// Keys are serializable.
1114
pub trait OverlayContentKey: Into<Vec<u8>> + TryFrom<Vec<u8>> + Clone {

trin-core/src/portalnet/types/messages.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ssz_types::{typenum, BitList, VariableList};
1717
use thiserror::Error;
1818
use validator::ValidationError;
1919

20-
use crate::portalnet::Enr;
20+
use crate::portalnet::{types::content_key::RawContentKey, Enr};
2121

2222
pub type ByteList = VariableList<u8, typenum::U2048>;
2323

@@ -492,7 +492,7 @@ impl TryInto<Value> for Content {
492492

493493
#[derive(Debug, PartialEq, Clone, Encode, Decode)]
494494
pub struct Offer {
495-
pub content_keys: Vec<Vec<u8>>,
495+
pub content_keys: Vec<RawContentKey>,
496496
}
497497

498498
#[derive(Debug, PartialEq, Clone, Encode, Decode)]

trin-core/src/utp/stream.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use tokio::{
2121

2222
use crate::{
2323
locks::RwLoggingExt,
24-
portalnet::types::messages::{ByteList, Content::Content, ProtocolId},
24+
portalnet::types::{
25+
content_key::RawContentKey,
26+
messages::{ByteList, Content::Content, ProtocolId},
27+
},
2528
utp::{
2629
packets::{ExtensionType, Packet, PacketType, HEADER_SIZE},
2730
time::{now_microseconds, Delay, Timestamp},
@@ -107,7 +110,7 @@ struct DelayDifferenceSample {
107110
/// and uTP listener
108111
pub enum UtpListenerRequest {
109112
/// Request to listen for Accept stream
110-
AcceptStream(ConnId, Vec<Vec<u8>>),
113+
AcceptStream(ConnId, Vec<RawContentKey>),
111114
/// Request to initialize uTP streram with remote node
112115
Connect(ConnId, NodeId, oneshot::Sender<anyhow::Result<UtpSocket>>),
113116
/// Request to listen for FindCOntent stream and send content data

trin-core/src/utp/trin_helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(dead_code)]
22
// These are just some Trin helper functions
33

4-
use crate::portalnet::types::messages::Content;
4+
use crate::portalnet::types::{content_key::RawContentKey, messages::Content};
55
use ssz_derive::{Decode, Encode};
66

77
// These Utp impl are related to sending messages over uTP not the implementation itself or stream
@@ -57,7 +57,7 @@ pub enum UtpStreamId {
5757
FindContentStream,
5858
FindContentData(Content),
5959
OfferStream,
60-
AcceptStream(Vec<Vec<u8>>),
60+
AcceptStream(Vec<RawContentKey>),
6161
}
6262

6363
#[cfg(test)]

0 commit comments

Comments
 (0)