Skip to content

Commit

Permalink
Merge pull request #115 from LetheanMovement/feature/valiant/display-…
Browse files Browse the repository at this point in the history
…cost-to-client

Display cost per minute and initial cost requirement to clients
  • Loading branch information
valiant1x committed Oct 15, 2019
2 parents a8b6cac + d84a6d8 commit 0131955
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, handler=None, level=logging.INFO, anon=True, name='audit'):
self.logger.setLevel(logging.INFO)
self.anon = anon

def audit(self, action, type, obj=None, anon=None, lthn=None, wallet=None, paymentid=None, sessionid=None, srcip=None, srcport=None, dstport=None, dstip=None, msg=None, method=None, uri=None, serviceid=None, cmd=None):
def audit(self, action, type, obj=None, anon=None, lthn=None, wallet=None, paymentid=None, cost_per_min=None, sessionid=None, srcip=None, srcport=None, dstport=None, dstip=None, msg=None, method=None, uri=None, serviceid=None, cmd=None):
if (anon=="yes" or (anon is None and self.anon is True)):
if paymentid:
paymentid = util.anonymise_paymentid(paymentid)
Expand All @@ -81,6 +81,8 @@ def audit(self, action, type, obj=None, anon=None, lthn=None, wallet=None, payme
json['wallet'] = wallet
if paymentid:
json['paymentid'] = paymentid
if cost_per_min:
json['cost_per_min'] = cost_per_min
if sessionid:
json['sessionid'] = sessionid
if srcip:
Expand Down
9 changes: 7 additions & 2 deletions lib/service_hac.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ def connect(self, sdp):
if (code<0):
return code
if (code==self.OK_NOPAYMENT):
log.L.warning("Now you need to pay to provider's wallet.")
log.A.audit(log.A.NPAYMENT, log.A.PWALLET, wallet=sdp["provider"]["wallet"], paymentid=self.cfg["paymentid"], anon="no")
cost=0.0
for serviceItem in sdp["services"]:
if serviceItem["id"] == self.cfg["paymentid"][:2]:
cost=serviceItem["cost"]
log.L.warning("Now you need to pay to provider's wallet. The cost of service is %s LTHN per minute. The minimum initial payment is %s minutes, for a total of %.8f LTHN." % (serviceItem["cost"], serviceItem["firstPrePaidMinutes"], float(serviceItem["cost"]) * float(serviceItem["firstPrePaidMinutes"])))
break
log.A.audit(log.A.NPAYMENT, log.A.PWALLET, wallet=sdp["provider"]["wallet"], paymentid=self.cfg["paymentid"], cost_per_min=cost, anon="no")
code = self.waitForPayment(providerid)
if (code<0):
return code
Expand Down
8 changes: 7 additions & 1 deletion lib/service_ovpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ def mgmtEvent(self, msg):
p = re.search("^>STATE:(\d*),RECONNECTING,auth-failure,,", msg)
if (p and self.isClient()):
if self.initphase==1:
log.A.audit(log.A.NPAYMENT, log.A.PWALLET, wallet=self.sdp["provider"]["wallet"], paymentid=self.cfg["paymentid"], anon="no")
cost=0.0
for serviceItem in self.sdp["services"]:
if serviceItem["id"] == self.cfg["paymentid"][:2]:
cost=serviceItem["cost"]
log.L.warning("Now you need to pay to provider's wallet. The cost of service is %s LTHN per minute. The minimum initial payment is %s minutes, for a total of %.8f LTHN." % (serviceItem["cost"], serviceItem["firstPrePaidMinutes"], float(serviceItem["cost"]) * float(serviceItem["firstPrePaidMinutes"])))
break
log.A.audit(log.A.NPAYMENT, log.A.PWALLET, wallet=self.sdp["provider"]["wallet"], paymentid=self.cfg["paymentid"], cost_per_min=cost, anon="no")
self.initphase += 1
elif time.time()-self.starttime>float(config.Config.CAP.paymentTimeout):
log.L.error("Timeout waiting for payment!")
Expand Down

0 comments on commit 0131955

Please sign in to comment.