Fix inundation concurrency issues
This commit is contained in:
parent
eb97a47a25
commit
ed00fd73d1
|
@ -453,8 +453,8 @@ class WarningTLV(TLV):
|
|||
|
||||
def handle(self, user: Any, sender: Any) -> None:
|
||||
user.add_message(f"warning: *A client warned you: {self.message}*"
|
||||
if not user.squinnondation.no_markdown else
|
||||
f"warning: A client warned you: {self.message}")
|
||||
if not user.squinnondation.no_markdown else
|
||||
"warning: A client warned you: {self.message}")
|
||||
|
||||
@staticmethod
|
||||
def construct(message: str) -> "WarningTLV":
|
||||
|
|
|
@ -662,14 +662,17 @@ class User(Peer):
|
|||
"""
|
||||
Remove messages which are overdue (older than 2 minutes) from the inundation dictionnary.
|
||||
"""
|
||||
self.data_lock.acquire()
|
||||
for key in self.recent_messages:
|
||||
if time.time() - self.recent_messages[key][1] > 120:
|
||||
self.recent_messages.pop(key)
|
||||
self.data_lock.release()
|
||||
|
||||
def main_inundation(self) -> None:
|
||||
"""
|
||||
The main inundation function.
|
||||
"""
|
||||
self.data_lock.acquire()
|
||||
for key in self.recent_messages:
|
||||
k = list(self.recent_messages[key][2].keys())
|
||||
for key2 in k:
|
||||
|
@ -691,6 +694,7 @@ class User(Peer):
|
|||
peer = self.recent_messages[key][2][key2][0]
|
||||
self.send_packet(peer, pkt)
|
||||
self.recent_messages[key][2].pop(key2)
|
||||
self.data_lock.release()
|
||||
|
||||
def add_system_message(self, msg: str, italic: bool = True, ignore_debug: bool = False) -> None:
|
||||
"""
|
||||
|
@ -1157,17 +1161,20 @@ class Inondator(Thread):
|
|||
|
||||
def run(self) -> None:
|
||||
while True:
|
||||
# clean the dictionnary
|
||||
if time.time() - self.last_check > 30:
|
||||
self.user.clean_inundation()
|
||||
self.last_check = time.time()
|
||||
try:
|
||||
# clean the dictionnary
|
||||
if time.time() - self.last_check > 30:
|
||||
self.user.clean_inundation()
|
||||
self.last_check = time.time()
|
||||
|
||||
# inundate
|
||||
self.user.main_inundation()
|
||||
# inundate
|
||||
self.user.main_inundation()
|
||||
|
||||
self.user.refresh_history()
|
||||
self.user.refresh_input()
|
||||
self.user.refresh_emoji_pad()
|
||||
self.user.refresh_history()
|
||||
self.user.refresh_input()
|
||||
self.user.refresh_emoji_pad()
|
||||
except Exception as e:
|
||||
self.user.add_system_message(f"An error occured while inondating: {e}", ignore_debug=True)
|
||||
|
||||
# Avoid infinite loops
|
||||
time.sleep(1)
|
||||
|
|
Loading…
Reference in New Issue