From 6b14a885bc9532b7c8f84d005e3f5b42d5c5d9da Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 17 Dec 2015 21:18:11 -0800 Subject: [PATCH] protocols: add support for endburst_delay in spawnServer (#128) --- protocols/inspircd.py | 16 ++++++++++++++-- protocols/ts6_common.py | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 7f2dfe1..6300720 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -2,6 +2,7 @@ import time import sys import os import re +import threading # Import hacks to access utils and classes... curdir = os.path.dirname(__file__) @@ -263,12 +264,17 @@ class InspIRCdProtocol(TS6BaseProtocol): else: self._send(source, 'AWAY') - def spawnServer(self, name, sid=None, uplink=None, desc=None): + def spawnServer(self, name, sid=None, uplink=None, desc=None, endburst_delay=0): """ Spawns a server off a PyLink server. desc (server description) defaults to the one in the config. uplink defaults to the main PyLink server, and sid (the server ID) is automatically generated if not given. + + If endburst_delay is set greater than zero, the sending of ENDBURST + will be delayed by the amount given. This can be used to prevent + pseudoserver bursts from triggering IRCd join-flood preventions, + and prevent connections from filling up the snomasks too much. """ # -> :0AL SERVER test.server * 1 0AM :some silly pseudoserver uplink = uplink or self.irc.sid @@ -289,7 +295,13 @@ class InspIRCdProtocol(TS6BaseProtocol): raise ValueError('Invalid server name %r' % name) self._send(uplink, 'SERVER %s * 1 %s :%s' % (name, sid, desc)) self.irc.servers[sid] = IrcServer(uplink, name, internal=True, desc=desc) - self._send(sid, 'ENDBURST') + + endburstf = lambda: self._send(sid, 'ENDBURST') + if endburst_delay: + # Delay ENDBURST by X seconds if requested. + threading.Timer(endburst_delay, endburstf, ()).start() + else: # Else, send burst immediately + endburstf() return sid def squitServer(self, source, target, text='No reason given'): diff --git a/protocols/ts6_common.py b/protocols/ts6_common.py index ae8a503..3330a4b 100644 --- a/protocols/ts6_common.py +++ b/protocols/ts6_common.py @@ -105,12 +105,15 @@ class TS6BaseProtocol(Protocol): self.irc.channels[target].topic = text self.irc.channels[target].topicset = True - def spawnServer(self, name, sid=None, uplink=None, desc=None): + def spawnServer(self, name, sid=None, uplink=None, desc=None, endburst_delay=0): """ Spawns a server off a PyLink server. desc (server description) defaults to the one in the config. uplink defaults to the main PyLink server, and sid (the server ID) is automatically generated if not given. + + Note: TS6 doesn't use a specific ENDBURST command, so the endburst_delay + option will be ignored if given. """ # -> :0AL SID test.server 1 0XY :some silly pseudoserver uplink = uplink or self.irc.sid