@@ -6,8 +6,8 @@ use crate::{
66 portalnet:: {
77 discovery:: Discovery ,
88 types:: {
9- CustomPayload , FindContent , FindNodes , FoundContent , Message , Nodes , Ping , Pong ,
10- ProtocolId , Request , Response , SszEnr ,
9+ ByteList , CustomPayload , FindContent , FindNodes , FoundContent , Message , Nodes , Ping ,
10+ Pong , ProtocolId , Request , Response , SszEnr ,
1111 } ,
1212 Enr , U256 ,
1313 } ,
@@ -18,6 +18,8 @@ use discv5::{enr::NodeId, kbucket::KBucketsTable};
1818use futures:: channel:: oneshot;
1919use log:: { debug, info} ;
2020use rocksdb:: DB ;
21+ use ssz:: Encode ;
22+ use ssz_types:: VariableList ;
2123use thiserror:: Error ;
2224use tokio:: sync:: {
2325 mpsc:: { self , UnboundedReceiver , UnboundedSender } ,
@@ -257,8 +259,11 @@ impl OverlayService {
257259 ) ;
258260 let enr_seq = self . local_enr ( ) . await . seq ( ) ;
259261 let data_radius = self . data_radius ( ) . await ;
260- let payload = Some ( CustomPayload :: new ( data_radius, None ) ) ;
261- Pong { enr_seq, payload }
262+ let custom_payload = CustomPayload :: new ( data_radius. as_ssz_bytes ( ) ) ;
263+ Pong {
264+ enr_seq,
265+ custom_payload,
266+ }
262267 }
263268
264269 /// Builds a `Nodes` response for a `FindNodes` request.
@@ -276,16 +281,13 @@ impl OverlayService {
276281 request : FindContent ,
277282 ) -> Result < FoundContent , OverlayRequestError > {
278283 match self . db . get ( & request. content_key ) {
279- Ok ( Some ( value) ) => Ok ( FoundContent {
280- enrs : vec ! [ ] ,
281- payload : value ,
282- } ) ,
284+ Ok ( Some ( value) ) => {
285+ let content = Some ( ByteList :: from ( VariableList :: from ( value ) ) ) ;
286+ Ok ( FoundContent :: new ( None , None , content ) )
287+ }
283288 Ok ( None ) => {
284- let enrs = self . find_nodes_close_to_content ( request. content_key ) . await ;
285- Ok ( FoundContent {
286- enrs,
287- payload : vec ! [ ] ,
288- } )
289+ let enrs = Some ( self . find_nodes_close_to_content ( request. content_key ) . await ) ;
290+ Ok ( FoundContent :: new ( None , enrs, None ) )
289291 }
290292 Err ( error) => panic ! ( "Unable to respond to FindContent: {}" , error) ,
291293 }
@@ -328,15 +330,15 @@ impl OverlayService {
328330 }
329331
330332 /// Returns a vector of the ENRs of the closest nodes by the given log2 distances.
331- async fn nodes_by_distance ( & self , mut log2_distances : Vec < u64 > ) -> Vec < Enr > {
333+ async fn nodes_by_distance ( & self , mut log2_distances : Vec < u64 > ) -> Vec < SszEnr > {
332334 let mut nodes_to_send = Vec :: new ( ) ;
333335 log2_distances. sort_unstable ( ) ;
334336 log2_distances. dedup ( ) ;
335337
336338 let mut log2_distances = log2_distances. as_slice ( ) ;
337339 if let Some ( 0 ) = log2_distances. first ( ) {
338340 // If the distance is 0 send our local ENR.
339- nodes_to_send. push ( self . local_enr ( ) . await ) ;
341+ nodes_to_send. push ( SszEnr :: new ( self . local_enr ( ) . await ) ) ;
340342 log2_distances = & log2_distances[ 1 ..] ;
341343 }
342344
@@ -347,7 +349,7 @@ impl OverlayService {
347349 . into_iter ( )
348350 . map ( |entry| entry. node . value . clone ( ) )
349351 {
350- nodes_to_send. push ( node. enr ( ) ) ;
352+ nodes_to_send. push ( SszEnr :: new ( node. enr ( ) ) ) ;
351353 }
352354 }
353355 nodes_to_send
0 commit comments