File: DHT_test_util.cc

package info (click to toggle)
libtoxcore 0.2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,124 kB
  • sloc: ansic: 75,034; cpp: 4,933; sh: 1,115; python: 651; makefile: 329; perl: 39
file content (32 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "DHT_test_util.hh"

#include <cstring>
#include <iomanip>

#include "DHT.h"
#include "crypto_core.h"
#include "crypto_core_test_util.hh"
#include "network.h"
#include "network_test_util.hh"

Node_format random_node_format(const Random *rng)
{
    Node_format node;
    auto const pk = random_pk(rng);
    std::copy(pk.begin(), pk.end(), node.public_key);
    node.ip_port = random_ip_port(rng);
    return node;
}

bool operator==(Node_format const &a, Node_format const &b)
{
    return std::memcmp(a.public_key, b.public_key, sizeof(a.public_key)) == 0
        && a.ip_port == b.ip_port;
}

std::ostream &operator<<(std::ostream &out, Node_format const &v)
{
    return out << "\n    Node_format{\n"
               << "      public_key = " << PublicKey(v.public_key) << ",\n"
               << "      ip_port = " << v.ip_port << " }";
}