work on torgossip
This commit is contained in:
parent
346d30086e
commit
4b36e9d3da
@ -27,6 +27,7 @@ conf['transports']['sneakernet'] = True
|
|||||||
conf['statistics']['i_dont_want_privacy'] = False
|
conf['statistics']['i_dont_want_privacy'] = False
|
||||||
conf['statistics']['server'] = ''
|
conf['statistics']['server'] = ''
|
||||||
conf['ui']['animated_background'] = True
|
conf['ui']['animated_background'] = True
|
||||||
|
conf['runtests']['skip_slow'] = False
|
||||||
|
|
||||||
json.dump(conf, open('static-data/default_config.json', 'w'), sort_keys=True, indent=4)
|
json.dump(conf, open('static-data/default_config.json', 'w'), sort_keys=True, indent=4)
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ if input("Use bootstrap list? y/n").lower() == 'y':
|
|||||||
conf['general']['use_bootstrap_list'] = True
|
conf['general']['use_bootstrap_list'] = True
|
||||||
conf['log']['file']['remove_on_exit'] = False
|
conf['log']['file']['remove_on_exit'] = False
|
||||||
conf['ui']['animated_background'] = False
|
conf['ui']['animated_background'] = False
|
||||||
|
conf['runtests']['skip_slow'] = True
|
||||||
if input('Stat reporting? y/n') == 'y':
|
if input('Stat reporting? y/n') == 'y':
|
||||||
conf['statistics']['i_dont_want_privacy'] = True
|
conf['statistics']['i_dont_want_privacy'] = True
|
||||||
conf['statistics']['server'] = input('Statistics server')
|
conf['statistics']['server'] = input('Statistics server')
|
||||||
|
@ -48,7 +48,8 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
controller = torcontroller.get_controller()
|
controller = torcontroller.get_controller()
|
||||||
|
|
||||||
def _client_pool(shared_state, socket_pool: dict):
|
def _client_pool(shared_state, socket_pool: dict):
|
||||||
peer_db: 'TorGossipPeers' = shared_state.get_by_string('TorGossipPeers')
|
peer_db: 'TorGossipPeers' = shared_state.get_by_string(
|
||||||
|
'TorGossipPeers')
|
||||||
socks_port = shared_state.get_by_string('NetController').socksPort
|
socks_port = shared_state.get_by_string('NetController').socksPort
|
||||||
|
|
||||||
peers = peer_db.get_highest_score_peers(20)
|
peers = peer_db.get_highest_score_peers(20)
|
||||||
@ -73,12 +74,10 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
except socket.GeneralProxyError:
|
except socket.GeneralProxyError:
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
def client_loop(shared_state, socket_pool):
|
def client_loop(shared_state, socket_pool):
|
||||||
|
|
||||||
sleep_t = 60
|
sleep_t = 60
|
||||||
block_db = shared_state.get_by_string('SafeDB')
|
block_db = shared_state.get_by_string('SafeDB')
|
||||||
peer_db = shared_state.get_by_string('TorGossipPeers')
|
|
||||||
|
|
||||||
peer_info = {}
|
peer_info = {}
|
||||||
|
|
||||||
@ -128,7 +127,7 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
sleep(1)
|
sleep(1)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
peer = peers[0]
|
peers[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error(
|
logger.error(
|
||||||
"There are no known TorGossip peers." +
|
"There are no known TorGossip peers." +
|
||||||
@ -139,7 +138,6 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
peers = list(socket_pool)
|
peers = list(socket_pool)
|
||||||
SystemRandom().shuffle(peers)
|
SystemRandom().shuffle(peers)
|
||||||
|
|
||||||
|
|
||||||
_client_pool(shared_state, socket_pool)
|
_client_pool(shared_state, socket_pool)
|
||||||
client_loop(shared_state, socket_pool)
|
client_loop(shared_state, socket_pool)
|
||||||
|
|
||||||
|
@ -6,13 +6,17 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from socket import socket
|
from socket import socket
|
||||||
|
|
||||||
|
import logger
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
from commands import GossipCommands
|
from commands import GossipCommands
|
||||||
|
from .commandsender import command_sender
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -34,11 +38,26 @@ def fanout_to_peers(
|
|||||||
block_hash: bytes,
|
block_hash: bytes,
|
||||||
block_data: 'KastenPacked',
|
block_data: 'KastenPacked',
|
||||||
fanout_count: int = 4):
|
fanout_count: int = 4):
|
||||||
peers_to_use = []
|
|
||||||
peers = list(socket_pool)
|
peers = list(socket_pool)
|
||||||
SystemRandom().shuffle(peers)
|
SystemRandom().shuffle(peers)
|
||||||
|
sent_counter = 0
|
||||||
|
|
||||||
for i in range(fanout_count):
|
fanout_count = min(fanout_count, len(peers))
|
||||||
peer: 'socket' = peers.pop()
|
fanout_count = max(1, fanout_count)
|
||||||
peer.sendall(G)
|
|
||||||
|
while sent_counter < fanout_count:
|
||||||
|
try:
|
||||||
|
peer = peers.pop()
|
||||||
|
except IndexError:
|
||||||
|
sleep(2)
|
||||||
|
|
||||||
|
command_sender(peer, GossipCommands.CHECK_HAS_BLOCK, block_hash)
|
||||||
|
if peer.recv(1) == b'\x01':
|
||||||
|
continue
|
||||||
|
command_sender(peer, GossipCommands.PUT_BLOCK, block_hash, block_data)
|
||||||
|
if peer.recv(1) != b'\x01':
|
||||||
|
logger.warn(f"Failed to fanout {block_hash} to {peer}", terminal=True)
|
||||||
|
continue
|
||||||
|
sent_counter += 1
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
class GossipCommands(IntEnum):
|
class GossipCommands(IntEnum):
|
||||||
PING = 1,
|
PING = 1,
|
||||||
CHECK_HAS_BLOCK = 2,
|
CHECK_HAS_BLOCK = 2, # Returns 1 if has block, 2 if not
|
||||||
LIST_BLOCKS_BY_TYPE = 3,
|
LIST_BLOCKS_BY_TYPE = 3,
|
||||||
LIST_BLOCKS_BY_TYPE_OFFSET = 4,
|
LIST_BLOCKS_BY_TYPE_OFFSET = 4,
|
||||||
GET_BLOCK = 5,
|
GET_BLOCK = 5,
|
||||||
|
@ -12,7 +12,7 @@ import blockio
|
|||||||
|
|
||||||
|
|
||||||
def _fake_onion():
|
def _fake_onion():
|
||||||
return b32encode(os.urandom(34)).decode('utf-8') + ".onion"
|
return b32encode(os.urandom(34) + int(3).to_bytes(1, 'little')).decode('utf-8') + ".onion"
|
||||||
|
|
||||||
def _shrink_peer_address(peer):
|
def _shrink_peer_address(peer):
|
||||||
# strip .onion and b32decode peer address for lower database mem usage
|
# strip .onion and b32decode peer address for lower database mem usage
|
||||||
@ -70,6 +70,9 @@ def torgossip_runtest(test_manager):
|
|||||||
# test block was uploaded by getting it
|
# test block was uploaded by getting it
|
||||||
s.sendall(b'5' + bl_new.id)
|
s.sendall(b'5' + bl_new.id)
|
||||||
assert s.recv(64) == bl_new.get_packed()
|
assert s.recv(64) == bl_new.get_packed()
|
||||||
|
# Test CHECK_HASH_BLOCK
|
||||||
|
s.sendall(b'2' + bl_new.id)
|
||||||
|
assert s.recv(32) == b'\x02'
|
||||||
|
|
||||||
s.sendall(b'40,tbt')
|
s.sendall(b'40,tbt')
|
||||||
assert len(s.recv(100000)) == len(
|
assert len(s.recv(100000)) == len(
|
||||||
@ -104,8 +107,7 @@ def torgossip_runtest(test_manager):
|
|||||||
announce_raw = _shrink_peer_address(announce_peer)
|
announce_raw = _shrink_peer_address(announce_peer)
|
||||||
s.sendall(b'8' + announce_raw)
|
s.sendall(b'8' + announce_raw)
|
||||||
assert s.recv(1) == b'1'
|
assert s.recv(1) == b'1'
|
||||||
print(type(announce_raw), type(shared_state.get_by_string(
|
|
||||||
'TorGossipPeers').get_highest_score_peers(100)[0][0]))
|
|
||||||
assert announce_raw == shared_state.get_by_string(
|
assert announce_raw == shared_state.get_by_string(
|
||||||
'TorGossipPeers').get_highest_score_peers(100)[0][0]
|
'TorGossipPeers').get_highest_score_peers(100)[0][0]
|
||||||
shared_state.get_by_string('TorGossipPeers').remove_peer(announce_raw)
|
shared_state.get_by_string('TorGossipPeers').remove_peer(announce_raw)
|
||||||
|
Loading…
Reference in New Issue
Block a user