work on new communicator with downloading new blocks
parent
31a35472ce
commit
a4824d9b8c
|
@ -125,7 +125,7 @@ class API:
|
||||||
except:
|
except:
|
||||||
data = ''
|
data = ''
|
||||||
startTime = math.floor(time.time())
|
startTime = math.floor(time.time())
|
||||||
# we should keep a hash DB of requests (with hmac) to prevent replays
|
|
||||||
action = request.args.get('action')
|
action = request.args.get('action')
|
||||||
#if not self.debug:
|
#if not self.debug:
|
||||||
token = request.args.get('token')
|
token = request.args.get('token')
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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
|
import onionrexceptions
|
||||||
from defusedxml import minidom
|
from defusedxml import minidom
|
||||||
|
|
||||||
|
@ -93,7 +93,16 @@ class OnionrCommunicatorDaemon:
|
||||||
for blockHash in self.blockQueue:
|
for blockHash in self.blockQueue:
|
||||||
content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash)
|
content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash)
|
||||||
if content != False:
|
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
|
return
|
||||||
|
|
||||||
def pickOnlinePeer(self):
|
def pickOnlinePeer(self):
|
||||||
|
|
|
@ -209,6 +209,22 @@ class OnionrUtils:
|
||||||
|
|
||||||
return pass1
|
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=''):
|
def checkPort(self, port, host=''):
|
||||||
'''
|
'''
|
||||||
Checks if a port is available, returns bool
|
Checks if a port is available, returns bool
|
||||||
|
|
Loading…
Reference in New Issue