From 1e3768416305c3136154a60744681202e7b23648 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 10 Aug 2018 02:03:49 -0500 Subject: [PATCH] work on blacklisting data --- onionr/onionrblacklist.py | 62 +++++++++++++++++++++++++++++++++++++++ onionr/onionrutils.py | 13 ++++++++ 2 files changed, 75 insertions(+) create mode 100644 onionr/onionrblacklist.py diff --git a/onionr/onionrblacklist.py b/onionr/onionrblacklist.py new file mode 100644 index 00000000..7261cf4f --- /dev/null +++ b/onionr/onionrblacklist.py @@ -0,0 +1,62 @@ +''' + Onionr - P2P Microblogging Platform & Social network. + + This file handles maintenence of a blacklist database, for blocks and peers +''' +''' + 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 . +''' +import sqlite3, os +class OnionrBlackList: + def __init__(self, coreInst): + self.blacklistDB = 'data/blacklist.db' + self._core = coreInst + + if not os.path.exists(self.blacklistDB): + self.generateDB() + + return + + def inBlacklist(self, data): + return + + def _dbExecute(self, toExec): + conn = sqlite3.connect(self.blacklistDB) + c = conn.cursor() + c.execute(toExec) + conn.commit() + conn.close() + + def deleteBeforeDate(self, date): + # TODO, delete blacklist entries before date + return + + def generateDB(self): + self._dbExecute'''CREATE TABLE blacklist( + hash text primary key not null, + type text + ); + ''') + return + + def clearDB(self): + self._dbExecute('''delete from blacklist;);''') + + + def addToDB(self, data): + hashed = self._core._crypto.sha3Hash(data) + if not hashed.isalnum(): + raise Exception("Hashed data is not alpha numeric") + insert = (hashed,) + self._dbExecute('insert into blacklist (hash) VALUES(' + data + ');') diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index afa86ef6..e25e692c 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -597,6 +597,19 @@ class OnionrUtils: else: self.powSalt = retData return retData + + def strToBytes(self, data): + try: + data = data.encode() + except AttributeError: + pass + return data + def bytesToStr(self, data): + try: + data = data.decode() + except AttributeError: + pass + return data def size(path='.'): '''