2019-08-29 16:16:03 +02:00
|
|
|
"""
|
|
|
|
src/network/announcethread.py
|
|
|
|
=================================
|
|
|
|
"""
|
2019-08-06 13:04:33 +02:00
|
|
|
|
2017-05-27 19:09:21 +02:00
|
|
|
import time
|
|
|
|
|
2019-08-06 13:04:33 +02:00
|
|
|
import state
|
2019-11-27 06:47:04 +01:00
|
|
|
|
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
|
|
|
|
from network.udp import UDPSocket
|
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"
|
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
|
|
|
|
if lastSelfAnnounced < time.time() - UDPSocket.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"""
|
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',
|
|
|
|
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]))
|