work on block insertion mixing
This commit is contained in:
parent
87ea8d137b
commit
01f9b9b470
12 changed files with 183 additions and 40 deletions
|
@ -1,3 +1,5 @@
|
|||
from . import insert
|
||||
from .insert import time_insert
|
||||
|
||||
insert = insert.insert_block
|
||||
insert = insert.insert_block
|
||||
time_insert = time_insert
|
4
src/onionrblocks/insert/__init__.py
Normal file
4
src/onionrblocks/insert/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import main, timeinsert
|
||||
|
||||
insert_block = main.insert_block
|
||||
time_insert = timeinsert.time_insert
|
|
@ -22,7 +22,7 @@ import json
|
|||
|
||||
from onionrutils import bytesconverter, epoch
|
||||
import filepaths, onionrstorage
|
||||
from . import storagecounter
|
||||
from .. import storagecounter
|
||||
from onionrplugins import onionrevents as events
|
||||
from etc import powchoice, onionrvalues
|
||||
import config, onionrcrypto as crypto, onionrexceptions
|
51
src/onionrblocks/insert/timeinsert.py
Normal file
51
src/onionrblocks/insert/timeinsert.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Wrapper to insert blocks with variable delay
|
||||
"""
|
||||
from . import main
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
|
||||
def time_insert(*args, **kwargs):
|
||||
"""Block insert wrapper to allow for insertions independent of mixmate.
|
||||
|
||||
Takes exact args as insert_block, with additional keyword:
|
||||
delay=n; where n=seconds to tell initial nodes to delay share for.
|
||||
|
||||
defaults to 0 or previously set value in current block meta
|
||||
"""
|
||||
try:
|
||||
kwargs['meta']
|
||||
except KeyError:
|
||||
kwargs['meta'] = {}
|
||||
|
||||
try:
|
||||
delay = int(kwargs['meta']['dly'])
|
||||
except KeyError:
|
||||
delay = 0
|
||||
try:
|
||||
delay = kwargs['delay']
|
||||
del kwargs['delay']
|
||||
except KeyError:
|
||||
delay = 0
|
||||
|
||||
# Ensure delay >=0
|
||||
if delay < 0:
|
||||
raise ValueError('delay cannot be less than 0')
|
||||
|
||||
kwargs['meta']['dly'] = delay
|
||||
|
||||
return main.insert_block(*args, **kwargs)
|
Loading…
Add table
Add a link
Reference in a new issue