@@ -19,13 +19,7 @@ use crate::{
19
19
utp:: stream:: UtpListenerRequest ,
20
20
} ;
21
21
22
- use crate :: {
23
- portalnet:: types:: content_key:: RawContentKey ,
24
- utp:: {
25
- stream:: { UtpListenerEvent , UtpPayload } ,
26
- trin_helpers:: UtpStreamId ,
27
- } ,
28
- } ;
22
+ use crate :: utp:: trin_helpers:: UtpStreamId ;
29
23
use delay_map:: HashSetDelay ;
30
24
use discv5:: {
31
25
enr:: NodeId ,
@@ -43,10 +37,7 @@ use rand::seq::SliceRandom;
43
37
use ssz:: Encode ;
44
38
use ssz_types:: { BitList , VariableList } ;
45
39
use thiserror:: Error ;
46
- use tokio:: sync:: {
47
- mpsc:: { self , UnboundedReceiver , UnboundedSender } ,
48
- RwLock as TRwLock ,
49
- } ;
40
+ use tokio:: sync:: mpsc:: { self , UnboundedReceiver , UnboundedSender } ;
50
41
51
42
/// Maximum number of ENRs in response to FindNodes.
52
43
pub const FIND_NODES_MAX_NODES : usize = 32 ;
@@ -265,8 +256,6 @@ pub struct OverlayService<TContentKey, TMetric> {
265
256
response_tx : UnboundedSender < OverlayResponse > ,
266
257
/// The sender half of a channel to send requests to uTP listener
267
258
utp_listener_tx : UnboundedSender < UtpListenerRequest > ,
268
- /// Receiver for UtpListener emitted events
269
- utp_listener_rx : Arc < TRwLock < UnboundedReceiver < UtpListenerEvent > > > ,
270
259
/// Phantom content key.
271
260
phantom_content_key : PhantomData < TContentKey > ,
272
261
/// Phantom metric (distance function).
@@ -292,7 +281,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
292
281
data_radius : Arc < U256 > ,
293
282
protocol : ProtocolId ,
294
283
utp_listener_sender : UnboundedSender < UtpListenerRequest > ,
295
- utp_listener_receiver : Arc < TRwLock < UnboundedReceiver < UtpListenerEvent > > > ,
296
284
enable_metrics : bool ,
297
285
) -> Result < UnboundedSender < OverlayRequest > , String > {
298
286
let ( request_tx, request_rx) = mpsc:: unbounded_channel ( ) ;
@@ -325,7 +313,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
325
313
response_rx,
326
314
response_tx,
327
315
utp_listener_tx : utp_listener_sender,
328
- utp_listener_rx : utp_listener_receiver,
329
316
phantom_content_key : PhantomData ,
330
317
phantom_metric : PhantomData ,
331
318
metrics,
@@ -397,9 +384,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
397
384
tokio:: time:: interval ( Duration :: from_secs ( BUCKET_REFRESH_INTERVAL ) ) ;
398
385
399
386
loop {
400
- // let utp_listener_rx = self.utp_listener_rx.clone();
401
- // let mut utp_listener_lock = utp_listener_rx.write_with_warn().await;
402
-
403
387
tokio:: select! {
404
388
Some ( request) = self . request_rx. recv( ) => self . process_request( request) ,
405
389
Some ( response) = self . response_rx. recv( ) => {
@@ -428,14 +412,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
428
412
self . peers_to_ping. insert( node_id) ;
429
413
}
430
414
}
431
- // Some(utp_event) = utp_listener_lock.recv() => {
432
- // match utp_event {
433
- // UtpListenerEvent::ProcessedClosedStreams(processed_streams) =>
434
- // {
435
- // self.handle_utp_payload(processed_streams);
436
- // }
437
- // }
438
- // }
439
415
_ = OverlayService :: <TContentKey , TMetric >:: bucket_maintenance_poll( self . protocol. clone( ) , & self . kbuckets) => { }
440
416
_ = bucket_refresh_interval. tick( ) => {
441
417
debug!( "[{:?}] Overlay bucket refresh lookup" , self . protocol) ;
@@ -666,26 +642,11 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
666
642
} else {
667
643
let conn_id: u16 = crate :: utp:: stream:: rand ( ) ;
668
644
669
- // listen for incoming connection request on conn_id, as part of utp handshake and
670
- // temporarily storing content data, so we can send it right after we receive
645
+ // Listen for incoming uTP connection request on as part of uTP handshake and
646
+ // storing content data, so we can send it inside UtpListener right after we receive
671
647
// SYN packet from the requester
672
- let utp_request = UtpListenerRequest :: FindContentData ( conn_id, content. clone ( ) ) ;
673
- if let Err ( err) = self . utp_listener_tx . send ( utp_request) {
674
- return Err ( OverlayRequestError :: UtpError ( format ! (
675
- "Unable to send uTP FindContentData stream request: {err}"
676
- ) ) ) ;
677
- }
678
-
679
- // also listen on conn_id + 1 because this is the receive path
680
648
let conn_id_recv = conn_id. wrapping_add ( 1 ) ;
681
649
682
- let utp_request = UtpListenerRequest :: FindContentStream ( conn_id_recv) ;
683
- if let Err ( err) = self . utp_listener_tx . send ( utp_request) {
684
- return Err ( OverlayRequestError :: UtpError ( format ! (
685
- "Unable to send uTP FindContent stream request: {err}"
686
- ) ) ) ;
687
- }
688
-
689
650
self . add_utp_connection (
690
651
source,
691
652
conn_id_recv,
@@ -704,8 +665,7 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
704
665
}
705
666
}
706
667
Err ( msg) => Err ( OverlayRequestError :: Failure ( format ! (
707
- "Unable to respond to FindContent: {}" ,
708
- msg
668
+ "Unable to respond to FindContent: {msg}" ,
709
669
) ) ) ,
710
670
}
711
671
}
@@ -748,24 +708,8 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
748
708
} ) ?;
749
709
}
750
710
751
- // listen for incoming connection request on conn_id, as part of utp handshake
711
+ // Listen for incoming connection request on conn_id, as part of utp handshake
752
712
let conn_id: u16 = crate :: utp:: stream:: rand ( ) ;
753
- let utp_request = UtpListenerRequest :: OfferStream ( conn_id) ;
754
- if let Err ( err) = self . utp_listener_tx . send ( utp_request) {
755
- return Err ( OverlayRequestError :: UtpError ( format ! (
756
- "Unable to send uTP Offer stream request: {err}"
757
- ) ) ) ;
758
- }
759
-
760
- // also listen on conn_id + 1 because this is the actual receive path for acceptor
761
- let conn_id_recv = conn_id. wrapping_add ( 1 ) ;
762
-
763
- let utp_request = UtpListenerRequest :: AcceptStream ( conn_id_recv, accept_keys. clone ( ) ) ;
764
- if let Err ( err) = self . utp_listener_tx . send ( utp_request) {
765
- return Err ( OverlayRequestError :: UtpError ( format ! (
766
- "Unable to send uTP Accept stream request: {err}"
767
- ) ) ) ;
768
- }
769
713
770
714
self . add_utp_connection ( source, conn_id, UtpStreamId :: AcceptStream ( accept_keys) ) ?;
771
715
@@ -777,19 +721,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
777
721
Ok ( accept)
778
722
}
779
723
780
- /// Handle all closed uTP streams, currently we process only AcceptStream here.
781
- /// FindContent payload is processed explicitly when we send FindContent request.
782
- fn handle_utp_payload ( & self , streams : Vec < ( UtpPayload , UtpStreamId ) > ) {
783
- for stream in streams {
784
- match stream {
785
- ( payload, UtpStreamId :: AcceptStream ( content_keys) ) => {
786
- self . process_accept_utp_payload ( content_keys, payload) ;
787
- }
788
- _ => { }
789
- }
790
- }
791
- }
792
-
793
724
/// Sends a TALK request via Discovery v5 to some destination node.
794
725
fn send_talk_req ( & self , request : Request , request_id : OverlayRequestId , destination : Enr ) {
795
726
let discovery = Arc :: clone ( & self . discovery ) ;
@@ -821,12 +752,6 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
821
752
} ) ;
822
753
}
823
754
824
- /// Process accepted uTP payload of the OFFER?ACCEPT stream
825
- fn process_accept_utp_payload ( & self , content_keys : Vec < RawContentKey > , payload : UtpPayload ) {
826
- // TODO: Verify the payload, store the content and propagate gossip.
827
- debug ! ( "DEBUG: Processing content keys: {content_keys:?}, with payload: {payload:?}, protocol: {:?}" , self . protocol) ;
828
- }
829
-
830
755
/// Processes an incoming request from some source node.
831
756
fn process_incoming_request ( & mut self , request : Request , _id : RequestId , source : NodeId ) {
832
757
// Look up the node in the routing table.
@@ -1354,7 +1279,6 @@ mod tests {
1354
1279
let discovery = Arc :: new ( Discovery :: new ( portal_config) . unwrap ( ) ) ;
1355
1280
1356
1281
let ( utp_listener_tx, _) = unbounded_channel :: < UtpListenerRequest > ( ) ;
1357
- let ( _, utp_listener_rx) = unbounded_channel :: < UtpListenerEvent > ( ) ;
1358
1282
1359
1283
// Initialize DB config
1360
1284
let storage_capacity: u32 = DEFAULT_STORAGE_CAPACITY . parse ( ) . unwrap ( ) ;
@@ -1392,7 +1316,6 @@ mod tests {
1392
1316
response_tx,
1393
1317
response_rx,
1394
1318
utp_listener_tx,
1395
- utp_listener_rx : Arc :: new ( TRwLock :: new ( utp_listener_rx) ) ,
1396
1319
phantom_content_key : PhantomData ,
1397
1320
phantom_metric : PhantomData ,
1398
1321
metrics,
0 commit comments