diff --git a/conf/example/config.json b/conf/example/config.json index 5ead613..d2f87ff 100644 --- a/conf/example/config.json +++ b/conf/example/config.json @@ -21,10 +21,10 @@ "protocol": null, "bind": null, "timeout": 30, - "maxdelay": 5, - "initialdelay": 1, - "factor": 2, - "jitter": 5, + "maxdelay": 360, + "initialdelay": 1.0, + "factor": 2.7182818284590451, + "jitter": 0.11962656472, "nickname": null, "username": null, "realname": null, diff --git a/threshold b/threshold index 9d4df1c..f87a78f 100755 --- a/threshold +++ b/threshold @@ -251,6 +251,7 @@ class IRCBotFactory(ReconnectingClientFactory): def __init__(self, name): self.instance = pool[name] self.name = name + self.client = None self.maxDelay = self.instance["maxdelay"] self.initialDelay = self.instance["initialdelay"] self.factor = self.instance["factor"] @@ -264,8 +265,9 @@ class IRCBotFactory(ReconnectingClientFactory): return entry def clientConnectionLost(self, connector, reason): - self.client.connected = False - self.client.channels = [] + if not self.client == None: + self.client.connected = False + self.client.channels = [] error = reason.getErrorMessage() log("%s: connection lost: %s" % (self.name, error)) helper.sendAll("%s: connection lost: %s" % (self.name, error)) @@ -273,8 +275,9 @@ class IRCBotFactory(ReconnectingClientFactory): #ReconnectingClientFactory.clientConnectionLost(self, connector, reason) def clientConnectionFailed(self, connector, reason): - self.client.connected = False - self.client.channels = [] + if not self.client == None: + self.client.connected = False + self.client.channels = [] error = reason.getErrorMessage() log("%s: connection failed: %s" % (self.name, error)) helper.sendAll("%s: connection failed: %s" % (self.name, error)) @@ -963,6 +966,10 @@ class Helper(object): "protocol": protocol, "bind": config["Default"]["bind"], "timeout": config["Default"]["timeout"], + "maxdelay": config["Default"]["maxdelay"], + "initialdelay": config["Default"]["initialdelay"], + "factor": config["Default"]["factor"], + "jitter": config["Default"]["jitter"], "nickname": nickname, "username": config["Default"]["username"], "realname": config["Default"]["realname"], @@ -1024,13 +1031,20 @@ class Helper(object): spl[2] = None toUnset = True - if spl[1] in ["port", "timeout", "maxdelay", "initialdelay", "factor", "jitter"]: + if spl[1] in ["port", "timeout", "maxdelay"]: try: spl[2] = int(spl[2]) except: failure("Value must be an integer, not %s" % spl[2]) return + if spl[2] in ["initialdelay", "factor", "jitter"]: + try: + spl[3] = float(spl[3]) + except: + failure("Value must be a floating point integer, not %s" % spl[3]) + return + if spl[1] == "protocol": if not toUnset: if not spl[2] in ["ssl", "plain"]: @@ -1108,13 +1122,20 @@ class Helper(object): spl[3] = None toUnset = True - if spl[2] in ["port", "timeout", "maxdelay", "initialdelay", "factor", "jitter"]: + if spl[2] in ["port", "timeout", "maxdelay"]: try: spl[3] = int(spl[3]) except: failure("Value must be an integer, not %s" % spl[3]) return + if spl[2] in ["initialdelay", "factor", "jitter"]: + try: + spl[3] = float(spl[3]) + except: + failure("Value must be a floating point integer, not %s" % spl[3]) + return + if spl[2] == "authtype": if not toUnset: if not spl[3] in ["sp", "ns"]: