added upload queue class to remember block inserts across restarts
parent
da2c6b5b9c
commit
97d04440ee
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
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()
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
3msj7fgyxgpfsjvvtcji7a4tkjbna6jmpealv6mun7435jjyptctfxyd.onion
|
Loading…
Reference in New Issue