work on peer blacklisting/profiling\nupdated readme

This commit is contained in:
Kevin Froman 2018-08-14 00:02:34 -05:00
parent a4c86630cf
commit 9f4024104a
No known key found for this signature in database
GPG key ID: 0D414D0FE405B63B
3 changed files with 37 additions and 17 deletions

View file

@ -52,7 +52,9 @@ class OnionrBlackList:
def generateDB(self):
self._dbExecute('''CREATE TABLE blacklist(
hash text primary key not null,
type text
dataType text,
blacklistDate int,
expire int
);
''')
return
@ -67,11 +69,20 @@ class OnionrBlackList:
myList.append(i[0])
return myList
def addToDB(self, data):
def addToDB(self, data, dataType=0, expire=0):
'''Add to the blacklist. Intended to be block hash, block data, peers, or transport addresses'''
# we hash the data so we can remove data entirely from our node's disk
hashed = self._core._utils.bytesToStr(self._core._crypto.sha3Hash(data))
if not hashed.isalnum():
raise Exception("Hashed data is not alpha numeric")
try:
int(dataType)
except ValueError:
raise Exception("dataType is not int")
try:
int(expire)
except ValueError:
raise Exception("expire is not int")
#TODO check for length sanity
insert = (hashed,)
self._dbExecute("insert into blacklist (hash) VALUES('%s');" % (hashed,))
self._dbExecute("insert into blacklist (hash, dataType, expire) VALUES('%s', %s, %s);" % (hashed, dataType, expire))

View file

@ -126,7 +126,8 @@ class OnionrUtils:
retVal = False
if newAdderList != False:
for adder in newAdderList.split(','):
if not adder in self._core.listAdders(randomOrder = False) and adder.strip() != self.getMyAddress():
adder = adder.strip()
if not adder in self._core.listAdders(randomOrder = False) and adder != self.getMyAddress() and not self._core._blacklist.inBlacklist(adder):
if self._core.addAddress(adder):
logger.info('Added %s to db.' % adder, timestamp = True)
retVal = True