summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authortravis laduke <[email protected]>2023-05-17 07:18:42 -0700
committerTravis LaDuke <[email protected]>2023-05-25 11:21:35 -0700
commite11d70e4080ffb7ebeb2b76e467d574f59afd5b4 (patch)
tree00123774e04ccb6d985cf690ac1df0da13069c83 /osdep
parent60d2138f30b0378a156c8b25d5a29682882aba0a (diff)
cache getifaddrs - windows
Diffstat (limited to 'osdep')
-rw-r--r--osdep/WindowsEthernetTap.cpp13
-rw-r--r--osdep/WindowsEthernetTap.hpp3
2 files changed, 15 insertions, 1 deletions
diff --git a/osdep/WindowsEthernetTap.cpp b/osdep/WindowsEthernetTap.cpp
index db65bbf4..7a9d4b30 100644
--- a/osdep/WindowsEthernetTap.cpp
+++ b/osdep/WindowsEthernetTap.cpp
@@ -467,7 +467,8 @@ WindowsEthernetTap::WindowsEthernetTap(
_pathToHelpers(hp),
_run(true),
_initialized(false),
- _enabled(true)
+ _enabled(true),
+ _lastIfAddrsUpdate(0)
{
char subkeyName[1024];
char subkeyClass[1024];
@@ -749,6 +750,14 @@ std::vector<InetAddress> WindowsEthernetTap::ips() const
if (!_initialized)
return addrs;
+ uint64_t now = OSUtils::now();
+
+ if ((now - _lastIfAddrsUpdate) <= GETIFADDRS_CACHE_TIME) {
+ return _ifaddrs;
+ }
+
+ _lastIfAddrsUpdate = now;
+
try {
MIB_UNICASTIPADDRESS_TABLE *ipt = (MIB_UNICASTIPADDRESS_TABLE *)0;
if (GetUnicastIpAddressTable(AF_UNSPEC,&ipt) == NO_ERROR) {
@@ -777,6 +786,8 @@ std::vector<InetAddress> WindowsEthernetTap::ips() const
std::sort(addrs.begin(),addrs.end());
addrs.erase(std::unique(addrs.begin(),addrs.end()),addrs.end());
+ _ifaddrs = addrs;
+
return addrs;
}
diff --git a/osdep/WindowsEthernetTap.hpp b/osdep/WindowsEthernetTap.hpp
index a08042d4..a79dac0e 100644
--- a/osdep/WindowsEthernetTap.hpp
+++ b/osdep/WindowsEthernetTap.hpp
@@ -152,6 +152,9 @@ private:
volatile bool _run;
volatile bool _initialized;
volatile bool _enabled;
+
+ mutable std::vector<InetAddress> _ifaddrs;
+ mutable uint64_t _lastIfAddrsUpdate;
};
} // namespace ZeroTier