work on new communicator with downloading new blocks

This commit is contained in:
Kevin Froman 2018-06-16 02:33:54 -05:00
parent 31a35472ce
commit a4824d9b8c
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 28 additions and 3 deletions

View File

@ -125,7 +125,7 @@ class API:
except:
data = ''
startTime = math.floor(time.time())
# we should keep a hash DB of requests (with hmac) to prevent replays
action = request.args.get('action')
#if not self.debug:
token = request.args.get('token')

View File

@ -19,7 +19,7 @@
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, os, core, config, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins
import sys, os, core, config, onionrblockapi as block, requests, time, logger, threading, onionrplugins as plugins, base64
import onionrexceptions
from defusedxml import minidom
@ -93,7 +93,16 @@ class OnionrCommunicatorDaemon:
for blockHash in self.blockQueue:
content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash)
if content != False:
newBlock = block.Block()
try:
content = content.encode()
except AttributeError:
pass
content = base64.b64decode(content).decode()
if self._core._crypto.sha3Hash(content) == blockHash:
metas = self._core._utils.getBlockMetadataFromData(content)
metadata = metas[0]
meta = metas[1]
#if self._core._crypto.verifyPow(metas[2], metas[1])
return
def pickOnlinePeer(self):

View File

@ -209,6 +209,22 @@ class OnionrUtils:
return pass1
def getBlockMetadataFromData(self, blockData):
'''
accepts block contents as string and returns a tuple of metadata, meta (meta being internal metadata)
'''
try:
blockData = blockData.encode()
except AttributeError:
pass
metadata = json.loads(blockData[:blockData.find(b'\n')].decode())
data = blockData[blockData.find(b'\n'):].decode()
try:
meta = json.loads(metadata['meta'])
except KeyError:
meta = {}
return (metadata, meta, data)
def checkPort(self, port, host=''):
'''
Checks if a port is available, returns bool