2022-02-26 07:07:18 +00:00
|
|
|
import config
|
2022-09-27 17:21:00 +00:00
|
|
|
from logger import log as logging
|
2022-07-11 15:27:13 +00:00
|
|
|
from gossip.peerset import gossip_peer_set
|
2022-02-26 07:07:18 +00:00
|
|
|
|
|
|
|
from getsocks import get_socks
|
|
|
|
from torpeer import TorPeer
|
|
|
|
|
2022-07-11 15:27:13 +00:00
|
|
|
MAX_TOR_PEERS = 20
|
2022-02-26 07:07:18 +00:00
|
|
|
|
|
|
|
def on_announce_rec(api, data=None):
|
2022-06-14 16:01:07 +00:00
|
|
|
announced: str = data['address']
|
2022-02-26 07:07:18 +00:00
|
|
|
try:
|
|
|
|
announced = announced.decode('utf-8')
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2022-06-14 16:01:07 +00:00
|
|
|
announced = announced.strip()
|
2022-07-11 15:27:13 +00:00
|
|
|
if not announced.endswith('.onion'):
|
|
|
|
return
|
|
|
|
socks_address, socks_port = get_socks()[0]
|
|
|
|
|
2022-02-26 07:07:18 +00:00
|
|
|
|
2022-08-03 02:06:30 +00:00
|
|
|
if announced.replace('.onion', '') == config.get(
|
|
|
|
'tor.transport_address', '').replace('.onion', ''):
|
2022-02-26 07:07:18 +00:00
|
|
|
return
|
|
|
|
|
2022-06-05 19:46:01 +00:00
|
|
|
|
2022-09-27 17:21:00 +00:00
|
|
|
logging.info(f"Peer {announced} announced to us.")
|
2022-02-26 07:07:18 +00:00
|
|
|
|
2022-04-20 05:28:29 +00:00
|
|
|
data['callback'](TorPeer(socks_address, socks_port, announced))
|