Beispiel #1
0
	h.update(addr)
	return h.hexdigest()

# returns hash distance from id1 to id2
def id_distance(id1, id2):
	if id1 == id2:
		# special case: if we're the only node, we need to have the distance
		# to our successor be maximum for forwarding to work correctly;
		# so if they're the same, the distance is 2^160
		return 2 ** 160
	l1 = long(id1, 16)
	l2 = long(id2, 16)
	if l1 > l2:
		return 2 ** 160 + l2 - l1
	else:
		return l2 - l1

def add_to_id(id, n):
	n = long(n)
	id = long(id, 16)
	sum = (id + n) & (2**160 - 1)
	return '%040x' % (id + n)

if __name__ == '__main__':
	if len(sys.argv) != 3:
		sys.exit("Usage: %s myhost server" % sys.argv[0])
	host = sys.argv[1]
	server = sys.argv[2]
	m = Manager(Main(), host, server)
	m.run()