diff --git a/onionr/communicator/__init__.py b/onionr/communicator/__init__.py index 95cb9c45..01c61c1e 100755 --- a/onionr/communicator/__init__.py +++ b/onionr/communicator/__init__.py @@ -21,7 +21,7 @@ import sys, os, time import config, logger import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block -from . import onlinepeers +from . import onlinepeers, uploadqueue from communicatorutils import servicecreator, onionrcommunicatortimers from communicatorutils import downloadblocks, lookupblocks, lookupadders from communicatorutils import servicecreator, connectnewpeers, uploadblocks @@ -93,6 +93,8 @@ class OnionrCommunicatorDaemon: # time app started running for info/statistics purposes self.startTime = epoch.get_epoch() + uploadqueue.UploadQueue(self) # extends our upload list and saves our list when Onionr exits + if developmentMode: OnionrCommunicatorTimers(self, self.heartbeat, 30) diff --git a/onionr/communicator/uploadqueue/__init__.py b/onionr/communicator/uploadqueue/__init__.py new file mode 100644 index 00000000..84f725f8 --- /dev/null +++ b/onionr/communicator/uploadqueue/__init__.py @@ -0,0 +1,58 @@ +''' + Onionr - Private P2P Communication + + Class to remember blocks that need to be uploaded and not shared on startup/shutdown +''' +''' + 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 . +''' + +import atexit +import json + +import deadsimplekv + +import filepaths +from onionrutils import localcommand + +UPLOAD_MEMORY_FILE = filepaths.upload_list + +def _add_to_hidden_blocks(cache): + for bl in cache: + localcommand.local_command('waitforshare/' + bl, post=True) + +class UploadQueue: + ''' + Saves and loads block upload info from json file + ''' + + def __init__(self, communicator: 'OnionrCommunicatorDaemon'): + self.communicator = communicator + cache = deadsimplekv.DeadSimpleKV(UPLOAD_MEMORY_FILE) + self.store_obj = cache + cache: list = cache.get('uploads') + + if cache == None: + cache = [] + + _add_to_hidden_blocks(cache) + self.communicator.blocksToUpload.extend(cache) + + atexit.register(self.save) + + def save(self): + bl: list = self.communicator.blocksToUpload + if len(bl) > 0: + self.store_obj.put('uploads', bl) + self.store_obj.flush() diff --git a/onionr/filepaths/__init__.py b/onionr/filepaths/__init__.py index 14006e90..59e13255 100644 --- a/onionr/filepaths/__init__.py +++ b/onionr/filepaths/__init__.py @@ -13,6 +13,7 @@ forward_keys_file = home + 'forward-keys.db' cached_storage = home + 'cachedstorage.dat' announce_cache = home + 'announcecache.dat' export_location = home + 'block-export/' +upload_list = home + 'upload-list.json' tor_hs_address_file = home + 'hs/hostname' diff --git a/onionr/static-data/bootstrap-nodes.txt b/onionr/static-data/bootstrap-nodes.txt index 0201f0fd..e69de29b 100755 --- a/onionr/static-data/bootstrap-nodes.txt +++ b/onionr/static-data/bootstrap-nodes.txt @@ -1 +0,0 @@ -3msj7fgyxgpfsjvvtcji7a4tkjbna6jmpealv6mun7435jjyptctfxyd.onion \ No newline at end of file