2020-01-28 08:15:11 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
|
|
|
|
|
|
|
remove onionr block from meta db
|
|
|
|
"""
|
2020-03-26 08:57:54 +00:00
|
|
|
import sys
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
import onionrexceptions
|
|
|
|
import onionrstorage
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import stringvalidators
|
2019-07-19 19:49:56 +00:00
|
|
|
from coredb import dbfiles
|
2019-09-21 23:49:24 +00:00
|
|
|
from onionrblocks import storagecounter
|
2020-01-28 08:15:11 +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-07-19 19:49:56 +00:00
|
|
|
def remove_block(block):
|
2020-03-28 01:03:30 +00:00
|
|
|
"""Remove a block from this node.
|
2019-06-22 22:54:41 +00:00
|
|
|
|
2020-03-28 01:03:30 +00:00
|
|
|
(does not automatically blacklist).
|
2020-03-26 08:57:54 +00:00
|
|
|
**You may want blacklist.addToDB(blockHash)
|
2020-01-28 08:15:11 +00:00
|
|
|
"""
|
2019-06-25 23:07:35 +00:00
|
|
|
if stringvalidators.validate_hash(block):
|
2019-07-28 05:33:26 +00:00
|
|
|
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
|
2019-06-22 22:54:41 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
t = (block,)
|
|
|
|
c.execute('Delete from hashes where hash=?;', t)
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
2019-07-19 19:49:56 +00:00
|
|
|
dataSize = sys.getsizeof(onionrstorage.getData(block))
|
2019-09-08 09:48:16 +00:00
|
|
|
storagecounter.StorageCounter().remove_bytes(dataSize)
|
2019-06-22 22:54:41 +00:00
|
|
|
else:
|
2019-10-14 00:56:14 +00:00
|
|
|
raise onionrexceptions.InvalidHexHash
|