@@ -21,9 +21,11 @@ use std::sync::Arc;
2121
2222use ccore:: encoded:: Header as EncodedHeader ;
2323use ccore:: {
24- Block , BlockChainClient , BlockId , BlockImportError , ChainNotify , Header , ImportError , Seal , UnverifiedParcel ,
24+ Block , BlockChainClient , BlockId , BlockImportError , BlockInfo , ChainInfo , ChainNotify , Client , Header , ImportBlock ,
25+ ImportError , Seal , UnverifiedParcel ,
2526} ;
2627use cnetwork:: { Api , NetworkExtension , NodeId , TimerToken } ;
28+ use ctypes:: parcel:: Action ;
2729use ctypes:: BlockNumber ;
2830use primitives:: { H256 , U256 } ;
2931use rlp:: { Encodable , UntrustedRlp } ;
@@ -41,13 +43,13 @@ pub struct Extension {
4143 requests : RwLock < HashMap < NodeId , Vec < ( u64 , RequestMessage ) > > > ,
4244 header_downloaders : RwLock < HashMap < NodeId , HeaderDownloader > > ,
4345 body_downloader : Mutex < BodyDownloader > ,
44- client : Arc < BlockChainClient > ,
46+ client : Arc < Client > ,
4547 api : Mutex < Option < Arc < Api > > > ,
4648 last_request : AtomicUsize ,
4749}
4850
4951impl Extension {
50- pub fn new ( client : Arc < BlockChainClient > ) -> Arc < Self > {
52+ pub fn new ( client : Arc < Client > ) -> Arc < Self > {
5153 Arc :: new ( Self {
5254 requests : RwLock :: new ( HashMap :: new ( ) ) ,
5355 header_downloaders : RwLock :: new ( HashMap :: new ( ) ) ,
@@ -394,7 +396,20 @@ impl Extension {
394396
395397 headers. first ( ) . map ( |header| header. number ( ) ) == Some ( * start_number)
396398 }
397- ( RequestMessage :: Bodies ( ..) , ResponseMessage :: Bodies ( ..) ) => true ,
399+ ( RequestMessage :: Bodies ( _) , ResponseMessage :: Bodies ( bodies) ) => {
400+ for body in bodies {
401+ for parcel in body {
402+ let is_valid = match & parcel. as_unsigned ( ) . action {
403+ Action :: Custom ( bytes) => self . client . custom_handlers ( ) . iter ( ) . any ( |c| c. is_target ( bytes) ) ,
404+ _ => true ,
405+ } ;
406+ if !is_valid {
407+ return false
408+ }
409+ }
410+ }
411+ true
412+ }
398413 ( RequestMessage :: StateHead ( ..) , ResponseMessage :: StateHead ( ..) ) => unimplemented ! ( ) ,
399414 (
400415 RequestMessage :: StateChunk {
0 commit comments