3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

relay: add a spawn_if_missing option to get_remote_sid()

This commit is contained in:
James Lu 2017-01-29 20:20:39 -08:00
parent 359132045d
commit e936b9cfd2

View File

@ -239,15 +239,20 @@ def spawn_relay_server(irc, remoteirc):
return sid return sid
def get_remote_sid(irc, remoteirc): def get_remote_sid(irc, remoteirc, spawn_if_missing=True):
"""Gets the remote server SID representing remoteirc on irc, spawning """Gets the remote server SID representing remoteirc on irc, spawning
it if it doesn't exist.""" it if it doesn't exist (and spawn_if_missing is enabled)."""
log.debug('(%s) Grabbing spawnlocks_servers[%s]', irc.name, irc.name) log.debug('(%s) Grabbing spawnlocks_servers[%s]', irc.name, irc.name)
if spawnlocks_servers[irc.name].acquire(5): if spawnlocks_servers[irc.name].acquire(5):
try: try:
sid = relayservers[irc.name][remoteirc.name] sid = relayservers[irc.name][remoteirc.name]
except KeyError: except KeyError:
if not spawn_if_missing:
log.debug('(%s) get_remote_sid: %s.relay doesn\'t have a known SID, ignoring.', irc.name, remoteirc.name)
spawnlocks_servers[irc.name].release()
return
log.debug('(%s) get_remote_sid: %s.relay doesn\'t have a known SID, spawning.', irc.name, remoteirc.name) log.debug('(%s) get_remote_sid: %s.relay doesn\'t have a known SID, spawning.', irc.name, remoteirc.name)
sid = spawn_relay_server(irc, remoteirc) sid = spawn_relay_server(irc, remoteirc)