added block type filter for public get blocks endpoint

master
Kevin Froman 2020-09-25 05:17:08 +00:00
parent 02cdbc75ce
commit 68a557daf5
4 changed files with 29 additions and 26 deletions

View File

@ -9,6 +9,7 @@ from onionrutils import bytesconverter, stringvalidators
from coredb import blockmetadb from coredb import blockmetadb
from utils import reconstructhash from utils import reconstructhash
from onionrblocks import BlockList from onionrblocks import BlockList
from onionrblocks.onionrblockapi import Block
from .. import apiutils from .. import apiutils
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -26,28 +27,32 @@ from .. import apiutils
""" """
def get_public_block_list(publicAPI, request): def get_public_block_list(public_API, request):
# Provide a list of our blocks, with a date offset # Provide a list of our blocks, with a date offset
dateAdjust = request.args.get('date') date_adjust = request.args.get('date')
bList = blockmetadb.get_block_list(date_rec=dateAdjust) type_filter = request.args.get('type')
b_list = blockmetadb.get_block_list(date_rec=date_adjust)
share_list = '' share_list = ''
if config.get('general.hide_created_blocks', True): if config.get('general.hide_created_blocks', True):
for b in publicAPI.hideBlocks: for b in public_API.hideBlocks:
if b in bList: if b in b_list:
# Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block
bList.remove(b) b_list.remove(b)
for b in bList: for b in b_list:
if type_filter:
if Block(b, decrypt=False).getType() != type_filter:
continue
share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),) share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),)
return Response(share_list) return Response(share_list)
def get_block_data(publicAPI, data): def get_block_data(public_API, data):
"""data is the block hash in hex""" """data is the block hash in hex"""
resp = '' resp = ''
if stringvalidators.validate_hash(data): if stringvalidators.validate_hash(data):
if not config.get('general.hide_created_blocks', True) \ if not config.get('general.hide_created_blocks', True) \
or data not in publicAPI.hideBlocks: or data not in public_API.hideBlocks:
if data in publicAPI._too_many.get(BlockList).get(): if data in public_API._too_many.get(BlockList).get():
block = apiutils.GetBlockData().get_block_data( block = apiutils.GetBlockData().get_block_data(
data, raw=True, decrypt=False) data, raw=True, decrypt=False)
try: try:

View File

@ -116,7 +116,6 @@ class SubprocessPOW:
metadata['n'] = secrets.randbits(16) metadata['n'] = secrets.randbits(16)
puzzle = self.puzzle puzzle = self.puzzle
difficulty = self.difficulty difficulty = self.difficulty
start = time.time()
while True: while True:
# Break if shutdown received # Break if shutdown received
@ -136,6 +135,5 @@ class SubprocessPOW:
token = bytesconverter.bytes_to_str(token) token = bytesconverter.bytes_to_str(token)
if puzzle == token[0:difficulty]: if puzzle == token[0:difficulty]:
pipe.send(payload) pipe.send(payload)
print(metadata['pow'], time.time() - start)
break break
nonce += 1 nonce += 1

View File

@ -1,9 +1,12 @@
''' """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
Load the user's inbox and return it as a list Load the user's inbox and return it as a list
''' """
''' from onionrblocks import onionrblockapi
from coredb import blockmetadb
from utils import reconstructhash, identifyhome
import deadsimplekv as simplekv
"""
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -16,12 +19,9 @@
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/>.
''' """
from onionrblocks import onionrblockapi
from coredb import blockmetadb
import filepaths
from utils import reconstructhash, identifyhome
import deadsimplekv as simplekv
def load_inbox(): def load_inbox():
inbox_list = [] inbox_list = []
deleted = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat').get('deleted_mail') deleted = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat').get('deleted_mail')

View File

@ -14,8 +14,8 @@
"hide_created_blocks": true, "hide_created_blocks": true,
"insert_deniable_blocks": true, "insert_deniable_blocks": true,
"max_block_age": 2678400, "max_block_age": 2678400,
"minimum_block_pow": 6, "minimum_block_pow": 4,
"minimum_send_pow": 6, "minimum_send_pow": 4,
"public_key": "", "public_key": "",
"random_bind_ip": true, "random_bind_ip": true,
"security_level": 0, "security_level": 0,