static void gen_message(Octstr *out) { static int send_seq = 0; unsigned char dest[21]; unsigned char orig[21]; unsigned char scts[TIMESTAMP_MAXLEN]; unsigned char message[481]; unsigned char udh[281]; if (awaiting_response == 1) return; random_address(dest, sizeof(dest)); random_address(orig, sizeof(orig)); make_timestamp(scts, time(NULL)); random_message(message, sizeof(message)); if (random() % 2 == 0) random_hex(udh, sizeof(udh)); else *udh = 0; if (logging == LOG_packets) printf("SND: Deliver message (random)\n"); if (*udh) { send_packet(out, 20, send_seq, 21, dest, 23, orig, 60, scts, 32, udh, 33, message, 0); } else { send_packet(out, 20, send_seq, 21, dest, 23, orig, 60, scts, 33, message, 0); } send_seq += 2; if (send_seq > 255) send_seq = 0; awaiting_response = 1; }
TEST_F(dht_routing_test, TestDhtRestart) { // insert some nodes for (int i = 0; i < 10; ++i) { DhtPeerID p; p.id = random_id(); p.addr = random_address(); DhtPeer* k = impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_TRUE(k) << "a DHT node failed to be inserted"; } impl->Restart(); }
TEST_F(dht_routing_test, TestRoutingTable) { // insert 128 random IDs uniformly distributed // all RTTs are 500, later we'll test to make sure we can replace // them with lower RTT nodes for (int i = 0; i < 256; ++i) { DhtID id = random_id(); id.id[0] = (uint(i) << 24) | 0xffffff; DhtPeerID p; p.id = id; p.addr = random_address(); DhtPeer* k = impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_TRUE(k) << "a DHT node failed to be inserted"; } EXPECT_EQ(256, impl->GetNumPeers()) << "the number of nodes is not the number we inserted"; EXPECT_EQ(32, impl->NumBuckets()) << "the number buckets is supposed to be 32 still"; // now, split the bucket DhtID id = random_id(); // copy just the 8 most significant bits from our ID uint mask = 0xffffffff >> 8; id.id[0] &= mask; id.id[0] |= my_id.id[0] & ~mask; DhtPeerID p; p.id = id; p.addr = random_address(); impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_EQ(33, impl->NumBuckets()) << "the number buckets is supposed to be 33"; // TODO: somehow assert that there are 14 nodes in bucket 1 and 128 nodes // in bucket 0 }
void get_ieee_node_identifier(uuid_node_t* node) { init_zuid_sys_dep_once(); bool& inited(ADOBE_THREAD_LOCAL_STORAGE_ACCESS(zuid_ieee_node_inited)); adobe::uuid_node_t& saved_node(ADOBE_THREAD_LOCAL_STORAGE_ACCESS(zuid_ieee_node)); if (!inited) { random_address(&saved_node); inited = true; } *node = saved_node; }