2019-12-23 07:51:24 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-07-09 06:25:20 +00:00
|
|
|
|
2019-12-23 07:51:24 +00:00
|
|
|
Check if a block should be downloaded
|
|
|
|
(if we already have it or its blacklisted or not)
|
|
|
|
"""
|
|
|
|
from coredb import blockmetadb
|
|
|
|
from onionrblocks import onionrblacklist
|
|
|
|
"""
|
2019-07-09 06:25:20 +00:00
|
|
|
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/>.
|
2019-12-23 07:51:24 +00:00
|
|
|
"""
|
|
|
|
|
2019-09-21 23:49:24 +00:00
|
|
|
|
2020-11-15 18:26:25 +00:00
|
|
|
def should_download(shared_state, block_hash) -> bool:
|
2019-12-23 07:51:24 +00:00
|
|
|
"""Return bool for if a (assumed to exist) block should be downloaded."""
|
2019-07-22 05:24:42 +00:00
|
|
|
blacklist = onionrblacklist.OnionrBlackList()
|
2019-12-23 07:51:24 +00:00
|
|
|
should = True
|
2020-11-15 18:26:25 +00:00
|
|
|
kv: "DeadSimpleKV" = shared_state.get_by_string("DeadSimpleKV")
|
2019-12-23 07:51:24 +00:00
|
|
|
if block_hash in blockmetadb.get_block_list():
|
|
|
|
# Don't download block we have
|
|
|
|
should = False
|
2019-07-09 06:25:20 +00:00
|
|
|
else:
|
2019-12-23 07:51:24 +00:00
|
|
|
if blacklist.inBlacklist(block_hash):
|
|
|
|
# Don't download blacklisted block
|
|
|
|
should = False
|
|
|
|
if should is False:
|
|
|
|
# Remove block from communicator queue if it shouldn't be downloaded
|
2019-07-09 06:25:20 +00:00
|
|
|
try:
|
2020-07-24 19:37:01 +00:00
|
|
|
del kv.get('blockQueue')[block_hash]
|
2019-07-09 06:25:20 +00:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2019-12-23 07:51:24 +00:00
|
|
|
return should
|