improve formatting in removeblock and blacklist
parent
787c733785
commit
85be8f76e5
|
@ -1,9 +1,15 @@
|
||||||
'''
|
"""Onionr - Private P2P Communication.
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
This file handles maintenence of a blacklist database, for blocks and peers
|
Handle maintenence of a blacklist database, for blocks and peers
|
||||||
'''
|
"""
|
||||||
'''
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
from onionrplugins.onionrevents import event
|
||||||
|
import onionrcrypto
|
||||||
|
from onionrutils import epoch, bytesconverter
|
||||||
|
from coredb import dbfiles
|
||||||
|
"""
|
||||||
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,11 +22,8 @@
|
||||||
|
|
||||||
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 sqlite3, os
|
|
||||||
import logger, onionrcrypto
|
|
||||||
from onionrutils import epoch, bytesconverter
|
|
||||||
from coredb import dbfiles
|
|
||||||
|
|
||||||
class OnionrBlackList:
|
class OnionrBlackList:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -57,7 +60,7 @@ class OnionrBlackList:
|
||||||
return
|
return
|
||||||
|
|
||||||
def deleteExpired(self, dataType=0):
|
def deleteExpired(self, dataType=0):
|
||||||
'''Delete expired entries'''
|
"""Delete expired entries"""
|
||||||
deleteList = []
|
deleteList = []
|
||||||
curTime = epoch.get_epoch()
|
curTime = epoch.get_epoch()
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@ class OnionrBlackList:
|
||||||
return
|
return
|
||||||
|
|
||||||
def clearDB(self):
|
def clearDB(self):
|
||||||
self._dbExecute('''DELETE FROM blacklist;''')
|
self._dbExecute("""DELETE FROM blacklist;""")
|
||||||
|
|
||||||
def getList(self):
|
def getList(self):
|
||||||
data = self._dbExecute('SELECT * FROM blacklist')
|
data = self._dbExecute('SELECT * FROM blacklist')
|
||||||
|
@ -88,11 +91,11 @@ class OnionrBlackList:
|
||||||
return myList
|
return myList
|
||||||
|
|
||||||
def addToDB(self, data, dataType=0, expire=0):
|
def addToDB(self, data, dataType=0, expire=0):
|
||||||
'''Add to the blacklist. Intended to be block hash, block data, peers, or transport addresses
|
"""Add to the blacklist. Intended to be block hash, block data, peers, or transport addresses
|
||||||
0=block
|
0=block
|
||||||
1=peer
|
1=peer
|
||||||
2=pubkey
|
2=pubkey
|
||||||
'''
|
"""
|
||||||
|
|
||||||
# we hash the data so we can remove data entirely from our node's disk
|
# we hash the data so we can remove data entirely from our node's disk
|
||||||
hashed = bytesconverter.bytes_to_str(onionrcrypto.hashers.sha3_hash(data))
|
hashed = bytesconverter.bytes_to_str(onionrcrypto.hashers.sha3_hash(data))
|
||||||
|
|
|
@ -1,14 +1,34 @@
|
||||||
|
"""Onionr - Private P2P Communication.
|
||||||
|
|
||||||
|
remove onionr block from meta db
|
||||||
|
"""
|
||||||
import sys, sqlite3
|
import sys, sqlite3
|
||||||
import onionrexceptions, onionrstorage
|
import onionrexceptions, onionrstorage
|
||||||
from onionrutils import stringvalidators
|
from onionrutils import stringvalidators
|
||||||
from coredb import dbfiles
|
from coredb import dbfiles
|
||||||
from onionrblocks import storagecounter
|
from onionrblocks import storagecounter
|
||||||
|
"""
|
||||||
|
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/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def remove_block(block):
|
def remove_block(block):
|
||||||
'''
|
"""
|
||||||
remove a block from this node (does not automatically blacklist)
|
remove a block from this node (does not automatically blacklist)
|
||||||
|
|
||||||
**You may want blacklist.addToDB(blockHash)
|
**You may want blacklist.addToDB(blockHash)
|
||||||
'''
|
"""
|
||||||
|
|
||||||
if stringvalidators.validate_hash(block):
|
if stringvalidators.validate_hash(block):
|
||||||
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
|
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
|
||||||
|
|
Loading…
Reference in New Issue