2022-02-07 01:18:53 +00:00
|
|
|
"""
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
get lists for user keys
|
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
import sqlite3
|
|
|
|
import logger
|
2019-06-25 23:07:35 +00:00
|
|
|
from onionrutils import epoch
|
2022-02-07 01:18:53 +00:00
|
|
|
import onionrvalues
|
2019-07-17 22:41:33 +00:00
|
|
|
from .. import dbfiles
|
2022-01-11 07:20:15 +00:00
|
|
|
from . import userinfo
|
2022-02-07 01:18:53 +00:00
|
|
|
"""
|
|
|
|
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/>.
|
|
|
|
"""
|
|
|
|
|
2022-01-11 07:20:15 +00:00
|
|
|
|
|
|
|
def list_pub_keys(randomOrder=True, getPow=False, trust=0):
|
2022-02-07 01:18:53 +00:00
|
|
|
"""
|
|
|
|
Return a list of public keys (misleading function name)
|
2019-06-22 21:16:12 +00:00
|
|
|
|
2022-02-07 01:18:53 +00:00
|
|
|
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 >= ?;'
|
|
|
|
|
2022-02-07 01:18:53 +00:00
|
|
|
peer_list = []
|
2019-06-22 21:16:12 +00:00
|
|
|
|
|
|
|
for i in c.execute(payload, (trust,)):
|
|
|
|
try:
|
|
|
|
if len(i[0]) != 0:
|
|
|
|
if getPow:
|
2022-02-07 01:18:53 +00:00
|
|
|
peer_list.append(i[0] + '-' + i[1])
|
2019-06-22 21:16:12 +00:00
|
|
|
else:
|
2022-02-07 01:18:53 +00:00
|
|
|
peer_list.append(i[0])
|
2019-06-22 21:16:12 +00:00
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
conn.close()
|
|
|
|
|
2022-02-07 01:18:53 +00:00
|
|
|
return peer_list
|