[or-cvs] r22204: {weather} Fix #1361: Accept strings like "MyGreatNode 64E0 A664 09CA 5 (in weather/trunk: . lib/weather)
Christian Fromme
kaner at strace.org
Sun Apr 18 09:55:46 UTC 2010
Author: kaner
Date: 2010-04-18 09:55:46 +0000 (Sun, 18 Apr 2010)
New Revision: 22204
Modified:
weather/trunk/TODO
weather/trunk/Weather.py
weather/trunk/lib/weather/utils.py
Log:
Fix #1361: Accept strings like "MyGreatNode 64E0 A664 09CA 5371 D02E 7176 902B 753A D041 F753"
Modified: weather/trunk/TODO
===================================================================
--- weather/trunk/TODO 2010-04-18 07:50:51 UTC (rev 22203)
+++ weather/trunk/TODO 2010-04-18 09:55:46 UTC (rev 22204)
@@ -4,9 +4,5 @@
* add /usr/sbin/sendmail support for sending email
-* Tolerate a string preceding the identity fingerprint, as long as the
-rest of the line is a valid fingerprint. So people can paste in lines like
- moria1 FFCB 46DB 1339 DA84 674C 70D7 CB58 6434 C437 0441
-
* Let's also look at server versions and alert admins when they should upgrade.
Modified: weather/trunk/Weather.py
===================================================================
--- weather/trunk/Weather.py 2010-04-18 07:50:51 UTC (rev 22203)
+++ weather/trunk/Weather.py 2010-04-18 09:55:46 UTC (rev 22204)
@@ -48,7 +48,9 @@
if not self.request.args.has_key("node"):
logging.error("Request provided no node ID")
return False
- self.node = self.request.args['node'][0]
+ n = self.request.args['node'][0]
+ # Accept node IDs with spaces in between
+ self.node = utils.unifyNodeID(n)
if not utils.checkNodeID(self.node):
logging.error("Bad node ID '%s'" % self.email)
return False
@@ -125,6 +127,7 @@
self.request.finish()
def _rollBack(self, errorMsg):
+ logging.error("Rolling back: %s" % errorMsg)
dbQuery = queries.ROLLBACK_Q % (self.email, self.node)
self.dbConn.runQuery(dbQuery).addCallback(
self._errOut, errorMsg).addErrback(
@@ -133,7 +136,10 @@
def _errback(self, failure):
self._errOut("Error in subscribe: %s" % (failure.getErrorMessage()))
- def _errOut(self, error):
+ def _errOut(self, error, extra=None):
+ if extra is not None:
+ # We're called by callback
+ error = extra
logging.error(error)
self.request.setResponseCode(http.INTERNAL_SERVER_ERROR)
self.request.write(utils.pageOut(error))
@@ -234,7 +240,7 @@
error = "Error in UnsubscribeRequest: %s" % (failure.getErrorMessage())
self._errOut(error)
- def _errOut(self, error):
+ def _errOut(self, error, extra=None):
logging.error(error)
self.request.setResponseCode(http.INTERNAL_SERVER_ERROR)
self.request.write(utils.pageOut(error))
Modified: weather/trunk/lib/weather/utils.py
===================================================================
--- weather/trunk/lib/weather/utils.py 2010-04-18 07:50:51 UTC (rev 22203)
+++ weather/trunk/lib/weather/utils.py 2010-04-18 09:55:46 UTC (rev 22204)
@@ -62,6 +62,22 @@
r = r.replace("-", "x")
return r
+def unifyNodeID(nodeID):
+ """Perform some basic unifying artistics on the node ID"""
+ if nodeID.find(" ") is -1:
+ # No spaces found, check length
+ if len(nodeID) is 40:
+ return nodeID
+ else:
+ logging.error("Bad nodeID: %s" % nodeID)
+ return nodeID
+ unified = nodeID.replace(" ", "")
+ if len(unified) > 40:
+ # Maybe someone pasted the ID like so:
+ # TorKServer 74E0 A664 09CA 5371 D02E 7176 902B 753A D041 F753
+ unified = nodeID.partition(" ")[2].replace(" ", "")
+ return unified
+
def checkNodeID(nodeID):
"""Check if a given Tor node ID looks ok"""
nodeOk = re.compile("(0x)?[a-fA-F0-9]{40}\Z")
More information about the tor-commits
mailing list