* moved metadata processor to its own module
* improved some comments * removed defunct utils functions
This commit is contained in:
parent
151b12424c
commit
ce2423e6d9
0
onionr/blockprocessor.py
Normal file
0
onionr/blockprocessor.py
Normal file
19
onionr/onionrsockets.py
Normal file
19
onionr/onionrsockets.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
'''
|
||||||
|
Onionr - P2P Anonymous Storage Network
|
||||||
|
|
||||||
|
Onionr Socket interface
|
||||||
|
'''
|
||||||
|
'''
|
||||||
|
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/>.
|
||||||
|
'''
|
@ -37,17 +37,20 @@ class OnionrUtils:
|
|||||||
Various useful functions for validating things, etc functions, connectivity
|
Various useful functions for validating things, etc functions, connectivity
|
||||||
'''
|
'''
|
||||||
def __init__(self, coreInstance):
|
def __init__(self, coreInstance):
|
||||||
self.fingerprintFile = 'data/own-fingerprint.txt'
|
#self.fingerprintFile = 'data/own-fingerprint.txt' #TODO Remove since probably not needed
|
||||||
self._core = coreInstance
|
self._core = coreInstance # onionr core instance
|
||||||
|
|
||||||
self.timingToken = ''
|
self.timingToken = '' # for when we make local connections to our http api, to bypass timing attack defense mechanism
|
||||||
self.avoidDupe = [] # list used to prevent duplicate requests per peer for certain actions
|
self.avoidDupe = [] # list used to prevent duplicate requests per peer for certain actions
|
||||||
self.peerProcessing = {} # dict of current peer actions: peer, actionList
|
self.peerProcessing = {} # dict of current peer actions: peer, actionList
|
||||||
self.storageCounter = storagecounter.StorageCounter(self._core)
|
self.storageCounter = storagecounter.StorageCounter(self._core) # used to keep track of how much data onionr is using on disk
|
||||||
config.reload()
|
config.reload() # onionr config
|
||||||
return
|
return
|
||||||
|
|
||||||
def getTimeBypassToken(self):
|
def getTimeBypassToken(self):
|
||||||
|
'''
|
||||||
|
Load our timingToken from disk for faster local HTTP API
|
||||||
|
'''
|
||||||
try:
|
try:
|
||||||
if os.path.exists('data/time-bypass.txt'):
|
if os.path.exists('data/time-bypass.txt'):
|
||||||
with open('data/time-bypass.txt', 'r') as bypass:
|
with open('data/time-bypass.txt', 'r') as bypass:
|
||||||
@ -64,22 +67,6 @@ class OnionrUtils:
|
|||||||
epoch = self.getEpoch()
|
epoch = self.getEpoch()
|
||||||
return epoch - (epoch % roundS)
|
return epoch - (epoch % roundS)
|
||||||
|
|
||||||
def incrementAddressSuccess(self, address):
|
|
||||||
'''
|
|
||||||
Increase the recorded sucesses for an address
|
|
||||||
'''
|
|
||||||
increment = self._core.getAddressInfo(address, 'success') + 1
|
|
||||||
self._core.setAddressInfo(address, 'success', increment)
|
|
||||||
return
|
|
||||||
|
|
||||||
def decrementAddressSuccess(self, address):
|
|
||||||
'''
|
|
||||||
Decrease the recorded sucesses for an address
|
|
||||||
'''
|
|
||||||
increment = self._core.getAddressInfo(address, 'success') - 1
|
|
||||||
self._core.setAddressInfo(address, 'success', increment)
|
|
||||||
return
|
|
||||||
|
|
||||||
def mergeKeys(self, newKeyList):
|
def mergeKeys(self, newKeyList):
|
||||||
'''
|
'''
|
||||||
Merge ed25519 key list to our database, comma seperated string
|
Merge ed25519 key list to our database, comma seperated string
|
||||||
@ -89,6 +76,7 @@ class OnionrUtils:
|
|||||||
if newKeyList != False:
|
if newKeyList != False:
|
||||||
for key in newKeyList.split(','):
|
for key in newKeyList.split(','):
|
||||||
key = key.split('-')
|
key = key.split('-')
|
||||||
|
# Test if key is valid
|
||||||
try:
|
try:
|
||||||
if len(key[0]) > 60 or len(key[1]) > 1000:
|
if len(key[0]) > 60 or len(key[1]) > 1000:
|
||||||
logger.warn('%s or its pow value is too large.' % key[0])
|
logger.warn('%s or its pow value is too large.' % key[0])
|
||||||
@ -100,15 +88,19 @@ class OnionrUtils:
|
|||||||
value = base64.b64decode(key[1])
|
value = base64.b64decode(key[1])
|
||||||
except binascii.Error:
|
except binascii.Error:
|
||||||
continue
|
continue
|
||||||
|
# Load the pow token
|
||||||
hashedKey = self._core._crypto.blake2bHash(key[0])
|
hashedKey = self._core._crypto.blake2bHash(key[0])
|
||||||
powHash = self._core._crypto.blake2bHash(value + hashedKey)
|
powHash = self._core._crypto.blake2bHash(value + hashedKey)
|
||||||
try:
|
try:
|
||||||
powHash = powHash.encode()
|
powHash = powHash.encode()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
# if POW meets required difficulty, TODO make configurable/dynamic
|
||||||
if powHash.startswith(b'0000'):
|
if powHash.startswith(b'0000'):
|
||||||
|
# if we don't already have the key and its not our key, add it.
|
||||||
if not key[0] in self._core.listPeers(randomOrder=False) and type(key) != None and key[0] != self._core._crypto.pubKey:
|
if not key[0] in self._core.listPeers(randomOrder=False) and type(key) != None and key[0] != self._core._crypto.pubKey:
|
||||||
if self._core.addPeer(key[0], key[1]):
|
if self._core.addPeer(key[0], key[1]):
|
||||||
|
# Check if the peer has a set username already
|
||||||
onionrusers.OnionrUser(self._core, key[0]).findAndSetID()
|
onionrusers.OnionrUser(self._core, key[0]).findAndSetID()
|
||||||
retVal = True
|
retVal = True
|
||||||
else:
|
else:
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name" : "metadataprocessor",
|
||||||
|
"version" : "1.0",
|
||||||
|
"author" : "onionr"
|
||||||
|
}
|
52
onionr/static-data/default-plugins/metadataprocessor/main.py
Normal file
52
onionr/static-data/default-plugins/metadataprocessor/main.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
'''
|
||||||
|
Onionr - P2P Anonymous Storage Network
|
||||||
|
|
||||||
|
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
|
||||||
|
from onionrblockapi import Block
|
||||||
|
|
||||||
|
plugin_name = 'metadataprocessor'
|
||||||
|
|
||||||
|
# event listeners
|
||||||
|
|
||||||
|
def on_processBlocks(api):
|
||||||
|
myBlock = api.data['block']
|
||||||
|
blockType = api.data['type']
|
||||||
|
print('blockType is ' + blockType)
|
||||||
|
if blockType == 'userInfo':
|
||||||
|
if myBlock.verifySig():
|
||||||
|
peerName = myBlock.getMetadata('name')
|
||||||
|
try:
|
||||||
|
if len(peerName) > 20:
|
||||||
|
raise onionrexceptions.InvalidMetdata('Peer name specified is too large')
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
except onionrexceptions.InvalidMetadata:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
api.get_core().setPeerInfo(signer, 'name', peerName)
|
||||||
|
logger.info('%s is now using the name %s.' % (signer, api.get_utils().escapeAnsi(peerName)))
|
||||||
|
|
||||||
|
def on_init(api, data = None):
|
||||||
|
|
||||||
|
pluginapi = api
|
||||||
|
|
||||||
|
return
|
Loading…
Reference in New Issue
Block a user