update dht_sec definition

This commit is contained in:
Arvid Norberg 2012-06-07 16:29:20 +00:00
parent dd9db7ebb8
commit 40284b2b99
7 changed files with 39 additions and 33 deletions

View File

@ -109,11 +109,11 @@ of IPs, as well as allowing more than one node ID per external IP, the node
ID can be restricted at each class level of the IP.</p>
<p>The expression to calculate a valid ID prefix (from an IPv4 address) is:</p>
<pre class="literal-block">
sha1((ip &amp; 0x30f3fff) .. r)
sha1((ip &amp; 0x01071f7f) .. r)
</pre>
<p>And for an IPv6 address (<tt class="docutils literal">ip</tt> is the high 64 bits of the address):</p>
<pre class="literal-block">
sha1((ip &amp; 0x103070f1f3f7fff) .. r)
sha1((ip &amp; 0x000103070f1f3f7f) .. r)
</pre>
<p><tt class="docutils literal">r</tt> is a random number in the range [0, 7]. The resulting integer,
representing the masked IP address is supposed to be big-endian before
@ -131,8 +131,8 @@ uint8_t* ip; // our external IPv4 or IPv6 address (network byte order)
int num_octets; // the number of octets to consider in ip (4 or 8)
uint8_t node_id[20]; // resulting node ID
uint8_t v4mask[] = { 0x03, 0x0f, 0x3f, 0xff };
uint8_t v6mask[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
uint8_t v4mask[] = { 0x01, 0x07, 0x1f, 0x7f };
uint8_t v6mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f };
uint8_t* mask = num_octets == 4 ? v4_mask : v8_mask;
for (int i = 0; i &lt; num_octets; ++i)
@ -152,11 +152,11 @@ node_id[19] = rand;
<pre class="literal-block">
IP rand example node ID
============ ===== ==========================================
124.31.75.21 1 <strong>8a84ac4d</strong> 0c5d6a4ec8a88e4c6ab4c28b95eee4 <strong>01</strong>
21.75.31.124 86 <strong>1167d8b9</strong> 4e7a08645677bbd1cfe7d8f956d532 <strong>56</strong>
65.23.51.170 22 <strong>508e075d</strong> bc8f112a3d426c84764f8c2a1150e6 <strong>16</strong>
84.124.73.14 65 <strong>095d76cb</strong> 1bb1fe518101ceef99462b947a01ff <strong>41</strong>
43.213.53.83 90 <strong>f62b5a2f</strong> 5b7c4be0237986d5243b87aa6d5130 <strong>5a</strong>
124.31.75.21 1 <strong>f766f9f5</strong> 0c5d6a4ec8a88e4c6ab4c28b95eee4 <strong>01</strong>
21.75.31.124 86 <strong>7ee04779</strong> 4e7a08645677bbd1cfe7d8f956d532 <strong>56</strong>
65.23.51.170 22 <strong>76a626ff</strong> bc8f112a3d426c84764f8c2a1150e6 <strong>16</strong>
84.124.73.14 65 <strong>beb4e619</strong> 1bb1fe518101ceef99462b947a01ff <strong>41</strong>
43.213.53.83 90 <strong>ace5613a</strong> 5b7c4be0237986d5243b87aa6d5130 <strong>5a</strong>
</pre>
<p>The bold parts of the node ID are the important parts. The rest are
random numbers.</p>

View File

