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

libbitcoin / libbitcoin-system / 18388593809

09 Oct 2025 08:40PM UTC coverage: 80.965% (-0.01%) from 80.978%
18388593809

push

github

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

Add endpoint::to_string(port) defaulted port value, and to_lower(port).

65 of 80 new or added lines in 4 files covered. (81.25%)

2 existing lines in 1 file now uncovered.

10591 of 13081 relevant lines covered (80.96%)

3619902.14 hits per line

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

73.33
/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/url.hpp>
24
#include <bitcoin/system/config/utilities.hpp>
25
#include <bitcoin/system/define.hpp>
26
#include <bitcoin/system/serial/serial.hpp>
27
#include <bitcoin/system/unicode/unicode.hpp>
28

29
namespace libbitcoin {
30
namespace system {
31
namespace config {
32

33
// Contructors.
34
// ----------------------------------------------------------------------------
35

36
endpoint::endpoint() NOEXCEPT
40✔
37
  : endpoint("localhost", {})
40✔
38
{
39
}
40✔
40

41
endpoint::endpoint(const std::string& uri) THROWS
33✔
42
  : endpoint()
33✔
43
{
44
    std::stringstream(uri) >> *this;
66✔
45
}
33✔
46

47
endpoint::endpoint(const std::string& host, uint16_t port) NOEXCEPT
41✔
48
  : host_(host), port_(port)
41✔
49
{
50
}
41✔
51

52
endpoint::endpoint(const asio::endpoint& uri) NOEXCEPT
×
53
  : endpoint(uri.address(), uri.port())
×
54
{
55
}
×
56

57
endpoint::endpoint(const asio::address& ip, uint16_t port) NOEXCEPT
×
58
  : endpoint(config::to_host(ip), port)
×
59
{
60
}
×
61

62
endpoint::endpoint(const config::authority& authority) NOEXCEPT
×
63
  : endpoint(authority.ip(), authority.port())
×
64
{
65
}
×
66

67
// Properties.
68
// ----------------------------------------------------------------------------
69

70
const std::string& endpoint::host() const NOEXCEPT
57✔
71
{
72
    return host_;
57✔
73
}
74

75
uint16_t endpoint::port() const NOEXCEPT
55✔
76
{
77
    return port_;
55✔
78
}
79

80
// Methods.
81
// ----------------------------------------------------------------------------
82

83
endpoint endpoint::to_local() const NOEXCEPT
1✔
84
{
85
    const auto host = (host_ == "*" ? "localhost" : host_);
1✔
86
    return { host, port_ };
1✔
87
}
88

89
std::string endpoint::to_string(uint16_t default_port) const NOEXCEPT
37✔
90
{
91
    const auto value = is_zero(port()) ? default_port : port();
37✔
92
    return is_zero(value) ? host() : host() + ":" + serialize(value);
124✔
93
}
94

95
std::string endpoint::to_lower(uint16_t default_port) const NOEXCEPT
18✔
96
{
97
    return system::ascii_to_lower(to_string(default_port));
18✔
98
}
99

100
// Operators.
101
// ----------------------------------------------------------------------------
102

103
bool operator==(const endpoint& left, const endpoint& right) NOEXCEPT
14✔
104
{
105
    return left.host() == right.host()
14✔
106
        && left.port() == right.port();
14✔
107
}
108

109
bool operator!=(const endpoint& left, const endpoint& right) NOEXCEPT
6✔
110
{
111
    return !(left == right);
6✔
112
}
113

114
std::istream& operator>>(std::istream& input, endpoint& argument) THROWS
33✔
115
{
116
    std::string value{};
33✔
117
    input >> value;
33✔
118

119
    if (!parse_endpoint(argument.host_, argument.port_, value))
33✔
120
        throw istream_exception(value);
6✔
121

122
    return input;
27✔
123
}
124

UNCOV
125
std::ostream& operator<<(std::ostream& output,
×
126
    const endpoint& argument) NOEXCEPT
127
{
128
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
NEW
129
    output << argument.to_string();
×
130
    BC_POP_WARNING()
UNCOV
131
    return output;
×
132
}
133

134
} // namespace config
135
} // namespace system
136
} // 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