Coverage Report

Created: 2025-11-24 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libtorrent/src/peer_info.cpp
Line
Count
Source
1
/*
2
3
Copyright (c) 2017-2018, 2020, Arvid Norberg
4
All rights reserved.
5
6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions
8
are met:
9
10
    * Redistributions of source code must retain the above copyright
11
      notice, this list of conditions and the following disclaimer.
12
    * Redistributions in binary form must reproduce the above copyright
13
      notice, this list of conditions and the following disclaimer in
14
      the documentation and/or other materials provided with the distribution.
15
    * Neither the name of the author nor the names of its
16
      contributors may be used to endorse or promote products derived
17
      from this software without specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
POSSIBILITY OF SUCH DAMAGE.
30
31
*/
32
33
#include "libtorrent/peer_info.hpp"
34
35
namespace libtorrent {
36
37
0
  peer_info::peer_info() = default;
38
0
  peer_info::~peer_info() = default;
39
0
  peer_info::peer_info(peer_info const&) = default;
40
0
  peer_info::peer_info(peer_info&&) = default;
41
0
  peer_info& peer_info::operator=(peer_info const&) = default;
42
43
  // This will no longer be necessary with C++17
44
  constexpr peer_flags_t peer_info::interesting;
45
  constexpr peer_flags_t peer_info::choked;
46
  constexpr peer_flags_t peer_info::remote_interested;
47
  constexpr peer_flags_t peer_info::remote_choked;
48
  constexpr peer_flags_t peer_info::supports_extensions;
49
  constexpr peer_flags_t peer_info::local_connection;
50
  constexpr peer_flags_t peer_info::outgoing_connection;
51
  constexpr peer_flags_t peer_info::handshake;
52
  constexpr peer_flags_t peer_info::connecting;
53
#if TORRENT_ABI_VERSION == 1
54
  constexpr peer_flags_t peer_info::queued;
55
#endif
56
  constexpr peer_flags_t peer_info::on_parole;
57
  constexpr peer_flags_t peer_info::seed;
58
  constexpr peer_flags_t peer_info::optimistic_unchoke;
59
  constexpr peer_flags_t peer_info::snubbed;
60
  constexpr peer_flags_t peer_info::upload_only;
61
  constexpr peer_flags_t peer_info::endgame_mode;
62
  constexpr peer_flags_t peer_info::holepunched;
63
  constexpr peer_flags_t peer_info::i2p_socket;
64
  constexpr peer_flags_t peer_info::utp_socket;
65
  constexpr peer_flags_t peer_info::ssl_socket;
66
  constexpr peer_flags_t peer_info::rc4_encrypted;
67
  constexpr peer_flags_t peer_info::plaintext_encrypted;
68
69
  constexpr peer_source_flags_t peer_info::tracker;
70
  constexpr peer_source_flags_t peer_info::dht;
71
  constexpr peer_source_flags_t peer_info::pex;
72
  constexpr peer_source_flags_t peer_info::lsd;
73
  constexpr peer_source_flags_t peer_info::resume_data;
74
  constexpr peer_source_flags_t peer_info::incoming;
75
76
  constexpr bandwidth_state_flags_t peer_info::bw_idle;
77
  constexpr bandwidth_state_flags_t peer_info::bw_limit;
78
  constexpr bandwidth_state_flags_t peer_info::bw_network;
79
  constexpr bandwidth_state_flags_t peer_info::bw_disk;
80
81
#if TORRENT_ABI_VERSION == 1
82
  constexpr bandwidth_state_flags_t peer_info::bw_torrent;
83
  constexpr bandwidth_state_flags_t peer_info::bw_global;
84
#endif
85
86
  constexpr connection_type_t peer_info::standard_bittorrent;
87
  constexpr connection_type_t peer_info::web_seed;
88
  constexpr connection_type_t peer_info::http_seed;
89
90
#if TORRENT_USE_I2P
91
  sha256_hash peer_info::i2p_destination() const
92
0
  {
93
0
    sha256_hash ret;
94
0
    if (!(flags & i2p_socket)) return ret;
95
96
0
    char const* destination = reinterpret_cast<char const*>(&ip);
97
0
    static_assert(sizeof(tcp::endpoint) * 2 >= sizeof(sha256_hash), "tcp::endpoint is smaller than expected");
98
99
0
    std::memcpy(ret.data(), destination, ret.size());
100
0
    return ret;
101
0
  }
102
103
  void peer_info::set_i2p_destination(sha256_hash dest)
104
0
  {
105
0
    flags |= i2p_socket;
106
0
    char* destination = reinterpret_cast<char*>(&ip);
107
0
    static_assert(sizeof(tcp::endpoint) * 2 >= sizeof(sha256_hash), "tcp::endpoint is smaller than expected");
108
109
0
    std::memcpy(destination, dest.data(), dest.size());
110
0
  }
111
#endif
112
}