@ -65,11 +65,11 @@ ID can be restricted at each class level of the IP.
The expression to calculate a valid ID prefix (from an IPv4 address) is::
sha1((ip & 0x30f3fff) .. r)
sha1((ip & 0x01071f7f) .. r)
And for an IPv6 address (``ip`` is the high 64 bits of the address)::
sha1((ip & 0x103070f1f3f7fff) .. r)
sha1((ip & 0x000103070f1f3f7f) .. r)
``r`` is a random number in the range [0, 7]. The resulting integer,
representing the masked IP address is supposed to be big-endian before
@ -91,8 +91,8 @@ Example code code for calculating a valid node ID::
int num_octets; // the number of octets to consider in ip (4 or 8)
uint8_t node_id[20]; // resulting node ID
uint8_t v4mask[] = { 0x03, 0x0f, 0x3f, 0xff };
uint8_t v6mask[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
uint8_t v4mask[] = { 0x01, 0x07, 0x1f, 0x7f };
uint8_t v6mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f };
uint8_t* mask = num_octets == 4 ? v4_mask : v8_mask;
for (int i = 0; i < num_octets; ++i)
@ -114,11 +114,11 @@ test vectors:
IP rand example node ID
============ ===== ==========================================
124.31.75.21 1 **8a84ac4d** 0c5d6a4ec8a88e4c6ab4c28b95eee4 **01**
21.75.31.124 86 **1167d8b9** 4e7a08645677bbd1cfe7d8f956d532 **56**
65.23.51.170 22 **508e075d** bc8f112a3d426c84764f8c2a1150e6 **16**
84.124.73.14 65 **095d76cb** 1bb1fe518101ceef99462b947a01ff **41**
43.213.53.83 90 **f62b5a2f** 5b7c4be0237986d5243b87aa6d5130 **5a**
124.31.75.21 1 **f766f9f5** 0c5d6a4ec8a88e4c6ab4c28b95eee4 **01**
21.75.31.124 86 **7ee04779** 4e7a08645677bbd1cfe7d8f956d532 **56**
65.23.51.170 22 **76a626ff** bc8f112a3d426c84764f8c2a1150e6 **16**
84.124.73.14 65 **beb4e619** 1bb1fe518101ceef99462b947a01ff **41**
43.213.53.83 90 **ace5613a** 5b7c4be0237986d5243b87aa6d5130 **5a**
The bold parts of the node ID are the important parts. The rest are
random numbers.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@ -5,15 +5,21 @@ import sys
def num_ids(bits, total_bits):
ret = 8;
modulus = 0x100
mod_shift = 6 * 32 / total_bits
while bits >= 0:
ret *= min(1 << bits, 256)
ret = min(ret, modulus)
if total_bits == 32:
bit_dec = 2
else:
bit_dec = 1
num_used = 7;
ret = 3
while bits > 0:
ret += min(num_used, bits)
num_used -= bit_dec
if num_used < 0: num_used = 0
bits -= 8
modulus <<= mod_shift
return ret
return 1 << ret
f = open('ip_id_v4.dat', 'w+')
for i in range(0, 33):

View File

@ -102,8 +102,8 @@ node_id generate_id_impl(address const& ip_, boost::uint32_t r)
{
boost::uint8_t* ip = 0;
const static boost::uint8_t v4mask[] = { 0x03, 0x0f, 0x3f, 0xff };
const static boost::uint8_t v6mask[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
const static boost::uint8_t v4mask[] = { 0x01, 0x07, 0x1f, 0x7f };
const static boost::uint8_t v6mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f };
boost::uint8_t const* mask = 0;
int num_octets = 0;

View File

@ -1733,11 +1733,11 @@ int test_main()
boost::uint8_t prefixes[][4] =
{
{0x8a, 0x84, 0xac, 0x4d},
{0x11, 0x67, 0xd8, 0xb9 },
{0x50, 0x8e, 0x07, 0x5d },
{0x09, 0x5d, 0x76, 0xcb },
{0xf6, 0x2b, 0x5a, 0x2f },
{0xf7, 0x66, 0xf9, 0xf5},
{0x7e, 0xe0, 0x47, 0x79 },
{0x76, 0xa6, 0x26, 0xff },
{0xbe, 0xb4, 0xe6, 0x19 },
{0xac, 0xe5, 0x61, 0x3a },
};
for (int i = 0; i < 5; ++i)