Onionr/static-data/default-plugins/tor/announce.py

29 lines
719 B
Python
Raw Normal View History

import config
import logger
from getsocks import get_socks
from torpeer import TorPeer
def on_announce_rec(api, data=None):
socks_address, socks_port = get_socks()[0]
announced = data['address']
try:
announced = announced.decode('utf-8')
except AttributeError:
pass
if announced == config.get('tor.transport_address'):
2022-04-20 05:28:29 +00:00
logger.warn(
"Received announcement for our own node, which shouldn't happen")
return
2022-04-20 05:28:29 +00:00
announced = announced.strip()
2022-06-05 19:46:01 +00:00
if not announced.endswith('.onion'):
announced += '.onion'
logger.info(f"Peer {announced} announced to us.", terminal=True)
2022-04-20 05:28:29 +00:00
data['callback'](TorPeer(socks_address, socks_port, announced))