@@ -328,6 +328,37 @@ func (c *MarketplaceClient) recursiveSelect(currentAsset *hummingbird.SearchAsse
328328
329329}
330330
331+ func (c * MarketplaceClient ) searchAllAssets (ctx context.Context , owned bool , ia * uint64 , ingress * uint32 , egress * uint32 ,
332+ minBW uint32 , startsAtLatest time.Time , stopsAtLatest time.Time ) ([]* hummingbird.SearchAsset , error ) {
333+ // TODO: this is a temporary fix for pagination. We just fetch all pages
334+ // To properly implement pagination, especially for the combine assets case, the recursive select algorithm would have to be changed.
335+ var assets []* hummingbird.SearchAsset
336+ for i := uint32 (0 ); ; i ++ {
337+ resp , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
338+ Msg : & hummingbird.SearchAssetsRequest {
339+ Owned : owned ,
340+ Ia : ia ,
341+ IfIdIngress : ingress ,
342+ IfIdEgress : egress ,
343+ MinRequiredBw : & minBW ,
344+ StartsAtLatest : timestamppb .New (startsAtLatest ),
345+ StopsAtEarliest : timestamppb .New (stopsAtLatest ),
346+ Page : i ,
347+ },
348+ })
349+ if err != nil {
350+ return nil , err
351+ }
352+ if len (resp .Msg .Assets ) == 0 {
353+ break
354+ }
355+ for _ , asset := range resp .Msg .Assets {
356+ assets = append (assets , asset )
357+ }
358+ }
359+ return assets , nil
360+ }
361+
331362// checkoutAssetForInterfacePairWithCombine tries to find assets that can be combined on the time axis. It does not check for combinations on the bandwidth axis.
332363func (c * MarketplaceClient ) checkoutAssetForInterfacePairWithCombine (ctx context.Context , pair InterfacePair , bwInKbps uint32 ,
333364 startsAt time.Time , stopsAt time.Time , combineCost uint64 ) ([]* hummingbird.BuyAsset , error ) {
@@ -336,61 +367,32 @@ func (c *MarketplaceClient) checkoutAssetForInterfacePairWithCombine(ctx context
336367 var ingressBuyAssets , egressBuyAssets , pairBuyAssets []* hummingbird.BuyAsset
337368 var ingressAssetPrice , egressAssetPrice , pairAssetPrice uint64
338369 var ok bool
339- ingressAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
340- Msg : & hummingbird.SearchAssetsRequest {
341- Owned : false ,
342- Ia : & pair .IA ,
343- IfIdIngress : & pair .Ingress ,
344- MinRequiredBw : & bwInKbps ,
345- StartsAtLatest : timestamppb .New (stopsAt ),
346- StopsAtEarliest : timestamppb .New (startsAt ),
347- },
348- })
370+ ingressAssetsResponse , err := c .searchAllAssets (ctx , false , & pair .IA , & pair .Ingress , nil , bwInKbps , stopsAt , startsAt )
349371 if err != nil {
350372 return nil , err
351373 }
352- ingressSearchAssets := filter (ingressAssetsResponse . Msg . Assets , func (a * hummingbird.SearchAsset ) bool {
374+ ingressSearchAssets := filter (ingressAssetsResponse , func (a * hummingbird.SearchAsset ) bool {
353375 return a .IfIdEgress == nil
354376 })
355377 ingressBuyAssets , ingressAssetPrice , ok = c .recursiveSelectStart (ingressSearchAssets , bwInKbps , startsAt , stopsAt , combineCost )
356378 if ok {
357- egressAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
358- Msg : & hummingbird.SearchAssetsRequest {
359- Owned : false ,
360- Ia : & pair .IA ,
361- IfIdEgress : & pair .Egress ,
362- MinRequiredBw : & bwInKbps ,
363- StartsAtLatest : timestamppb .New (stopsAt ),
364- StopsAtEarliest : timestamppb .New (startsAt ),
365- },
366- })
379+ egressAssetsResponse , err := c .searchAllAssets (ctx , false , & pair .IA , nil , & pair .Egress , bwInKbps , stopsAt , startsAt )
367380 if err != nil {
368381 return nil , err
369382 }
370- egressSearchAssets := filter (egressAssetsResponse . Msg . Assets , func (a * hummingbird.SearchAsset ) bool {
383+ egressSearchAssets := filter (egressAssetsResponse , func (a * hummingbird.SearchAsset ) bool {
371384 return a .IfIdIngress == nil
372385 })
373386 egressBuyAssets , egressAssetPrice , ok = c .recursiveSelectStart (egressSearchAssets , bwInKbps , startsAt , stopsAt , combineCost )
374387 if ok {
375388 ingressAndEgressSuccess = true
376389 }
377390 }
378-
379- pairAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
380- Msg : & hummingbird.SearchAssetsRequest {
381- Owned : false ,
382- Ia : & pair .IA ,
383- IfIdIngress : & pair .Ingress ,
384- IfIdEgress : & pair .Egress ,
385- MinRequiredBw : & bwInKbps ,
386- StartsAtLatest : timestamppb .New (stopsAt ),
387- StopsAtEarliest : timestamppb .New (startsAt ),
388- },
389- })
391+ pairAssetsResponse , err := c .searchAllAssets (ctx , false , & pair .IA , & pair .Ingress , & pair .Egress , bwInKbps , stopsAt , startsAt )
390392 if err != nil {
391393 return nil , err
392394 }
393- pairBuyAssets , pairAssetPrice , ok = c .recursiveSelectStart (pairAssetsResponse . Msg . Assets , bwInKbps , startsAt , stopsAt , combineCost )
395+ pairBuyAssets , pairAssetPrice , ok = c .recursiveSelectStart (pairAssetsResponse , bwInKbps , startsAt , stopsAt , combineCost )
394396 if ok {
395397 if ingressAndEgressSuccess {
396398 if ingressAssetPrice + egressAssetPrice < pairAssetPrice {
@@ -414,56 +416,26 @@ func (c *MarketplaceClient) checkoutAssetForInterfacePairWithCombine(ctx context
414416// The function does not combine assets. If no single (ingress-asset, egress-asset) tuple or interface-pair asset can satisfy the request, no buy order is returned.
415417func (c * MarketplaceClient ) checkoutAssetForInterfacePair (ctx context.Context , pair InterfacePair , bwInKbps uint32 , startsAt time.Time , stopsAt time.Time ) ([]* hummingbird.BuyAsset , error ) {
416418 var ingressSearchAssets , egressSearchAssets , pairSearchAssets []* hummingbird.SearchAsset
417- ingressAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
418- Msg : & hummingbird.SearchAssetsRequest {
419- Owned : false ,
420- Ia : & pair .IA ,
421- IfIdIngress : & pair .Ingress ,
422- MinRequiredBw : & bwInKbps ,
423- StartsAtLatest : timestamppb .New (startsAt ),
424- StopsAtEarliest : timestamppb .New (stopsAt ),
425- },
426- })
419+ ingressAssetsResponse , err := c .searchAllAssets (ctx , false , & pair .IA , & pair .Ingress , nil , bwInKbps , startsAt , stopsAt )
427420 if err != nil {
428421 return nil , err
429422 }
430- ingressSearchAssets = filter (ingressAssetsResponse . Msg . Assets , func (a * hummingbird.SearchAsset ) bool {
423+ ingressSearchAssets = filter (ingressAssetsResponse , func (a * hummingbird.SearchAsset ) bool {
431424 return a .IfIdEgress == nil
432425 })
433426 if len (ingressSearchAssets ) != 0 {
434- egressAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
435- Msg : & hummingbird.SearchAssetsRequest {
436- Owned : false ,
437- Ia : & pair .IA ,
438- IfIdEgress : & pair .Egress ,
439- MinRequiredBw : & bwInKbps ,
440- StartsAtLatest : timestamppb .New (startsAt ),
441- StopsAtEarliest : timestamppb .New (stopsAt ),
442- },
443- })
427+ egressAssetsResponse , err := c .searchAllAssets (ctx , false , & pair .IA , nil , & pair .Ingress , bwInKbps , startsAt , stopsAt )
444428 if err != nil {
445429 return nil , err
446430 }
447- egressSearchAssets = filter (egressAssetsResponse . Msg . Assets , func (a * hummingbird.SearchAsset ) bool {
431+ egressSearchAssets = filter (egressAssetsResponse , func (a * hummingbird.SearchAsset ) bool {
448432 return a .IfIdIngress == nil
449433 })
450434 }
451-
452- pairAssetsResponse , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
453- Msg : & hummingbird.SearchAssetsRequest {
454- Owned : false ,
455- Ia : & pair .IA ,
456- IfIdIngress : & pair .Ingress ,
457- IfIdEgress : & pair .Egress ,
458- MinRequiredBw : & bwInKbps ,
459- StartsAtLatest : timestamppb .New (startsAt ),
460- StopsAtEarliest : timestamppb .New (stopsAt ),
461- },
462- })
435+ pairSearchAssets , err = c .searchAllAssets (ctx , false , & pair .IA , & pair .Ingress , & pair .Egress , bwInKbps , startsAt , stopsAt )
463436 if err != nil {
464437 return nil , err
465438 }
466- pairSearchAssets = pairAssetsResponse .Msg .Assets
467439
468440 duration := stopsAt .Sub (startsAt )
469441 actualPrice := func (a * hummingbird.SearchAsset ) uint64 {
@@ -605,31 +577,15 @@ func (c *MarketplaceClient) ObtainReservationsForInterfacePairs(ctx context.Cont
605577 }
606578 var foundAssets []* hummingbird.SearchAsset
607579 if combineAssets {
608- foundAssetsResp , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
609- Msg : & hummingbird.SearchAssetsRequest {
610- Owned : true ,
611- MinRequiredBw : & bwInKbps ,
612- StartsAtLatest : timestamppb .New (stopsAt ),
613- StopsAtEarliest : timestamppb .New (startsAt ),
614- },
615- })
580+ foundAssets , err = c .searchAllAssets (ctx , true , nil , nil , nil , bwInKbps , stopsAt , startsAt )
616581 if err != nil {
617582 return nil , err
618583 }
619- foundAssets = foundAssetsResp .Msg .Assets
620584 } else {
621- foundAssetsResp , err := c .client .SearchAssets (ctx , & connect.Request [hummingbird.SearchAssetsRequest ]{
622- Msg : & hummingbird.SearchAssetsRequest {
623- Owned : true ,
624- MinRequiredBw : & bwInKbps ,
625- StartsAtLatest : timestamppb .New (startsAt ),
626- StopsAtEarliest : timestamppb .New (stopsAt ),
627- },
628- })
585+ foundAssets , err = c .searchAllAssets (ctx , true , nil , nil , nil , bwInKbps , startsAt , stopsAt )
629586 if err != nil {
630587 return nil , err
631588 }
632- foundAssets = foundAssetsResp .Msg .Assets
633589 }
634590
635591 foundAssetsMap := make (map [uint64 ][]* hummingbird.SearchAsset )
0 commit comments