refactored onionr commands and other small adjustments

master
Kevin Froman 2019-06-01 11:54:36 -05:00
parent 7e85b4a995
commit 3322778ff4
7 changed files with 96 additions and 50 deletions

View File

@ -40,7 +40,7 @@ Project maintainers who do not follow or enforce the Code of Conduct in good fai
## Attribution ## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org [homepage]: https://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/ [version]: https://contributor-covenant.org/version/1/4/

View File

@ -5,7 +5,7 @@
</p> </p>
<p align="center"> <p align="center">
Anonymous P2P communication network 🕵️ Private P2P Communication network 🕵️
</p> </p>
(***pre-alpha & experimental, not well tested or easy to use yet***) (***pre-alpha & experimental, not well tested or easy to use yet***)
@ -19,7 +19,7 @@
# About # About
Onionr is a decentralized, peer-to-peer communication and storage network, designed to be anonymous and resistant to (meta)data analysis and spam/disruption. Onionr is a decentralized, peer-to-peer communication and storage network, designed to be anonymous and resistant to (meta)data analysis, spam, and corruption.
Onionr stores data in independent packages referred to as 'blocks'. The blocks are synced to all other nodes in the network. Blocks and user IDs cannot be easily proven to have been created by a particular user. Even if there is enough evidence to believe that a specific user created a block, nodes still operate behind Tor or I2P and as such cannot be trivially unmasked. Onionr stores data in independent packages referred to as 'blocks'. The blocks are synced to all other nodes in the network. Blocks and user IDs cannot be easily proven to have been created by a particular user. Even if there is enough evidence to believe that a specific user created a block, nodes still operate behind Tor or I2P and as such cannot be trivially unmasked.

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
''' '''
Onionr - P2P Anonymous Storage Network Onionr - Private P2P Communication
Onionr is the name for both the protocol and the original/reference software. This file initializes Onionr when ran to be a daemon or with commands
Run with 'help' for usage. Run with 'help' for usage.
''' '''
@ -23,14 +23,14 @@
import sys import sys
MIN_PY_VERSION = 6 MIN_PY_VERSION = 6
if sys.version_info[0] == 2 or sys.version_info[1] < MIN_PY_VERSION: if sys.version_info[0] == 2 or sys.version_info[1] < MIN_PY_VERSION:
print('Error, Onionr requires Python 3.%s+' % (MIN_PY_VERSION,)) sys.stderr.write('Error, Onionr requires Python 3.%s+' % (MIN_PY_VERSION,))
sys.exit(1) sys.exit(1)
import os, base64, random, getpass, shutil, time, platform, datetime, re, json, getpass, sqlite3 import os, base64, random, getpass, shutil, time, platform, datetime, re, json, getpass, sqlite3
import webbrowser, uuid, signal import webbrowser, uuid, signal
from threading import Thread from threading import Thread
import api, core, config, logger, onionrplugins as plugins, onionrevents as events import api, core, config, logger, onionrplugins as plugins, onionrevents as events
import onionrutils import onionrutils
import netcontroller, onionrstorage import netcontroller
from netcontroller import NetController from netcontroller import NetController
from onionrblockapi import Block from onionrblockapi import Block
import onionrproofs, onionrexceptions, communicator, setupconfig import onionrproofs, onionrexceptions, communicator, setupconfig
@ -42,7 +42,7 @@ try:
except ImportError: except ImportError:
raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)") raise Exception("You need the PySocks module (for use with socks5 proxy to use Tor)")
ONIONR_TAGLINE = 'Anonymous P2P Platform - GPLv3 - https://Onionr.net' ONIONR_TAGLINE = 'Private P2P Communication - GPLv3 - https://Onionr.net'
ONIONR_VERSION = '0.0.0' # for debugging and stuff ONIONR_VERSION = '0.0.0' # for debugging and stuff
ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION) ONIONR_VERSION_TUPLE = tuple(ONIONR_VERSION.split('.')) # (MAJOR, MINOR, VERSION)
API_VERSION = '0' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you. API_VERSION = '0' # increments of 1; only change when something fundamental about how the API works changes. This way other nodes know how to communicate without learning too much information about you.
@ -165,17 +165,6 @@ class Onionr:
if not message is None: if not message is None:
logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True) logger.info(logger.colors.fg.lightgreen + '-> ' + str(message) + logger.colors.reset + logger.colors.fg.lightgreen + ' <-\n', sensitive=True)
def doExport(self, bHash):
exportDir = self.dataDir + 'block-export/'
if not os.path.exists(exportDir):
if os.path.exists(self.dataDir):
os.mkdir(exportDir)
else:
logger.error('Onionr Not initialized')
data = onionrstorage.getData(self.onionrCore, bHash)
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
exportFile.write(data)
def deleteRunFiles(self): def deleteRunFiles(self):
try: try:
os.remove(self.onionrCore.publicApiHostFile) os.remove(self.onionrCore.publicApiHostFile)
@ -211,19 +200,11 @@ class Onionr:
return columns return columns
''' '''
THIS SECTION HANDLES THE COMMANDS Handle command line commands
''' '''
def exportBlock(self): def exportBlock(self):
exportDir = self.dataDir + 'block-export/' commands.exportblocks(self)
try:
assert self.onionrUtils.validateHash(sys.argv[2])
except (IndexError, AssertionError):
logger.error('No valid block hash specified.')
sys.exit(1)
else:
bHash = sys.argv[2]
self.doExport(bHash)
def showDetails(self): def showDetails(self):
commands.onionrstatistics.show_details(self) commands.onionrstatistics.show_details(self)
@ -247,23 +228,7 @@ class Onionr:
commands.pubkeymanager.friend_command(self) commands.pubkeymanager.friend_command(self)
def banBlock(self): def banBlock(self):
try: commands.banblocks.ban_block(self)
ban = sys.argv[2]
except IndexError:
ban = logger.readline('Enter a block hash:')
if self.onionrUtils.validateHash(ban):
if not self.onionrCore._blacklist.inBlacklist(ban):
try:
self.onionrCore._blacklist.addToDB(ban)
self.onionrCore.removeBlock(ban)
except Exception as error:
logger.error('Could not blacklist block', error=error)
else:
logger.info('Block blacklisted')
else:
logger.warn('That block is already blacklisted')
else:
logger.error('Invalid block hash')
def listConn(self): def listConn(self):
commands.onionrstatistics.show_peers(self) commands.onionrstatistics.show_peers(self)

