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