mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 20:52:42 +01:00
relay/ts6_common: be more error tolerant with network (dis)connections
This commit is contained in:
parent
504e2683fb
commit
c3e8420aa0
@ -30,8 +30,6 @@ killcache = ExpiringDict(max_len=5, max_age_seconds=10)
|
|||||||
|
|
||||||
def initializeAll(irc):
|
def initializeAll(irc):
|
||||||
"""Initializes all relay channels for the given IRC object."""
|
"""Initializes all relay channels for the given IRC object."""
|
||||||
log.debug('(%s) initializeAll: waiting for world.started', irc.name)
|
|
||||||
world.started.wait()
|
|
||||||
for chanpair, entrydata in db.items():
|
for chanpair, entrydata in db.items():
|
||||||
network, channel = chanpair
|
network, channel = chanpair
|
||||||
initializeChannel(irc, channel)
|
initializeChannel(irc, channel)
|
||||||
@ -149,7 +147,12 @@ def getRemoteSid(irc, remoteirc):
|
|||||||
try:
|
try:
|
||||||
sid = relayservers[irc.name][remoteirc.name]
|
sid = relayservers[irc.name][remoteirc.name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
sid = irc.proto.spawnServer('%s.relay' % remoteirc.name)
|
try:
|
||||||
|
sid = irc.proto.spawnServer('%s.relay' % remoteirc.name)
|
||||||
|
except ValueError: # Network not initialized yet.
|
||||||
|
log.exception('(%s) Failed to spawn server for %r:',
|
||||||
|
irc.name, remoteirc.name)
|
||||||
|
return
|
||||||
relayservers[irc.name][remoteirc.name] = sid
|
relayservers[irc.name][remoteirc.name] = sid
|
||||||
return sid
|
return sid
|
||||||
|
|
||||||
@ -203,10 +206,15 @@ def getRemoteUser(irc, remoteirc, user, spawnIfMissing=True):
|
|||||||
if hideoper_mode:
|
if hideoper_mode:
|
||||||
modes.append((hideoper_mode, None))
|
modes.append((hideoper_mode, None))
|
||||||
rsid = getRemoteSid(remoteirc, irc)
|
rsid = getRemoteSid(remoteirc, irc)
|
||||||
u = remoteirc.proto.spawnClient(nick, ident=ident,
|
try:
|
||||||
host=host, realname=realname,
|
u = remoteirc.proto.spawnClient(nick, ident=ident,
|
||||||
modes=modes, ts=userobj.ts,
|
host=host, realname=realname,
|
||||||
opertype=opertype, server=rsid).uid
|
modes=modes, ts=userobj.ts,
|
||||||
|
opertype=opertype, server=rsid).uid
|
||||||
|
except ValueError:
|
||||||
|
log.exception('(%s) Failed to spawn relay user %s on %s.', irc.name,
|
||||||
|
nick, remoteirc.name)
|
||||||
|
return
|
||||||
remoteirc.users[u].remote = (irc.name, user)
|
remoteirc.users[u].remote = (irc.name, user)
|
||||||
remoteirc.users[u].opertype = opertype
|
remoteirc.users[u].opertype = opertype
|
||||||
away = userobj.away
|
away = userobj.away
|
||||||
@ -955,10 +963,14 @@ def handle_disconnect(irc, numeric, command, args):
|
|||||||
for name, ircobj in world.networkobjects.items():
|
for name, ircobj in world.networkobjects.items():
|
||||||
if name != irc.name:
|
if name != irc.name:
|
||||||
rsid = getRemoteSid(ircobj, irc)
|
rsid = getRemoteSid(ircobj, irc)
|
||||||
ircobj.proto.squitServer(ircobj.sid, rsid, text='Home network lost connection.')
|
# Let's be super extra careful here...
|
||||||
del relayservers[name][irc.name]
|
if rsid and name in relayservers and irc.name in relayservers[name]:
|
||||||
del relayservers[irc.name]
|
ircobj.proto.squitServer(ircobj.sid, rsid, text='Home network lost connection.')
|
||||||
# handle_quit(irc, k[1], 'PYLINK_DISCONNECT', {'text': 'Home network lost connection.'})
|
del relayservers[name][irc.name]
|
||||||
|
try:
|
||||||
|
del relayservers[irc.name]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT")
|
utils.add_hook(handle_disconnect, "PYLINK_DISCONNECT")
|
||||||
|
|
||||||
|
@ -201,6 +201,7 @@ class TS6BaseProtocol(Protocol):
|
|||||||
split_server = args[0]
|
split_server = args[0]
|
||||||
affected_users = []
|
affected_users = []
|
||||||
log.info('(%s) Netsplit on server %s', self.irc.name, split_server)
|
log.info('(%s) Netsplit on server %s', self.irc.name, split_server)
|
||||||
|
assert split_server in self.irc.servers, "Tried to split a server (%s) that didn't exist!" % split_server
|
||||||
# Prevent RuntimeError: dictionary changed size during iteration
|
# Prevent RuntimeError: dictionary changed size during iteration
|
||||||
old_servers = self.irc.servers.copy()
|
old_servers = self.irc.servers.copy()
|
||||||
for sid, data in old_servers.items():
|
for sid, data in old_servers.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user