* further splitting onionrutils into a module
This commit is contained in:
parent
0d258e1a16
commit
d378340099
31 changed files with 234 additions and 199 deletions
|
@ -20,6 +20,7 @@
|
|||
import time, sys
|
||||
import onionrexceptions, logger, onionrpeers
|
||||
from utils import networkmerger
|
||||
from onionrutils import stringvalidators
|
||||
# secrets module was added into standard lib in 3.6+
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] < 6:
|
||||
from dependencies import secrets
|
||||
|
@ -30,7 +31,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
|||
retData = False
|
||||
tried = comm_inst.offlinePeers
|
||||
if peer != '':
|
||||
if comm_inst._core._utils.validateID(peer):
|
||||
if stringvalidators.validate_transport(peer):
|
||||
peerList = [peer]
|
||||
else:
|
||||
raise onionrexceptions.InvalidAddress('Will not attempt connection test to invalid address')
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
'''
|
||||
import logger
|
||||
import onionrevents as events
|
||||
from onionrutils import localcommand
|
||||
def handle_daemon_commands(comm_inst):
|
||||
cmd = comm_inst._core.daemonQueue()
|
||||
response = ''
|
||||
|
@ -39,7 +40,7 @@ def handle_daemon_commands(comm_inst):
|
|||
if response == '':
|
||||
response = 'none'
|
||||
elif cmd[0] == 'localCommand':
|
||||
response = comm_inst._core._utils.localCommand(cmd[1])
|
||||
response = localcommand.local_command(comm_inst._core, cmd[1])
|
||||
elif cmd[0] == 'pex':
|
||||
for i in comm_inst.timers:
|
||||
if i.timerFunction.__name__ == 'lookupAdders':
|
||||
|
@ -49,7 +50,7 @@ def handle_daemon_commands(comm_inst):
|
|||
|
||||
if cmd[0] not in ('', None):
|
||||
if response != '':
|
||||
comm_inst._core._utils.localCommand('queueResponseAdd/' + cmd[4], post=True, postData={'data': response})
|
||||
localcommand.local_command(comm_inst._core, 'queueResponseAdd/' + cmd[4], post=True, postData={'data': response})
|
||||
response = ''
|
||||
|
||||
comm_inst.decrementThreadCount('daemonCommands')
|
|
@ -18,6 +18,7 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import logger
|
||||
from onionrutils import stringvalidators
|
||||
|
||||
def lookup_new_peer_transports_with_communicator(comm_inst):
|
||||
logger.info('Looking up new addresses...')
|
||||
|
@ -39,7 +40,7 @@ def lookup_new_peer_transports_with_communicator(comm_inst):
|
|||
invalid = []
|
||||
for x in newPeers:
|
||||
x = x.strip()
|
||||
if not comm_inst._core._utils.validateID(x) or x in comm_inst.newPeers or x == comm_inst._core.hsAddress:
|
||||
if not stringvalidators.validate_transport(x) or x in comm_inst.newPeers or x == comm_inst._core.hsAddress:
|
||||
# avoid adding if its our address
|
||||
invalid.append(x)
|
||||
for x in invalid:
|
||||
|
|
|
@ -20,17 +20,19 @@
|
|||
'''
|
||||
import logger
|
||||
from utils import netutils
|
||||
from onionrutils import localcommand
|
||||
def net_check(comm_inst):
|
||||
'''Check if we are connected to the internet or not when we can't connect to any peers'''
|
||||
rec = False # for detecting if we have received incoming connections recently
|
||||
c = comm_inst._core
|
||||
if len(comm_inst.onlinePeers) == 0:
|
||||
try:
|
||||
if (comm_inst._core._utils.getEpoch() - int(comm_inst._core._utils.localCommand('/lastconnect'))) <= 60:
|
||||
if (c._utils.getEpoch() - int(localcommand.local_command(c, '/lastconnect'))) <= 60:
|
||||
comm_inst.isOnline = True
|
||||
rec = True
|
||||
except ValueError:
|
||||
pass
|
||||
if not rec and not netutils.checkNetwork(comm_inst._core._utils, torPort=comm_inst.proxyPort):
|
||||
if not rec and not netutils.checkNetwork(c._utils, torPort=comm_inst.proxyPort):
|
||||
if not comm_inst.shutdown:
|
||||
logger.warn('Network check failed, are you connected to the Internet, and is Tor working?')
|
||||
comm_inst.isOnline = False
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import communicator, onionrblockapi
|
||||
from onionrutils import stringvalidators
|
||||
|
||||
def service_creator(daemon):
|
||||
assert isinstance(daemon, communicator.OnionrCommunicatorDaemon)
|
||||
core = daemon._core
|
||||
|
@ -30,7 +32,7 @@ def service_creator(daemon):
|
|||
if not b in daemon.active_services:
|
||||
bl = onionrblockapi.Block(b, core=core, decrypt=True)
|
||||
bs = utils.bytesToStr(bl.bcontent) + '.onion'
|
||||
if utils.validatePubKey(bl.signer) and utils.validateID(bs):
|
||||
if utils.validatePubKey(bl.signer) and stringvalidators.validate_transport(bs):
|
||||
signer = utils.bytesToStr(bl.signer)
|
||||
daemon.active_services.append(b)
|
||||
daemon.active_services.append(signer)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
import logger
|
||||
from communicatorutils import proxypicker
|
||||
import onionrblockapi as block
|
||||
from onionrutils import localcommand
|
||||
|
||||
def upload_blocks_from_communicator(comm_inst):
|
||||
# when inserting a block, we try to upload it to a few peers to add some deniability
|
||||
|
@ -42,7 +43,7 @@ def upload_blocks_from_communicator(comm_inst):
|
|||
proxyType = proxypicker.pick_proxy(peer)
|
||||
logger.info("Uploading block to " + peer)
|
||||
if not comm_inst._core._utils.doPostRequest(url, data=data, proxyType=proxyType) == False:
|
||||
comm_inst._core._utils.localCommand('waitforshare/' + bl, post=True)
|
||||
localcommand.local_command(comm_inst._core, 'waitforshare/' + bl, post=True)
|
||||
finishedUploads.append(bl)
|
||||
for x in finishedUploads:
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue