boiler plate and bug fixes

This commit is contained in:
Kevin Froman 2019-11-15 22:18:38 -06:00
parent 15b3d506ff
commit 6cc01fa240
14 changed files with 102 additions and 12 deletions

View file

@ -19,6 +19,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import sys, os, time
import config, logger
import onionrexceptions, onionrpeers
from onionrblocks import onionrblockapi as block

View file

@ -55,6 +55,9 @@ BLOCK_METADATA_LENGTHS = {'meta': 1000, 'sig': 200, 'signer': 200, 'time': 10, '
"""Public key that signs MOTD messages shown in the web UI"""
MOTD_SIGN_KEY = "TRH763JURNY47QPBTTQ4LLPYCYQK6Q5YA33R6GANKZK5C5DKCIGQ"
"""Public key that signs update notifications."""
UPDATE_SIGN_KEY = "TRH763JURNY47QPBTTQ4LLPYCYQK6Q5YA33R6GANKZK5C5DKCIGQ"
platform = platform.system()
if platform == 'Windows':
SCRIPT_NAME = 'run-windows.bat'

View file

@ -46,4 +46,4 @@ def accept_upload(request):
resp = Response(resp, 400)
else:
resp = Response(resp)
return resp
return resp

View file

@ -1,3 +1,22 @@
"""
Onionr - Private P2P Communication
Read onionr site files
"""
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from typing import Union, Tuple
import tarfile
import io

View file

@ -1,4 +0,0 @@
import zipfile
def get_zip_site_file(path):
with zipfile.ZipFile(zip_file, 'r') as zf:
for member in zf.infolist():

View file

@ -1,5 +1,25 @@
"""
Onionr - Private P2P Communication
Create and insert Onionr blocks
"""
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from typing import Union
import json
from onionrutils import bytesconverter, epoch
import filepaths, onionrstorage
from . import storagecounter

View file

@ -23,6 +23,7 @@ import subprocess
import platform
from etc import onionrvalues
from etc import cleanup
from onionrutils import localcommand
import logger
import filepaths
@ -38,7 +39,9 @@ def restart():
try:
pid = os.fork()
if pid != 0: return
except (AttributeError, OSError) as e: pass
except (AttributeError, OSError) as e:
if platform.platform() != 'Windows':
logger.warn('Could not fork on restart')
daemonlaunch.kill_daemon()
while localcommand.local_command('ping', maxWait=8) == 'pong!':
@ -46,6 +49,8 @@ def restart():
time.sleep(15)
while os.path.exists(filepaths.private_API_host_file) or os.path.exists(filepaths.daemon_mark_file):
time.sleep(1)
cleanup.delete_run_files()
subprocess.Popen([SCRIPT_NAME, 'start'])
restart.onionr_help = 'Gracefully restart Onionr'

View file

@ -51,6 +51,9 @@ class SignatureError(Exception):
class ReplayAttack(Exception):
pass
class InvalidUpdate(Exception):
pass
class DifficultyTooLarge(Exception):
pass

View file

@ -5,4 +5,6 @@ UserIDSecretKey = NewType('UserIDSecretKey', str)
DeterministicKeyPassphrase = NewType('DeterministicKeyPassphrase', str)
BlockHash = NewType('BlockHash', str)
BlockHash = NewType('BlockHash', str)
RestartRequiredStatus = NewType('RestartRequiredStatus', bool)

View file

@ -26,6 +26,7 @@ import logger
from onionrplugins import onionrevents
import onionrexceptions
from onionrusers import onionrusers
from onionrutils import updater
def process_block_metadata(blockHash: str):
'''
@ -67,4 +68,5 @@ def process_block_metadata(blockHash: str):
expireTime = min(expireTime, curTime + onionrvalues.DEFAULT_EXPIRE)
blockmetadb.update_block_info(blockHash, 'expire', expireTime)
if blockType == 'update': updater.update_event(myBlock)
onionrevents.event('processblocks', data = {'block': myBlock, 'type': blockType, 'signer': signer, 'validSig': valid})

View file

@ -0,0 +1,29 @@
"""
Onionr - Private P2P Communication
Lib to keep Onionr up to date
"""
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from onionrtypes import RestartRequiredStatus
from onionrblocks.onionrblockapi import Block
from etc import onionrvalues
import onionrexceptions
import notifier
def update_event(bl: Block)->RestartRequiredStatus:
"""Show update notification if available, return bool of if update happend"""
if not bl.isSigner(onionrvalues.UPDATE_SIGN_KEY): raise onionrexceptions.InvalidUpdate
notifier.notify(message="A new Onionr update is available. Stay updated to remain secure.")