// ID returns the ID of a given Conn. func ID(c Conn) string { l := fmt.Sprintf("%s/%s", c.LocalMultiaddr(), c.LocalPeer().Pretty()) r := fmt.Sprintf("%s/%s", c.RemoteMultiaddr(), c.RemotePeer().Pretty()) lh := u.Hash([]byte(l)) rh := u.Hash([]byte(r)) ch := u.XOR(lh, rh) return peer.ID(ch).Pretty() }
// Distance returns the distance metric in this key space func (s *xorKeySpace) Distance(k1, k2 Key) *big.Int { // XOR the keys k3 := u.XOR(k1.Bytes, k2.Bytes) // interpret it as an integer dist := big.NewInt(0).SetBytes(k3) return dist }
func commonPrefixLen(a, b ID) int { return ks.ZeroPrefixLen(u.XOR(a, b)) }
func xor(a, b ID) ID { return ID(u.XOR(a, b)) }