forked from leeter/WinMTR-refresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinMTRNetworkData.h
More file actions
75 lines (65 loc) · 1.98 KB
/
Copy pathWinMTRNetworkData.h
File metadata and controls
75 lines (65 loc) · 1.98 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <cstdint>
#include <stop_token>
#include <string>
#include <vector>
namespace winmtr::network_data {
struct IpConnectionInfo final {
std::wstring address;
std::wstring hostname;
std::wstring city;
std::wstring region;
std::wstring country;
std::wstring countryCode;
std::wstring asn;
std::wstring isp;
std::wstring source;
std::wstring failureReason;
[[nodiscard]] bool available() const noexcept { return !address.empty(); }
};
enum class EcsSupport {
supported,
unsupported,
unknown
};
struct DnsConnectionInfo final {
std::wstring publicAddress;
std::wstring hostname;
std::wstring city;
std::wstring region;
std::wstring country;
std::wstring countryCode;
std::wstring asn;
std::wstring provider;
std::wstring ecsSubnet;
EcsSupport ecsSupport = EcsSupport::unknown;
std::vector<std::wstring> localServers;
std::wstring source;
std::wstring metadataSource;
std::wstring failureReason;
};
struct CurrentNetworkInfo final {
IpConnectionInfo ipv4;
IpConnectionInfo ipv6;
DnsConnectionInfo dns;
std::vector<std::wstring> successfulSources;
std::wstring refreshError;
std::uint64_t updatedAtUnixMs = 0;
bool complete = false;
bool timedOut = false;
bool refreshing = false;
bool stale = false;
[[nodiscard]] bool anyAvailable() const noexcept
{
return ipv4.available() || ipv6.available() || !dns.publicAddress.empty() || !dns.localServers.empty();
}
};
// These routines are intentionally synchronous. Callers run them on a background
// std::jthread so Windows 7 does not need the Windows Runtime asynchronous APIs.
[[nodiscard]] CurrentNetworkInfo queryCurrent(std::stop_token stopToken = {});
[[nodiscard]] IpConnectionInfo queryAddress(const std::wstring& address,
std::stop_token stopToken = {}, bool resolveHostname = true,
bool allowSecondaryHttpFallback = false);
[[nodiscard]] std::wstring formatDetails(const CurrentNetworkInfo& info);
[[nodiscard]] bool isPublicAddress(const std::wstring& address) noexcept;
} // namespace winmtr::network_data