mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Merge branch 'devel' into engine-rework
Conflicts: classes.py
This commit is contained in:
commit
0033612fa3
12
classes.py
12
classes.py
@ -1295,7 +1295,7 @@ utils._proto_utils_class = PyLinkNetworkCoreWithUtils # Used by compatibility w
|
||||
|
||||
class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
||||
S2S_BUFSIZE = 510
|
||||
SOCKET_REPOLL_WAIT = 0.5
|
||||
SOCKET_REPOLL_WAIT = 1.0
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -1540,6 +1540,11 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
||||
data = b''
|
||||
try:
|
||||
data = self._socket.recv(2048)
|
||||
except (BlockingIOError, ssl.SSLWantReadError, ssl.SSLWantWriteError):
|
||||
log.debug('(%s) No data to read, trying again later...', self.name)
|
||||
if self._aborted.wait(self.SOCKET_REPOLL_WAIT):
|
||||
break
|
||||
continue
|
||||
except OSError:
|
||||
# Suppress socket read warnings from lingering recv() calls if
|
||||
# we've been told to shutdown.
|
||||
@ -1577,8 +1582,9 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils):
|
||||
|
||||
try:
|
||||
self._socket.send(encoded_data)
|
||||
except (OSError, AttributeError):
|
||||
log.exception("(%s) Failed to send message %r; did the network disconnect?", self.name, data)
|
||||
except:
|
||||
log.exception("(%s) Failed to send message %r; aborting!", self.name, data)
|
||||
self.disconnect()
|
||||
|
||||
def send(self, data, queue=True):
|
||||
"""send() wrapper with optional queueing support."""
|
||||
|
@ -33,10 +33,7 @@ default_permissions = {"*!*@*": ['relay.linked'],
|
||||
def initialize_all(irc):
|
||||
"""Initializes all relay channels for the given IRC object."""
|
||||
|
||||
# Wait for all IRC objects to be created first. This prevents
|
||||
# relay servers from being spawned too early (before server authentication),
|
||||
# which would break connections.
|
||||
if world.started.wait(TCONDITION_TIMEOUT):
|
||||
def _initialize_all():
|
||||
for chanpair, entrydata in db.items():
|
||||
network, channel = chanpair
|
||||
|
||||
@ -48,6 +45,14 @@ def initialize_all(irc):
|
||||
if network == irc.name:
|
||||
initialize_channel(irc, channel)
|
||||
|
||||
# Wait for all IRC objects to be created first. This prevents
|
||||
# relay servers from being spawned too early (before server authentication),
|
||||
# which would break connections.
|
||||
if world.started.wait(TCONDITION_TIMEOUT):
|
||||
t = threading.Thread(target=_initialize_all, daemon=True,
|
||||
name='relay initialize_all thread from network %r' % irc.name)
|
||||
t.start()
|
||||
|
||||
def main(irc=None):
|
||||
"""Main function, called during plugin loading at start."""
|
||||
log.debug('relay.main: loading links database')
|
||||
@ -281,14 +286,9 @@ def get_relay_server_sid(irc, remoteirc, spawn_if_missing=True):
|
||||
sid = spawn_relay_server(irc, remoteirc)
|
||||
|
||||
log.debug('(%s) get_relay_server_sid: got %s for %s.relay', irc.name, sid, remoteirc.name)
|
||||
if sid not in irc.servers:
|
||||
log.warning('(%s) Possible desync? SID %s for %s.relay doesn\'t exist anymore', irc.name, sid, remoteirc.name)
|
||||
# Our stored server doesn't exist anymore. This state is probably a holdover from a netsplit,
|
||||
# so let's refresh it.
|
||||
sid = spawn_relay_server(irc, remoteirc)
|
||||
elif sid in irc.servers and irc.servers[sid].remote != remoteirc.name:
|
||||
log.debug('(%s) Possible desync? SID %s for %s.relay doesn\'t exist anymore is mismatched (got %s.relay)', irc.name, irc.servers[sid].remote, remoteirc.name)
|
||||
sid = spawn_relay_server(irc, remoteirc)
|
||||
if (sid not in irc.servers) or (sid in irc.servers and irc.servers[sid].remote != remoteirc.name):
|
||||
# SID changed in the meantime; abort.
|
||||
return
|
||||
|
||||
log.debug('(%s) get_relay_server_sid: got %s for %s.relay (round 2)', irc.name, sid, remoteirc.name)
|
||||
spawnlocks_servers[irc.name].release()
|
||||
@ -336,7 +336,7 @@ def spawn_relay_user(irc, remoteirc, user, times_tagged=0):
|
||||
|
||||
rsid = get_relay_server_sid(remoteirc, irc)
|
||||
if not rsid:
|
||||
log.error('(%s) spawn_relay_user: aborting user spawn for %s/%s @ %s (failed to retrieve a '
|
||||
log.debug('(%s) spawn_relay_user: aborting user spawn for %s/%s @ %s (failed to retrieve a '
|
||||
'working SID).', irc.name, user, nick, remoteirc.name)
|
||||
return
|
||||
try:
|
||||
@ -505,9 +505,8 @@ def initialize_channel(irc, channel):
|
||||
# from the config. Skip this.
|
||||
continue
|
||||
|
||||
# Give each network a tiny bit of leeway to finish up its connection.
|
||||
# This is better than just dropping users their completely.
|
||||
if not remoteirc.connected.wait(TCONDITION_TIMEOUT):
|
||||
# Remote net isn't ready yet, try again later.
|
||||
if not remoteirc.connected.is_set():
|
||||
continue
|
||||
|
||||
# Join their (remote) users and set their modes, if applicable.
|
||||
@ -1475,7 +1474,10 @@ def handle_messages(irc, numeric, command, args):
|
||||
# Otherwise, the sender doesn't have a client representing them
|
||||
# on the remote network, and we won't have anything to send our
|
||||
# messages from.
|
||||
# Note: don't spam ulined senders (e.g. services announcers) with
|
||||
# these notices.
|
||||
if homenet not in remoteusers.keys():
|
||||
if not _is_uline(irc, numeric):
|
||||
irc.msg(numeric, 'You must be in a common channel '
|
||||
'with %r in order to send messages.' % \
|
||||
irc.users[target].nick, notice=True)
|
||||
@ -1483,6 +1485,7 @@ def handle_messages(irc, numeric, command, args):
|
||||
remoteirc = world.networkobjects[homenet]
|
||||
|
||||
if (not remoteirc.has_cap('can-spawn-clients')) and not conf.conf.get('relay', {}).get('allow_clientbot_pms'):
|
||||
if not _is_uline(irc, numeric):
|
||||
irc.msg(numeric, 'Private messages to users connected via Clientbot have '
|
||||
'been administratively disabled.', notice=True)
|
||||
return
|
||||
|
@ -60,7 +60,7 @@ def cb_relay_core(irc, source, command, args):
|
||||
|
||||
real_command = 'ACTION'
|
||||
|
||||
elif not irc.is_channel(args['target']):
|
||||
elif not irc.is_channel(args['target'].lstrip(''.join(irc.prefixmodes.values()))):
|
||||
# Target is a user; handle this accordingly.
|
||||
if relay_conf.get('allow_clientbot_pms'):
|
||||
real_command = 'PNOTICE' if args.get('is_notice') else 'PM'
|
||||
@ -113,8 +113,12 @@ def cb_relay_core(irc, source, command, args):
|
||||
netname = sourcenet
|
||||
|
||||
# Figure out where the message is destined to.
|
||||
target = args.get('channel') or args.get('target')
|
||||
if target is None or not (irc.is_channel(target) or private):
|
||||
stripped_target = target = args.get('channel') or args.get('target')
|
||||
if target is not None:
|
||||
# HACK: cheap fix to prevent @#channel messages from interpreted as non-channel specific
|
||||
stripped_target = target.lstrip(''.join(irc.prefixmodes.values()))
|
||||
|
||||
if target is None or not (irc.is_channel(stripped_target) or private):
|
||||
# Non-channel specific message (e.g. QUIT or NICK). If this isn't a PM, figure out
|
||||
# all channels that the sender shares over the relay, and relay them to those
|
||||
# channels.
|
||||
@ -127,7 +131,7 @@ def cb_relay_core(irc, source, command, args):
|
||||
else:
|
||||
# Pluralize the channel so that we can iterate over it.
|
||||
targets = [target]
|
||||
args['channel'] = target
|
||||
args['channel'] = stripped_target
|
||||
log.debug('(%s) relay_cb_core: Relaying event %s to channels: %s', irc.name, real_command, targets)
|
||||
|
||||
identhost = ''
|
||||
|
@ -98,6 +98,10 @@ def _map(irc, source, args, show_relay=True):
|
||||
if remoteirc.has_cap('can-track-servers'):
|
||||
# Only ever show relay subservers once - this prevents infinite loops.
|
||||
showall(remoteirc, remoteirc.sid, hops=hops, is_relay_server=True)
|
||||
else:
|
||||
# For Clientbot links, show the server we're actually connected to.
|
||||
reply("%s\x02%s\x02 (actual server name)" %
|
||||
(' '*(hops+1), remoteirc.uplink))
|
||||
|
||||
else:
|
||||
# Afterwards, decrement the hopcount.
|
||||
|
@ -87,7 +87,8 @@ def handle_stats(irc, source, command, args):
|
||||
try:
|
||||
permissions.check_permissions(irc, source, perms)
|
||||
except utils.NotAuthorizedError as e:
|
||||
irc.msg(source, 'Error: %s' % e) # Note, no irc.error() because this is not a command, but a handler
|
||||
# Note, no irc.error() because this is not a command, but a handler
|
||||
irc.msg(source, 'Error: %s' % e, notice=True)
|
||||
return
|
||||
|
||||
log.info('(%s) /STATS %s requested by %s', irc.name, stats_type, irc.get_hostmask(source))
|
||||
|
Loading…
Reference in New Issue
Block a user