resource page at <http://www.catb.org/~esr/irker/>.
Requires Python 2.6 or 2.5 with the simplejson library installed, and
-the irc client library at version >= 2.0.2: see
+the irc client library at version >= 3.4 which requires 2.6: see
http://pypi.python.org/pypi/irc/
"""
# No user-serviceable parts below this line
-version = "1.11"
+version = "1.16"
import sys, getopt, urlparse, time, random, socket, signal
import threading, Queue, SocketServer
break
elif xmit_timeout or ping_timeout:
self.irker.debug(1, "timing out connection to %s at %s (ping_timeout=%s, xmit_timeout=%s)" % (self.servername, time.asctime(), ping_timeout, xmit_timeout))
- with self.irker.library_lock:
+ with self.irker.irc.mutex:
self.connection.context = None
self.connection.quit("transmission timeout")
self.connection = None
break
elif not self.connection:
# Queue is nonempty but server isn't connected.
- with self.irker.library_lock:
+ with self.irker.irc.mutex:
self.connection = self.irker.irc.server()
self.connection.context = self
# Try to avoid colliding with other instances
nickname=self.nickname(),
username="irker",
ircname="irker relaying client")
+ if hasattr(self.connection, "buffer"):
+ self.connection.buffer.errors = 'replace'
self.status = "handshaking"
self.irker.debug(1, "XMIT_TTL bump (%s connection) at %s" % (self.servername, time.asctime()))
self.last_xmit = time.time()
self.status = "expired"
break
elif self.status == "ready":
- with self.irker.library_lock:
- (channel, message) = self.queue.get()
- if channel not in self.channels_joined:
- self.connection.join(channel)
- self.irker.debug(1, "joining %s on %s." % (channel, self.servername))
- for segment in message.split("\n"):
- self.connection.privmsg(channel, segment)
- time.sleep(ANTI_FLOOD_DELAY)
- self.last_xmit = self.channels_joined[channel] = time.time()
- self.irker.debug(1, "XMIT_TTL bump (%s transmission) at %s" % (self.servername, time.asctime()))
- self.queue.task_done()
+ (channel, message) = self.queue.get()
+ if channel not in self.channels_joined:
+ self.connection.join(channel)
+ self.irker.debug(1, "joining %s on %s." % (channel, self.servername))
+ for segment in message.split("\n"):
+ self.connection.privmsg(channel, segment)
+ time.sleep(ANTI_FLOOD_DELAY)
+ self.last_xmit = self.channels_joined[channel] = time.time()
+ self.irker.debug(1, "XMIT_TTL bump (%s transmission) at %s" % (self.servername, time.asctime()))
+ self.queue.task_done()
except:
(exc_type, _exc_value, exc_traceback) = sys.exc_info()
self.irker.logerr("exception %s in thread for %s" % \
# when we need to be able to for debugging purposes.
if debuglvl > 0:
raise exc_type, _exc_value, exc_traceback
+ else:
+ # Maybe this should have its own status?
+ self.status = "expired"
def live(self):
"Should this connection not be scavenged?"
return self.status != "expired"
class Target():
"Represent a transmission target."
def __init__(self, url):
+ # Pre-2.6 Pythons don't recognize irc: as a valid URL prefix.
+ url = url.replace("irc://", "http://")
parsed = urlparse.urlparse(url)
irchost, _, ircport = parsed.netloc.partition(':')
if not ircport:
# got kicked, and irkerd crashed because the server returned
# "#channel" in the notification that our kick handler saw.
self.channel = parsed.path.lstrip('/').lower()
+ # This deals with a tweak in recent versions of urlparse.
+ if parsed.fragment:
+ self.channel += "#" + parsed.fragment
isnick = self.channel.endswith(",isnick")
if isnick:
self.channel = self.channel[:-7]
self.irc.add_global_handler("featurelist", self._handle_features)
self.irc.add_global_handler("disconnect", self._handle_disconnect)
self.irc.add_global_handler("kick", self._handle_kick)
- self.library_lock = threading.Lock()
- thread = threading.Thread(target=self._process_forever)
+ thread = threading.Thread(target=self.irc.process_forever)
thread.setDaemon(True)
self.irc._thread = thread
thread.start()
"Debugging information."
if self.debuglevel >= level:
sys.stderr.write("irkerd: %s\n" % errmsg)
- def _process_forever(self):
- "IRC library process_forever with mutex."
- self.debug(1, "process_forever()")
- while True:
- with self.library_lock:
- self.irc.process_once(ANTI_BUZZ_DELAY)
def _handle_ping(self, connection, _event):
"PING arrived, bump the last-received time for the connection."
if connection.context:
"Determine if and how we can set deaf mode."
if connection.context:
cxt = connection.context
- for lump in event.arguments():
+ arguments = event.arguments
+ # irclib 5.0 compatibility, because the maintainer is a fool
+ if callable(arguments):
+ arguments = arguments()
+ for lump in arguments:
if lump.startswith("DEAF="):
connection.mode(cxt.nickname(), "+"+lump[5:])
elif lump.startswith("MAXCHANNELS="):
connection.context.handle_disconnect()
def _handle_kick(self, connection, event):
"Server hung up the connection."
- self.debug(1, "irker has been kicked from %s on %s" % (event.target(), connection.server))
+ target = event.target
+ # irclib 5.0 compatibility, because the maintainer continues to be a
+ # fool.
+ if callable(target):
+ target = target()
+ self.debug(1, "irker has been kicked from %s on %s" % (target, connection.server))
if connection.context:
- connection.context.handle_kick(event.target())
+ connection.context.handle_kick(target)
def handle(self, line):
"Perform a JSON relay request."
try: