mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-11-04 00:47:21 +01:00 
			
		
		
		
	relay, inspircd: move endburst delay code to a private API
This is a very specific hack that shouldn't be extended across the protocol module spec. So far, all other protocol modules ignore the endburst_delay option anyways.
This commit is contained in:
		
							parent
							
								
									ccbd79a95c
								
							
						
					
					
						commit
						a425f873b5
					
				@ -221,15 +221,25 @@ def spawn_relay_server(irc, remoteirc):
 | 
			
		||||
    """
 | 
			
		||||
    if irc.connected.is_set():
 | 
			
		||||
        try:
 | 
			
		||||
            # ENDBURST is delayed by 3 secs on supported IRCds to prevent
 | 
			
		||||
            # triggering join-flood protection and the like.
 | 
			
		||||
            suffix = irc.serverdata.get('server_suffix', conf.conf.get('relay', {}).get('server_suffix', 'relay'))
 | 
			
		||||
 | 
			
		||||
            # Strip any leading or trailing .'s
 | 
			
		||||
            suffix = suffix.strip('.')
 | 
			
		||||
 | 
			
		||||
            # On some IRCds (e.g. InspIRCd), we have to delay endburst to prevent triggering
 | 
			
		||||
            # join flood protections that are counted locally.
 | 
			
		||||
            needs_delayed_eob = hasattr(irc, '_endburst_delay')
 | 
			
		||||
            if needs_delayed_eob:
 | 
			
		||||
                old_eob_delay = irc._endburst_delay
 | 
			
		||||
                irc._endburst_delay = 3
 | 
			
		||||
 | 
			
		||||
            sid = irc.spawn_server('%s.%s' % (remoteirc.name, suffix),
 | 
			
		||||
                                        desc="PyLink Relay network - %s" %
 | 
			
		||||
                                        (remoteirc.get_full_network_name()), endburst_delay=3)
 | 
			
		||||
                                              desc="PyLink Relay network - %s" %
 | 
			
		||||
                                              (remoteirc.get_full_network_name()))
 | 
			
		||||
 | 
			
		||||
            # Set _endburst_delay back to its last value.
 | 
			
		||||
            if needs_delayed_eob:
 | 
			
		||||
                irc._endburst_delay = old_eob_delay
 | 
			
		||||
 | 
			
		||||
        except (RuntimeError, ValueError):  # Network not initialized yet, or a server name conflict.
 | 
			
		||||
            log.exception('(%s) Failed to spawn server for %r (possible jupe?):',
 | 
			
		||||
                          irc.name, remoteirc.name)
 | 
			
		||||
 | 
			
		||||
@ -37,6 +37,10 @@ class InspIRCdProtocol(TS6BaseProtocol):
 | 
			
		||||
        # Track the modules supported by the uplink.
 | 
			
		||||
        self._modsupport = set()
 | 
			
		||||
 | 
			
		||||
        # Settable by plugins (e.g. relay) as needed, used to work around +j being triggered
 | 
			
		||||
        # by bursting users.
 | 
			
		||||
        self._endburst_delay = 0
 | 
			
		||||
 | 
			
		||||
    ### Outgoing commands
 | 
			
		||||
 | 
			
		||||
    def spawn_client(self, nick, ident='null', host='null', realhost=None, modes=set(),
 | 
			
		||||
@ -360,15 +364,17 @@ class InspIRCdProtocol(TS6BaseProtocol):
 | 
			
		||||
        self.servers[sid] = Server(self, uplink, name, internal=True, desc=desc)
 | 
			
		||||
        self._send_with_prefix(uplink, 'SERVER %s * %s %s :%s' % (name, self.servers[sid].hopcount, sid, desc))
 | 
			
		||||
 | 
			
		||||
        # Endburst delay clutter
 | 
			
		||||
 | 
			
		||||
        def endburstf():
 | 
			
		||||
            # Delay ENDBURST by X seconds if requested.
 | 
			
		||||
            if self._aborted.wait(endburst_delay):
 | 
			
		||||
            if self._aborted.wait(self._endburst_delay):
 | 
			
		||||
                # We managed to catch the abort flag before sending ENDBURST, so break
 | 
			
		||||
                log.debug('(%s) stopping endburstf() for %s as aborted was set', self.name, sid)
 | 
			
		||||
                return
 | 
			
		||||
            self._send_with_prefix(sid, 'ENDBURST')
 | 
			
		||||
 | 
			
		||||
        if endburst_delay:
 | 
			
		||||
        if self._endburst_delay:
 | 
			
		||||
            t = threading.Thread(target=endburstf, name="protocols/inspircd delayed ENDBURST thread for %s@%s" % (sid, self.name))
 | 
			
		||||
            t.daemon = True
 | 
			
		||||
            t.start()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user