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
|
|
|
"""
|
2017-05-27 19:09:21 +02:00
|
|
|
import time
|
|
|
|
|
2019-08-06 13:04:33 +02:00
|
|
|
import state
|
2017-05-27 19:09:21 +02:00
|
|
|
from bmconfigparser import BMConfigParser
|
2019-11-27 06:47:04 +01:00
|
|
|
from network.assemble import assemble_addr
|
2017-05-27 19:09:21 +02:00
|
|
|
from network.connectionpool import BMConnectionPool
|
2019-11-03 16:11:52 +01:00
|
|
|
from node import Peer
|
2019-08-06 13:04:33 +02:00
|
|
|
from threads import StoppableThread
|
2017-05-27 19:09:21 +02:00
|
|
|
|
2019-08-01 13:37:26 +02:00
|
|
|
|
|
|
|
class AnnounceThread(StoppableThread):
|
2019-08-29 16:16:03 +02:00
|
|
|
"""A thread to manage regular announcing of this node"""
|
2019-08-06 13:04:33 +02:00
|
|
|
name = "Announcer"
|
2021-01-27 20:46:21 +01:00
|
|
|
announceInterval = 60
|
2017-05-27 19:09:21 +02:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
lastSelfAnnounced = 0
|
2017-05-29 14:35:08 +02:00
|
|
|
while not self._stopped and state.shutdown == 0:
|
2017-05-27 19:09:21 +02:00
|
|
|
processed = 0
|
2021-01-27 20:46:21 +01:00
|
|
|
if lastSelfAnnounced < time.time() - self.announceInterval:
|
2017-05-27 19:09:21 +02:00
|
|
|
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"""
|
2017-05-27 19:09:21 +02:00
|
|
|
for connection in BMConnectionPool().udpSockets.values():
|
2017-08-09 17:34:47 +02:00
|
|
|
if not connection.announcing:
|
|
|
|
continue
|
2017-05-27 19:09:21 +02:00
|
|
|
for stream in state.streamsInWhichIAmParticipating:
|
2019-08-29 15:54:13 +02:00
|
|
|
addr = (
|
|
|
|
stream,
|
2019-11-03 16:11:52 +01:00
|
|
|
Peer(
|
|
|
|
'127.0.0.1',
|
2020-01-06 12:44:47 +01:00
|
|
|
BMConfigParser().safeGetInt(
|
|
|
|
'bitmessagesettings', 'port')),
|
2019-08-29 15:54:13 +02:00
|
|
|
time.time())
|
2019-11-27 06:47:04 +01:00
|
|
|
connection.append_write_buf(assemble_addr([addr]))
|