add only-free payment rate manager for testing
This commit is contained in:
parent
1a6290eacc
commit
bcd026a1b6
3 changed files with 69 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
from lbrynet.core.Strategy import get_default_strategy
|
from lbrynet.core.Strategy import get_default_strategy, OnlyFreeStrategy
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
@ -81,3 +81,46 @@ class NegotiatedPaymentRateManager(object):
|
||||||
return (offer.is_too_low and
|
return (offer.is_too_low and
|
||||||
round(Decimal.from_float(offer.rate), 5) >= round(self.strategy.max_rate, 5))
|
round(Decimal.from_float(offer.rate), 5) >= round(self.strategy.max_rate, 5))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class OnlyFreePaymentsManager(object):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
"""
|
||||||
|
A payment rate manager that will only ever accept and offer a rate of 0.0,
|
||||||
|
Used for testing
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.base = BasePaymentRateManager(0.0, 0.0)
|
||||||
|
self.points_paid = 0.0
|
||||||
|
self.generous = True
|
||||||
|
self.strategy = OnlyFreeStrategy()
|
||||||
|
|
||||||
|
def get_rate_blob_data(self, peer, blobs):
|
||||||
|
response = self.strategy.make_offer(peer, blobs)
|
||||||
|
return response.rate
|
||||||
|
|
||||||
|
def accept_rate_blob_data(self, peer, blobs, offer):
|
||||||
|
offer = self.strategy.respond_to_offer(offer, peer, blobs)
|
||||||
|
self.strategy.update_accepted_offers(peer, offer)
|
||||||
|
return offer.is_accepted
|
||||||
|
|
||||||
|
def reply_to_offer(self, peer, blobs, offer):
|
||||||
|
reply = self.strategy.respond_to_offer(offer, peer, blobs)
|
||||||
|
self.strategy.update_accepted_offers(peer, reply)
|
||||||
|
return reply
|
||||||
|
|
||||||
|
def get_rate_for_peer(self, peer):
|
||||||
|
return self.strategy.accepted_offers.get(peer, False)
|
||||||
|
|
||||||
|
def record_points_paid(self, amount):
|
||||||
|
self.points_paid += amount
|
||||||
|
|
||||||
|
def record_offer_reply(self, peer, offer):
|
||||||
|
self.strategy.update_accepted_offers(peer, offer)
|
||||||
|
|
||||||
|
def price_limit_reached(self, peer):
|
||||||
|
if peer in self.strategy.pending_sent_offers:
|
||||||
|
offer = self.strategy.pending_sent_offers[peer]
|
||||||
|
if offer.rate > 0.0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
|
@ -9,6 +9,14 @@ def get_default_price_model(blob_tracker, base_price, **kwargs):
|
||||||
return MeanAvailabilityWeightedPrice(blob_tracker, base_price, **kwargs)
|
return MeanAvailabilityWeightedPrice(blob_tracker, base_price, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ZeroPrice(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.base_price = 0.0
|
||||||
|
|
||||||
|
def calculate_price(self, blob):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
class MeanAvailabilityWeightedPrice(object):
|
class MeanAvailabilityWeightedPrice(object):
|
||||||
"""Calculate mean-blob-availability and stream-position weighted price for a blob
|
"""Calculate mean-blob-availability and stream-position weighted price for a blob
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from decimal import Decimal
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
from lbrynet.interfaces import INegotiationStrategy
|
from lbrynet.interfaces import INegotiationStrategy
|
||||||
from lbrynet.core.Offer import Offer
|
from lbrynet.core.Offer import Offer
|
||||||
from lbrynet.core.PriceModel import MeanAvailabilityWeightedPrice
|
from lbrynet.core.PriceModel import MeanAvailabilityWeightedPrice, ZeroPrice
|
||||||
|
|
||||||
|
|
||||||
def get_default_strategy(blob_tracker, **kwargs):
|
def get_default_strategy(blob_tracker, **kwargs):
|
||||||
|
@ -134,3 +134,19 @@ class BasicAvailabilityWeightedStrategy(Strategy):
|
||||||
with_premium = self._premium(rate, offer_count)
|
with_premium = self._premium(rate, offer_count)
|
||||||
rounded_price = round(with_premium, 5)
|
rounded_price = round(with_premium, 5)
|
||||||
return self._bounded_price(rounded_price)
|
return self._bounded_price(rounded_price)
|
||||||
|
|
||||||
|
|
||||||
|
class OnlyFreeStrategy(Strategy):
|
||||||
|
implementer(INegotiationStrategy)
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
price_model = ZeroPrice()
|
||||||
|
Strategy.__init__(self, price_model, 0.0, 0.0, True)
|
||||||
|
|
||||||
|
def _get_mean_rate(self, rates):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
def _get_response_rate(self, rates, offer_count):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
def _make_rate_offer(self, rates, offer_count):
|
||||||
|
return 0.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue