progress in removing core
This commit is contained in:
parent
1775b96a04
commit
dbbefafd19
22 changed files with 224 additions and 75 deletions
|
@ -21,20 +21,22 @@ import sqlite3
|
|||
import onionrevents as events
|
||||
from onionrutils import stringvalidators
|
||||
from . import listkeys
|
||||
def add_peer(core_inst, peerID, name=''):
|
||||
from utils import gettransports
|
||||
from .. import dbfiles
|
||||
def add_peer(peerID, name=''):
|
||||
'''
|
||||
Adds a public key to the key database (misleading function name)
|
||||
'''
|
||||
if peerID in core_inst.listPeers() or peerID == core_inst._crypto.pubKey:
|
||||
if peerID in listkeys.list_peers() or peerID == core_inst._crypto.pubKey:
|
||||
raise ValueError("specified id is already known")
|
||||
|
||||
# This function simply adds a peer to the DB
|
||||
if not stringvalidators.validate_pub_key(peerID):
|
||||
return False
|
||||
|
||||
events.event('pubkey_add', data = {'key': peerID}, onionr = core_inst.onionrInst)
|
||||
#events.event('pubkey_add', data = {'key': peerID}, onionr = core_inst.onionrInst)
|
||||
|
||||
conn = sqlite3.connect(core_inst.peerDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=30)
|
||||
hashID = core_inst._crypto.pubKeyHashID(peerID)
|
||||
c = conn.cursor()
|
||||
t = (peerID, name, 'unknown', hashID, 0)
|
||||
|
@ -54,7 +56,7 @@ def add_peer(core_inst, peerID, name=''):
|
|||
|
||||
return True
|
||||
|
||||
def add_address(core_inst, address):
|
||||
def add_address(address):
|
||||
'''
|
||||
Add an address to the address database (only tor currently)
|
||||
'''
|
||||
|
@ -62,9 +64,9 @@ def add_address(core_inst, address):
|
|||
if type(address) is None or len(address) == 0:
|
||||
return False
|
||||
if stringvalidators.validate_transport(address):
|
||||
if address == core_inst.config.get('i2p.ownAddr', None) or address == core_inst.hsAddress:
|
||||
if address == gettransports.transports[0]:
|
||||
return False
|
||||
conn = sqlite3.connect(core_inst.addressDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
# check if address is in database
|
||||
# this is safe to do because the address is validated above, but we strip some chars here too just in case
|
||||
|
@ -84,7 +86,7 @@ def add_address(core_inst, address):
|
|||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
events.event('address_add', data = {'address': address}, onionr = core_inst.onionrInst)
|
||||
#events.event('address_add', data = {'address': address}, onionr = core_inst.onionrInst)
|
||||
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -21,6 +21,7 @@ import sqlite3
|
|||
import logger
|
||||
from onionrutils import epoch
|
||||
from .. import dbfiles
|
||||
from . import userinfo
|
||||
def list_peers(randomOrder=True, getPow=False, trust=0):
|
||||
'''
|
||||
Return a list of public keys (misleading function name)
|
||||
|
@ -58,11 +59,11 @@ def list_peers(randomOrder=True, getPow=False, trust=0):
|
|||
|
||||
return peerList
|
||||
|
||||
def list_adders(core_inst, randomOrder=True, i2p=True, recent=0):
|
||||
def list_adders(randomOrder=True, i2p=True, recent=0):
|
||||
'''
|
||||
Return a list of transport addresses
|
||||
'''
|
||||
conn = sqlite3.connect(core_inst.addressDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
if randomOrder:
|
||||
addresses = c.execute('SELECT * FROM adders ORDER BY RANDOM();')
|
||||
|
@ -77,7 +78,7 @@ def list_adders(core_inst, randomOrder=True, i2p=True, recent=0):
|
|||
testList = list(addressList) # create new list to iterate
|
||||
for address in testList:
|
||||
try:
|
||||
if recent > 0 and (epoch.get_epoch() - core_inst.getAddressInfo(address, 'lastConnect')) > recent:
|
||||
if recent > 0 and (epoch.get_epoch() - userinfo.get_user_info(address, 'lastConnect')) > recent:
|
||||
raise TypeError # If there is no last-connected date or it was too long ago, don't add peer to list if recent is not 0
|
||||
except TypeError:
|
||||
addressList.remove(address)
|
||||
|
|
|
@ -20,21 +20,21 @@
|
|||
import sqlite3
|
||||
import onionrevents as events
|
||||
from onionrutils import stringvalidators
|
||||
|
||||
def remove_address(core_inst, address):
|
||||
from .. import dbfiles
|
||||
def remove_address(address):
|
||||
'''
|
||||
Remove an address from the address database
|
||||
'''
|
||||
|
||||
if stringvalidators.validate_transport(address):
|
||||
conn = sqlite3.connect(core_inst.addressDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
t = (address,)
|
||||
c.execute('Delete from adders where address=?;', t)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
events.event('address_remove', data = {'address': address}, onionr = core_inst.onionrInst)
|
||||
#events.event('address_remove', data = {'address': address}, onionr = core_inst.onionrInst)
|
||||
return True
|
||||
else:
|
||||
return False
|
|
@ -18,7 +18,8 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sqlite3
|
||||
def get_address_info(core_inst, address, info):
|
||||
from .. import dbfiles
|
||||
def get_address_info(address, info):
|
||||
'''
|
||||
Get info about an address from its database entry
|
||||
|
||||
|
@ -34,7 +35,7 @@ def get_address_info(core_inst, address, info):
|
|||
introduced 9
|
||||
'''
|
||||
|
||||
conn = sqlite3.connect(core_inst.addressDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
command = (address,)
|
||||
|
@ -54,12 +55,12 @@ def get_address_info(core_inst, address, info):
|
|||
|
||||
return retVal
|
||||
|
||||
def set_address_info(core_inst, address, key, data):
|
||||
def set_address_info(address, key, data):
|
||||
'''
|
||||
Update an address for a key
|
||||
'''
|
||||
|
||||
conn = sqlite3.connect(core_inst.addressDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.address_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
command = (data, address)
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sqlite3
|
||||
def get_user_info(core_inst, peer, info):
|
||||
from .. import dbfiles
|
||||
def get_user_info(peer, info):
|
||||
'''
|
||||
Get info about a peer from their database entry
|
||||
|
||||
|
@ -29,7 +30,7 @@ def get_user_info(core_inst, peer, info):
|
|||
trust int 4
|
||||
hashID text 5
|
||||
'''
|
||||
conn = sqlite3.connect(core_inst.peerDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
command = (peer,)
|
||||
|
@ -50,12 +51,12 @@ def get_user_info(core_inst, peer, info):
|
|||
|
||||
return retVal
|
||||
|
||||
def set_peer_info(core_inst, peer, key, data):
|
||||
def set_peer_info(peer, key, data):
|
||||
'''
|
||||
Update a peer for a key
|
||||
'''
|
||||
|
||||
conn = sqlite3.connect(core_inst.peerDB, timeout=30)
|
||||
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=30)
|
||||
c = conn.cursor()
|
||||
|
||||
command = (data, peer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue