From 9a84dbde71c526061a77224226255cf527e8b7b3 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 30 Aug 2017 19:18:39 -0700 Subject: [PATCH] protocols: consistently track ENDBURST on sub-servers too --- protocols/hybrid.py | 11 +++++------ protocols/inspircd.py | 1 + protocols/ngircd.py | 18 +++++++++++------- protocols/p10.py | 9 ++++++--- protocols/ts6.py | 10 +++------- protocols/unreal.py | 1 + 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/protocols/hybrid.py b/protocols/hybrid.py index f5672ae..f09e1a6 100644 --- a/protocols/hybrid.py +++ b/protocols/hybrid.py @@ -17,13 +17,11 @@ class HybridProtocol(TS6Protocol): self.casemapping = 'ascii' self.caps = {} self.hook_map = {'EOB': 'ENDBURST', 'TBURST': 'TOPIC', 'SJOIN': 'JOIN'} - self.has_eob = False self.protocol_caps -= {'slash-in-hosts'} def post_connect(self): """Initializes a connection to a server.""" ts = self.start_ts - self.has_eob = False f = self.send # https://github.com/grawity/irc-docs/blob/master/server/ts6.txt#L80 @@ -227,12 +225,13 @@ class HybridProtocol(TS6Protocol): return {'channel': channel, 'setter': setter, 'ts': ts, 'text': topic} def handle_eob(self, numeric, command, args): - log.debug('(%s) end of burst received', self.name) - if not self.has_eob: # Only call ENDBURST hooks if we haven't already. + """EOB (end-of-burst) handler.""" + log.debug('(%s) end of burst received from %s', self.name, numeric) + if not self.servers[numeric].has_eob: + # Don't fight with TS6's generic PING-as-EOB + self.servers[numeric].has_eob = True return {} - self.has_eob = True - def handle_svsmode(self, numeric, command, args): """ Handles SVSMODE, which is used for sending services metadata diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 38fc127..8fd9087 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -716,6 +716,7 @@ class InspIRCdProtocol(TS6BaseProtocol): def handle_endburst(self, numeric, command, args): """ENDBURST handler; sends a hook with empty contents.""" + self.servers[numeric].has_eob = True return {} def handle_away(self, numeric, command, args): diff --git a/protocols/ngircd.py b/protocols/ngircd.py index 8714683..7dbc0ea 100644 --- a/protocols/ngircd.py +++ b/protocols/ngircd.py @@ -504,16 +504,20 @@ class NgIRCdProtocol(IRCS2SProtocol): assert 'IRC+' in args[1], "Linking to non-ngIRCd server using this protocol module is not supported" def handle_ping(self, source, command, args): - if source == self.uplink: - self._send_with_prefix(self.sid, 'PONG %s :%s' % (self._expandPUID(self.sid), args[-1]), queue=False) + """ + Handles incoming PINGs (and implicit end of burst). + """ + self._send_with_prefix(self.sid, 'PONG %s :%s' % (self._expandPUID(self.sid), args[-1]), queue=False) - if not self.has_eob: - # Treat the first PING we receive as end of burst. - self.has_eob = True + if not self.servers[source].has_eob: + # Treat the first PING we receive as end of burst. + self.servers[source].has_eob = True + + if source == self.uplink: self.connected.set() - # Return the endburst hook. - return {'parse_as': 'ENDBURST'} + # Return the endburst hook. + return {'parse_as': 'ENDBURST'} def handle_server(self, source, command, args): """ diff --git a/protocols/p10.py b/protocols/p10.py index 264a52c..abd3cbb 100644 --- a/protocols/p10.py +++ b/protocols/p10.py @@ -1110,15 +1110,18 @@ class P10Protocol(IRCS2SProtocol): return {'channel': channel, 'users': [source], 'modes': self._channels[channel].modes, 'ts': ts or int(time.time())} - handle_create = handle_join + def handle_end_of_burst(self, source, command, args): - """Handles end of burst from our uplink.""" + """Handles end of burst from servers.""" + # Send EOB acknowledgement; this is required by the P10 specification, # and needed if we want to be able to receive channel messages, etc. if source == self.uplink: self._send_with_prefix(self.sid, 'EA') - return {} + + self.servers[source].has_eob = True + return {} def handle_kick(self, source, command, args): """Handles incoming KICKs.""" diff --git a/protocols/ts6.py b/protocols/ts6.py index 2c42bd4..93c83c0 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -20,9 +20,6 @@ class TS6Protocol(TS6BaseProtocol): self.hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE', 'EUID': 'UID', 'RSFNC': 'SVSNICK', 'ETB': 'TOPIC', 'USERMODE': 'MODE'} - # Track whether we've received end-of-burst from the uplink. - self.has_eob = False - self.required_caps = {'EUID', 'SAVE', 'TB', 'ENCAP', 'QS', 'CHW'} # From ChatIRCd: https://github.com/ChatLounge/ChatIRCd/blob/master/doc/technical/ChatIRCd-extra.txt @@ -264,7 +261,6 @@ class TS6Protocol(TS6BaseProtocol): def post_connect(self): """Initializes a connection to a server.""" ts = self.start_ts - self.has_eob = False f = self.send @@ -445,10 +441,10 @@ class TS6Protocol(TS6BaseProtocol): if self.is_internal_server(destination): self._send_with_prefix(destination, 'PONG %s %s' % (destination, source), queue=False) - if destination == self.sid and not self.has_eob: - # Charybdis' endburst is just sending a PING to the other server. + if not self.servers[source].has_eob: + # TS6 endburst is just sending a PING to the other server. # https://github.com/charybdis-ircd/charybdis/blob/dc336d1/modules/core/m_server.c#L484-L485 - self.has_eob = True + self.servers[source].has_eob = True # Return the endburst hook. return {'parse_as': 'ENDBURST'} diff --git a/protocols/unreal.py b/protocols/unreal.py index 18444b9..985faa8 100644 --- a/protocols/unreal.py +++ b/protocols/unreal.py @@ -379,6 +379,7 @@ class UnrealProtocol(TS6BaseProtocol): def handle_eos(self, numeric, command, args): """EOS is used to denote end of burst.""" + self.servers[numeric].has_eob = True return {} def handle_uid(self, numeric, command, args):