mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-23 08:04:20 +01:00
summary: use proxy if configuration says to.
All plugins should take care to do this if config specifies always-use-proxy! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
df4b422491
commit
6cd4726369
@@ -1,3 +1,4 @@
|
||||
pyln-client>=0.7.3
|
||||
requests>=2.0.0
|
||||
requests>=2.10.0
|
||||
requests[socks]>=2.10.0
|
||||
packaging>=14.1
|
||||
|
||||
@@ -53,14 +53,15 @@ class PeerThread(threading.Thread):
|
||||
|
||||
|
||||
class PriceThread(threading.Thread):
|
||||
def __init__(self):
|
||||
def __init__(self, proxies):
|
||||
super().__init__()
|
||||
self.daemon = True
|
||||
self.proxies = proxies
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
try:
|
||||
r = requests.get('https://www.bitstamp.net/api/v2/ticker/BTC{}'.format(plugin.currency))
|
||||
r = requests.get('https://www.bitstamp.net/api/v2/ticker/BTC{}'.format(plugin.currency), proxies=self.proxies)
|
||||
plugin.fiat_per_btc = float(r.json()['last'])
|
||||
except Exception as ex:
|
||||
plugin.log("[PriceThread] " + str(ex), 'warn')
|
||||
@@ -232,11 +233,21 @@ def init(options, configuration, plugin):
|
||||
plugin.persist['availcount'] = 0
|
||||
|
||||
info = plugin.rpc.getinfo()
|
||||
config = plugin.rpc.listconfigs()
|
||||
if 'always-use-proxy' in config:
|
||||
paddr = config['proxy']
|
||||
# Default port in 9050
|
||||
if ':' not in paddr:
|
||||
paddr += ':9050'
|
||||
proxies = { 'https': 'socks5h://' + paddr,
|
||||
'http': 'socks5h://' + paddr }
|
||||
else:
|
||||
proxies = None
|
||||
|
||||
# Measure availability
|
||||
PeerThread().start()
|
||||
# Try to grab conversion price
|
||||
PriceThread().start()
|
||||
PriceThread(proxies).start()
|
||||
|
||||
# Prefer IPv4, otherwise take any to give out address.
|
||||
best_address = None
|
||||
|
||||
Reference in New Issue
Block a user