[or-cvs] r24159: {arm} Few fixes for the tor utils: fix: bin function wasn't availa (arm/trunk/src/util)
Damian Johnson
atagar1 at gmail.com
Sun Jan 30 09:06:01 UTC 2011
Author: atagar
Date: 2011-01-30 09:06:00 +0000 (Sun, 30 Jan 2011)
New Revision: 24159
Modified:
arm/trunk/src/util/torTools.py
Log:
Few fixes for the tor utils:
fix: bin function wasn't available before python 2.6 (caught by Paul Menzel)
fix: applying ip masks was done backwards
change: when resolving our own nickname fetch via config instead
Modified: arm/trunk/src/util/torTools.py
===================================================================
--- arm/trunk/src/util/torTools.py 2011-01-29 23:06:27 UTC (rev 24158)
+++ arm/trunk/src/util/torTools.py 2011-01-30 09:06:00 UTC (rev 24159)
@@ -815,12 +815,18 @@
if self.isAlive():
# query the nickname if it isn't yet cached
if not relayFingerprint in self._nicknameLookupCache:
- nsEntry = self.getInfo("ns/id/%s" % relayFingerprint)
-
- if nsEntry: relayNickname = nsEntry[2:nsEntry.find(" ", 2)]
- else: relayNickname = None
-
- self._nicknameLookupCache[relayFingerprint] = relayNickname
+ if relayFingerprint == getInfo("fingerprint"):
+ # this is us, simply check the config
+ myNickname = self.getOption("Nickname", "Unnamed")
+ self._nicknameLookupCache[relayFingerprint] = myNickname
+ else:
+ # check the consensus for the relay
+ nsEntry = self.getInfo("ns/id/%s" % relayFingerprint)
+
+ if nsEntry: relayNickname = nsEntry[2:nsEntry.find(" ", 2)]
+ else: relayNickname = None
+
+ self._nicknameLookupCache[relayFingerprint] = relayNickname
result = self._nicknameLookupCache[relayFingerprint]
@@ -1554,8 +1560,9 @@
if self.ipAddress != "*":
self.ipAddressBin = ""
for octet in self.ipAddress.split("."):
- # bin converts the int to a binary string, then we pad with zeros
- self.ipAddressBin += ("%8s" % bin(int(octet))[2:]).replace(" ", "0")
+ # Converts the int to a binary string, padded with zeros. Source:
+ # http://www.daniweb.com/code/snippet216539.html
+ self.ipAddressBin += "".join([str((int(octet) >> y) & 1) for y in range(7, -1, -1)])
else:
self.ipAddressBin = "0" * 32
@@ -1595,10 +1602,9 @@
if not isIpMatch and self.ipMask != 32:
inputAddressBin = ""
for octet in ipAddress.split("."):
- inputAddressBin += ("%8s" % bin(int(octet))[2:]).replace(" ", "0")
+ inputAddressBin += "".join([str((int(octet) >> y) & 1) for y in range(7, -1, -1)])
- cropSize = 32 - self.ipMask
- isIpMatch = self.ipAddressBin[:cropSize] == inputAddressBin[:cropSize]
+ isIpMatch = self.ipAddressBin[:self.ipMask] == inputAddressBin[:self.ipMask]
if isIpMatch: return self.isAccept
More information about the tor-commits
mailing list