mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-10 12:39:51 +00:00
commit
94dc214982
3 changed files with 37 additions and 35 deletions
|
@ -78,6 +78,7 @@ def parse_servers(result):
|
||||||
servers[host] = out
|
servers[host] = out
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
|
|
||||||
def filter_version(servers):
|
def filter_version(servers):
|
||||||
def is_recent(version):
|
def is_recent(version):
|
||||||
try:
|
try:
|
||||||
|
@ -97,12 +98,14 @@ def filter_protocol(hostmap, protocol = 's'):
|
||||||
eligible.append(serialize_server(host, port, protocol))
|
eligible.append(serialize_server(host, port, protocol))
|
||||||
return eligible
|
return eligible
|
||||||
|
|
||||||
|
|
||||||
def pick_random_server(hostmap = None, protocol = 's', exclude_set = set()):
|
def pick_random_server(hostmap = None, protocol = 's', exclude_set = set()):
|
||||||
if hostmap is None:
|
if hostmap is None:
|
||||||
hostmap = constants.net.DEFAULT_SERVERS
|
hostmap = constants.net.DEFAULT_SERVERS
|
||||||
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set)
|
eligible = list(set(filter_protocol(hostmap, protocol)) - exclude_set)
|
||||||
return random.choice(eligible) if eligible else None
|
return random.choice(eligible) if eligible else None
|
||||||
|
|
||||||
|
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
proxy_modes = ['socks4', 'socks5', 'http']
|
proxy_modes = ['socks4', 'socks5', 'http']
|
||||||
|
@ -312,9 +315,6 @@ class Network(util.DaemonThread):
|
||||||
def is_connecting(self):
|
def is_connecting(self):
|
||||||
return self.connection_status == 'connecting'
|
return self.connection_status == 'connecting'
|
||||||
|
|
||||||
def is_up_to_date(self):
|
|
||||||
return self.unanswered_requests == {}
|
|
||||||
|
|
||||||
@with_interface_lock
|
@with_interface_lock
|
||||||
def queue_request(self, method, params, interface=None):
|
def queue_request(self, method, params, interface=None):
|
||||||
# If you want to queue a request on any interface it must go
|
# If you want to queue a request on any interface it must go
|
||||||
|
@ -416,7 +416,7 @@ class Network(util.DaemonThread):
|
||||||
self.print_error("connecting to %s as new interface" % server)
|
self.print_error("connecting to %s as new interface" % server)
|
||||||
self.set_status('connecting')
|
self.set_status('connecting')
|
||||||
self.connecting.add(server)
|
self.connecting.add(server)
|
||||||
c = Connection(server, self.socket_queue, self.config.path)
|
Connection(server, self.socket_queue, self.config.path)
|
||||||
|
|
||||||
def start_random_interface(self):
|
def start_random_interface(self):
|
||||||
with self.interface_lock:
|
with self.interface_lock:
|
||||||
|
@ -569,6 +569,7 @@ class Network(util.DaemonThread):
|
||||||
self.interface = None
|
self.interface = None
|
||||||
self.start_interface(server)
|
self.start_interface(server)
|
||||||
return
|
return
|
||||||
|
|
||||||
i = self.interfaces[server]
|
i = self.interfaces[server]
|
||||||
if self.interface != i:
|
if self.interface != i:
|
||||||
self.print_error("switching to", server)
|
self.print_error("switching to", server)
|
||||||
|
@ -601,7 +602,7 @@ class Network(util.DaemonThread):
|
||||||
|
|
||||||
def process_response(self, interface, response, callbacks):
|
def process_response(self, interface, response, callbacks):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.print_error("<--", response)
|
self.print_error(interface.host, "<--", response)
|
||||||
error = response.get('error')
|
error = response.get('error')
|
||||||
result = response.get('result')
|
result = response.get('result')
|
||||||
method = response.get('method')
|
method = response.get('method')
|
||||||
|
@ -798,6 +799,7 @@ class Network(util.DaemonThread):
|
||||||
server, socket = self.socket_queue.get()
|
server, socket = self.socket_queue.get()
|
||||||
if server in self.connecting:
|
if server in self.connecting:
|
||||||
self.connecting.remove(server)
|
self.connecting.remove(server)
|
||||||
|
|
||||||
if socket:
|
if socket:
|
||||||
self.new_interface(server, socket)
|
self.new_interface(server, socket)
|
||||||
else:
|
else:
|
||||||
|
@ -1008,6 +1010,7 @@ class Network(util.DaemonThread):
|
||||||
interface.mode = 'default'
|
interface.mode = 'default'
|
||||||
interface.request = None
|
interface.request = None
|
||||||
self.notify('updated')
|
self.notify('updated')
|
||||||
|
|
||||||
# refresh network dialog
|
# refresh network dialog
|
||||||
self.notify('interfaces')
|
self.notify('interfaces')
|
||||||
|
|
||||||
|
|
|
@ -42,23 +42,25 @@ class SPV(ThreadJob):
|
||||||
interface = self.network.interface
|
interface = self.network.interface
|
||||||
if not interface:
|
if not interface:
|
||||||
return
|
return
|
||||||
|
|
||||||
blockchain = interface.blockchain
|
blockchain = interface.blockchain
|
||||||
if not blockchain:
|
if not blockchain:
|
||||||
return
|
return
|
||||||
lh = self.network.get_local_height()
|
|
||||||
|
local_height = self.network.get_local_height()
|
||||||
unverified = self.wallet.get_unverified_txs()
|
unverified = self.wallet.get_unverified_txs()
|
||||||
for tx_hash, tx_height in unverified.items():
|
for tx_hash, tx_height in unverified.items():
|
||||||
# do not request merkle branch before headers are available
|
# do not request merkle branch before headers are available
|
||||||
if (tx_height > 0) and (tx_height <= lh):
|
if tx_height <= 0 or tx_height > local_height:
|
||||||
|
continue
|
||||||
|
|
||||||
header = blockchain.read_header(tx_height)
|
header = blockchain.read_header(tx_height)
|
||||||
if header is None:
|
if header is None:
|
||||||
index = tx_height // 2016
|
index = tx_height // 2016
|
||||||
if index < len(blockchain.checkpoints):
|
if index < len(blockchain.checkpoints):
|
||||||
self.network.request_chunk(interface, index)
|
self.network.request_chunk(interface, index)
|
||||||
else:
|
elif (tx_hash not in self.requested_merkle
|
||||||
if (tx_hash not in self.requested_merkle
|
|
||||||
and tx_hash not in self.merkle_roots):
|
and tx_hash not in self.merkle_roots):
|
||||||
|
|
||||||
self.network.get_merkle_for_transaction(
|
self.network.get_merkle_for_transaction(
|
||||||
tx_hash,
|
tx_hash,
|
||||||
tx_height,
|
tx_height,
|
||||||
|
@ -70,14 +72,14 @@ class SPV(ThreadJob):
|
||||||
self.blockchain = self.network.blockchain()
|
self.blockchain = self.network.blockchain()
|
||||||
self.undo_verifications()
|
self.undo_verifications()
|
||||||
|
|
||||||
def verify_merkle(self, r):
|
def verify_merkle(self, response):
|
||||||
if self.wallet.verifier is None:
|
if self.wallet.verifier is None:
|
||||||
return # we have been killed, this was just an orphan callback
|
return # we have been killed, this was just an orphan callback
|
||||||
if r.get('error'):
|
if response.get('error'):
|
||||||
self.print_error('received an error:', r)
|
self.print_error('received an error:', response)
|
||||||
return
|
return
|
||||||
params = r['params']
|
params = response['params']
|
||||||
merkle = r['result']
|
merkle = response['result']
|
||||||
# Verify the hash of the server-provided merkle branch to a
|
# Verify the hash of the server-provided merkle branch to a
|
||||||
# transaction matches the merkle root of its block
|
# transaction matches the merkle root of its block
|
||||||
tx_hash = params[0]
|
tx_hash = params[0]
|
||||||
|
|
|
@ -218,10 +218,7 @@ class Abstract_Wallet(PrintError):
|
||||||
self.load_unverified_transactions()
|
self.load_unverified_transactions()
|
||||||
self.remove_local_transactions_we_dont_have()
|
self.remove_local_transactions_we_dont_have()
|
||||||
|
|
||||||
# There is a difference between wallet.up_to_date and network.is_up_to_date().
|
# wallet.up_to_date is true when the wallet is synchronized
|
||||||
# network.is_up_to_date() returns true when all requests have been answered and processed
|
|
||||||
# wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
|
|
||||||
# Neither of them considers the verifier.
|
|
||||||
self.up_to_date = False
|
self.up_to_date = False
|
||||||
|
|
||||||
# save wallet type the first time
|
# save wallet type the first time
|
||||||
|
|
Loading…
Add table
Reference in a new issue