This repository has been archived on 2024-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-21/src/network/announcethread.py

44 lines
1.2 KiB
Python
Raw Normal View History

2019-08-29 16:16:03 +02:00
"""
2020-01-06 12:44:47 +01:00
Announce myself (node address)
2019-08-29 16:16:03 +02:00
"""
import time
# magic imports!
import connectionpool
from bmconfigparser import config
from protocol import assembleAddrMessage
from node import Peer
from threads import StoppableThread
class AnnounceThread(StoppableThread):
2019-08-29 16:16:03 +02:00
"""A thread to manage regular announcing of this node"""
name = "Announcer"
announceInterval = 60
def run(self):
lastSelfAnnounced = 0
while not self._stopped:
processed = 0
if lastSelfAnnounced < time.time() - self.announceInterval:
self.announceSelf()
lastSelfAnnounced = time.time()
if processed == 0:
self.stop.wait(10)
2019-08-29 16:16:03 +02:00
@staticmethod
def announceSelf():
"""Announce our presence"""
for connection in connectionpool.pool.udpSockets.values():
if not connection.announcing:
continue
for stream in connectionpool.pool.streams:
2019-08-29 15:54:13 +02:00
addr = (
stream,
Peer(
'127.0.0.1',
config.safeGetInt('bitmessagesettings', 'port')),
int(time.time()))
connection.append_write_buf(assembleAddrMessage([addr]))