parent
160469f50f
commit
1bd0aa9419
@ -0,0 +1,27 @@ |
||||
import os |
||||
from shutil import move |
||||
|
||||
from onionrblocks import insert |
||||
from onionrstorage import deleteBlock |
||||
from onionrcommands.exportblocks import export_block |
||||
from filepaths import export_location, block_data_location, data_nonce_file |
||||
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT |
||||
from onionrstorage.removeblock import remove_block |
||||
from onionrstorage import deleteBlock |
||||
from coredb.blockmetadb import get_block_list |
||||
from utils import bettersleep |
||||
from gevent import sleep |
||||
|
||||
def test_sneakernet_import(test_manager): |
||||
in_db = lambda b: b in get_block_list() |
||||
bl = insert(os.urandom(10)) |
||||
assert in_db(bl) |
||||
export_block(bl) |
||||
assert os.path.exists(export_location + bl + BLOCK_EXPORT_FILE_EXT) |
||||
remove_block(bl) |
||||
deleteBlock(bl) |
||||
assert not in_db(bl) |
||||
os.remove(data_nonce_file) |
||||
move(export_location + bl + BLOCK_EXPORT_FILE_EXT, block_data_location) |
||||
sleep(1) |
||||
assert in_db(bl) |
@ -0,0 +1,54 @@ |
||||
"""Onionr - Private P2P Communication. |
||||
|
||||
Detect new block files in a given directory |
||||
""" |
||||
import os |
||||
|
||||
from watchdog.observers import Observer |
||||
from watchdog.events import FileSystemEventHandler |
||||
|
||||
import config |
||||
from filepaths import block_data_location |
||||
from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT |
||||
from onionrblocks.blockimporter import import_block_from_data |
||||
""" |
||||
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/>. |
||||
""" |
||||
|
||||
watch_paths = config.get('transports.sneakernet.paths', list([])) |
||||
if block_data_location not in watch_paths: |
||||
watch_paths.append(block_data_location) |
||||
|
||||
|
||||
class _Importer(FileSystemEventHandler): |
||||
@staticmethod |
||||
def on_created(event): |
||||
if not event.src_path.endswith(BLOCK_EXPORT_FILE_EXT): |
||||
return |
||||
with open(event.src_path, 'rb') as block_file: |
||||
import_block_from_data(block_file.read()) |
||||
if block_data_location in event.src_path: |
||||
try: |
||||
os.remove(event.src_path) |
||||
except FileNotFoundError: |
||||
pass |
||||
|
||||
|
||||
def sneakernet_import_thread(): |
||||
observer = Observer() |
||||
for path in watch_paths: |
||||
observer.schedule(_Importer(), path, recursive=True) |
||||
observer.start() |
||||
while observer.isAlive(): |
||||
observer.join(60) |
@ -1,5 +0,0 @@ |
||||
{ |
||||
"name" : "metadataprocessor", |
||||
"version" : "1.0", |
||||
"author" : "onionr" |
||||
} |
@ -1,59 +0,0 @@ |
||||
''' |
||||
Onionr - Private P2P Communication |
||||
|
||||
This processes metadata for 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/>. |
||||
''' |
||||
|
||||
# useful libraries |
||||
import logger, config |
||||
import os, sys, json, time, random, shutil, base64, getpass, datetime, re |
||||
import onionrusers, onionrexceptions |
||||
from onionrutils import stringvalidators |
||||
|
||||
plugin_name = 'metadataprocessor' |
||||
|
||||
# event listeners |
||||
|
||||
def _processForwardKey(api, myBlock): |
||||
''' |
||||
Get the forward secrecy key specified by the user for us to use |
||||
''' |
||||
peer = onionrusers.OnionrUser(myBlock.signer) |
||||
key = myBlock.getMetadata('newFSKey') |
||||
|
||||
# We don't need to validate here probably, but it helps |
||||
if stringvalidators.validate_pub_key(key): |
||||
peer.addForwardKey(key) |
||||
else: |
||||
raise onionrexceptions.InvalidPubkey("%s is not a valid pubkey key" % (key,)) |
||||
|
||||
def on_processblocks(api, data=None): |
||||
# Generally fired by utils. |
||||
myBlock = api.data['block'] |
||||
blockType = api.data['type'] |
||||
# Process specific block types |
||||
|
||||
# forwardKey blocks, add a new forward secrecy key for a peer |
||||
if blockType == 'forwardKey': |
||||
if api.data['validSig'] == True: |
||||
_processForwardKey(api, myBlock) |
||||
|
||||
def on_init(api, data = None): |
||||
|
||||
pluginapi = api |
||||
|
||||
return |
@ -1 +1 @@ |
||||
1585525008 |
||||
1585619396 |
Loading…
Reference in new issue