View File

@ -1,5 +1,5 @@
''' '''
Onionr - P2P Anonymous Storage Network Onionr - Private P2P Communication
This module defines commands for CLI usage This module defines commands for CLI usage
''' '''
@ -20,7 +20,7 @@
import webbrowser, sys import webbrowser, sys
import logger import logger
from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders from . import pubkeymanager, onionrstatistics, daemonlaunch, filecommands, plugincommands, keyadders, banblocks, exportblocks
def show_help(o_inst, command): def show_help(o_inst, command):

View File

@ -0,0 +1,39 @@
'''
Onionr - P2P Anonymous Storage Network
This file contains the command for banning blocks from the node
'''
'''
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 sys
import logger
def ban_block(o_inst):
try:
ban = sys.argv[2]
except IndexError:
ban = logger.readline('Enter a block hash:')
if o_inst.onionrUtils.validateHash(ban):
if not o_inst.onionrCore._blacklist.inBlacklist(ban):
try:
o_inst.onionrCore._blacklist.addToDB(ban)
o_inst.onionrCore.removeBlock(ban)
except Exception as error:
logger.error('Could not blacklist block', error=error)
else:
logger.info('Block blacklisted')
else:
logger.warn('That block is already blacklisted')
else:
logger.error('Invalid block hash')

View File

@ -0,0 +1,42 @@
'''
Onionr - Private P2P Communication
This file handles the command for exporting blocks to disk
'''
'''
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 sys
import logger, onionrstorage
def doExport(o_inst, bHash):
exportDir = o_inst.dataDir + 'block-export/'
if not os.path.exists(exportDir):
if os.path.exists(o_inst.dataDir):
os.mkdir(exportDir)
else:
logger.error('Onionr Not initialized')
data = onionrstorage.getData(o_inst.onionrCore, bHash)
with open('%s/%s.dat' % (exportDir, bHash), 'wb') as exportFile:
exportFile.write(data)
def export_block(o_inst):
exportDir = o_inst.dataDir + 'block-export/'
try:
assert o_inst.onionrUtils.validateHash(sys.argv[2])
except (IndexError, AssertionError):
logger.error('No valid block hash specified.')
sys.exit(1)
else:
bHash = sys.argv[2]
o_inst.doExport(bHash)

View File