Ejemplo n.º 1
0
Archivo: xor.go Proyecto: rht/bssim
// 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
}
Ejemplo n.º 2
0
Archivo: conn.go Proyecto: rht/bssim
// 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()
}
Ejemplo n.º 3
0
Archivo: util.go Proyecto: rht/bssim
func commonPrefixLen(a, b ID) int {
	return ks.ZeroPrefixLen(u.XOR(a, b))
}
Ejemplo n.º 4
0
Archivo: util.go Proyecto: rht/bssim
func xor(a, b ID) ID {
	return ID(u.XOR(a, b))
}