Browse Source

64-bits alignment for RoutingKey

pull/72/head
orignal 11 years ago
parent
commit
eb44fdf7a8
  1. 9
      Identity.cpp
  2. 7
      Identity.h

9
Identity.cpp

@ -98,12 +98,11 @@ namespace data
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2) XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2)
{ {
// TODO: implementation depends on CPU
XORMetric m; XORMetric m;
((uint64_t *)m.metric)[0] = ((uint64_t *)key1.hash)[0] ^ ((uint64_t *)key2.hash)[0]; m.metric_ll[0] = key1.hash_ll[0] ^ key2.hash_ll[0];
((uint64_t *)m.metric)[1] = ((uint64_t *)key1.hash)[1] ^ ((uint64_t *)key2.hash)[1]; m.metric_ll[1] = key1.hash_ll[1] ^ key2.hash_ll[1];
((uint64_t *)m.metric)[2] = ((uint64_t *)key1.hash)[2] ^ ((uint64_t *)key2.hash)[2]; m.metric_ll[2] = key1.hash_ll[2] ^ key2.hash_ll[2];
((uint64_t *)m.metric)[3] = ((uint64_t *)key1.hash)[3] ^ ((uint64_t *)key2.hash)[3]; m.metric_ll[3] = key1.hash_ll[3] ^ key2.hash_ll[3];
return m; return m;
} }
} }

7
Identity.h

@ -89,14 +89,19 @@ namespace data
void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions
// kademlia // kademlia
struct RoutingKey union RoutingKey
{ {
uint8_t hash[32]; uint8_t hash[32];
uint64_t hash_ll[4];
}; };
struct XORMetric struct XORMetric
{
union
{ {
uint8_t metric[32]; uint8_t metric[32];
uint64_t metric_ll[4];
};
void SetMin () { memset (metric, 0, 32); }; void SetMin () { memset (metric, 0, 32); };
void SetMax () { memset (metric, 0xFF, 32); }; void SetMax () { memset (metric, 0xFF, 32); };

Loading…
Cancel
Save