Compare commits
No commits in common. "911d8118bc9fbf080b6e852524472d320cbd718c" and "421c6da25a0635e733a2f635c76d41235d3fc7b3" have entirely different histories.
911d8118bc
...
421c6da25a
@ -65,7 +65,6 @@ import onionrvalues # noqa
|
|||||||
|
|
||||||
import onionrexceptions # noqa
|
import onionrexceptions # noqa
|
||||||
import onionrsetup as setup # noqa
|
import onionrsetup as setup # noqa
|
||||||
setup.setup_config()
|
|
||||||
|
|
||||||
setup.setup_default_plugins()
|
setup.setup_default_plugins()
|
||||||
|
|
||||||
@ -85,7 +84,7 @@ import bigbrother # noqa
|
|||||||
from onionrcommands import parser # noqa
|
from onionrcommands import parser # noqa
|
||||||
from onionrplugins import onionrevents as events # noqa
|
from onionrplugins import onionrevents as events # noqa
|
||||||
|
|
||||||
|
setup.setup_config()
|
||||||
|
|
||||||
import config # noqa
|
import config # noqa
|
||||||
from utils import identifyhome # noqa
|
from utils import identifyhome # noqa
|
||||||
|
@ -23,7 +23,6 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
untrusted_exec = True
|
|
||||||
|
|
||||||
def block_system(cmd):
|
def block_system(cmd):
|
||||||
"""Prevent os.system except for whitelisted commands+contexts."""
|
"""Prevent os.system except for whitelisted commands+contexts."""
|
||||||
@ -37,8 +36,6 @@ def block_exec(event, info):
|
|||||||
# because libraries have stupid amounts of compile/exec/eval,
|
# because libraries have stupid amounts of compile/exec/eval,
|
||||||
# We have to use a whitelist where it can be tolerated
|
# We have to use a whitelist where it can be tolerated
|
||||||
# Generally better than nothing, not a silver bullet
|
# Generally better than nothing, not a silver bullet
|
||||||
if untrusted_exec:
|
|
||||||
return
|
|
||||||
whitelisted_code = [
|
whitelisted_code = [
|
||||||
'netrc.py',
|
'netrc.py',
|
||||||
'shlex.py',
|
'shlex.py',
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
Dandelion ++ Gossip client logic
|
Dandelion ++ Gossip client logic
|
||||||
"""
|
"""
|
||||||
import traceback
|
import traceback
|
||||||
from threading import Thread
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from typing import Set, Tuple
|
from typing import Set, Tuple
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@ -86,11 +85,7 @@ def start_gossip_client():
|
|||||||
Stream new blocks
|
Stream new blocks
|
||||||
"""
|
"""
|
||||||
bl: Block
|
bl: Block
|
||||||
|
do_announce()
|
||||||
def _start_announce():
|
|
||||||
sleep(60)
|
|
||||||
do_announce()
|
|
||||||
Thread(target=_start_announce, daemon=True).start()
|
|
||||||
|
|
||||||
# Start a thread that runs every 1200 secs to
|
# Start a thread that runs every 1200 secs to
|
||||||
# Ask peers for a subset for their peer set
|
# Ask peers for a subset for their peer set
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from queue import Empty, Queue
|
from queue import Queue
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from secrets import choice
|
from secrets import choice
|
||||||
import traceback
|
import traceback
|
||||||
@ -112,9 +112,7 @@ async def stem_out(d_phase: 'DandelionPhase'):
|
|||||||
"Did not stem out any blocks in time, " +
|
"Did not stem out any blocks in time, " +
|
||||||
"if this happens regularly you may be under attack",
|
"if this happens regularly you may be under attack",
|
||||||
terminal=True)
|
terminal=True)
|
||||||
for s in peer_sockets:
|
list(map(lambda p: p.close(), peer_sockets))
|
||||||
if s:
|
|
||||||
s.close()
|
|
||||||
peer_sockets.clear()
|
peer_sockets.clear()
|
||||||
break
|
break
|
||||||
# If above loop ran out of time or NotEnoughEdges, loops below will not execute
|
# If above loop ran out of time or NotEnoughEdges, loops below will not execute
|
||||||
@ -126,8 +124,6 @@ async def stem_out(d_phase: 'DandelionPhase'):
|
|||||||
for routine in stream_routines:
|
for routine in stream_routines:
|
||||||
try:
|
try:
|
||||||
await routine
|
await routine
|
||||||
except Empty:
|
|
||||||
pass
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warn(traceback.format_exc())
|
logger.warn(traceback.format_exc())
|
||||||
else:
|
else:
|
||||||
|
@ -8,8 +8,6 @@ if TYPE_CHECKING:
|
|||||||
from onionrplugins import onionrevents
|
from onionrplugins import onionrevents
|
||||||
import logger
|
import logger
|
||||||
|
|
||||||
from socks import GeneralProxyError
|
|
||||||
|
|
||||||
from ..peer import Peer
|
from ..peer import Peer
|
||||||
from ..commands import GossipCommands, command_to_byte
|
from ..commands import GossipCommands, command_to_byte
|
||||||
from ..constants import PEER_AMOUNT_TO_ASK, TRANSPORT_SIZE_BYTES
|
from ..constants import PEER_AMOUNT_TO_ASK, TRANSPORT_SIZE_BYTES
|
||||||
@ -24,15 +22,11 @@ def _do_ask_peer(peer):
|
|||||||
_ask_peer(peer)
|
_ask_peer(peer)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
logger.debug("Timed out when asking for new peers")
|
logger.debug("Timed out when asking for new peers")
|
||||||
except GeneralProxyError:
|
|
||||||
logger.debug("Proxy error")
|
|
||||||
logger.debug(format_exc(), terminal=True)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error(format_exc(), terminal=True)
|
logger.error(format_exc(), terminal=True)
|
||||||
|
|
||||||
def _ask_peer(peer):
|
def _ask_peer(peer):
|
||||||
s: 'socket' = peer.get_socket(12)
|
s: 'socket' = peer.get_socket(12)
|
||||||
|
|
||||||
s.sendall(command_to_byte(GossipCommands.PEER_EXCHANGE))
|
s.sendall(command_to_byte(GossipCommands.PEER_EXCHANGE))
|
||||||
# Get 10 max peers
|
# Get 10 max peers
|
||||||
for _ in range(MAX_PEERS):
|
for _ in range(MAX_PEERS):
|
||||||
@ -55,8 +49,7 @@ def _ask_peer(peer):
|
|||||||
|
|
||||||
def get_new_peers():
|
def get_new_peers():
|
||||||
if not len(gossip_peer_set):
|
if not len(gossip_peer_set):
|
||||||
logger.debug("Peer set empty, cannot get new peers")
|
raise ValueError("Peer set empty")
|
||||||
return
|
|
||||||
|
|
||||||
# Deep copy the peer list
|
# Deep copy the peer list
|
||||||
peer_list: Peer = list(gossip_peer_set)
|
peer_list: Peer = list(gossip_peer_set)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import traceback
|
|
||||||
from gossip.commands import GossipCommands, command_to_byte
|
from gossip.commands import GossipCommands, command_to_byte
|
||||||
from .peerset import gossip_peer_set
|
from .peerset import gossip_peer_set
|
||||||
|
|
||||||
@ -9,14 +8,12 @@ def connect_peer(peer):
|
|||||||
if peer in gossip_peer_set:
|
if peer in gossip_peer_set:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
s = peer.get_socket(120)
|
s = peer.get_socket(15)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warn(f"Could not connect to {peer.transport_address}")
|
logger.warn(f"Could not connect to {peer.transport_address}")
|
||||||
logger.warn(traceback.format_exc())
|
|
||||||
else:
|
else:
|
||||||
with s:
|
s.sendall(command_to_byte(GossipCommands.PING))
|
||||||
s.sendall(command_to_byte(GossipCommands.PING))
|
if s.recv(5).decode('utf-8') == 'PONG':
|
||||||
|
gossip_peer_set.add(peer)
|
||||||
if s.recv(4).decode('utf-8') == 'PONG':
|
logger.info(f"connected to {peer.transport_address}")
|
||||||
gossip_peer_set.add(peer)
|
s.close()
|
||||||
logger.info(f"connected to {peer.transport_address}", terminal=True)
|
|
||||||
|
@ -60,7 +60,6 @@ def gossip_server():
|
|||||||
match GossipCommands(cmd):
|
match GossipCommands(cmd):
|
||||||
case GossipCommands.PING:
|
case GossipCommands.PING:
|
||||||
writer.write(b'PONG')
|
writer.write(b'PONG')
|
||||||
break
|
|
||||||
case GossipCommands.ANNOUNCE:
|
case GossipCommands.ANNOUNCE:
|
||||||
async def _read_announce():
|
async def _read_announce():
|
||||||
address = await reader.readuntil(b'\n')
|
address = await reader.readuntil(b'\n')
|
||||||
|
@ -61,7 +61,7 @@ async def diffuse_blocks(reader: 'StreamReader', writer: 'StreamWriter'):
|
|||||||
_add_to_queue
|
_add_to_queue
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _send_block(block: 'Block'):
|
async def _send_block(bl: 'Block'):
|
||||||
writer.write(block.id)
|
writer.write(block.id)
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ def show_stats():
|
|||||||
# file and folder size stats
|
# file and folder size stats
|
||||||
'div1': True, # this creates a solid line across the screen, a div
|
'div1': True, # this creates a solid line across the screen, a div
|
||||||
'Total Block Size':
|
'Total Block Size':
|
||||||
sizeutils.human_size(sizeutils.size(home + 'blocks.db')),
|
sizeutils.human_size(sizeutils.size(home + 'blocks/')),
|
||||||
'Total Plugin Size':
|
'Total Plugin Size':
|
||||||
sizeutils.human_size(sizeutils.size(home + 'plugins/')),
|
sizeutils.human_size(sizeutils.size(home + 'plugins/')),
|
||||||
'Log File Size':
|
'Log File Size':
|
||||||
|
@ -20,9 +20,6 @@ def on_announce_rec(api, data=None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
announced = announced.strip()
|
announced = announced.strip()
|
||||||
if not announced.endswith('.onion'):
|
announced += '.onion'
|
||||||
announced += '.onion'
|
|
||||||
|
|
||||||
logger.info(f"Peer {announced} announced to us.", terminal=True)
|
|
||||||
|
|
||||||
data['callback'](TorPeer(socks_address, socks_port, announced))
|
data['callback'](TorPeer(socks_address, socks_port, announced))
|
||||||
|
@ -2,7 +2,6 @@ import shelve
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import os
|
import os
|
||||||
import dbm
|
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
@ -40,14 +39,14 @@ def on_bootstrap(api, data):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
load_existing_peers(callback_func)
|
load_existing_peers(callback_func)
|
||||||
except dbm.error:
|
except FileNotFoundError:
|
||||||
try:
|
try:
|
||||||
with open(bootstrap_file, 'r') as bootstrap_file_obj:
|
with open(bootstrap_file, 'r') as bootstrap_file_obj:
|
||||||
bootstrap_nodes = set(bootstrap_file_obj.read().split(','))
|
bootstrap_nodes = set(bootstrap_file_obj.read().split(','))
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
bootstrap_nodes = set()
|
bootstrap_nodes = set()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(traceback.format_exc(), terminal=True)
|
logger.warn(traceback.format_exc())
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user