@@ -297,7 +297,13 @@ impl Taker {
297297 /// If that fails too. Open an issue at [our github](https://github.com/citadel-tech/coinswap/issues)
298298 pub fn send_coinswap ( & mut self , swap_params : SwapParams ) -> Result < ( ) , TakerError > {
299299 log:: info!( "Syncing Offerbook" ) ;
300- self . sync_offerbook ( swap_params. maker_count ) ?;
300+ self . sync_offerbook ( ) ?;
301+
302+ // Error early if hop_count > available good makers.
303+ if swap_params. maker_count > self . offerbook . all_makers . len ( ) {
304+ return Err ( TakerError :: NotEnoughMakersInOfferBook ) ;
305+ }
306+
301307 // Generate new random preimage and initiate the first hop.
302308 let mut preimage = [ 0u8 ; 32 ] ;
303309 OsRng . fill_bytes ( & mut preimage) ;
@@ -1920,7 +1926,7 @@ impl Taker {
19201926 }
19211927
19221928 /// Synchronizes the offer book with addresses obtained from directory servers and local configurations.
1923- pub fn sync_offerbook ( & mut self , maker_count : usize ) -> Result < ( ) , TakerError > {
1929+ pub fn sync_offerbook ( & mut self ) -> Result < ( ) , TakerError > {
19241930 let directory_address = match self . config . connection_type {
19251931 ConnectionType :: CLEARNET => {
19261932 let mut address = self . config . directory_server_address . clone ( ) ;
@@ -1952,18 +1958,21 @@ impl Taker {
19521958 socks_port = Some ( self . config . socks_port ) ;
19531959 }
19541960 }
1955- let addresses_from_dns = fetch_addresses_from_dns (
1956- socks_port,
1957- directory_address,
1958- maker_count,
1959- self . config . connection_type ,
1960- ) ?;
1961- let offers = fetch_offer_from_makers ( addresses_from_dns, & self . config ) ?;
1961+ let addresses_from_dns =
1962+ fetch_addresses_from_dns ( socks_port, directory_address, self . config . connection_type ) ?;
19621963
1963- let new_offers = offers
1964+ // Filter for new addresses only.
1965+ let know_addrs = self
1966+ . offerbook
1967+ . all_makers
1968+ . iter ( )
1969+ . map ( |oa| oa. address . clone ( ) )
1970+ . collect :: < Vec < _ > > ( ) ;
1971+ let new_addrs = addresses_from_dns
19641972 . into_iter ( )
1965- . filter ( |offer | !self . offerbook . bad_makers . contains ( offer ) )
1973+ . filter ( |addr | !know_addrs . contains ( addr ) )
19661974 . collect :: < Vec < _ > > ( ) ;
1975+ let new_offers = fetch_offer_from_makers ( new_addrs, & self . config ) ?;
19671976
19681977 for offer in new_offers {
19691978 log:: info!(
@@ -1976,10 +1985,11 @@ impl Taker {
19761985 . verify_fidelity_proof ( & offer. offer . fidelity , & offer. address . to_string ( ) )
19771986 {
19781987 log:: warn!(
1979- "Fidelity Proof Verification failed with error: {:?}. Rejecting Offer from Maker : {}" ,
1988+ "Fidelity Proof Verification failed with error: {:?}. Adding this to bad maker list : {}" ,
19801989 e,
19811990 offer. address. to_string( )
19821991 ) ;
1992+ self . offerbook . add_bad_maker ( & offer) ;
19831993 } else {
19841994 log:: info!( "Fideity Bond verification succes. Adding offer to our OfferBook" ) ;
19851995 self . offerbook . add_new_offer ( & offer) ;
0 commit comments