2019-06-26 06:34:34 +00:00
|
|
|
'''
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
get lists for user keys or transport addresses
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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-06-22 21:16:12 +00:00
|
|
|
import sqlite3
|
|
|
|
import logger
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import epoch
|
2019-10-29 05:36:56 +00:00
|
|
|
from etc import onionrvalues
|
2019-07-17 22:41:33 +00:00
|
|
|
from .. import dbfiles
|
2022-01-11 07:20:15 +00:00
|
|
|
from . import userinfo
|
|
|
|
|
|
|
|
def list_pub_keys(randomOrder=True, getPow=False, trust=0):
|
2019-06-22 21:16:12 +00:00
|
|
|
'''
|
|
|
|
Return a list of public keys (misleading function name)
|
|
|
|
|
|
|
|
randomOrder determines if the list should be in a random order
|
|
|
|
trust sets the minimum trust to list
|
|
|
|
'''
|
2019-10-29 05:36:56 +00:00
|
|
|
conn = sqlite3.connect(dbfiles.user_id_info_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
|
2019-06-22 21:16:12 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
payload = ''
|
|
|
|
|
|
|
|
if trust not in (0, 1, 2):
|
|
|
|
logger.error('Tried to select invalid trust.')
|
|
|
|
return
|
|
|
|
|
|
|
|
if randomOrder:
|
|
|
|
payload = 'SELECT * FROM peers WHERE trust >= ? ORDER BY RANDOM();'
|
|
|
|
else:
|
|
|
|
payload = 'SELECT * FROM peers WHERE trust >= ?;'
|
|
|
|
|
|
|
|
peerList = []
|
|
|
|
|
|
|
|
for i in c.execute(payload, (trust,)):
|
|
|
|
try:
|
|
|
|
if len(i[0]) != 0:
|
|
|
|
if getPow:
|
|
|
|
peerList.append(i[0] + '-' + i[1])
|
|
|
|
else:
|
|
|
|
peerList.append(i[0])
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
return peerList
|