• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-system / 15655570685

14 Jun 2025 07:53PM UTC coverage: 81.172% (+0.08%) from 81.096%
15655570685

push

github

web-flow
Merge pull request #1701 from evoskuil/master

Move authority and endpoint config classes from network.

177 of 206 new or added lines in 5 files covered. (85.92%)

10610 of 13071 relevant lines covered (81.17%)

3626848.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/config/endpoint.cpp
1
/**
2
 * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/system/config/endpoint.hpp>
20

21
#include <sstream>
22
#include <bitcoin/system/config/authority.hpp>
23
#include <bitcoin/system/config/utilities.hpp>
24
#include <bitcoin/system/define.hpp>
25
#include <bitcoin/system/serial/serial.hpp>
26

27
namespace libbitcoin {
28
namespace system {
29
namespace config {
30

31
// Contructors.
32
// ----------------------------------------------------------------------------
33

34
endpoint::endpoint() NOEXCEPT
45✔
35
  : endpoint({}, "localhost", {})
90✔
36
{
37
}
45✔
38

39
endpoint::endpoint(const std::string& uri) THROWS
38✔
40
  : endpoint()
38✔
41
{
42
    std::stringstream(uri) >> *this;
76✔
43
}
38✔
44

NEW
45
endpoint::endpoint(const std::string& host, uint16_t port) NOEXCEPT
×
NEW
46
  : endpoint({}, host, port)
×
47
{
NEW
48
}
×
49

50
endpoint::endpoint(const std::string& scheme, const std::string& host,
47✔
51
    uint16_t port) NOEXCEPT
47✔
52
  : scheme_(scheme), host_(host), port_(port)
47✔
53
{
54
}
47✔
55

NEW
56
endpoint::endpoint(const asio::endpoint& uri) NOEXCEPT
×
NEW
57
  : endpoint(uri.address(), uri.port())
×
58
{
NEW
59
}
×
60

NEW
61
endpoint::endpoint(const asio::address& ip, uint16_t port) NOEXCEPT
×
NEW
62
  : endpoint(config::to_host(ip), port)
×
63
{
NEW
64
}
×
65

NEW
66
endpoint::endpoint(const config::authority& authority) NOEXCEPT
×
NEW
67
  : endpoint(authority.ip(), authority.port())
×
68
{
NEW
69
}
×
70

71
// Properties.
72
// ----------------------------------------------------------------------------
73

74
const std::string& endpoint::scheme() const NOEXCEPT
23✔
75
{
76
    return scheme_;
23✔
77
}
78

79
const std::string& endpoint::host() const NOEXCEPT
34✔
80
{
81
    return host_;
34✔
82
}
83

84
uint16_t endpoint::port() const NOEXCEPT
40✔
85
{
86
    return port_;
40✔
87
}
88

89
// Methods.
90
// ----------------------------------------------------------------------------
91

92
std::string endpoint::to_uri() const NOEXCEPT
11✔
93
{
94
    std::stringstream value{};
11✔
95
    value << *this;
11✔
96
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
97
    return value.str();
11✔
98
    BC_POP_WARNING()
99
}
11✔
100

101
endpoint endpoint::to_local() const NOEXCEPT
2✔
102
{
103
    const auto host = (host_ == "*" ? "localhost" : host_);
2✔
104
    return endpoint(scheme_, host, port_);
2✔
105
}
106

107
// protected
NEW
108
std::string endpoint::to_authority() const NOEXCEPT
×
109
{
NEW
110
    return is_zero(port()) ? host() : host() + ":" + serialize(port());
×
111
}
112

113
// Operators.
114
// ----------------------------------------------------------------------------
115

116
bool operator==(const endpoint& left, const endpoint& right) NOEXCEPT
14✔
117
{
118
    return left.host() == right.host()
14✔
119
        && left.port() == right.port()
12✔
120
        && left.scheme() == right.scheme();
22✔
121
}
122

123
bool operator!=(const endpoint& left, const endpoint& right) NOEXCEPT
6✔
124
{
125
    return !(left == right);
6✔
126
}
127

128
std::istream& operator>>(std::istream& input,
38✔
129
    endpoint& argument) THROWS
130
{
131
    std::string value{};
38✔
132
    input >> value;
38✔
133

134
    if (!parse_endpoint(argument.scheme_, argument.host_, argument.port_, value))
38✔
135
        throw istream_exception(value);
8✔
136

137
    return input;
30✔
138
}
139

140
std::ostream& operator<<(std::ostream& output,
11✔
141
    const endpoint& argument) NOEXCEPT
142
{
143
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
144
    output
11✔
145
        << (argument.scheme().empty() ? "" : argument.scheme() + "://")
11✔
146
        << (argument.host())
147
        << (is_zero(argument.port()) ? "" : ":" + serialize(argument.port()));
49✔
148
    BC_POP_WARNING()
149
    return output;
11✔
150
}
151

152
} // namespace config
153
} // namespace system
154
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc