| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "EPollManager.h" | ||
| 18 | #include "Warnings.h" // WarningHolder -- needed directly for NOPCH builds | ||
| 19 | |||
| 20 | #include <arpa/inet.h> | ||
| 21 | #include <curl/curl.h> | ||
| 22 | #include <net/if.h> | ||
| 23 | #include <netinet/in.h> | ||
| 24 | #include <sys/types.h> | ||
| 25 | #include <algorithm> | ||
| 26 | #include <chrono> | ||
| 27 | #include <cmath> | ||
| 28 | #include <condition_variable> | ||
| 29 | #include <cstddef> | ||
| 30 | #include <cstdint> | ||
| 31 | #include <cstdlib> | ||
| 32 | #include <ctime> | ||
| 33 | #include <ctype.h> | ||
| 34 | #include <deque> | ||
| 35 | #include <errno.h> | ||
| 36 | #include <functional> | ||
| 37 | #include <ifaddrs.h> | ||
| 38 | #include <list> | ||
| 39 | #include <map> | ||
| 40 | #include <math.h> | ||
| 41 | #include <memory> | ||
| 42 | #include <string_view> | ||
| 43 | #include <mutex> | ||
| 44 | #include <netdb.h> | ||
| 45 | #include <set> | ||
| 46 | #include <stdio.h> | ||
| 47 | #include <string.h> | ||
| 48 | #include <string> | ||
| 49 | #include <strings.h> | ||
| 50 | #include <thread> | ||
| 51 | #include <unistd.h> | ||
| 52 | #include <utility> | ||
| 53 | #include <vector> | ||
| 54 | |||
| 55 | #include "CurlManager.h" | ||
| 56 | #include "FileMonitor.h" | ||
| 57 | #include "NetworkController.h" | ||
| 58 | #include "NetworkMonitor.h" | ||
| 59 | #include "Player.h" | ||
| 60 | #include "Plugins.h" | ||
| 61 | #include "Sequence.h" | ||
| 62 | #include "command.h" | ||
| 63 | #include "common.h" | ||
| 64 | #include "fppversion.h" | ||
| 65 | #include "log.h" | ||
| 66 | #include "settings.h" | ||
| 67 | #include "channeloutput/ChannelOutputSetup.h" | ||
| 68 | #include "channeloutput/channeloutputthread.h" | ||
| 69 | #include "e131bridge.h" | ||
| 70 | #include "commands/Commands.h" | ||
| 71 | #include "mediaoutput/MediaOutputBase.h" | ||
| 72 | #include "mediaoutput/mediaoutput.h" | ||
| 73 | |||
| 74 | #include "MultiSync.h" | ||
| 75 | #include "Timers.h" | ||
| 76 | |||
| 77 | // Quiescence for the MultiSync settings listeners. The settings code copies | ||
| 78 | // the listeners out and calls them with no lock held, so unregistering one | ||
| 79 | // does not wait for a call already in progress (or about to start from a | ||
| 80 | // copy). Each call counts itself in here and gives up once ShutdownSync() has | ||
| 81 | // set the flag; ShutdownSync() waits for the count to drain before it closes | ||
| 82 | // the sockets ReloadSyncDestinations() works on. Defined ahead of INSTANCE so | ||
| 83 | // they outlive it during static destruction. | ||
| 84 | static std::mutex s_listenerQuiesceLock; | ||
| 85 | static std::condition_variable s_listenerQuiesceCV; | ||
| 86 | static int s_listenersInFlight = 0; | ||
| 87 | static bool s_listenersShutdown = false; | ||
| 88 | |||
| 89 | // Serializes OpenControlSockets(): it is reached lazily from several threads | ||
| 90 | // (the main loop, command and API threads), which could each see no socket | ||
| 91 | // and open one, leaking all but the last. | ||
| 92 | static std::mutex s_controlSockOpenLock; | ||
| 93 | |||
| 94 | // Addresses with an HTTP re-ping queued or running. PeriodicPing() re-queues | ||
| 95 | // every stale non-MultiSync remote on each pass, and those probes mostly sit | ||
| 96 | // out a connect timeout against boxes that are down, so without this the | ||
| 97 | // queue grows faster than it drains. Guarded by m_httpProbeLock. | ||
| 98 | static std::set<std::string> s_httpPingPending; | ||
| 99 | |||
| 100 | // The most HTTP re-pings that may wait in the queue. Every path that queues | ||
| 101 | // one is fed from the network, and the Twinkly discovery replies by anyone | ||
| 102 | // on the LAN, so the queue needs a bound of its own; real remotes and lights | ||
| 103 | // come to far fewer. | ||
| 104 | #define HTTP_PING_MAX_QUEUED 512 | ||
| 105 | |||
| 106 | // caller holds m_httpProbeLock | ||
| 107 | 159 | static void QueueHTTPPing(std::deque<std::string>& queue, const std::string& address) { | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
|
159 | if (queue.size() >= HTTP_PING_MAX_QUEUED) { |
| 109 | ✗ | LogDebug(VB_SYNC, "Not probing %s over HTTP: %d probes already queued\n", address.c_str(), (int)queue.size()); | |
| 110 | ✗ | return; | |
| 111 | } | ||
| 112 |
1/4✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
159 | if (s_httpPingPending.insert(address).second) { |
| 113 | 159 | queue.push_back(address); | |
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | MultiSync MultiSync::INSTANCE; | ||
| 118 | MultiSync* multiSync = &MultiSync::INSTANCE; | ||
| 119 | |||
| 120 | static const char* MULTISYNC_MULTICAST_ADDRESS = "239.70.80.80"; // 239.F.P.P | ||
| 121 | |||
| 122 | // Ping packet extraData lengths (see docs/ControlProtocol.txt). Each version | ||
| 123 | // only appends to the one before, and receivers parse by length, never by the | ||
| 124 | // version byte: every FPP release and xLights treat an unknown version as v3. | ||
| 125 | static constexpr int PING_V3_LEN = 294; | ||
| 126 | static constexpr int PING_UUID_MAX = 64; // plus its NUL | ||
| 127 | static constexpr int PING_V4_LEN = PING_V3_LEN + PING_UUID_MAX + 1; | ||
| 128 | static uint32_t MULTISYNC_MULTICAST_ADD = inet_addr(MULTISYNC_MULTICAST_ADDRESS); | ||
| 129 | |||
| 130 | 2751 | NetInterfaceInfo::NetInterfaceInfo() : | |
| 131 | 2751 | address(0), | |
| 132 | 2751 | broadcastAddress(0), | |
| 133 | 2751 | multicastSocket(-1) { | |
| 134 | 2751 | } | |
| 135 | 265 | NetInterfaceInfo::~NetInterfaceInfo() { | |
| 136 |
2/2✓ Branch 0 taken 206 times.
✓ Branch 1 taken 59 times.
|
265 | if (multicastSocket != -1) { |
| 137 | 206 | LogDebug(VB_SYNC, "Closing multicast socket for %s\n", interfaceName.c_str()); | |
| 138 | 206 | close(multicastSocket); | |
| 139 | } | ||
| 140 | 265 | } | |
| 141 | |||
| 142 | 13137 | static bool GetIPForHost(std::string& target) { | |
| 143 | // ResolveHostToIPv4() is reentrant (gethostbyname()/inet_ntoa() return | ||
| 144 | // pointers into static, per-process buffers, and MultiSync resolves from | ||
| 145 | // several threads concurrently -- DiscoverIPViaHTTP runs from a curl | ||
| 146 | // completion while the main-loop ProcessControlPacket path resolves too). | ||
| 147 | // It also caches, which matters here: this is called once per configured | ||
| 148 | // output address from three separate points during startup, and a name that | ||
| 149 | // does not resolve costs seconds every time. We still rewrite target as a | ||
| 150 | // dotted-quad, because callers depend on that form (split(target, '.') and | ||
| 151 | // inet_addr(target)). | ||
| 152 |
1/2✓ Branch 0 taken 13137 times.
✗ Branch 1 not taken.
|
13137 | std::string ip = ResolveHostToIPv4(target); |
| 153 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 13106 times.
|
13137 | if (ip.empty()) { |
| 154 | 31 | return false; | |
| 155 | } | ||
| 156 |
1/2✓ Branch 0 taken 13106 times.
✗ Branch 1 not taken.
|
13106 | target = ip; |
| 157 | 13106 | return true; | |
| 158 | 13137 | } | |
| 159 | |||
| 160 | // 169.254/16: what an interface holds when DHCP hasn't answered (yet). | ||
| 161 | 2743499 | static bool IsIPv4LinkLocal(const std::string& address) { | |
| 162 |
2/4✓ Branch 0 taken 2743499 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2743499 times.
✗ Branch 3 not taken.
|
5486998 | return startsWith(address, "169.254."); |
| 163 | } | ||
| 164 | |||
| 165 | // Adds the hosts in a comma-separated remote list setting (MultiSyncRemotes, | ||
| 166 | // MultiSyncExtraRemotes) to `remotes`. Quotes are stripped from each end of an | ||
| 167 | // entry on its own, not only as a pair: the web UI used to PUT | ||
| 168 | // MultiSyncRemotes as a JSON string, which stores the whole list quoted | ||
| 169 | // ("a,b,c", so the first entry has only an opening quote and the last only a | ||
| 170 | // closing one) and an empty list as a bare pair of quotes, while an entry | ||
| 171 | // typed with its own quotes has both. Left in, a quote fails inet_addr(), and | ||
| 172 | // a lone "" becomes a host name that costs a full DNS timeout (~4s, on the | ||
| 173 | // settings-reload thread) on every reload. | ||
| 174 | 2754 | static void AddRemotesFromSetting(const char* setting, std::set<std::string>& remotes) { | |
| 175 |
4/6✓ Branch 0 taken 2754 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2754 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 65 times.
✓ Branch 5 taken 2754 times.
|
2819 | for (auto& token : split(getSetting(setting), ',')) { |
| 176 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | TrimWhiteSpace(token); |
| 177 |
8/8✓ Branch 0 taken 85 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 67 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 63 times.
✓ Branch 6 taken 22 times.
✓ Branch 7 taken 65 times.
|
87 | while (!token.empty() && (token.front() == '"' || token.back() == '"')) { |
| 178 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 4 times.
|
22 | if (token.front() == '"') { |
| 179 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | token.erase(0, 1); |
| 180 | } | ||
| 181 |
5/6✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 4 times.
|
22 | if (!token.empty() && token.back() == '"') { |
| 182 | 18 | token.pop_back(); | |
| 183 | } | ||
| 184 |
1/2✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
|
22 | TrimWhiteSpace(token); |
| 185 | } | ||
| 186 |
3/4✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
✓ Branch 3 taken 2 times.
|
65 | if (token != "") { |
| 187 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | remotes.insert(token); |
| 188 | } | ||
| 189 | 2754 | } | |
| 190 | 2754 | } | |
| 191 | |||
| 192 | // Parses MultiSyncUnicastSubnets: comma-separated A.B.C.D/N subnets or bare | ||
| 193 | // A.B.C.D addresses (a /32). Each entry is returned as (network, mask) in | ||
| 194 | // network byte order. An entry that doesn't parse is logged and skipped. | ||
| 195 | 54 | static std::vector<std::pair<uint32_t, uint32_t>> ParseUnicastSubnetFilter() { | |
| 196 | 54 | std::vector<std::pair<uint32_t, uint32_t>> filters; | |
| 197 |
4/6✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✓ Branch 5 taken 54 times.
|
61 | for (auto& token : split(getSetting("MultiSyncUnicastSubnets"), ',')) { |
| 198 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | TrimWhiteSpace(token); |
| 199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (token.empty()) { |
| 200 | 3 | continue; | |
| 201 | } | ||
| 202 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | std::string ip = token; |
| 203 | 7 | int bits = 32; | |
| 204 | 7 | size_t slash = token.find('/'); | |
| 205 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (slash != std::string::npos) { |
| 206 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | ip = token.substr(0, slash); |
| 207 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::string b = token.substr(slash + 1); |
| 208 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | TrimWhiteSpace(ip); |
| 209 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | TrimWhiteSpace(b); |
| 210 | 3 | char* end = nullptr; | |
| 211 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | long v = b.empty() ? -1 : strtol(b.c_str(), &end, 10); |
| 212 |
4/8✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
3 | if (v < 0 || v > 32 || (end && *end)) { |
| 213 | ✗ | LogWarn(VB_SYNC, "Ignoring invalid MultiSync unicast subnet '%s'\n", token.c_str()); | |
| 214 | ✗ | continue; | |
| 215 | } | ||
| 216 | 3 | bits = (int)v; | |
| 217 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | } |
| 218 | struct in_addr a; | ||
| 219 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (inet_pton(AF_INET, ip.c_str(), &a) != 1) { |
| 220 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | LogWarn(VB_SYNC, "Ignoring invalid MultiSync unicast subnet '%s'\n", token.c_str()); |
| 221 | 3 | continue; | |
| 222 | } | ||
| 223 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | uint32_t mask = bits == 0 ? 0 : htonl(0xFFFFFFFFu << (32 - bits)); |
| 224 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | filters.emplace_back(a.s_addr & mask, mask); |
| 225 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
|
61 | } |
| 226 | 54 | return filters; | |
| 227 | ✗ | } | |
| 228 | |||
| 229 | // Whether `sys` is the device reporting (hostname, fppMode, type, uuid) from | ||
| 230 | // some other address. A ping packet carries no UUID, so a ping alone can only | ||
| 231 | // be matched on what it does carry; when both sides do know a UUID of the same | ||
| 232 | // kind (real or MAC-derived) that decides it instead, which keeps two | ||
| 233 | // controllers left on the same default hostname apart. | ||
| 234 | 2 | static bool IsSameDevice(const MultiSyncSystem& sys, const std::string& hostname, | |
| 235 | FPPMode fppMode, MultiSyncSystemType type, const std::string& uuid) { | ||
| 236 | // update() stores MASTER_MODE as PLAYER_MODE | ||
| 237 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (fppMode == MASTER_MODE) { |
| 238 | ✗ | fppMode = PLAYER_MODE; | |
| 239 | } | ||
| 240 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2 | if (hostname.empty() || sys.hostname != hostname || sys.fppMode != fppMode) { |
| 241 | ✗ | return false; | |
| 242 | } | ||
| 243 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | auto known = [](const std::string& u) { return !u.empty() && u != "Unknown"; }; |
| 244 |
4/8✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 | if (known(uuid) && known(sys.uuid) && |
| 245 |
10/28✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
10 | startsWith(uuid, MAC_UUID_PREFIX) == startsWith(sys.uuid, MAC_UUID_PREFIX)) { |
| 246 | 2 | return uuid == sys.uuid; | |
| 247 | } | ||
| 248 | ✗ | return sys.type == type; | |
| 249 | } | ||
| 250 | |||
| 251 | 10808 | void MultiSyncSystem::update(MultiSyncSystemType type, | |
| 252 | unsigned int majorVersion, unsigned int minorVersion, | ||
| 253 | FPPMode fppMode, | ||
| 254 | const std::string& address, | ||
| 255 | const std::string& hostname, | ||
| 256 | const std::string& version, | ||
| 257 | const std::string& model, | ||
| 258 | const std::string& ranges, | ||
| 259 | const std::string& uuid, | ||
| 260 | const bool multiSync, | ||
| 261 | const bool sendingMultiSync) { | ||
| 262 | // UUID precedence. A device that reports its own UUID always wins; the | ||
| 263 | // MAC-derived identity below is only ever a stand-in for one, so it must | ||
| 264 | // never overwrite a real UUID, and a real UUID arriving later must replace | ||
| 265 | // it. | ||
| 266 |
7/10✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124 times.
✓ Branch 3 taken 10684 times.
✓ Branch 4 taken 124 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 124 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 124 times.
✓ Branch 9 taken 10684 times.
|
10808 | if (uuid != "Unknown" && uuid != "") { |
| 267 |
8/16✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 124 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 102 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 21 times.
✓ Branch 8 taken 124 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 124 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
497 | if (!startsWith(uuid, MAC_UUID_PREFIX) || this->uuid.empty() || |
| 268 |
8/16✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 123 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 123 times.
✓ Branch 10 taken 124 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
126 | startsWith(this->uuid, MAC_UUID_PREFIX)) { |
| 269 |
1/2✓ Branch 0 taken 124 times.
✗ Branch 1 not taken.
|
124 | this->uuid = uuid; |
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | // Nothing reported a UUID for this device. That is the normal case for | ||
| 274 | // every controller that isn't full FPP: the ping packet carries no UUID | ||
| 275 | // field at all, so ProcessPingPacket() has none to pass on, and | ||
| 276 | // NetworkController only fills one in for an FPP instance. Without an | ||
| 277 | // identity the UI has to key the row on the hostname, which collides as | ||
| 278 | // soon as two controllers ship with the same default name and changes | ||
| 279 | // under it whenever someone renames one. | ||
| 280 | // | ||
| 281 | // The MAC is the stable identity such a device does have, and the kernel | ||
| 282 | // already knows it for anything on a directly attached subnet. Only look | ||
| 283 | // it up while we still have nothing -- once an identity of either kind is | ||
| 284 | // recorded this stops running, so it costs one small read per device | ||
| 285 | // rather than one per ping. | ||
| 286 |
2/2✓ Branch 0 taken 4641 times.
✓ Branch 1 taken 6167 times.
|
10808 | if (this->uuid.empty()) { |
| 287 | // The parameter, not this->address: on a system being created that | ||
| 288 | // member is still empty here, and is only assigned further down. | ||
| 289 |
1/2✓ Branch 0 taken 4641 times.
✗ Branch 1 not taken.
|
4641 | std::string mac = GetMacForAddress(address); |
| 290 |
2/2✓ Branch 0 taken 203 times.
✓ Branch 1 taken 4438 times.
|
4641 | if (!mac.empty()) { |
| 291 |
1/2✓ Branch 0 taken 203 times.
✗ Branch 1 not taken.
|
203 | this->uuid = MAC_UUID_PREFIX + mac; |
| 292 | } | ||
| 293 | 4641 | } | |
| 294 | |||
| 295 | // If this record is from info learned via the MultiSync protocol, | ||
| 296 | // don't allow it to be overwritten by data discovered elsewhere | ||
| 297 | // except for uuid. | ||
| 298 |
3/4✓ Branch 0 taken 4866 times.
✓ Branch 1 taken 5942 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4866 times.
|
10808 | if (this->multiSync && !multiSync) |
| 299 | ✗ | return; | |
| 300 | |||
| 301 | 10808 | this->fppMode = fppMode; | |
| 302 | 10808 | this->sendingMultiSync = sendingMultiSync; | |
| 303 |
2/2✓ Branch 0 taken 177 times.
✓ Branch 1 taken 10631 times.
|
10808 | if (fppMode == MASTER_MODE) { |
| 304 | 177 | this->fppMode = PLAYER_MODE; | |
| 305 | 177 | this->sendingMultiSync = true; | |
| 306 | } | ||
| 307 | |||
| 308 | 10808 | this->type = type; | |
| 309 | 10808 | this->majorVersion = majorVersion; | |
| 310 | 10808 | this->minorVersion = minorVersion; | |
| 311 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | this->address = address; |
| 312 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | this->hostname = hostname; |
| 313 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | this->version = version; |
| 314 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | this->model = model; |
| 315 |
9/10✓ Branch 0 taken 6380 times.
✓ Branch 1 taken 4428 times.
✓ Branch 2 taken 6380 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 245 times.
✓ Branch 5 taken 6135 times.
✓ Branch 6 taken 224 times.
✓ Branch 7 taken 21 times.
✓ Branch 8 taken 6359 times.
✓ Branch 9 taken 4449 times.
|
10808 | if (!ranges.empty() && (ranges != "0-0" || this->ranges.empty())) { |
| 316 |
1/2✓ Branch 0 taken 6359 times.
✗ Branch 1 not taken.
|
6359 | this->ranges = ranges; |
| 317 | } | ||
| 318 | |||
| 319 |
4/4✓ Branch 0 taken 5942 times.
✓ Branch 1 taken 4866 times.
✓ Branch 2 taken 5707 times.
✓ Branch 3 taken 235 times.
|
10808 | if (!this->multiSync && multiSync) { |
| 320 | 5707 | this->multiSync = true; | |
| 321 | } | ||
| 322 | |||
| 323 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | std::vector<std::string> parts = split(address, '.'); |
| 324 | // ipa-ipd hold the legacy IPv4 octets used in the (IPv4-only) ping packet. | ||
| 325 | // An IPv6 peer has no such octets, so skip the IPv4 hostname lookup that | ||
| 326 | // would only fail and log an error; the octets stay zeroed below. | ||
| 327 |
6/6✓ Branch 0 taken 5 times.
✓ Branch 1 taken 10803 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 10805 times.
|
10808 | if (parts.size() != 4 && address.find(':') == std::string::npos) { |
| 328 |
3/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if (!GetIPForHost(this->address)) { |
| 329 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_SYNC, "Error looking up hostname: %s\n", address.c_str()); |
| 330 | } else { | ||
| 331 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | parts = split(this->address, '.'); |
| 332 | } | ||
| 333 | } | ||
| 334 |
2/2✓ Branch 0 taken 10805 times.
✓ Branch 1 taken 3 times.
|
10808 | if (parts.size() >= 4) { |
| 335 | 10805 | this->ipa = atoi(parts[0].c_str()); | |
| 336 | 10805 | this->ipb = atoi(parts[1].c_str()); | |
| 337 | 10805 | this->ipc = atoi(parts[2].c_str()); | |
| 338 | 10805 | this->ipd = atoi(parts[3].c_str()); | |
| 339 | } else { | ||
| 340 | 3 | this->ipa = 0; | |
| 341 | 3 | this->ipb = 0; | |
| 342 | 3 | this->ipc = 0; | |
| 343 | 3 | this->ipd = 0; | |
| 344 | } | ||
| 345 | |||
| 346 | // A system is a valid target for "Send MultiSync to ALL KNOWN remotes via | ||
| 347 | // Unicast" only if it's a full FPP instance (type below the 0x80 boundary | ||
| 348 | // that separates full-FPP systems from external controllers) running in | ||
| 349 | // Remote mode. This deliberately excludes WLED, ESPixelStick, Falcon and | ||
| 350 | // Experience controllers, xSchedule, and any FPP instance acting as a | ||
| 351 | // player/master. We intentionally do NOT require that the system was | ||
| 352 | // learned via the UDP MultiSync protocol so that FPP remotes discovered | ||
| 353 | // via HTTP (e.g. on a network segment where multicast is blocked - the | ||
| 354 | // very case this mode exists for) are still targeted. | ||
| 355 |
2/2✓ Branch 0 taken 10686 times.
✓ Branch 1 taken 122 times.
|
21494 | this->supportsUnicast = (this->type < kSysTypeFalconController) && |
| 356 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 10534 times.
|
10686 | (this->fppMode == REMOTE_MODE); |
| 357 | 10808 | } | |
| 358 | |||
| 359 | 141 | static void SetIfNotEmpty(Json::Value& v, const char* key, const std::string& s) { | |
| 360 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 86 times.
|
141 | if (!s.empty()) { |
| 361 |
2/4✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
|
55 | v[key] = s; |
| 362 | } | ||
| 363 | 141 | } | |
| 364 | |||
| 365 | 2 | Json::Value MultiSyncSystemInfo::toJSON() const { | |
| 366 | 2 | Json::Value v; | |
| 367 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "Platform", platform); |
| 368 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "Variant", variant); |
| 369 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "SubPlatform", subPlatform); |
| 370 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "OSVersion", osVersion); |
| 371 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "OSRelease", osRelease); |
| 372 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "Kernel", kernel); |
| 373 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "HostDescription", hostDescription); |
| 374 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "backgroundColor", backgroundColor); |
| 375 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "Branch", branch); |
| 376 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "LocalGitVersion", localGitVersion); |
| 377 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "RemoteGitVersion", remoteGitVersion); |
| 378 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | SetIfNotEmpty(v, "UpgradeSource", upgradeSource); |
| 379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (channelInputsEnabled >= 0) { |
| 380 | ✗ | v["channelInputsEnabled"] = channelInputsEnabled ? true : false; | |
| 381 | } | ||
| 382 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (channelOutputsEnabled >= 0) { |
| 383 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | v["channelOutputsEnabled"] = channelOutputsEnabled ? true : false; |
| 384 | } | ||
| 385 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!ips.empty()) { |
| 386 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Json::Value a(Json::arrayValue); |
| 387 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (auto& ip : ips) { |
| 388 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | a.append(ip); |
| 389 | } | ||
| 390 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | v["IPs"] = a; |
| 391 | 2 | } | |
| 392 | 2 | return v; | |
| 393 | ✗ | } | |
| 394 | |||
| 395 | 29786 | Json::Value MultiSyncCapeInfo::toJSON() const { | |
| 396 |
1/2✓ Branch 0 taken 29786 times.
✗ Branch 1 not taken.
|
29786 | Json::Value v; |
| 397 |
2/4✓ Branch 0 taken 29786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29786 times.
✗ Branch 3 not taken.
|
29786 | v["present"] = present; |
| 398 |
2/2✓ Branch 0 taken 29773 times.
✓ Branch 1 taken 13 times.
|
29786 | if (!present) { |
| 399 | 29773 | return v; | |
| 400 | } | ||
| 401 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(v, "id", id); |
| 402 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(v, "name", name); |
| 403 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(v, "description", description); |
| 404 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(v, "version", version); |
| 405 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(v, "designer", designer); |
| 406 | // Only emitted when the cape opts out, so the common case adds no bytes. | ||
| 407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!sendStats) { |
| 408 | ✗ | v["sendStats"] = 0; | |
| 409 | } | ||
| 410 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | Json::Value vendor; |
| 411 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(vendor, "name", vendorName); |
| 412 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(vendor, "url", vendorURL); |
| 413 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(vendor, "email", vendorEmail); |
| 414 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | SetIfNotEmpty(vendor, "image", vendorImage); |
| 415 |
3/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 1 times.
|
13 | if (!vendor.empty()) { |
| 416 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 | v["vendor"] = vendor; |
| 417 | } | ||
| 418 | 13 | return v; | |
| 419 | 13 | } | |
| 420 | |||
| 421 | // A field of what a remote sent us (system info, cape info), read so that a | ||
| 422 | // value of the wrong type gives the default instead of throwing: the reply is | ||
| 423 | // parsed in a curl callback on the main loop, and {"Platform":{}} ended fppd. | ||
| 424 | 62 | static std::string ReplyString(const Json::Value& v, const char* key, const std::string& dflt = "") { | |
| 425 |
2/4✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
|
62 | const Json::Value f = v.get(key, Json::Value()); |
| 426 |
9/16✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 39 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 39 times.
✓ Branch 12 taken 23 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 39 times.
✗ Branch 15 not taken.
|
124 | return (f.isString() || f.isNumeric() || f.isBool()) ? f.asString() : dflt; |
| 427 | 62 | } | |
| 428 | 1 | static bool ReplyBool(const Json::Value& v, const char* key, bool dflt) { | |
| 429 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | const Json::Value f = v.get(key, Json::Value()); |
| 430 |
4/10✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
3 | return (f.isBool() || f.isNumeric()) ? f.asBool() : dflt; |
| 431 | 2 | } | |
| 432 | 6 | static int ReplyInt(const Json::Value& v, const char* key, int dflt) { | |
| 433 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | const Json::Value f = v.get(key, Json::Value()); |
| 434 |
5/10✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
12 | return f.isConvertibleTo(Json::intValue) && !f.isNull() ? f.asInt() : dflt; |
| 435 | 6 | } | |
| 436 | |||
| 437 | 6 | MultiSyncCapeInfo MultiSyncCapeInfo::fromCapeJSON(const Json::Value& v) { | |
| 438 | 6 | MultiSyncCapeInfo cape; | |
| 439 | 6 | cape.valid = true; | |
| 440 | 6 | cape.present = true; | |
| 441 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | cape.id = ReplyString(v, "id"); |
| 442 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | cape.name = ReplyString(v, "name"); |
| 443 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | cape.description = ReplyString(v, "description"); |
| 444 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | cape.version = ReplyString(v, "version"); |
| 445 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | cape.designer = ReplyString(v, "designer"); |
| 446 | // Absent (including on every unsigned cape) means no opt-out. | ||
| 447 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | cape.sendStats = ReplyInt(v, "sendStats", 1) != 0; |
| 448 |
11/22✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
18 | if (JsonHas(v, "vendor") && v["vendor"].isObject()) { |
| 449 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | const Json::Value& vendor = v["vendor"]; |
| 450 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | cape.vendorName = ReplyString(vendor, "name"); |
| 451 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | cape.vendorURL = ReplyString(vendor, "url"); |
| 452 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | cape.vendorEmail = ReplyString(vendor, "email"); |
| 453 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | cape.vendorImage = ReplyString(vendor, "image"); |
| 454 | } | ||
| 455 | 6 | return cape; | |
| 456 | ✗ | } | |
| 457 | |||
| 458 | 80298 | Json::Value MultiSyncSystem::toJSON(bool local, bool timestamps) { | |
| 459 | 80298 | Json::Value system; | |
| 460 | |||
| 461 |
3/6✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80298 times.
✗ Branch 5 not taken.
|
80298 | system["type"] = MultiSync::GetTypeString(type, local); |
| 462 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["typeId"] = (int)type; |
| 463 |
2/2✓ Branch 0 taken 75072 times.
✓ Branch 1 taken 5226 times.
|
80298 | if (timestamps) { |
| 464 |
2/4✓ Branch 0 taken 75072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 75072 times.
✗ Branch 3 not taken.
|
75072 | system["lastSeen"] = (Json::UInt64)lastSeen; |
| 465 |
2/4✓ Branch 0 taken 75072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 75072 times.
✗ Branch 3 not taken.
|
75072 | system["lastSeenStr"] = lastSeenStr; |
| 466 | } | ||
| 467 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["majorVersion"] = majorVersion; |
| 468 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["minorVersion"] = minorVersion; |
| 469 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["uuid"] = uuid; |
| 470 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["fppMode"] = fppMode; |
| 471 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["multisync"] = sendingMultiSync; |
| 472 | |||
| 473 |
1/2✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
|
80298 | char* s = modeToString(fppMode); |
| 474 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["fppModeString"] = s; |
| 475 | 80298 | free(s); | |
| 476 | |||
| 477 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["address"] = address; |
| 478 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["hostname"] = hostname; |
| 479 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["version"] = version; |
| 480 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["model"] = model; |
| 481 |
2/4✓ Branch 0 taken 80298 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
|
80298 | system["channelRanges"] = ranges; |
| 482 | |||
| 483 |
4/6✓ Branch 0 taken 29785 times.
✓ Branch 1 taken 50513 times.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80298 times.
✗ Branch 5 not taken.
|
80298 | system["local"] = local ? 1 : 0; |
| 484 | |||
| 485 |
4/6✓ Branch 0 taken 71186 times.
✓ Branch 1 taken 9112 times.
✓ Branch 2 taken 80298 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80298 times.
✗ Branch 5 not taken.
|
80298 | system["multiSyncCapable"] = multiSync ? 1 : 0; |
| 486 | |||
| 487 |
2/2✓ Branch 0 taken 29785 times.
✓ Branch 1 taken 50513 times.
|
80298 | if (local) { |
| 488 |
3/6✓ Branch 0 taken 29785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29785 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29785 times.
✗ Branch 5 not taken.
|
29785 | system["HostDescription"] = getSetting("HostDescription"); |
| 489 |
3/6✓ Branch 0 taken 29785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29785 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29785 times.
✗ Branch 5 not taken.
|
29785 | system["channelInputsEnabled"] = InputsEnabled(); |
| 490 |
3/6✓ Branch 0 taken 29785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29785 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29785 times.
✗ Branch 5 not taken.
|
29785 | system["channelOutputsEnabled"] = HasUniverseOutputs(); |
| 491 | } | ||
| 492 | |||
| 493 | // Detail fetched over HTTP from FPP remotes (see CheckSystemInfoRefreshes). | ||
| 494 | // Absent for the local systems -- a browser rendering the multisync page | ||
| 495 | // already has all of this for the box serving the page -- and for anything | ||
| 496 | // that isn't a full FPP instance. | ||
| 497 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 80296 times.
|
80298 | if (systemInfo.valid) { |
| 498 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | system["systemInfo"] = systemInfo.toJSON(); |
| 499 | } | ||
| 500 |
2/2✓ Branch 0 taken 29786 times.
✓ Branch 1 taken 50512 times.
|
80298 | if (capeInfo.valid) { |
| 501 |
2/4✓ Branch 0 taken 29786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29786 times.
✗ Branch 3 not taken.
|
29786 | system["capeInfo"] = capeInfo.toJSON(); |
| 502 | } | ||
| 503 | |||
| 504 | 80298 | return system; | |
| 505 | ✗ | } | |
| 506 | |||
| 507 | /* | ||
| 508 | * | ||
| 509 | */ | ||
| 510 | 3252 | MultiSync::MultiSync() : | |
| 511 | 3252 | m_broadcastSock(-1), | |
| 512 | 3252 | m_controlSock(-1), | |
| 513 | 3252 | m_receiveSock(-1), | |
| 514 | 3252 | m_lastMediaHalfSecond(0), | |
| 515 | 3252 | m_remoteOffset(0.0), | |
| 516 | 3252 | m_lastPingTime(0), | |
| 517 | 3252 | m_lastCheckTime(0), | |
| 518 | 3252 | m_lastFrame(0), | |
| 519 | 3252 | m_sendMulticast(false), | |
| 520 |
2/4✓ Branch 0 taken 3252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3252 times.
✗ Branch 3 not taken.
|
6504 | m_sendBroadcast(false) { |
| 521 | 3252 | memset(rcvBuffers, 0, sizeof(rcvBuffers)); | |
| 522 | 3252 | memset(rcvCmbuf, 0, sizeof(rcvCmbuf)); | |
| 523 | 3252 | } | |
| 524 | |||
| 525 | /* | ||
| 526 | * | ||
| 527 | */ | ||
| 528 | 600 | MultiSync::~MultiSync() { | |
| 529 | 600 | ShutdownSync(); | |
| 530 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
|
600 | for (auto& a : m_syncStats) { |
| 531 | ✗ | MultiSyncStats* stats = (MultiSyncStats*)a.second; | |
| 532 | ✗ | delete stats; | |
| 533 | } | ||
| 534 | 600 | m_syncStats.clear(); | |
| 535 | 600 | } | |
| 536 | |||
| 537 | /* | ||
| 538 | * | ||
| 539 | */ | ||
| 540 | 2652 | int MultiSync::Init(void) { | |
| 541 |
3/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 2591 times.
|
2652 | if (getFPPmode() == REMOTE_MODE) { |
| 542 | 61 | m_multiSyncEnabled = false; | |
| 543 | } else { | ||
| 544 |
1/2✓ Branch 0 taken 2591 times.
✗ Branch 1 not taken.
|
2591 | m_multiSyncEnabled = getSettingInt("MultiSyncEnabled", 0); |
| 545 | } | ||
| 546 | |||
| 547 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | FillInInterfaces(); |
| 548 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | FillLocalSystemInfo(); |
| 549 | |||
| 550 | // Keep the configured-output-range cache (used to backfill ranges for | ||
| 551 | // non-FPP remotes in GetSystems()) in sync with co-universes.json. Watching | ||
| 552 | // the file confines the file read + hostname resolution to actual config | ||
| 553 | // changes instead of every GetSystems() call. TriggerFileChanged() does the | ||
| 554 | // initial load now. | ||
| 555 |
3/6✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2652 times.
✗ Branch 5 not taken.
|
2947 | std::string coUniversesFile = FPP_DIR_CONFIG("/co-universes.json"); |
| 556 |
2/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
|
5304 | FileMonitor::INSTANCE.AddFile("MultiSync/co-universes.json", coUniversesFile, |
| 557 | 5674 | [this]() { ReloadConfiguredOutputRanges(); }) | |
| 558 |
2/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✗ Branch 3 not taken.
|
5304 | .TriggerFileChanged("MultiSync/co-universes.json", coUniversesFile); |
| 559 | |||
| 560 |
3/4✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2651 times.
|
2652 | if (!OpenReceiveSocket()) |
| 561 | 1 | return 0; | |
| 562 | |||
| 563 |
2/4✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2651 times.
|
2651 | if (!OpenBroadcastSocket()) |
| 564 | ✗ | return 0; | |
| 565 | |||
| 566 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 2607 times.
|
2651 | if (m_multiSyncEnabled) { |
| 567 |
2/4✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
|
44 | if (!OpenControlSockets()) |
| 568 | ✗ | return 0; | |
| 569 | } | ||
| 570 | |||
| 571 | 7254 | std::function<void(NetworkMonitor::NetEventType i, int up, const std::string&)> f = [this](NetworkMonitor::NetEventType i, int up, const std::string& name) { | |
| 572 | 1952 | LogDebug(VB_SYNC, "MultiSync::NetworkChanged - Interface: %s Up: %d Msg: %d\n", name.c_str(), up, i); | |
| 573 |
3/4✓ Branch 0 taken 804 times.
✓ Branch 1 taken 1148 times.
✓ Branch 2 taken 804 times.
✗ Branch 3 not taken.
|
1952 | if (i == NetworkMonitor::NetEventType::DEL_ADDR && !up) { |
| 574 | 804 | RemoveInterface(name); | |
| 575 | // The interface may still hold another address -- the DHCP lease | ||
| 576 | // that replaced a 169.254 fallback, typically -- so pick it back up | ||
| 577 | // rather than leave the interface out, and drop the deleted address | ||
| 578 | // from what we announce. | ||
| 579 |
2/2✓ Branch 0 taken 240 times.
✓ Branch 1 taken 564 times.
|
804 | if (FillInInterfaces()) { |
| 580 | 240 | setupMulticastReceive(true); | |
| 581 | } | ||
| 582 | 804 | FillLocalSystemInfo(); | |
| 583 |
3/4✓ Branch 0 taken 689 times.
✓ Branch 1 taken 459 times.
✓ Branch 2 taken 689 times.
✗ Branch 3 not taken.
|
1148 | } else if (i == NetworkMonitor::NetEventType::NEW_ADDR && up) { |
| 584 | 689 | bool changed = FillInInterfaces(); | |
| 585 | 689 | setupMulticastReceive(true); | |
| 586 | // Always, not just when an interface appeared: a new address on an | ||
| 587 | // interface we already had can retire its 169.254 fallback. | ||
| 588 | 689 | changed |= FillLocalSystemInfo(); | |
| 589 |
2/2✓ Branch 0 taken 213 times.
✓ Branch 1 taken 476 times.
|
689 | if (changed) { |
| 590 | 213 | Ping(0, false); | |
| 591 | } | ||
| 592 | } | ||
| 593 | 2651 | }; | |
| 594 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | NetworkMonitor::INSTANCE.registerCallback(f); |
| 595 | |||
| 596 | // The sync send methods and the unicast remote list are picked up live. | ||
| 597 | // fppd already re-reads /media/settings whenever the web UI writes it | ||
| 598 | // (FileMonitor in fppd.cpp), so all that was missing was rebuilding the | ||
| 599 | // destination list these settings feed -- editing the remote list on the | ||
| 600 | // MultiSync page no longer needs an fppd restart to take effect. The | ||
| 601 | // control socket itself is unaffected by any of them; if it isn't open yet | ||
| 602 | // (MultiSync disabled, or nothing has needed it), OpenControlSockets() | ||
| 603 | // reads the current settings when it does open. | ||
| 604 | 4421 | for (const char* s : { "MultiSyncRemotes", "MultiSyncExtraRemotes", | |
| 605 | "MultiSyncBroadcast", "MultiSyncMulticast", "MultiSyncUnicast", | ||
| 606 |
2/2✓ Branch 0 taken 15906 times.
✓ Branch 1 taken 2651 times.
|
21208 | "MultiSyncUnicastSubnets" }) { |
| 607 |
3/6✓ Branch 0 taken 15906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15906 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15906 times.
✗ Branch 5 not taken.
|
77760 | registerSettingsListener("MultiSync", s, [this](const std::string& v) { |
| 608 | { | ||
| 609 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | std::unique_lock<std::mutex> lock(s_listenerQuiesceLock); |
| 610 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (s_listenersShutdown) { |
| 611 | ✗ | return; | |
| 612 | } | ||
| 613 | 8 | ++s_listenersInFlight; | |
| 614 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | } |
| 615 | struct InFlight { | ||
| 616 | 8 | ~InFlight() { | |
| 617 | 8 | std::unique_lock<std::mutex> lock(s_listenerQuiesceLock); | |
| 618 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (--s_listenersInFlight == 0) { |
| 619 | 8 | s_listenerQuiesceCV.notify_all(); | |
| 620 | } | ||
| 621 | 8 | } | |
| 622 | } inFlight; | ||
| 623 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (m_controlSock >= 0) { |
| 624 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | ReloadSyncDestinations(); |
| 625 | } | ||
| 626 | 8 | }); | |
| 627 | } | ||
| 628 | |||
| 629 | 2651 | return 1; | |
| 630 | 2652 | } | |
| 631 | |||
| 632 | /* | ||
| 633 | * | ||
| 634 | */ | ||
| 635 | 10811 | void MultiSync::UpdateSystem(MultiSyncSystemType type, | |
| 636 | unsigned int majorVersion, unsigned int minorVersion, | ||
| 637 | FPPMode fppMode, | ||
| 638 | const std::string& address, | ||
| 639 | const std::string& hostname, | ||
| 640 | const std::string& version, | ||
| 641 | const std::string& model, | ||
| 642 | const std::string& ranges, | ||
| 643 | const std::string& uuid, | ||
| 644 | const bool multiSync, | ||
| 645 | const bool sendingMultiSync) { | ||
| 646 |
3/4✓ Branch 0 taken 10576 times.
✓ Branch 1 taken 235 times.
✓ Branch 2 taken 10811 times.
✗ Branch 3 not taken.
|
10811 | LogDebug(VB_SYNC, "UpdateSystem(%d, %u, %u, %d, '%s', '%s', '%s', '%s', '%s', '%s', %s)\n", |
| 647 | (int)type, majorVersion, minorVersion, (int)fppMode, | ||
| 648 | address.c_str(), hostname.c_str(), version.c_str(), model.c_str(), | ||
| 649 | ranges.c_str(), uuid.c_str(), multiSync ? "true" : "false"); | ||
| 650 | |||
| 651 | char timeStr[34]; | ||
| 652 | 10811 | memset(timeStr, 0, sizeof(timeStr)); | |
| 653 | 10811 | time_t t = time(NULL); | |
| 654 | struct tm tm; | ||
| 655 | 10811 | localtime_r(&t, &tm); | |
| 656 | 10811 | snprintf(timeStr, sizeof(timeStr), "%4d-%.2d-%.2d %.2d:%.2d:%.2d", | |
| 657 | 10811 | 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, | |
| 658 | tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
| 659 | |||
| 660 |
1/2✓ Branch 0 taken 10811 times.
✗ Branch 1 not taken.
|
10811 | std::string ipForAddress = address; |
| 661 |
1/2✓ Branch 0 taken 10811 times.
✗ Branch 1 not taken.
|
10811 | GetIPForHost(ipForAddress); |
| 662 | |||
| 663 | // Loopback is this box finding itself, not a discoverable peer. Avahi | ||
| 664 | // resolves our own _fppd._udp advertisement to 127.0.0.1, so mDNS hands it | ||
| 665 | // straight back to us; a channel output or an HTTP discovery subnet aimed | ||
| 666 | // at localhost does the same. The resulting entry is useless to every | ||
| 667 | // consumer of the systems list -- no peer can reach it, and the multisync | ||
| 668 | // page drops the row rather than render a link a browser cannot follow. | ||
| 669 | // Reject it here, at the one place m_remoteSystems ever grows, so no | ||
| 670 | // discovery path can reintroduce it. Local interface addresses come from | ||
| 671 | // FillInInterfaces(), which already skips "lo", so this never rejects one | ||
| 672 | // of our own entries. | ||
| 673 |
7/10✓ Branch 0 taken 10811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10809 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 10809 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10809 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 10809 times.
|
10811 | if (IsLoopbackAddress(address) || IsLoopbackAddress(ipForAddress)) { |
| 674 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SYNC, "Ignoring loopback address %s in discovery\n", address.c_str()); |
| 675 | 2 | return; | |
| 676 | } | ||
| 677 | |||
| 678 |
1/2✓ Branch 0 taken 10809 times.
✗ Branch 1 not taken.
|
10809 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 679 | 10809 | bool found = false; | |
| 680 | 10809 | bool unicastChanged = false; | |
| 681 | |||
| 682 | // A device that started before DHCP answered announced itself from a | ||
| 683 | // 169.254 address, and keeps that entry here after it has a real one. The | ||
| 684 | // link-local address is only reachable from the same link, so once the | ||
| 685 | // device reports from a routable address that is the address to list: move | ||
| 686 | // the link-local entry over to it (or drop it, if the routable address | ||
| 687 | // already has its own entry) rather than listing the device twice. | ||
| 688 |
2/2✓ Branch 0 taken 10807 times.
✓ Branch 1 taken 2 times.
|
10809 | if (ipForAddress.find(':') == std::string::npos) { |
| 689 | 10807 | MultiSyncSystem* existing = nullptr; | |
| 690 |
2/2✓ Branch 0 taken 2714327 times.
✓ Branch 1 taken 9287 times.
|
2723614 | for (auto& sys : m_remoteSystems) { |
| 691 |
6/6✓ Branch 0 taken 2712808 times.
✓ Branch 1 taken 1519 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2712807 times.
✓ Branch 4 taken 1520 times.
✓ Branch 5 taken 2712807 times.
|
2714327 | if (address == sys.address || ipForAddress == sys.address) { |
| 692 | 1520 | existing = &sys; | |
| 693 | 1520 | break; | |
| 694 | } | ||
| 695 | } | ||
| 696 | // A ping carries no UUID, but the entry already at this address may know one | ||
| 697 |
1/2✓ Branch 0 taken 10807 times.
✗ Branch 1 not taken.
|
10807 | std::string knownUUID = uuid; |
| 698 |
8/10✓ Branch 0 taken 10807 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10807 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10684 times.
✓ Branch 5 taken 123 times.
✓ Branch 6 taken 1442 times.
✓ Branch 7 taken 9242 times.
✓ Branch 8 taken 1442 times.
✓ Branch 9 taken 9365 times.
|
10807 | if ((knownUUID.empty() || knownUUID == "Unknown") && existing) { |
| 699 |
1/2✓ Branch 0 taken 1442 times.
✗ Branch 1 not taken.
|
1442 | knownUUID = existing->uuid; |
| 700 | } | ||
| 701 | |||
| 702 |
3/4✓ Branch 0 taken 10807 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10805 times.
|
10807 | if (IsIPv4LinkLocal(ipForAddress)) { |
| 703 | // The other direction: a sender that still announces its old | ||
| 704 | // 169.254 address alongside the new one (an older FPP) would | ||
| 705 | // otherwise re-add the entry on every ping. Only while the | ||
| 706 | // routable entry is current, so a device that genuinely fell back | ||
| 707 | // to link-local (lost its lease) is still picked up. | ||
| 708 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (auto& sys : m_remoteSystems) { |
| 709 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!existing && sys.address.find(':') == std::string::npos && |
| 710 |
5/10✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
3 | !IsIPv4LinkLocal(sys.address) && sys.lastSeen + 120 >= (unsigned long)t && |
| 711 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | IsSameDevice(sys, hostname, fppMode, type, knownUUID)) { |
| 712 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_SYNC, "Ignoring link-local %s for %s, also seen at %s\n", |
| 713 | address.c_str(), hostname.c_str(), sys.address.c_str()); | ||
| 714 | 1 | return; | |
| 715 | } | ||
| 716 | } | ||
| 717 | } else { | ||
| 718 | 10805 | bool haveEntry = existing != nullptr; | |
| 719 |
2/2✓ Branch 0 taken 2714701 times.
✓ Branch 1 taken 10805 times.
|
2725506 | for (auto it = m_remoteSystems.begin(); it != m_remoteSystems.end();) { |
| 720 |
7/10✓ Branch 0 taken 2714701 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2714700 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2714700 times.
✓ Branch 9 taken 1 times.
|
2714701 | if (!IsIPv4LinkLocal(it->address) || !IsSameDevice(*it, hostname, fppMode, type, knownUUID)) { |
| 721 | 2714700 | ++it; | |
| 722 | 2714700 | continue; | |
| 723 | } | ||
| 724 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (haveEntry) { |
| 725 | ✗ | LogInfo(VB_SYNC, "Removing link-local %s for %s, now at %s\n", | |
| 726 | it->address.c_str(), hostname.c_str(), ipForAddress.c_str()); | ||
| 727 | ✗ | unicastChanged |= it->supportsUnicast; | |
| 728 | ✗ | it = m_remoteSystems.erase(it); | |
| 729 | ✗ | continue; | |
| 730 | } | ||
| 731 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogInfo(VB_SYNC, "Moving %s from link-local %s to %s\n", |
| 732 | hostname.c_str(), it->address.c_str(), ipForAddress.c_str()); | ||
| 733 | // Set here rather than left to update() below: update() leaves | ||
| 734 | // a multisync-learned entry alone when the report isn't one. | ||
| 735 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | it->address = ipForAddress; |
| 736 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::vector<std::string> parts = split(ipForAddress, '.'); |
| 737 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (parts.size() == 4) { |
| 738 | 1 | it->ipa = atoi(parts[0].c_str()); | |
| 739 | 1 | it->ipb = atoi(parts[1].c_str()); | |
| 740 | 1 | it->ipc = atoi(parts[2].c_str()); | |
| 741 | 1 | it->ipd = atoi(parts[3].c_str()); | |
| 742 | } | ||
| 743 | // Never fetched while link-local (CheckSystemInfoRefreshes skips it) | ||
| 744 | 1 | it->infoNextFetch = 0; | |
| 745 | 1 | unicastChanged |= it->supportsUnicast; | |
| 746 | 1 | haveEntry = true; | |
| 747 | 1 | ++it; | |
| 748 | 1 | } | |
| 749 | } | ||
| 750 |
2/2✓ Branch 0 taken 10806 times.
✓ Branch 1 taken 1 times.
|
10807 | } |
| 751 | |||
| 752 |
2/2✓ Branch 0 taken 2714701 times.
✓ Branch 1 taken 10808 times.
|
2725509 | for (auto& sys : m_remoteSystems) { |
| 753 |
8/8✓ Branch 0 taken 2712867 times.
✓ Branch 1 taken 1834 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2712866 times.
✓ Branch 4 taken 316 times.
✓ Branch 5 taken 1519 times.
✓ Branch 6 taken 1519 times.
✓ Branch 7 taken 2713182 times.
|
2716852 | if ((address == sys.address || ipForAddress == sys.address) && |
| 754 |
1/2✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
|
2151 | ((hostname == sys.hostname) || |
| 755 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 316 times.
|
632 | (address == sys.hostname) || |
| 756 | 316 | (hostname == sys.address))) { | |
| 757 | 1519 | found = true; | |
| 758 | 1519 | bool wasUnicast = sys.supportsUnicast; | |
| 759 |
1/2✓ Branch 0 taken 1519 times.
✗ Branch 1 not taken.
|
1519 | sys.update(type, majorVersion, minorVersion, fppMode, address, hostname, version, model, ranges, uuid, multiSync, sendingMultiSync); |
| 760 |
1/2✓ Branch 0 taken 1519 times.
✗ Branch 1 not taken.
|
1519 | ApplyUUIDHint(sys); |
| 761 |
1/2✓ Branch 0 taken 1519 times.
✗ Branch 1 not taken.
|
1519 | sys.lastSeenStr = timeStr; |
| 762 | 1519 | sys.lastSeen = t; | |
| 763 | 1519 | unicastChanged |= (wasUnicast != sys.supportsUnicast); | |
| 764 | } | ||
| 765 | } | ||
| 766 |
2/2✓ Branch 0 taken 12295 times.
✓ Branch 1 taken 10808 times.
|
23103 | for (auto& sys : m_localSystems) { |
| 767 |
6/6✓ Branch 0 taken 5844 times.
✓ Branch 1 taken 6451 times.
✓ Branch 2 taken 5829 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 5829 times.
✓ Branch 5 taken 6466 times.
|
18139 | if ((address == sys.address) && |
| 768 | 5844 | (hostname == sys.hostname)) { | |
| 769 | 5829 | found = true; | |
| 770 |
1/2✓ Branch 0 taken 5829 times.
✗ Branch 1 not taken.
|
5829 | sys.update(type, majorVersion, minorVersion, fppMode, address, hostname, version, model, ranges, uuid, multiSync, sendingMultiSync); |
| 771 | 5829 | sys.lastSeen = t; | |
| 772 |
1/2✓ Branch 0 taken 5829 times.
✗ Branch 1 not taken.
|
5829 | sys.lastSeenStr = timeStr; |
| 773 | } | ||
| 774 | } | ||
| 775 |
2/2✓ Branch 0 taken 3460 times.
✓ Branch 1 taken 7348 times.
|
10808 | if (!found) { |
| 776 | // Every ping carrying a new address adds a system, and pings come | ||
| 777 | // from anyone on the LAN; entries are otherwise only pruned after two | ||
| 778 | // hours. Past the cap, the system seen longest ago makes room. | ||
| 779 | static constexpr size_t MAX_REMOTE_SYSTEMS = 2048; | ||
| 780 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 3408 times.
|
3460 | if (m_remoteSystems.size() >= MAX_REMOTE_SYSTEMS) { |
| 781 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | auto oldest = std::min_element(m_remoteSystems.begin(), m_remoteSystems.end(), |
| 782 | 106444 | [](const MultiSyncSystem& a, const MultiSyncSystem& b) { return a.lastSeen < b.lastSeen; }); | |
| 783 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | LogWarn(VB_SYNC, "More than %zu remote systems known; forgetting %s to make room\n", |
| 784 | MAX_REMOTE_SYSTEMS, oldest->address.c_str()); | ||
| 785 | 52 | unicastChanged |= oldest->supportsUnicast; | |
| 786 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | m_remoteSystems.erase(oldest); |
| 787 | } | ||
| 788 | 3460 | MultiSyncSystem sys; | |
| 789 |
1/2✓ Branch 0 taken 3460 times.
✗ Branch 1 not taken.
|
3460 | sys.update(type, majorVersion, minorVersion, fppMode, address, hostname, version, model, ranges, uuid, multiSync, sendingMultiSync); |
| 790 |
1/2✓ Branch 0 taken 3460 times.
✗ Branch 1 not taken.
|
3460 | ApplyUUIDHint(sys); |
| 791 |
1/2✓ Branch 0 taken 3460 times.
✗ Branch 1 not taken.
|
3460 | sys.lastSeenStr = timeStr; |
| 792 | 3460 | sys.lastSeen = t; | |
| 793 | 3460 | unicastChanged |= sys.supportsUnicast; | |
| 794 |
1/2✓ Branch 0 taken 3460 times.
✗ Branch 1 not taken.
|
3460 | m_remoteSystems.push_back(sys); |
| 795 | 3460 | } | |
| 796 | |||
| 797 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | ReconcileDeviceIdentity(hostname, fppMode); |
| 798 | |||
| 799 | // If a remote became (or stopped being) a unicast target, refresh the | ||
| 800 | // cached "all known remotes" destination list. The snapshot is taken here | ||
| 801 | // while we still hold m_systemsLock, but the rebuild has to run after it is | ||
| 802 | // released: UpdateUnicastDestinations() takes m_unicastUpdateLock, which is | ||
| 803 | // never acquired while m_systemsLock is held. | ||
| 804 |
4/4✓ Branch 0 taken 175 times.
✓ Branch 1 taken 10633 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 171 times.
|
10808 | bool rebuildUnicast = m_sendUnicast && unicastChanged; |
| 805 | 10808 | std::vector<std::string> unicastAddrs; | |
| 806 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10804 times.
|
10808 | if (rebuildUnicast) { |
| 807 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | for (auto& sys : m_remoteSystems) { |
| 808 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (sys.supportsUnicast) { |
| 809 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | unicastAddrs.push_back(sys.address); |
| 810 | } | ||
| 811 | } | ||
| 812 | } | ||
| 813 |
1/2✓ Branch 0 taken 10808 times.
✗ Branch 1 not taken.
|
10808 | lock.unlock(); |
| 814 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10804 times.
|
10808 | if (rebuildUnicast) { |
| 815 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | UpdateUnicastDestinations(unicastAddrs); |
| 816 | } | ||
| 817 |
4/4✓ Branch 0 taken 10808 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10808 times.
✓ Branch 3 taken 3 times.
|
10812 | } |
| 818 | |||
| 819 | /* | ||
| 820 | * | ||
| 821 | */ | ||
| 822 | 4161 | MultiSyncSystemType MultiSync::ModelStringToType(std::string model) { | |
| 823 |
10/20✓ Branch 0 taken 4161 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4161 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4161 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4161 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4159 times.
✓ Branch 10 taken 4161 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4161 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4159 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12483 | if (startsWith(model, "Raspberry Pi Model A Rev") || (model == "Raspberry Pi Model A")) |
| 824 | 2 | return kSysTypeFPPRaspberryPiA; | |
| 825 |
10/20✓ Branch 0 taken 4159 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4159 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4159 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4159 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4157 times.
✓ Branch 10 taken 4159 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4159 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4157 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12477 | if (startsWith(model, "Raspberry Pi Model B Rev") || (model == "Raspberry Pi Model B")) |
| 826 | 2 | return kSysTypeFPPRaspberryPiB; | |
| 827 |
10/20✓ Branch 0 taken 4157 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4157 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4157 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4157 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4155 times.
✓ Branch 10 taken 4157 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4157 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4155 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12471 | if (startsWith(model, "Raspberry Pi Model A Plus") || (model == "Raspberry Pi Model A+")) |
| 828 | 2 | return kSysTypeFPPRaspberryPiAPlus; | |
| 829 |
10/20✓ Branch 0 taken 4155 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4155 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4155 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4155 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4153 times.
✓ Branch 10 taken 4155 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4155 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4153 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12465 | if (startsWith(model, "Raspberry Pi Model B Plus") || (model == "Raspberry Pi Model B+")) |
| 830 | 2 | return kSysTypeFPPRaspberryPiBPlus; | |
| 831 |
5/14✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4153 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4153 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4153 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4153 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
20765 | if ((startsWith(model, "Raspberry Pi 2 Model B 1.1")) || |
| 832 |
6/16✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4153 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4153 times.
✓ Branch 6 taken 4153 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4153 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4153 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
12459 | (startsWith(model, "Raspberry Pi 2 Model B 1.0"))) |
| 833 | ✗ | return kSysTypeFPPRaspberryPi2B; | |
| 834 |
3/6✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4153 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4153 times.
|
8306 | if (startsWith(model, "Raspberry Pi 2 Model B")) |
| 835 | ✗ | return kSysTypeFPPRaspberryPi2BNew; | |
| 836 |
10/20✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4153 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4153 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4153 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4151 times.
✓ Branch 10 taken 4153 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4153 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4151 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12459 | if (startsWith(model, "Raspberry Pi 3 Model B Rev") || (model == "Raspberry Pi 3 Model B")) |
| 837 | 2 | return kSysTypeFPPRaspberryPi3B; | |
| 838 |
10/20✓ Branch 0 taken 4151 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4151 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4151 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4151 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4149 times.
✓ Branch 10 taken 4151 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4151 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4149 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12453 | if (startsWith(model, "Raspberry Pi 3 Model B Plus") || (model == "Raspberry Pi 3 Model B+")) |
| 839 | 2 | return kSysTypeFPPRaspberryPi3BPlus; | |
| 840 |
3/6✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4149 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4149 times.
|
8298 | if (startsWith(model, "Raspberry Pi Zero Rev")) |
| 841 | ✗ | return kSysTypeFPPRaspberryPiZero; | |
| 842 |
3/6✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4149 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4149 times.
|
8298 | if (startsWith(model, "Raspberry Pi Zero W")) |
| 843 | ✗ | return kSysTypeFPPRaspberryPiZeroW; | |
| 844 |
3/6✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4149 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4149 times.
|
8298 | if (startsWith(model, "Raspberry Pi Zero 2 W")) |
| 845 | ✗ | return kSysTypeFPPRaspberryPiZero2W; | |
| 846 |
10/20✓ Branch 0 taken 4149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4149 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4149 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4149 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4147 times.
✓ Branch 10 taken 4149 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4149 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 4147 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
12447 | if (startsWith(model, "Raspberry Pi 3 Model A Plus") || (model == "Raspberry Pi 3 Model A+")) |
| 847 | 2 | return kSysTypeFPPRaspberryPi3APlus; | |
| 848 |
16/30✓ Branch 0 taken 4147 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4147 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4140 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 4140 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4140 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4138 times.
✓ Branch 12 taken 4140 times.
✓ Branch 13 taken 7 times.
✓ Branch 14 taken 4140 times.
✓ Branch 15 taken 7 times.
✓ Branch 16 taken 4147 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4147 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 9 times.
✓ Branch 21 taken 4138 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
20721 | if (startsWith(model, "Raspberry Pi 4") || startsWith(model, "Raspberry Pi Compute Module 4")) |
| 849 | 9 | return kSysTypeFPPRaspberryPi4; | |
| 850 |
16/30✓ Branch 0 taken 4138 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4045 times.
✓ Branch 5 taken 93 times.
✓ Branch 6 taken 4045 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4045 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4043 times.
✓ Branch 12 taken 4045 times.
✓ Branch 13 taken 93 times.
✓ Branch 14 taken 4045 times.
✓ Branch 15 taken 93 times.
✓ Branch 16 taken 4138 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4138 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 95 times.
✓ Branch 21 taken 4043 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
20504 | if (startsWith(model, "Raspberry Pi 5") || startsWith(model, "Raspberry Pi Compute Module 5")) |
| 851 | 95 | return kSysTypeFPPRaspberryPi5; | |
| 852 |
3/6✓ Branch 0 taken 4043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4043 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4043 times.
|
8086 | if (startsWith(model, "SanCloud BeagleBone Enhanced")) |
| 853 | ✗ | return kSysTypeFPPSanCloudBeagleBoneEnhanced; | |
| 854 |
4/6✓ Branch 0 taken 4043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4043 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
✓ Branch 5 taken 3996 times.
|
8086 | if (contains(model, "BeagleBone Black")) { |
| 855 |
3/6✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 47 times.
|
94 | if (contains(model, "Wireless")) { |
| 856 | ✗ | return kSysTypeFPPBeagleBoneBlackWireless; | |
| 857 | } | ||
| 858 | 47 | return kSysTypeFPPBeagleBoneBlack; | |
| 859 | } | ||
| 860 |
3/6✓ Branch 0 taken 3996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3996 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3996 times.
|
7992 | if (contains(model, "BeagleBone Green")) { |
| 861 | ✗ | if (contains(model, "Wireless")) { | |
| 862 | ✗ | return kSysTypeFPPBeagleBoneGreenWireless; | |
| 863 | } | ||
| 864 | ✗ | return kSysTypeFPPBeagleBoneGreen; | |
| 865 | } | ||
| 866 | // This is fed both the device-tree model ("BeagleBoard.org PocketBeagle2") | ||
| 867 | // and, for HTTP-discovered controllers, a remote's 'Variant' setting, which | ||
| 868 | // spells the board with a space ("PocketBeagle 2", "PocketBeagle 2 | ||
| 869 | // Industrial"). Both spellings have to be caught here, and before the | ||
| 870 | // PocketBeagle test below -- otherwise a PocketBeagle 2 falls through and | ||
| 871 | // gets reported as a PocketBeagle 1. | ||
| 872 |
14/28✓ Branch 0 taken 3996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3878 times.
✓ Branch 5 taken 118 times.
✓ Branch 6 taken 3878 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3878 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3876 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 3878 times.
✓ Branch 13 taken 118 times.
✓ Branch 14 taken 3996 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3996 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 122 times.
✓ Branch 19 taken 3874 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
27616 | if (contains(model, "PocketBeagle2") || contains(model, "PocketBeagle 2") || |
| 873 |
10/16✓ Branch 0 taken 3876 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3876 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 3874 times.
✓ Branch 6 taken 3876 times.
✓ Branch 7 taken 120 times.
✓ Branch 8 taken 3876 times.
✓ Branch 9 taken 120 times.
✓ Branch 10 taken 3878 times.
✓ Branch 11 taken 118 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
11748 | contains(model, "BeaglePlay")) { |
| 874 | 122 | return kSysTypeFPPPocketBeagle2; | |
| 875 | } | ||
| 876 |
4/6✓ Branch 0 taken 3874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3874 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 41 times.
✓ Branch 5 taken 3833 times.
|
7748 | if (contains(model, "PocketBeagle")) { |
| 877 | 41 | return kSysTypeFPPPocketBeagle; | |
| 878 | } | ||
| 879 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3833 times.
|
3833 | if (model == "MacOS") { |
| 880 | ✗ | return kSysTypeMacOS; | |
| 881 | } | ||
| 882 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3833 times.
|
3833 | if (model == "Armbian") { |
| 883 | ✗ | return kSysTypeFPPArmbian; | |
| 884 | } | ||
| 885 | // FIXME, fill in the rest of the types | ||
| 886 | |||
| 887 | 3833 | return kSysTypeFPP; | |
| 888 | } | ||
| 889 | |||
| 890 | /* | ||
| 891 | * | ||
| 892 | */ | ||
| 893 | 4145 | bool MultiSync::FillLocalSystemInfo(void) { | |
| 894 | 4145 | MultiSyncSystem newSystem; | |
| 895 | |||
| 896 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | std::string model = GetHardwareModel(); |
| 897 | #ifdef PLATFORM_ARMBIAN | ||
| 898 | MultiSyncSystemType type = ModelStringToType("Armbian"); | ||
| 899 | #else | ||
| 900 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
|
4145 | MultiSyncSystemType type = ModelStringToType(model); |
| 901 | #endif | ||
| 902 | |||
| 903 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | std::string multiSyncInterface = getSetting("MultiSyncInterface"); |
| 904 | char addressBuf[128]; | ||
| 905 | 4145 | std::list<std::string> addresses; | |
| 906 | |||
| 907 | 4145 | std::string dockerAddress; | |
| 908 |
3/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3847 times.
✓ Branch 3 taken 298 times.
|
4145 | if (FileExists("/etc/fpp/container")) { |
| 909 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3847 times.
|
3847 | if (getenv("FPP_DOCKER_IP")) { |
| 910 | ✗ | dockerAddress = getenv("FPP_DOCKER_IP"); | |
| 911 | ✗ | addresses.push_back(dockerAddress); | |
| 912 | } | ||
| 913 | |||
| 914 |
1/2✓ Branch 0 taken 3847 times.
✗ Branch 1 not taken.
|
3847 | std::string a = getSetting("MultiSyncExternalIPAddress"); |
| 915 |
6/8✓ Branch 0 taken 3847 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3845 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 3845 times.
|
3847 | if (a != "" && a != dockerAddress) { |
| 916 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | addresses.push_back(a); |
| 917 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | dockerAddress = a; |
| 918 | } | ||
| 919 | 3847 | } | |
| 920 | |||
| 921 |
7/10✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4145 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4143 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 4143 times.
✓ Branch 9 taken 2 times.
|
4145 | if (multiSyncInterface == "" && dockerAddress == "") { |
| 922 | // get all the addresses | ||
| 923 | struct ifaddrs *interfaces, *tmp; | ||
| 924 | 4143 | getifaddrs(&interfaces); | |
| 925 | 4143 | tmp = interfaces; | |
| 926 | 4143 | std::vector<std::pair<std::string, std::string>> ifAddrs; // interface, address | |
| 927 | 4143 | std::set<std::string> routableIfs; | |
| 928 |
2/2✓ Branch 0 taken 22308 times.
✓ Branch 1 taken 4143 times.
|
26451 | while (tmp) { |
| 929 |
4/4✓ Branch 0 taken 22306 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8619 times.
✓ Branch 3 taken 13687 times.
|
22308 | if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) { |
| 930 |
1/2✓ Branch 0 taken 8619 times.
✗ Branch 1 not taken.
|
8619 | if (strncmp("usb", tmp->ifa_name, 3) != 0) { |
| 931 | // skip the usb* interfaces as we won't support multisync on those | ||
| 932 | 8619 | memset(addressBuf, 0, sizeof(addressBuf)); | |
| 933 | |||
| 934 | 8619 | struct sockaddr_in* sa = (struct sockaddr_in*)(tmp->ifa_addr); | |
| 935 | 8619 | inet_ntop(AF_INET, &sa->sin_addr, addressBuf, INET_ADDRSTRLEN); | |
| 936 |
3/4✓ Branch 0 taken 8619 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4470 times.
✓ Branch 3 taken 4149 times.
|
8619 | if (isSupportedForMultisync(addressBuf, tmp->ifa_name)) { |
| 937 |
1/2✓ Branch 0 taken 4470 times.
✗ Branch 1 not taken.
|
4470 | ifAddrs.emplace_back(tmp->ifa_name, addressBuf); |
| 938 |
3/6✓ Branch 0 taken 4470 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4470 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4470 times.
✗ Branch 5 not taken.
|
8940 | if (!IsIPv4LinkLocal(addressBuf)) { |
| 939 |
2/4✓ Branch 0 taken 4470 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4470 times.
✗ Branch 3 not taken.
|
8940 | routableIfs.insert(tmp->ifa_name); |
| 940 | } | ||
| 941 | } | ||
| 942 | } | ||
| 943 |
1/2✓ Branch 0 taken 13687 times.
✗ Branch 1 not taken.
|
13687 | } else if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) { |
| 944 | // FIXME for ipv6 multisync | ||
| 945 | } | ||
| 946 | 22308 | tmp = tmp->ifa_next; | |
| 947 | } | ||
| 948 | 4143 | freeifaddrs(interfaces); | |
| 949 | // A 169.254 address alongside a DHCP/static one on the same interface | ||
| 950 | // is only the fallback from before the lease arrived. Announcing it | ||
| 951 | // too just lists this box twice on every peer, once at an address | ||
| 952 | // nothing off this link can reach. | ||
| 953 |
2/2✓ Branch 0 taken 4470 times.
✓ Branch 1 taken 4143 times.
|
8613 | for (auto& [intf, addr] : ifAddrs) { |
| 954 |
3/10✓ Branch 0 taken 4470 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4470 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 4470 times.
✗ Branch 9 not taken.
|
4470 | if (!IsIPv4LinkLocal(addr) || !routableIfs.contains(intf)) { |
| 955 |
1/2✓ Branch 0 taken 4470 times.
✗ Branch 1 not taken.
|
4470 | addresses.push_back(addr); |
| 956 | } | ||
| 957 | } | ||
| 958 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
4145 | } else if (dockerAddress == "") { |
| 959 | ✗ | memset(addressBuf, 0, sizeof(addressBuf)); | |
| 960 | ✗ | GetInterfaceAddress(multiSyncInterface.c_str(), addressBuf, NULL, NULL); | |
| 961 | ✗ | addresses.push_back(addressBuf); | |
| 962 | } | ||
| 963 | |||
| 964 |
3/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2652 times.
✓ Branch 3 taken 1493 times.
|
4145 | if (m_hostname == "") { |
| 965 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | m_hostname = getSetting("HostName"); |
| 966 | } | ||
| 967 | |||
| 968 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4145 times.
|
4145 | if (m_hostname == "") { |
| 969 | ✗ | m_hostname = "FPP"; | |
| 970 | } | ||
| 971 | |||
| 972 | 4145 | newSystem.lastSeen = (unsigned long)time(NULL); | |
| 973 | 4145 | newSystem.type = type; | |
| 974 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.majorVersion = atoi(getFPPMajorVersion()); |
| 975 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.minorVersion = atoi(getFPPMinorVersion()); |
| 976 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.hostname = m_hostname; |
| 977 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.fppMode = getFPPmode(); |
| 978 | 4145 | newSystem.sendingMultiSync = m_multiSyncEnabled; | |
| 979 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
|
4145 | newSystem.version = getFPPVersion(); |
| 980 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.model = model; |
| 981 | 4145 | newSystem.ipa = 0; | |
| 982 | 4145 | newSystem.ipb = 0; | |
| 983 | 4145 | newSystem.ipc = 0; | |
| 984 | 4145 | newSystem.ipd = 0; | |
| 985 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | newSystem.uuid = getSetting("SystemUUID"); |
| 986 | |||
| 987 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | LogDebug(VB_SYNC, "Host name: %s\n", newSystem.hostname.c_str()); |
| 988 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | LogDebug(VB_SYNC, "Version: %s\n", newSystem.version.c_str()); |
| 989 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | LogDebug(VB_SYNC, "Model: %s\n", newSystem.model.c_str()); |
| 990 | |||
| 991 | // The local system's cape. Remotes are probed for theirs over HTTP (see | ||
| 992 | // FetchCapeInfo); the local entry is never probed, so without this the | ||
| 993 | // systems list showed a cape on every box except the one serving the page. | ||
| 994 | // Same file the local /api/cape answers from; absent means no cape, which | ||
| 995 | // is an answer (present=false), not "unknown". | ||
| 996 | { | ||
| 997 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | Json::Value capeJson; |
| 998 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
|
4145 | std::string capeFile = FPP_DIR_MEDIA("/tmp/cape-info.json"); |
| 999 |
9/14✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4140 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 4140 times.
|
4145 | if (FileExists(capeFile) && LoadJsonFromFile(capeFile, capeJson) && capeJson.isObject()) { |
| 1000 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | newSystem.capeInfo = MultiSyncCapeInfo::fromCapeJSON(capeJson); |
| 1001 | } else { | ||
| 1002 | 4140 | newSystem.capeInfo.valid = true; | |
| 1003 | 4140 | newSystem.capeInfo.present = false; | |
| 1004 | } | ||
| 1005 | 4145 | } | |
| 1006 | |||
| 1007 | 4145 | bool changed = false; | |
| 1008 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1009 | |||
| 1010 | // Addresses this box no longer has. Every ping goes out once per local | ||
| 1011 | // system, so an entry left here keeps announcing an address that is gone | ||
| 1012 | // -- typically the 169.254 one held until DHCP answered. | ||
| 1013 |
2/2✓ Branch 0 taken 2103 times.
✓ Branch 1 taken 4145 times.
|
6248 | for (auto it = m_localSystems.begin(); it != m_localSystems.end();) { |
| 1014 |
3/4✓ Branch 0 taken 2103 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 489 times.
✓ Branch 3 taken 1614 times.
|
2103 | if (std::find(addresses.begin(), addresses.end(), it->address) == addresses.end()) { |
| 1015 |
1/2✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
|
489 | LogDebug(VB_SYNC, "Removing Local System Address: %s\n", it->address.c_str()); |
| 1016 | 489 | changed = true; | |
| 1017 |
1/2✓ Branch 0 taken 489 times.
✗ Branch 1 not taken.
|
489 | it = m_localSystems.erase(it); |
| 1018 | } else { | ||
| 1019 | 1614 | ++it; | |
| 1020 | } | ||
| 1021 | } | ||
| 1022 | |||
| 1023 |
3/4✓ Branch 0 taken 4472 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4472 times.
✓ Branch 3 taken 4145 times.
|
8617 | for (auto address : addresses) { |
| 1024 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4472 times.
|
4472 | if (address.empty()) { |
| 1025 | // A failed GetInterfaceAddress()/inet_ntop() leaves the buffer empty; | ||
| 1026 | // skip it rather than record a bogus local system. | ||
| 1027 | ✗ | continue; | |
| 1028 | } | ||
| 1029 | 4472 | bool found = false; | |
| 1030 |
2/2✓ Branch 0 taken 2362 times.
✓ Branch 1 taken 4472 times.
|
6834 | for (auto& sys : m_localSystems) { |
| 1031 |
2/2✓ Branch 0 taken 1614 times.
✓ Branch 1 taken 748 times.
|
2362 | if (sys.address == address) { |
| 1032 | 1614 | found = true; | |
| 1033 |
1/2✓ Branch 0 taken 1614 times.
✗ Branch 1 not taken.
|
1614 | sys.capeInfo = newSystem.capeInfo; |
| 1034 | } | ||
| 1035 | } | ||
| 1036 |
2/2✓ Branch 0 taken 2858 times.
✓ Branch 1 taken 1614 times.
|
4472 | if (!found) { |
| 1037 |
1/2✓ Branch 0 taken 2858 times.
✗ Branch 1 not taken.
|
2858 | LogDebug(VB_SYNC, "Adding Local System Address: %s\n", address.c_str()); |
| 1038 | 2858 | changed = true; | |
| 1039 |
1/2✓ Branch 0 taken 2858 times.
✗ Branch 1 not taken.
|
2858 | newSystem.address = address; |
| 1040 |
1/2✓ Branch 0 taken 2858 times.
✗ Branch 1 not taken.
|
2858 | std::vector<std::string> parts = split(newSystem.address, '.'); |
| 1041 |
2/2✓ Branch 0 taken 2857 times.
✓ Branch 1 taken 1 times.
|
2858 | if (parts.size() >= 4) { |
| 1042 | 2857 | newSystem.ipa = atoi(parts[0].c_str()); | |
| 1043 | 2857 | newSystem.ipb = atoi(parts[1].c_str()); | |
| 1044 | 2857 | newSystem.ipc = atoi(parts[2].c_str()); | |
| 1045 | 2857 | newSystem.ipd = atoi(parts[3].c_str()); | |
| 1046 | } else { | ||
| 1047 | 1 | newSystem.ipa = 0; | |
| 1048 | 1 | newSystem.ipb = 0; | |
| 1049 | 1 | newSystem.ipc = 0; | |
| 1050 | 1 | newSystem.ipd = 0; | |
| 1051 | } | ||
| 1052 |
1/2✓ Branch 0 taken 2858 times.
✗ Branch 1 not taken.
|
2858 | m_localSystems.push_back(newSystem); |
| 1053 | 2858 | } | |
| 1054 |
1/2✓ Branch 0 taken 4472 times.
✗ Branch 1 not taken.
|
4472 | } |
| 1055 | 4145 | return changed; | |
| 1056 | 4145 | } | |
| 1057 | |||
| 1058 | /* | ||
| 1059 | * | ||
| 1060 | */ | ||
| 1061 | 4145 | std::string MultiSync::GetHardwareModel(void) { | |
| 1062 | #ifdef PLATFORM_OSX | ||
| 1063 | return "MacOS"; | ||
| 1064 | #else | ||
| 1065 | 4145 | std::string result; | |
| 1066 | 4145 | std::string filename; | |
| 1067 | |||
| 1068 |
3/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 319 times.
✓ Branch 3 taken 3826 times.
|
4145 | if (FileExists("/sys/firmware/devicetree/base/model")) |
| 1069 |
1/2✓ Branch 0 taken 319 times.
✗ Branch 1 not taken.
|
319 | filename = "/sys/firmware/devicetree/base/model"; |
| 1070 |
2/4✓ Branch 0 taken 3826 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3826 times.
✗ Branch 3 not taken.
|
3826 | else if (FileExists("/sys/class/dmi/id/product_name")) |
| 1071 |
1/2✓ Branch 0 taken 3826 times.
✗ Branch 1 not taken.
|
3826 | filename = "/sys/class/dmi/id/product_name"; |
| 1072 | |||
| 1073 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
|
4145 | if (filename != "") { |
| 1074 | char buf[128]; | ||
| 1075 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | FILE* fd = fopen(filename.c_str(), "r"); |
| 1076 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | if (fd) { |
| 1077 |
2/4✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
|
4145 | if (fgets(buf, 127, fd)) |
| 1078 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | result = buf; |
| 1079 | else | ||
| 1080 | ✗ | result = "Unknown Hardware Platform"; | |
| 1081 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | fclose(fd); |
| 1082 | } else { | ||
| 1083 | ✗ | result = "Unknown Hardware Platform"; | |
| 1084 | } | ||
| 1085 | } else { | ||
| 1086 | ✗ | result = "Unknown Hardware Platform"; | |
| 1087 | } | ||
| 1088 | |||
| 1089 |
4/6✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4145 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3826 times.
✓ Branch 5 taken 319 times.
|
8290 | if (endsWith(result, "\n")) { |
| 1090 |
3/6✓ Branch 0 taken 3826 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3826 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3826 times.
✗ Branch 5 not taken.
|
15304 | replaceAll(result, "\n", ""); |
| 1091 | } | ||
| 1092 | |||
| 1093 |
1/2✓ Branch 0 taken 4145 times.
✗ Branch 1 not taken.
|
4145 | TrimWhiteSpace(result); |
| 1094 | |||
| 1095 | 4145 | return result; | |
| 1096 | #endif | ||
| 1097 | 4145 | } | |
| 1098 | |||
| 1099 | /* | ||
| 1100 | * | ||
| 1101 | */ | ||
| 1102 | 80310 | std::string MultiSync::GetTypeString(MultiSyncSystemType type, bool local) { | |
| 1103 |
4/4✓ Branch 0 taken 29785 times.
✓ Branch 1 taken 50525 times.
✓ Branch 2 taken 29713 times.
✓ Branch 3 taken 72 times.
|
80310 | if (local && type == kSysTypeFPP) { |
| 1104 | // unknown hardware, but we can figure out the OS version | ||
| 1105 |
1/2✓ Branch 0 taken 29713 times.
✗ Branch 1 not taken.
|
29713 | if (FileExists("/etc/os-release")) { |
| 1106 |
2/4✓ Branch 0 taken 29713 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29713 times.
✗ Branch 3 not taken.
|
29713 | std::string file = GetFileContents("/etc/os-release"); |
| 1107 |
1/2✓ Branch 0 taken 29713 times.
✗ Branch 1 not taken.
|
29713 | std::vector<std::string> lines = split(file, '\n'); |
| 1108 | 29713 | std::map<std::string, std::string> values; | |
| 1109 |
2/2✓ Branch 0 taken 297130 times.
✓ Branch 1 taken 29713 times.
|
326843 | for (auto& str : lines) { |
| 1110 | 297130 | size_t pos = str.find("="); | |
| 1111 |
1/2✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
|
297130 | if (pos != std::string::npos) { |
| 1112 |
1/2✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
|
297130 | std::string key = str.substr(0, pos); |
| 1113 |
1/2✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
|
297130 | std::string val = str.substr(pos + 1); |
| 1114 |
2/2✓ Branch 0 taken 207991 times.
✓ Branch 1 taken 89139 times.
|
297130 | if (val[0] == '"') { |
| 1115 |
1/2✓ Branch 0 taken 207991 times.
✗ Branch 1 not taken.
|
207991 | val = val.substr(1, val.length() - 2); |
| 1116 | } | ||
| 1117 |
1/2✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
|
297130 | TrimWhiteSpace(key); |
| 1118 |
1/2✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
|
297130 | TrimWhiteSpace(val); |
| 1119 |
2/4✓ Branch 0 taken 297130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 297130 times.
✗ Branch 3 not taken.
|
297130 | values[key] = val; |
| 1120 | 297130 | } | |
| 1121 | } | ||
| 1122 |
4/8✓ Branch 0 taken 29713 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29713 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29713 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29713 times.
✗ Branch 7 not taken.
|
59426 | if (values["NAME"] != "") { |
| 1123 |
4/8✓ Branch 0 taken 29713 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29713 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29713 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 29713 times.
✗ Branch 7 not taken.
|
59426 | return "FPP (" + values["NAME"] + ")"; |
| 1124 | } | ||
| 1125 | ✗ | if (values["PRETTY_NAME"] != "") { | |
| 1126 | ✗ | return "FPP (" + values["PRETTY_NAME"] + ")"; | |
| 1127 | } | ||
| 1128 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 29713 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29713 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 29713 times.
|
89139 | } |
| 1129 | ✗ | return "FPP (unknown hardware)"; | |
| 1130 | } | ||
| 1131 |
59/59✓ Branch 0 taken 29 times.
✓ Branch 1 taken 47538 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 60 times.
✓ Branch 6 taken 54 times.
✓ Branch 7 taken 54 times.
✓ Branch 8 taken 60 times.
✓ Branch 9 taken 59 times.
✓ Branch 10 taken 53 times.
✓ Branch 11 taken 53 times.
✓ Branch 12 taken 54 times.
✓ Branch 13 taken 59 times.
✓ Branch 14 taken 73 times.
✓ Branch 15 taken 65 times.
✓ Branch 16 taken 51 times.
✓ Branch 17 taken 51 times.
✓ Branch 18 taken 51 times.
✓ Branch 19 taken 57 times.
✓ Branch 20 taken 54 times.
✓ Branch 21 taken 51 times.
✓ Branch 22 taken 51 times.
✓ Branch 23 taken 50 times.
✓ Branch 24 taken 73 times.
✓ Branch 25 taken 50 times.
✓ Branch 26 taken 56 times.
✓ Branch 27 taken 50 times.
✓ Branch 28 taken 52 times.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 1 times.
✓ Branch 32 taken 52 times.
✓ Branch 33 taken 51 times.
✓ Branch 34 taken 52 times.
✓ Branch 35 taken 52 times.
✓ Branch 36 taken 50 times.
✓ Branch 37 taken 60 times.
✓ Branch 38 taken 49 times.
✓ Branch 39 taken 52 times.
✓ Branch 40 taken 52 times.
✓ Branch 41 taken 52 times.
✓ Branch 42 taken 52 times.
✓ Branch 43 taken 52 times.
✓ Branch 44 taken 65 times.
✓ Branch 45 taken 52 times.
✓ Branch 46 taken 49 times.
✓ Branch 47 taken 50 times.
✓ Branch 48 taken 97 times.
✓ Branch 49 taken 60 times.
✓ Branch 50 taken 51 times.
✓ Branch 51 taken 52 times.
✓ Branch 52 taken 55 times.
✓ Branch 53 taken 68 times.
✓ Branch 54 taken 60 times.
✓ Branch 55 taken 51 times.
✓ Branch 56 taken 68 times.
✓ Branch 57 taken 54 times.
✓ Branch 58 taken 48 times.
|
50597 | switch (type) { |
| 1132 | 29 | case kSysTypeUnknown: | |
| 1133 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
58 | return "Unknown System Type"; |
| 1134 | 47538 | case kSysTypeFPP: | |
| 1135 |
1/2✓ Branch 0 taken 47538 times.
✗ Branch 1 not taken.
|
95076 | return "FPP (unknown hardware)"; |
| 1136 | 60 | case kSysTypeFPPRaspberryPiA: | |
| 1137 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Raspberry Pi A"; |
| 1138 | 60 | case kSysTypeFPPRaspberryPiB: | |
| 1139 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Raspberry Pi B"; |
| 1140 | 60 | case kSysTypeFPPRaspberryPiAPlus: | |
| 1141 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Raspberry Pi A Plus"; |
| 1142 | 60 | case kSysTypeFPPRaspberryPiBPlus: | |
| 1143 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Raspberry Pi B+"; |
| 1144 | 54 | case kSysTypeFPPRaspberryPi2B: | |
| 1145 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 | return "Raspberry Pi 2 B"; |
| 1146 | 54 | case kSysTypeFPPRaspberryPi2BNew: | |
| 1147 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 | return "Raspberry Pi 2 B v1.2+"; |
| 1148 | 60 | case kSysTypeFPPRaspberryPi3B: | |
| 1149 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Raspberry Pi 3 B"; |
| 1150 | 59 | case kSysTypeFPPRaspberryPi3BPlus: | |
| 1151 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
118 | return "Raspberry Pi 3 B+"; |
| 1152 | 53 | case kSysTypeFPPRaspberryPiZero: | |
| 1153 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
106 | return "Raspberry Pi Zero"; |
| 1154 | 53 | case kSysTypeFPPRaspberryPiZeroW: | |
| 1155 |
1/2✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
|
106 | return "Raspberry Pi Zero W"; |
| 1156 | 54 | case kSysTypeFPPRaspberryPiZero2W: | |
| 1157 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 | return "Raspberry Pi Zero 2 W"; |
| 1158 | 59 | case kSysTypeFPPRaspberryPi3APlus: | |
| 1159 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
118 | return "Raspberry Pi 3 A+"; |
| 1160 | 73 | case kSysTypeFPPRaspberryPi4: | |
| 1161 |
1/2✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
|
146 | return "Raspberry Pi 4"; |
| 1162 | 65 | case kSysTypeFPPRaspberryPi5: | |
| 1163 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
130 | return "Raspberry Pi 5"; |
| 1164 | 51 | case kSysTypeFalconController: | |
| 1165 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Falcon Controller"; |
| 1166 | 51 | case kSysTypeFalconF16v2: | |
| 1167 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Falcon F16v2"; |
| 1168 | 51 | case kSysTypeFalconF4v2_64Mb: | |
| 1169 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Falcon F4v2_64Mb"; |
| 1170 | 57 | case kSysTypeFalconF16v2R: | |
| 1171 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
114 | return "Falcon F16v2R"; |
| 1172 | 54 | case kSysTypeFalconF4v2: | |
| 1173 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 | return "Falcon F4v2"; |
| 1174 | 51 | case kSysTypeFalconF4v3: | |
| 1175 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Falcon F4v3"; |
| 1176 | 51 | case kSysTypeFalconF16v3: | |
| 1177 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Falcon F16v3"; |
| 1178 | 50 | case kSysTypeFalconF48: | |
| 1179 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
100 | return "Falcon F48"; |
| 1180 | 73 | case kSysTypeFalconF16v4: | |
| 1181 |
1/2✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
|
146 | return "Falcon F16v4"; |
| 1182 | 50 | case kSysTypeFalconF48v4: | |
| 1183 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
100 | return "Falcon F48v4"; |
| 1184 | 56 | case kSysTypeFalconF16v5: | |
| 1185 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
112 | return "Falcon F16v5"; |
| 1186 | 50 | case kSysTypeFalconF32v5: | |
| 1187 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
100 | return "Falcon F32v5"; |
| 1188 | 52 | case kSysTypeFalconF48v5: | |
| 1189 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "Falcon F48v5"; |
| 1190 | 1 | case kSysTypeExperienceGP16: | |
| 1191 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | return "Genius Pixel 16"; |
| 1192 | 1 | case kSysTypeExperienceGP8: | |
| 1193 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | return "Genius Pixel 8"; |
| 1194 | 1 | case kSysTypeExperienceGLR: | |
| 1195 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | return "Genius Long Range"; |
| 1196 | 52 | case kSysTypeExperienceG16Pro: | |
| 1197 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "Genius PRO 16"; |
| 1198 | 51 | case kSysTypeExperienceG32Pro: | |
| 1199 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "Genius PRO 32"; |
| 1200 | 52 | case kSysTypeExperienceAURORACORE16: | |
| 1201 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "LOR AURORA CORE 16"; |
| 1202 | 52 | case kSysTypeExperienceVIVID8: | |
| 1203 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "YPS VIVID 8"; |
| 1204 | 50 | case kSysTypeExperiencePIXELLINK4: | |
| 1205 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
100 | return "Genius PIXEL LINK 4"; |
| 1206 | 60 | case kSysTypeExperienceGenius: | |
| 1207 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Genius Controller"; |
| 1208 | 49 | case kSysTypeOtherSystem: | |
| 1209 |
1/2✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
|
98 | return "Other Unknown System"; |
| 1210 | 52 | case kSysTypeFPPBeagleBoneBlack: | |
| 1211 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "BeagleBone Black"; |
| 1212 | 52 | case kSysTypeFPPBeagleBoneBlackWireless: | |
| 1213 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "BeagleBone Black Wireless"; |
| 1214 | 52 | case kSysTypeFPPBeagleBoneGreen: | |
| 1215 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "BeagleBone Green"; |
| 1216 | 52 | case kSysTypeFPPBeagleBoneGreenWireless: | |
| 1217 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "BeagleBone Green Wireless"; |
| 1218 | 52 | case kSysTypeFPPPocketBeagle: | |
| 1219 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "PocketBeagle"; |
| 1220 | 65 | case kSysTypeFPPPocketBeagle2: | |
| 1221 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
130 | return "PocketBeagle2"; |
| 1222 | 52 | case kSysTypeFPPSanCloudBeagleBoneEnhanced: | |
| 1223 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "SanCloud BeagleBone Enhanced"; |
| 1224 | 49 | case kSysTypexSchedule: | |
| 1225 |
1/2✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
|
98 | return "xSchedule"; |
| 1226 | 50 | case kSysTypeESPixelStick: | |
| 1227 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
100 | return "ESPixelStick-ESP8266"; |
| 1228 | 97 | case kSysTypeESPixelStickESP32: | |
| 1229 |
1/2✓ Branch 0 taken 97 times.
✗ Branch 1 not taken.
|
194 | return "ESPixelStick-ESP32"; |
| 1230 | 60 | case kSysTypeBaldrick: | |
| 1231 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "Baldrick"; |
| 1232 | 51 | case kSysTypeMacOS: | |
| 1233 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "MacOS"; |
| 1234 | 52 | case kSysTypeFPPArmbian: | |
| 1235 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
104 | return "Armbian"; |
| 1236 | 55 | case kSysTypeSanDevices: | |
| 1237 |
1/2✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
|
110 | return "SanDevices"; |
| 1238 | 68 | case kSysTypeAlphaPix: | |
| 1239 |
1/2✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
|
136 | return "AlphaPix"; |
| 1240 | 60 | case kSysTypeHinksPix: | |
| 1241 |
1/2✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
|
120 | return "HinksPix"; |
| 1242 | 51 | case kSysTypeDIYLEDExpress: | |
| 1243 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
102 | return "DIYLEDExpress"; |
| 1244 | 68 | case kSysTypeWLED: | |
| 1245 |
1/2✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
|
136 | return "WLED"; |
| 1246 | 54 | case kSysTypeTwinkly: | |
| 1247 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
108 | return "Twinkly"; |
| 1248 | 48 | default: | |
| 1249 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
96 | return "Unknown System Type"; |
| 1250 | } | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | 25042 | static std::string createRanges(std::vector<std::pair<uint32_t, uint32_t>> ranges, int limit) { | |
| 1254 | 25042 | bool first = true; | |
| 1255 |
1/2✓ Branch 0 taken 25042 times.
✗ Branch 1 not taken.
|
25042 | std::string range(""); |
| 1256 | char buf[64]; | ||
| 1257 | 25042 | memset(buf, 0, sizeof(buf)); | |
| 1258 |
2/2✓ Branch 0 taken 25224 times.
✓ Branch 1 taken 25042 times.
|
50266 | for (auto& a : ranges) { |
| 1259 |
2/2✓ Branch 0 taken 182 times.
✓ Branch 1 taken 25042 times.
|
25224 | if (!first) { |
| 1260 |
1/2✓ Branch 0 taken 182 times.
✗ Branch 1 not taken.
|
182 | range += ","; |
| 1261 | } | ||
| 1262 | 25224 | snprintf(buf, sizeof(buf), "%d-%d", a.first, (a.first + a.second - 1)); | |
| 1263 |
1/2✓ Branch 0 taken 25224 times.
✗ Branch 1 not taken.
|
25224 | range += buf; |
| 1264 | 25224 | first = false; | |
| 1265 | } | ||
| 1266 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 25042 times.
|
25051 | while (range.size() > limit) { |
| 1267 | // range won't fit within the space in the Ping packet, we need to shrink the range | ||
| 1268 | // we'll find the smallest gap and combine into a larger range | ||
| 1269 | 9 | int minGap = 9999999; | |
| 1270 | 9 | int minIdx = -1; | |
| 1271 | 9 | int last = ranges[0].first + ranges[0].second - 1; | |
| 1272 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 9 times.
|
99 | for (int x = 1; x < ranges.size(); x++) { |
| 1273 | 90 | int gap = ranges[x].first - last; | |
| 1274 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 72 times.
|
90 | if (gap < minGap) { |
| 1275 | 18 | minIdx = x; | |
| 1276 | 18 | minGap = gap; | |
| 1277 | } | ||
| 1278 | 90 | last = ranges[x].first + ranges[x].second - 1; | |
| 1279 | } | ||
| 1280 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (minIdx > 0) { |
| 1281 | 9 | int newLast = ranges[minIdx].first + ranges[minIdx].second; | |
| 1282 | 9 | ranges[minIdx - 1].second = newLast - ranges[minIdx - 1].first; | |
| 1283 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | ranges.erase(ranges.begin() + minIdx); |
| 1284 | } | ||
| 1285 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | range = createRanges(ranges, 999999); |
| 1286 | } | ||
| 1287 | 25042 | return range; | |
| 1288 | ✗ | } | |
| 1289 | |||
| 1290 | // Build a map of configured-output controller address -> channel range string. | ||
| 1291 | // Output-only controllers (WLED, Falcon, etc.) generally don't report their own | ||
| 1292 | // channel ranges, but FPP knows them from its universe output configuration, so | ||
| 1293 | // we backfill the ranges from our own config (issue #2667). Each address is | ||
| 1294 | // keyed both by the raw configured value and by its resolved IP so that we can | ||
| 1295 | // match a system regardless of whether it was discovered/stored by hostname or | ||
| 1296 | // by IP. | ||
| 1297 | 2727 | static std::map<std::string, std::string> GetConfiguredOutputRanges() { | |
| 1298 | 2727 | std::map<std::string, std::vector<std::pair<uint32_t, uint32_t>>> byAddress; | |
| 1299 | |||
| 1300 |
6/10✓ Branch 0 taken 2727 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2727 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2727 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2727 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 982 times.
✓ Branch 9 taken 1745 times.
|
5454 | if (FileExists(FPP_DIR_CONFIG("/co-universes.json"))) { |
| 1301 |
4/8✓ Branch 0 taken 982 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 982 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 982 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 982 times.
✗ Branch 7 not taken.
|
982 | Json::Value outputs = LoadJsonFromFile(FPP_DIR_CONFIG("/co-universes.json"), JsonRoot::Object); |
| 1302 |
1/2✓ Branch 0 taken 982 times.
✗ Branch 1 not taken.
|
982 | const Json::Value& cos = outputs["channelOutputs"]; |
| 1303 |
8/10✓ Branch 0 taken 1961 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1960 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1960 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 979 times.
✓ Branch 7 taken 981 times.
✓ Branch 8 taken 979 times.
✓ Branch 9 taken 982 times.
|
1961 | for (Json::ArrayIndex i = 0; cos.isArray() && i < cos.size(); i++) { |
| 1304 |
1/2✓ Branch 0 taken 979 times.
✗ Branch 1 not taken.
|
979 | const Json::Value& co = cos[i]; |
| 1305 |
6/12✓ Branch 0 taken 979 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 979 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 979 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 979 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 979 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 979 times.
|
979 | if (!co.isObject() || !co["universes"].isArray()) { |
| 1306 | ✗ | continue; | |
| 1307 | } | ||
| 1308 |
8/14✓ Branch 0 taken 979 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 979 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 979 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1095 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1095 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2074 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1095 times.
✓ Branch 13 taken 979 times.
|
2074 | for (const auto& u : co["universes"]) { |
| 1309 | // Read at startup: a universe with a field of the wrong type is | ||
| 1310 | // left out here (ChannelOutputSetup reports it), not thrown on. | ||
| 1311 |
5/8✓ Branch 0 taken 1095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1094 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1094 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1093 times.
✓ Branch 7 taken 1 times.
|
2189 | if (!u.isObject() || !u["address"].isString() || |
| 1312 |
7/12✓ Branch 0 taken 1093 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1093 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1092 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1092 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1092 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1092 times.
✗ Branch 11 not taken.
|
1093 | !u["startChannel"].isIntegral() || !u["channelCount"].isIntegral() || |
| 1313 |
7/10✓ Branch 0 taken 1094 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1092 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1092 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 1092 times.
|
3281 | !u["startChannel"].isConvertibleTo(Json::uintValue) || |
| 1314 |
3/6✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1092 times.
|
1092 | !u["channelCount"].isConvertibleTo(Json::uintValue)) { |
| 1315 | 4 | continue; | |
| 1316 | } | ||
| 1317 |
2/4✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
|
1092 | std::string address = u["address"].asString(); |
| 1318 |
2/4✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
|
1092 | uint32_t count = u["channelCount"].asUInt(); |
| 1319 |
2/4✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
|
1092 | uint32_t start = u["startChannel"].asUInt(); |
| 1320 |
6/8✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1092 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1091 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1091 times.
|
1092 | if (address.empty() || count == 0 || start == 0) { |
| 1321 | 1 | continue; | |
| 1322 | } | ||
| 1323 | // channelRanges is a zero-based convention everywhere else -- | ||
| 1324 | // see the GetRequiredChannelRange() implementations, which all | ||
| 1325 | // report (startChannel - 1). The universes in co-universes.json | ||
| 1326 | // store the user-facing one-based start channel, so convert here | ||
| 1327 | // or every backfilled remote is reported one channel high. | ||
| 1328 |
2/4✓ Branch 0 taken 1091 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1091 times.
✗ Branch 3 not taken.
|
1091 | byAddress[address].emplace_back(start - 1, count); |
| 1329 |
2/2✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 1 times.
|
1092 | } |
| 1330 | } | ||
| 1331 | 982 | } | |
| 1332 | |||
| 1333 | 2727 | std::map<std::string, std::string> result; | |
| 1334 |
2/2✓ Branch 0 taken 1037 times.
✓ Branch 1 taken 2727 times.
|
3764 | for (auto& [address, ranges] : byAddress) { |
| 1335 |
1/2✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
|
1037 | std::sort(ranges.begin(), ranges.end()); |
| 1336 | // merge contiguous/overlapping ranges so the reported string is clean | ||
| 1337 | 1037 | std::vector<std::pair<uint32_t, uint32_t>> merged; | |
| 1338 |
2/2✓ Branch 0 taken 1091 times.
✓ Branch 1 taken 1037 times.
|
2128 | for (const auto& r : ranges) { |
| 1339 |
6/6✓ Branch 0 taken 54 times.
✓ Branch 1 taken 1037 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 41 times.
✓ Branch 5 taken 1050 times.
|
1091 | if (!merged.empty() && r.first <= (merged.back().first + merged.back().second)) { |
| 1340 | 41 | uint32_t end = std::max(merged.back().first + merged.back().second, r.first + r.second); | |
| 1341 | 41 | merged.back().second = end - merged.back().first; | |
| 1342 | } else { | ||
| 1343 |
1/2✓ Branch 0 taken 1050 times.
✗ Branch 1 not taken.
|
1050 | merged.push_back(r); |
| 1344 | } | ||
| 1345 | } | ||
| 1346 |
2/4✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1037 times.
✗ Branch 3 not taken.
|
1037 | std::string rangeStr = createRanges(merged, 999999); |
| 1347 |
2/4✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1037 times.
✗ Branch 3 not taken.
|
1037 | result[address] = rangeStr; |
| 1348 |
1/2✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
|
1037 | std::string ip = address; |
| 1349 |
7/8✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1028 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1026 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1035 times.
|
1037 | if (GetIPForHost(ip) && ip != address) { |
| 1350 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result[ip] = rangeStr; |
| 1351 | } | ||
| 1352 | 1037 | } | |
| 1353 | 2727 | return result; | |
| 1354 | 2727 | } | |
| 1355 | |||
| 1356 | 2727 | void MultiSync::ReloadConfiguredOutputRanges() { | |
| 1357 | // Build the map outside the lock: GetConfiguredOutputRanges() reads | ||
| 1358 | // co-universes.json and may run blocking DNS lookups to resolve configured | ||
| 1359 | // output hostnames. Then swap it in under the lock that guards GetSystems(). | ||
| 1360 | // This runs once at startup and again only when co-universes.json changes. | ||
| 1361 |
1/2✓ Branch 0 taken 2727 times.
✗ Branch 1 not taken.
|
2727 | std::map<std::string, std::string> ranges = GetConfiguredOutputRanges(); |
| 1362 |
1/2✓ Branch 0 taken 2727 times.
✗ Branch 1 not taken.
|
2727 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1363 | 2727 | m_configuredOutputRanges = std::move(ranges); | |
| 1364 | 2727 | } | |
| 1365 | |||
| 1366 | 18150 | Json::Value MultiSync::GetSystems(bool localOnly, bool timestamps) { | |
| 1367 |
1/2✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
|
18150 | Json::Value result; |
| 1368 |
1/2✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
|
18150 | Json::Value systems(Json::arrayValue); |
| 1369 | |||
| 1370 |
1/2✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
|
18150 | auto ranges = GetOutputRangesSnapshot(true); |
| 1371 |
2/4✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18150 times.
✗ Branch 3 not taken.
|
18150 | std::string range = createRanges(*ranges, 999999); |
| 1372 | |||
| 1373 |
1/2✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
|
18150 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1374 |
2/2✓ Branch 0 taken 29785 times.
✓ Branch 1 taken 18150 times.
|
47935 | for (auto& sys : m_localSystems) { |
| 1375 |
1/2✓ Branch 0 taken 29785 times.
✗ Branch 1 not taken.
|
29785 | sys.ranges = range; |
| 1376 |
2/4✓ Branch 0 taken 29785 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29785 times.
✗ Branch 3 not taken.
|
29785 | systems.append(sys.toJSON(true, timestamps)); |
| 1377 | } | ||
| 1378 |
2/2✓ Branch 0 taken 12548 times.
✓ Branch 1 taken 5602 times.
|
18150 | if (!localOnly) { |
| 1379 | // m_configuredOutputRanges is rebuilt only when co-universes.json changes | ||
| 1380 | // (see ReloadConfiguredOutputRanges()), so this is a plain in-memory map | ||
| 1381 | // lookup -- no per-call file read and, crucially, no blocking DNS. (This | ||
| 1382 | // endpoint is polled frequently by the UI and is also invoked indirectly | ||
| 1383 | // by the config backup generated on every settings change, so the old | ||
| 1384 | // resolve-per-remote-per-call cost was very visible.) We only backfill a | ||
| 1385 | // range for remotes that didn't advertise one of their own, and we do it | ||
| 1386 | // in the emitted JSON rather than mutating the stored system so a later | ||
| 1387 | // co-universes.json change is still reflected. | ||
| 1388 |
2/2✓ Branch 0 taken 50513 times.
✓ Branch 1 taken 12548 times.
|
63061 | for (auto& sys : m_remoteSystems) { |
| 1389 |
1/2✓ Branch 0 taken 50513 times.
✗ Branch 1 not taken.
|
50513 | Json::Value sysJson = sys.toJSON(false, timestamps); |
| 1390 |
9/10✓ Branch 0 taken 167 times.
✓ Branch 1 taken 50346 times.
✓ Branch 2 taken 167 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
✓ Branch 5 taken 23 times.
✓ Branch 6 taken 17 times.
✓ Branch 7 taken 50473 times.
✓ Branch 8 taken 17 times.
✓ Branch 9 taken 50496 times.
|
50513 | if ((sys.ranges.empty() || sys.ranges == "0-0") && !m_configuredOutputRanges.empty()) { |
| 1391 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | auto it = m_configuredOutputRanges.find(sys.address); |
| 1392 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 7 times.
|
17 | if (it == m_configuredOutputRanges.end()) { |
| 1393 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | it = m_configuredOutputRanges.find(sys.hostname); |
| 1394 | } | ||
| 1395 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 10 times.
|
17 | if (it != m_configuredOutputRanges.end()) { |
| 1396 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | sysJson["channelRanges"] = it->second; |
| 1397 | } | ||
| 1398 | } | ||
| 1399 |
1/2✓ Branch 0 taken 50513 times.
✗ Branch 1 not taken.
|
50513 | systems.append(sysJson); |
| 1400 | 50513 | } | |
| 1401 | } | ||
| 1402 |
2/4✓ Branch 0 taken 18150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18150 times.
✗ Branch 3 not taken.
|
18150 | result["systems"] = systems; |
| 1403 | 18150 | return result; | |
| 1404 | 18150 | } | |
| 1405 | |||
| 1406 | // The packet counters are bumped as packets are processed, on the main loop, | ||
| 1407 | // without m_statsLock (only the lookup of a sender's stats takes it), while | ||
| 1408 | // GetSyncStats() reads them and ResetSyncStats() zeroes them from API threads. | ||
| 1409 | // So every access is a relaxed atomic one; MultiSyncStats keeps plain fields, | ||
| 1410 | // as MultiSync.h is a plugin-facing header. | ||
| 1411 | 13460 | static inline void BumpStat(uint32_t& c) { | |
| 1412 | 13460 | __atomic_fetch_add(&c, 1, __ATOMIC_RELAXED); | |
| 1413 | 13460 | } | |
| 1414 | |||
| 1415 | 89 | Json::Value MultiSync::GetSyncStats() { | |
| 1416 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | Json::Value result; |
| 1417 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | Json::Value systems(Json::arrayValue); |
| 1418 | |||
| 1419 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | std::unique_lock<std::recursive_mutex> slock(m_statsLock); |
| 1420 |
2/2✓ Branch 0 taken 2130 times.
✓ Branch 1 taken 89 times.
|
2219 | for (auto& a : m_syncStats) { |
| 1421 | 2130 | MultiSyncStats* stats = (MultiSyncStats*)a.second; | |
| 1422 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | systems.append(stats->toJSON()); |
| 1423 | } | ||
| 1424 | // m_syncMaster is rewritten from the sync-receive path on the main loop, so | ||
| 1425 | // it is only ever touched under m_statsLock. Copy it out here and use the | ||
| 1426 | // copy below: m_statsLock and m_systemsLock are never held together. | ||
| 1427 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | std::string syncMaster = m_syncMaster; |
| 1428 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | slock.unlock(); |
| 1429 | |||
| 1430 |
2/4✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
|
89 | result["systems"] = systems; |
| 1431 | |||
| 1432 | 89 | std::string masterHostname; | |
| 1433 | |||
| 1434 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1435 |
2/2✓ Branch 0 taken 462 times.
✓ Branch 1 taken 89 times.
|
551 | for (auto& sys : m_remoteSystems) { |
| 1436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 462 times.
|
462 | if (sys.address == syncMaster) |
| 1437 | ✗ | masterHostname = sys.hostname; | |
| 1438 | } | ||
| 1439 |
1/2✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
|
89 | lock.unlock(); |
| 1440 | |||
| 1441 |
2/4✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
|
89 | result["masterIP"] = syncMaster; |
| 1442 |
2/4✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
|
89 | result["masterHostname"] = masterHostname; |
| 1443 | |||
| 1444 | 89 | return result; | |
| 1445 | 89 | } | |
| 1446 | |||
| 1447 | 2 | void MultiSync::ResetSyncStats() { | |
| 1448 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::unique_lock<std::recursive_mutex> slock(m_statsLock); |
| 1449 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (auto& a : m_syncStats) { |
| 1450 | 2 | MultiSyncStats* stats = (MultiSyncStats*)a.second; | |
| 1451 | 2 | __atomic_store_n(&stats->pktCommand, 0, __ATOMIC_RELAXED); | |
| 1452 | 2 | __atomic_store_n(&stats->pktSyncSeqOpen, 0, __ATOMIC_RELAXED); | |
| 1453 | 2 | __atomic_store_n(&stats->pktSyncSeqStart, 0, __ATOMIC_RELAXED); | |
| 1454 | 2 | __atomic_store_n(&stats->pktSyncSeqStop, 0, __ATOMIC_RELAXED); | |
| 1455 | 2 | __atomic_store_n(&stats->pktSyncSeqSync, 0, __ATOMIC_RELAXED); | |
| 1456 | 2 | __atomic_store_n(&stats->pktSyncMedOpen, 0, __ATOMIC_RELAXED); | |
| 1457 | 2 | __atomic_store_n(&stats->pktSyncMedStart, 0, __ATOMIC_RELAXED); | |
| 1458 | 2 | __atomic_store_n(&stats->pktSyncMedStop, 0, __ATOMIC_RELAXED); | |
| 1459 | 2 | __atomic_store_n(&stats->pktSyncMedSync, 0, __ATOMIC_RELAXED); | |
| 1460 | 2 | __atomic_store_n(&stats->pktBlank, 0, __ATOMIC_RELAXED); | |
| 1461 | 2 | __atomic_store_n(&stats->pktPing, 0, __ATOMIC_RELAXED); | |
| 1462 | 2 | __atomic_store_n(&stats->pktPlugin, 0, __ATOMIC_RELAXED); | |
| 1463 | 2 | __atomic_store_n(&stats->pktFPPCommand, 0, __ATOMIC_RELAXED); | |
| 1464 | 2 | __atomic_store_n(&stats->pktError, 0, __ATOMIC_RELAXED); | |
| 1465 | } | ||
| 1466 | 2 | } | |
| 1467 | |||
| 1468 | 2649 | void MultiSync::Discover() { | |
| 1469 | 2649 | Ping(1); | |
| 1470 | 2649 | PerformHTTPDiscovery(); | |
| 1471 | 2649 | PerformTwinklyDiscovery(); | |
| 1472 | 2649 | } | |
| 1473 | |||
| 1474 | 2649 | void MultiSync::PerformHTTPDiscovery() { | |
| 1475 |
1/2✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
|
2649 | std::string subnetsStr = getSetting("MultiSyncHTTPSubnets"); |
| 1476 | |||
| 1477 |
6/10✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2649 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2649 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2649 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 907 times.
✓ Branch 9 taken 1742 times.
|
5298 | if (FileExists(FPP_DIR_CONFIG("/co-universes.json"))) { |
| 1478 |
4/8✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 907 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 907 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 907 times.
✗ Branch 7 not taken.
|
907 | Json::Value outputs = LoadJsonFromFile(FPP_DIR_CONFIG("/co-universes.json"), JsonRoot::Object); |
| 1479 |
1/2✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
|
907 | const Json::Value& cos = outputs["channelOutputs"]; |
| 1480 |
8/10✓ Branch 0 taken 1811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1810 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1810 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 904 times.
✓ Branch 7 taken 906 times.
✓ Branch 8 taken 904 times.
✓ Branch 9 taken 907 times.
|
1811 | for (Json::ArrayIndex co = 0; cos.isArray() && co < cos.size(); co++) { |
| 1481 |
8/16✓ Branch 0 taken 904 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 904 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 904 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 904 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 904 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 904 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 904 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 904 times.
|
904 | if (!cos[co].isObject() || !cos[co]["universes"].isArray()) { |
| 1482 | ✗ | continue; | |
| 1483 | } | ||
| 1484 |
2/4✓ Branch 0 taken 904 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 904 times.
✗ Branch 3 not taken.
|
904 | const Json::Value& universes = cos[co]["universes"]; |
| 1485 |
3/4✓ Branch 0 taken 1900 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 996 times.
✓ Branch 3 taken 904 times.
|
1900 | for (Json::ArrayIndex i = 0; i < universes.size(); i++) { |
| 1486 | // shape-checked: this runs at startup, and a wrong type threw | ||
| 1487 |
11/16✓ Branch 0 taken 996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 995 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 995 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 995 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 995 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 994 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 994 times.
✓ Branch 15 taken 2 times.
|
996 | if (universes[i].isObject() && universes[i]["address"].isString()) { |
| 1488 |
3/4✓ Branch 0 taken 994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 904 times.
|
994 | if (subnetsStr != "") { |
| 1489 |
1/2✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
|
90 | subnetsStr += ","; |
| 1490 | } | ||
| 1491 |
4/8✓ Branch 0 taken 994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 994 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 994 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 994 times.
✗ Branch 7 not taken.
|
994 | subnetsStr += universes[i]["address"].asString(); |
| 1492 | } | ||
| 1493 | } | ||
| 1494 | } | ||
| 1495 | 907 | } | |
| 1496 | |||
| 1497 |
3/4✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 939 times.
✓ Branch 3 taken 1710 times.
|
2649 | if (subnetsStr != "") { |
| 1498 |
1/2✓ Branch 0 taken 939 times.
✗ Branch 1 not taken.
|
939 | std::vector<std::string> tokens = split(subnetsStr, ','); |
| 1499 | 939 | std::set<std::string> subnets; | |
| 1500 | 939 | std::set<std::string> exacts; | |
| 1501 | // This runs at startup: an unbounded "10.0.0.0/8" (16.7M addresses, | ||
| 1502 | // held twice) or "[1-100000000]" ran fppd out of memory on every | ||
| 1503 | // start. A /16 is the most a scan may cover, octet ranges stay | ||
| 1504 | // within 0..255, and the total is capped. | ||
| 1505 | static constexpr size_t MAX_DISCOVERY_ADDRESSES = 65536; | ||
| 1506 | 939 | bool truncated = false; | |
| 1507 | 538 | auto addAddress = [&subnets, &truncated](const std::string& a) { | |
| 1508 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
|
538 | if (subnets.size() >= MAX_DISCOVERY_ADDRESSES) { |
| 1509 | ✗ | truncated = true; | |
| 1510 | ✗ | return false; | |
| 1511 | } | ||
| 1512 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
538 | subnets.insert(a); |
| 1513 | 538 | return true; | |
| 1514 | 939 | }; | |
| 1515 |
3/4✓ Branch 0 taken 1065 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1065 times.
✓ Branch 3 taken 939 times.
|
2004 | for (std::string token : tokens) { |
| 1516 |
1/2✓ Branch 0 taken 1065 times.
✗ Branch 1 not taken.
|
1065 | TrimWhiteSpace(token); |
| 1517 |
2/4✓ Branch 0 taken 1065 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1065 times.
✗ Branch 3 not taken.
|
1065 | if (token != "") { |
| 1518 | 1065 | size_t pos = token.find('['); | |
| 1519 | 1065 | size_t posSlash = token.find('/'); | |
| 1520 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1063 times.
|
1065 | if (pos != std::string::npos) { |
| 1521 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::string rng = token.substr(pos + 1); |
| 1522 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | token = token.substr(0, pos); |
| 1523 | 2 | size_t pos2 = rng.find(']'); | |
| 1524 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::string postfix = ""; |
| 1525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (pos2 != (rng.size() - 1)) { |
| 1526 | ✗ | postfix = rng.substr(pos2 + 1); | |
| 1527 | } | ||
| 1528 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::vector<std::string> r1 = split(rng, ','); |
| 1529 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (const auto& a : r1) { |
| 1530 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::vector<std::string> r = split(a, '-'); |
| 1531 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (r.empty()) { |
| 1532 | ✗ | continue; | |
| 1533 | } | ||
| 1534 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | int start = std::clamp(atoi(r[0].c_str()), 0, 255); |
| 1535 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | int end = r.size() == 2 ? std::clamp(atoi(r[1].c_str()), 0, 255) : start; |
| 1536 |
2/2✓ Branch 0 taken 306 times.
✓ Branch 1 taken 2 times.
|
308 | for (int x = start; x <= end; x++) { |
| 1537 |
4/8✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 306 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 306 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 306 times.
|
306 | if (!addAddress(token + std::to_string(x) + postfix)) { |
| 1538 | ✗ | break; | |
| 1539 | } | ||
| 1540 | } | ||
| 1541 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } |
| 1542 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1058 times.
|
1065 | } else if (posSlash != std::string::npos) { |
| 1543 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | std::vector<std::string> parts = split(token, '/'); |
| 1544 | 5 | int prefix = 32; | |
| 1545 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (parts.size() == 2) { |
| 1546 | 5 | prefix = atoi(parts[1].c_str()); | |
| 1547 | } | ||
| 1548 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
5 | if (prefix < 16 || prefix > 32) { |
| 1549 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogWarn(VB_SYNC, "MultiSync HTTP discovery: ignoring %s, only /16 to /32 can be scanned\n", |
| 1550 | token.c_str()); | ||
| 1551 | 2 | continue; | |
| 1552 | } | ||
| 1553 | 3 | int ips = 1 << (32 - prefix); | |
| 1554 | // From the network address, whatever host in it was written: | ||
| 1555 | // 10.88.0.5/29 is 10.88.0.0/29. | ||
| 1556 | 3 | uint32_t mask = 0xFFFFFFFFu << (32 - prefix); | |
| 1557 | 3 | unsigned long firstIP = htonl(inet_addr(parts[0].c_str())) & mask; | |
| 1558 | // If prefix is a /31 or /32, we scan all IPs, otherwise skip network | ||
| 1559 | // and broadcast | ||
| 1560 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (prefix <= 30) { |
| 1561 | 2 | ips -= 2; | |
| 1562 | 2 | firstIP++; | |
| 1563 | } | ||
| 1564 | struct in_addr ia; | ||
| 1565 | char ip[16]; | ||
| 1566 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 3 times.
|
17 | for (int i = 0; i < ips; i++) { |
| 1567 | 14 | ia.s_addr = ntohl(firstIP + i); | |
| 1568 | 14 | inet_ntop(AF_INET, &ia, ip, sizeof(ip)); | |
| 1569 |
3/6✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
|
28 | if (!addAddress(ip)) { |
| 1570 | ✗ | break; | |
| 1571 | } | ||
| 1572 | } | ||
| 1573 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | } else { |
| 1574 |
1/2✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
|
1058 | std::string address2 = token; |
| 1575 |
1/2✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
|
1058 | GetIPForHost(address2); |
| 1576 |
7/10✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218 times.
✓ Branch 3 taken 840 times.
✓ Branch 4 taken 218 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 218 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 218 times.
✓ Branch 9 taken 840 times.
|
1058 | if (isSupportedForMultisync(address2.c_str(), "") && addAddress(token)) { |
| 1577 |
1/2✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
|
218 | exacts.insert(token); |
| 1578 | } | ||
| 1579 | 1058 | } | |
| 1580 | } | ||
| 1581 |
2/2✓ Branch 0 taken 1063 times.
✓ Branch 1 taken 2 times.
|
1065 | } |
| 1582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 939 times.
|
939 | if (truncated) { |
| 1583 | ✗ | LogWarn(VB_SYNC, "MultiSync HTTP discovery: more than %zu addresses configured, scanning only the first %zu\n", | |
| 1584 | MAX_DISCOVERY_ADDRESSES, MAX_DISCOVERY_ADDRESSES); | ||
| 1585 | } | ||
| 1586 |
2/2✓ Branch 0 taken 139 times.
✓ Branch 1 taken 800 times.
|
939 | if (!subnets.empty()) { |
| 1587 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | DiscoverViaHTTP(subnets, exacts); |
| 1588 | } | ||
| 1589 | 939 | } | |
| 1590 | 2649 | } | |
| 1591 | |||
| 1592 | // Twinkly's own discovery protocol: a short datagram to UDP 5555, to which every | ||
| 1593 | // light on the segment replies with its address and name. One broadcast | ||
| 1594 | // enumerates all of them, with none of the per-address cost of an HTTP sweep - | ||
| 1595 | // which matters here because they cannot be found any other way. They publish | ||
| 1596 | // nothing over mDNS or SSDP and their embedded server answers "/" with a 404, so | ||
| 1597 | // a light that is not already a configured channel output is otherwise invisible. | ||
| 1598 | // | ||
| 1599 | // Nothing here (or in the detector this hands off to) authenticates. That is | ||
| 1600 | // deliberate: a Twinkly keeps exactly ONE verified token, so logging in would | ||
| 1601 | // invalidate the token a running Twinkly channel output is streaming with. | ||
| 1602 | #define TWINKLY_DISCOVERY_PORT 5555 | ||
| 1603 | static const char TWINKLY_DISCOVERY_MSG[] = { 0x01, 'd', 'i', 's', 'c', 'o', 'v', 'e', 'r' }; | ||
| 1604 | // Replies are taken only this long after a discovery broadcast, and from at | ||
| 1605 | // most this many addresses per broadcast. The socket stays open for the life | ||
| 1606 | // of fppd and its port is in every broadcast, so without them any host on the | ||
| 1607 | // LAN could grow the seen set and the probe queue by one entry per source | ||
| 1608 | // address it sent from, for as long as fppd ran. The lights answer within | ||
| 1609 | // milliseconds. | ||
| 1610 | #define TWINKLY_REPLY_WINDOW_MS 5000 | ||
| 1611 | #define TWINKLY_MAX_REPLIES 128 | ||
| 1612 | static std::atomic<long long> s_twinklyRepliesUntilMS{ 0 }; | ||
| 1613 | |||
| 1614 | 2649 | bool MultiSync::OpenTwinklyDiscoverySocket() { | |
| 1615 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2649 times.
|
2649 | if (m_twinklyDiscoverySock >= 0) { |
| 1616 | ✗ | return true; | |
| 1617 | } | ||
| 1618 | 2649 | int sock = OpenSocket(AF_INET, SOCK_DGRAM, 0); | |
| 1619 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2649 times.
|
2649 | if (sock < 0) { |
| 1620 | ✗ | LogWarn(VB_SYNC, "Could not open Twinkly discovery socket: %s\n", FPPstrerror(errno)); | |
| 1621 | ✗ | return false; | |
| 1622 | } | ||
| 1623 | 2649 | int broadcast = 1; | |
| 1624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2649 times.
|
2649 | if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) < 0) { |
| 1625 | ✗ | LogWarn(VB_SYNC, "Could not set SO_BROADCAST for Twinkly discovery: %s\n", FPPstrerror(errno)); | |
| 1626 | ✗ | close(sock); | |
| 1627 | ✗ | return false; | |
| 1628 | } | ||
| 1629 | 2649 | m_twinklyDiscoverySock = sock; | |
| 1630 | 5301 | std::function<bool(int)> f = [this](int i) { | |
| 1631 | 3 | return ProcessTwinklyDiscoveryReplies(); | |
| 1632 | 2649 | }; | |
| 1633 |
1/2✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
|
2649 | EPollManager::INSTANCE.addFileDescriptor(m_twinklyDiscoverySock, f); |
| 1634 | 2649 | return true; | |
| 1635 | 2649 | } | |
| 1636 | |||
| 1637 | 2649 | void MultiSync::PerformTwinklyDiscovery() { | |
| 1638 |
2/4✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2649 times.
|
2649 | if (!OpenTwinklyDiscoverySocket()) { |
| 1639 | ✗ | return; | |
| 1640 | } | ||
| 1641 | { | ||
| 1642 |
1/2✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
|
2649 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1643 | 2649 | m_twinklyDiscoverySeen.clear(); | |
| 1644 | 2649 | } | |
| 1645 |
1/2✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
|
2649 | s_twinklyRepliesUntilMS = GetMonotonicTimeMS() + TWINKLY_REPLY_WINDOW_MS; |
| 1646 | |||
| 1647 | // Under m_socketLock, which the sync sends need every frame: never block. | ||
| 1648 |
1/2✓ Branch 0 taken 2649 times.
✗ Branch 1 not taken.
|
2649 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 1649 |
2/2✓ Branch 0 taken 2479 times.
✓ Branch 1 taken 2649 times.
|
5128 | for (auto& a : m_interfaces) { |
| 1650 | struct sockaddr_in bda; | ||
| 1651 | 2479 | memset((void*)&bda, 0, sizeof(struct sockaddr_in)); | |
| 1652 | 2479 | bda.sin_family = AF_INET; | |
| 1653 | 2479 | bda.sin_port = htons(TWINKLY_DISCOVERY_PORT); | |
| 1654 | 2479 | bda.sin_addr.s_addr = a.second.broadcastAddress; | |
| 1655 | |||
| 1656 |
1/2✓ Branch 0 taken 2479 times.
✗ Branch 1 not taken.
|
2479 | if (sendto(m_twinklyDiscoverySock, TWINKLY_DISCOVERY_MSG, sizeof(TWINKLY_DISCOVERY_MSG), MSG_DONTWAIT, |
| 1657 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2479 times.
|
2479 | (struct sockaddr*)&bda, sizeof(struct sockaddr_in)) < 0) { |
| 1658 | ✗ | LogDebug(VB_SYNC, "Could not send Twinkly discovery on %s: %s\n", | |
| 1659 | a.second.interfaceName.c_str(), FPPstrerror(errno)); | ||
| 1660 | } | ||
| 1661 | } | ||
| 1662 | 2649 | } | |
| 1663 | |||
| 1664 | // A reply is the device's own address (4 bytes, least significant first), then | ||
| 1665 | // "OK", then its name. The source address of the datagram is what gets probed | ||
| 1666 | // rather than that embedded copy: it is the address that actually answered, and | ||
| 1667 | // so the one we have to talk to. The payload is only inspected far enough to | ||
| 1668 | // be reasonably sure this is a light rather than something else listening on | ||
| 1669 | // 5555 -- the HTTP detector is what confirms it. | ||
| 1670 | // | ||
| 1671 | // Always returns false: a true return from an EPollManager callback is fppd's | ||
| 1672 | // signal that bridge data is ready to push out, which this is not. | ||
| 1673 | 3 | bool MultiSync::ProcessTwinklyDiscoveryReplies() { | |
| 1674 | char buf[256]; | ||
| 1675 | // a bounded number of replies a wakeup, like the other sockets the main | ||
| 1676 | // loop reads; the socket is level-triggered, so the rest come next pass | ||
| 1677 |
1/2✓ Branch 0 taken 347 times.
✗ Branch 1 not taken.
|
347 | for (int n = 0; n < 1024; n++) { |
| 1678 | struct sockaddr_in src; | ||
| 1679 | 347 | memset(&src, 0, sizeof(src)); | |
| 1680 | 347 | socklen_t slen = sizeof(src); | |
| 1681 |
1/2✓ Branch 0 taken 347 times.
✗ Branch 1 not taken.
|
347 | ssize_t len = recvfrom(m_twinklyDiscoverySock, buf, sizeof(buf), MSG_DONTWAIT, |
| 1682 | (struct sockaddr*)&src, &slen); | ||
| 1683 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 344 times.
|
347 | if (len <= 0) { |
| 1684 | 3 | return false; | |
| 1685 | } | ||
| 1686 |
8/12✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 344 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 344 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 344 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 324 times.
✓ Branch 10 taken 20 times.
✓ Branch 11 taken 324 times.
|
344 | if (len < 7 || buf[4] != 'O' || buf[5] != 'K' || GetMonotonicTimeMS() > s_twinklyRepliesUntilMS) { |
| 1687 | 192 | continue; | |
| 1688 | } | ||
| 1689 | 324 | char ipStr[INET_ADDRSTRLEN] = { 0 }; | |
| 1690 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 324 times.
|
324 | if (!inet_ntop(AF_INET, &src.sin_addr, ipStr, sizeof(ipStr))) { |
| 1691 | ✗ | continue; | |
| 1692 | } | ||
| 1693 |
1/2✓ Branch 0 taken 324 times.
✗ Branch 1 not taken.
|
324 | std::string address(ipStr); |
| 1694 | { | ||
| 1695 |
1/2✓ Branch 0 taken 324 times.
✗ Branch 1 not taken.
|
324 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1696 |
2/2✓ Branch 0 taken 172 times.
✓ Branch 1 taken 152 times.
|
324 | if (m_twinklyDiscoverySeen.size() >= TWINKLY_MAX_REPLIES) { |
| 1697 | 172 | continue; | |
| 1698 | } | ||
| 1699 |
2/4✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 152 times.
|
152 | if (!m_twinklyDiscoverySeen.insert(address).second) { |
| 1700 | // the lights answer each broadcast more than once | ||
| 1701 | ✗ | continue; | |
| 1702 | } | ||
| 1703 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 172 times.
|
324 | } |
| 1704 |
1/2✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
|
152 | LogInfo(VB_SYNC, "Twinkly device answered discovery at %s\n", address.c_str()); |
| 1705 | // Through the queue, under the in-flight cap. Started directly, one | ||
| 1706 | // per answering address, a burst of replies -- or of datagrams | ||
| 1707 | // claiming to be replies, from as many addresses -- started that many | ||
| 1708 | // HTTP probes at once. | ||
| 1709 | { | ||
| 1710 |
1/2✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
|
152 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1711 |
1/2✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
|
152 | QueueHTTPPing(m_httpPingQueue, address); |
| 1712 | 152 | } | |
| 1713 |
1/2✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
|
152 | PumpHTTPPings(); |
| 1714 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 172 times.
|
324 | } |
| 1715 | ✗ | return false; | |
| 1716 | } | ||
| 1717 | |||
| 1718 | 139 | void MultiSync::DiscoverIPViaHTTP(const std::string& ip, const std::string& html, bool allowUnknown) { | |
| 1719 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | LogDebug(VB_SYNC, "Checking HTTP response from %s\n", ip.c_str()); |
| 1720 | |||
| 1721 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | if (html.size()) { |
| 1722 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | std::string d = html; |
| 1723 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 138 times.
|
139 | if (d.size() > 500) { |
| 1724 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | d = d.substr(0, 500); |
| 1725 | } | ||
| 1726 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | LogExcess(VB_SYNC, "IP: %s Resp: %s\n", ip.c_str(), d.c_str()); |
| 1727 | 139 | } | |
| 1728 | |||
| 1729 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | std::string address2 = ip; |
| 1730 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | GetIPForHost(address2); |
| 1731 | |||
| 1732 |
5/10✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 139 times.
|
139 | if (!isSupportedForMultisync(ip.c_str(), "") || !isSupportedForMultisync(address2.c_str(), "")) { |
| 1733 | ✗ | if (allowUnknown) { | |
| 1734 | ✗ | UpdateSystem(kSysTypeUnknown, 0, 0, UNKNOWN_MODE, ip, ip, "Unknown", "Unknown", "0-0", "Unknown", false, false); | |
| 1735 | } | ||
| 1736 | ✗ | FinishHTTPDiscovery(); | |
| 1737 | ✗ | return; | |
| 1738 | } | ||
| 1739 | |||
| 1740 |
3/8✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
139 | NetworkController::DetectControllerViaHTML(ip, html, [this, ip, allowUnknown](NetworkController* nc) { |
| 1741 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 75 times.
|
132 | if (nc) { |
| 1742 | 57 | UpdateSystem(nc->typeId, nc->majorVersion, nc->minorVersion, | |
| 1743 | 57 | nc->systemMode, nc->ip, nc->hostname, nc->version, | |
| 1744 | 57 | nc->typeStr, nc->ranges, nc->uuid, false, nc->sendingMultiSync); | |
| 1745 | 57 | ApplyPeerUUIDs(nc->peerUUIDs); | |
| 1746 |
1/2✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
|
57 | delete nc; |
| 1747 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 50 times.
|
75 | } else if (allowUnknown) { |
| 1748 |
5/10✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 25 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 25 times.
✗ Branch 9 not taken.
|
225 | UpdateSystem(kSysTypeUnknown, 0, 0, UNKNOWN_MODE, ip, ip, "Unknown", "Unknown", "0-0", "Unknown", false, false); |
| 1749 | } | ||
| 1750 | 132 | FinishHTTPDiscovery(); | |
| 1751 | 132 | }); | |
| 1752 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | } |
| 1753 | |||
| 1754 | // How many addresses in the configured HTTP scan are probed at once. The | ||
| 1755 | // version this replaced put every address of every configured subnet on one | ||
| 1756 | // curl multi handle in a single burst and blocked until the last one answered; | ||
| 1757 | // a /24 is 254 sockets, and several subnets are common. That is now spread out, | ||
| 1758 | // because it shares the multi handle with the rest of fppd rather than owning a | ||
| 1759 | // private one -- but it can still be wide, since almost every address in a scan | ||
| 1760 | // has nothing on it and simply burns the connect timeout. | ||
| 1761 | #define HTTP_DISCOVERY_MAX_IN_FLIGHT 48 | ||
| 1762 | |||
| 1763 | // The discovery probe cannot be a plain addGet(): it has to keep the options | ||
| 1764 | // the hand-rolled multi handle set. HTTP09_ALLOWED is the load-bearing one -- | ||
| 1765 | // some of the older controllers this is trying to identify answer with a bare | ||
| 1766 | // HTTP/0.9 body, which curl rejects by default. The timeouts are far tighter | ||
| 1767 | // than CurlManager's defaults for the reason above: most addresses are dead. | ||
| 1768 | 404 | static void discoveryGet(const std::string& url, std::function<void(int rc, const std::string& resp)>&& callback) { | |
| 1769 | 404 | CURL* curl = CurlManager::INSTANCE.createCurl(url); | |
| 1770 | // a device merely on the LAN can stream an endless body; detection only | ||
| 1771 | // ever looks at the start of a page, so a cut-off one is still fine | ||
| 1772 | 404 | CurlManager::limitResponseSize(curl); | |
| 1773 | 404 | curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 1000L); | |
| 1774 | 404 | curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 5000L); | |
| 1775 | 404 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | |
| 1776 | 404 | curl_easy_setopt(curl, CURLOPT_TCP_FASTOPEN, 1L); | |
| 1777 | 404 | curl_easy_setopt(curl, CURLOPT_HTTP09_ALLOWED, 1L); | |
| 1778 |
4/8✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 404 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 404 times.
✗ Branch 7 not taken.
|
404 | CurlManager::INSTANCE.addCURL(url, curl, [callback](CURL* c) { |
| 1779 | 329 | CurlManager::CurlPrivateData* data = nullptr; | |
| 1780 | 329 | long rc = 0; | |
| 1781 |
1/2✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
|
329 | curl_easy_getinfo(c, CURLINFO_PRIVATE, &data); |
| 1782 |
1/2✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
|
329 | curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &rc); |
| 1783 | 329 | std::string resp; | |
| 1784 |
5/6✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 190 times.
✓ Branch 4 taken 139 times.
✓ Branch 5 taken 190 times.
|
329 | if (data && !data->resp.empty()) { |
| 1785 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | resp.assign(reinterpret_cast<char*>(data->resp.data()), data->resp.size()); |
| 1786 | } | ||
| 1787 |
1/2✓ Branch 0 taken 329 times.
✗ Branch 1 not taken.
|
329 | callback((int)rc, resp); |
| 1788 | 329 | }); | |
| 1789 | 404 | } | |
| 1790 | |||
| 1791 | 139 | void MultiSync::DiscoverViaHTTP(const std::set<std::string>& ipSet, const std::set<std::string>& exacts) { | |
| 1792 | { | ||
| 1793 |
1/2✓ Branch 0 taken 139 times.
✗ Branch 1 not taken.
|
139 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1794 |
2/2✓ Branch 0 taken 515 times.
✓ Branch 1 taken 139 times.
|
654 | for (auto& ip : ipSet) { |
| 1795 |
1/2✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
|
515 | LogExcess(VB_SYNC, " %s\n", ip.c_str()); |
| 1796 |
2/4✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 515 times.
✗ Branch 3 not taken.
|
515 | m_httpDiscoveryQueue.emplace_back(ip, exacts.find(ip) != exacts.end()); |
| 1797 | } | ||
| 1798 | 139 | } | |
| 1799 | 139 | PumpHTTPDiscovery(); | |
| 1800 | 139 | } | |
| 1801 | |||
| 1802 | // Starts scan probes until the cap is reached or the queue runs dry. Called | ||
| 1803 | // from DiscoverViaHTTP() and again from each completion. | ||
| 1804 | 865 | void MultiSync::PumpHTTPDiscovery() { | |
| 1805 | while (true) { | ||
| 1806 | 865 | std::string ip; | |
| 1807 | 865 | bool exact = false; | |
| 1808 | { | ||
| 1809 |
1/2✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
|
865 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1810 |
6/6✓ Branch 0 taken 504 times.
✓ Branch 1 taken 361 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 404 times.
✓ Branch 4 taken 461 times.
✓ Branch 5 taken 404 times.
|
865 | if (m_httpDiscoveryQueue.empty() || m_httpDiscoveriesInFlight >= HTTP_DISCOVERY_MAX_IN_FLIGHT) { |
| 1811 | 922 | return; | |
| 1812 | } | ||
| 1813 |
1/2✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
|
404 | std::tie(ip, exact) = m_httpDiscoveryQueue.front(); |
| 1814 | 404 | m_httpDiscoveryQueue.pop_front(); | |
| 1815 | 404 | ++m_httpDiscoveriesInFlight; | |
| 1816 |
2/2✓ Branch 0 taken 404 times.
✓ Branch 1 taken 461 times.
|
865 | } |
| 1817 | |||
| 1818 | // ip may be a hostname, so this must not be a fixed-size buffer | ||
| 1819 | // (a fixed buffer would silently truncate hostnames and they'd | ||
| 1820 | // never get discovered - see issue #2667) | ||
| 1821 |
5/12✓ Branch 0 taken 404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 404 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 404 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 404 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 404 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
1212 | discoveryGet(buildHttpURL(ip, "/"), [this, ip, exact](int rc, const std::string& resp) { |
| 1822 | // A 200 is the normal answer. rc == 0 with a body is the HTTP/0.9 | ||
| 1823 | // case -- there is no status line to report -- and is equally good; | ||
| 1824 | // rc == 0 with nothing is a transfer that never connected. This is | ||
| 1825 | // the same accept/reject the CURLcode-based version made. | ||
| 1826 | // | ||
| 1827 | // An `exact` address is one that was configured rather than swept | ||
| 1828 | // for - a channel output's destination, or an entry the user typed - | ||
| 1829 | // so anything that answered at all is worth identifying. Twinkly | ||
| 1830 | // lights need that: they have no web UI and serve a 404 at "/", and | ||
| 1831 | // only a follow-up call to their own API says what they are. The | ||
| 1832 | // broad sweep stays 200-only, so a subnet full of unrelated devices | ||
| 1833 | // that 404 does not drag the whole detector chain through each one. | ||
| 1834 |
12/12✓ Branch 0 taken 201 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 191 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 190 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 102 times.
✓ Branch 7 taken 98 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 92 times.
✓ Branch 10 taken 139 times.
✓ Branch 11 taken 190 times.
|
329 | if (rc == 200 || (rc == 0 && !resp.empty()) || (exact && !resp.empty())) { |
| 1835 | 139 | LogDebug(VB_SYNC, "IP %s completed with code %d\n", ip.c_str(), rc); | |
| 1836 | 139 | DiscoverIPViaHTTP(ip, resp, exact); | |
| 1837 | 139 | return; // DiscoverIPViaHTTP() releases the slot | |
| 1838 | } | ||
| 1839 | 190 | LogDebug(VB_SYNC, "No/Error response from %s. Response code: %d\n", ip.c_str(), rc); | |
| 1840 | 190 | FinishHTTPDiscovery(); | |
| 1841 | }); | ||
| 1842 |
2/2✓ Branch 0 taken 404 times.
✓ Branch 1 taken 461 times.
|
1269 | } |
| 1843 | } | ||
| 1844 | |||
| 1845 | 322 | void MultiSync::FinishHTTPDiscovery() { | |
| 1846 | { | ||
| 1847 |
1/2✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
|
322 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 1848 | 322 | --m_httpDiscoveriesInFlight; | |
| 1849 | 322 | } | |
| 1850 | 322 | PumpHTTPDiscovery(); | |
| 1851 | 322 | } | |
| 1852 | |||
| 1853 | 5601 | void MultiSync::WriteRuntimeInfoFile() { | |
| 1854 |
1/2✓ Branch 0 taken 5601 times.
✗ Branch 1 not taken.
|
5601 | Json::Value v = GetSystems(true, false); |
| 1855 |
2/4✓ Branch 0 taken 5601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5601 times.
✗ Branch 3 not taken.
|
5601 | std::string filename = FPP_DIR_MEDIA("/fpp-info.json"); |
| 1856 |
2/4✓ Branch 0 taken 5601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5601 times.
✗ Branch 3 not taken.
|
5601 | Json::Value systems = v["systems"]; |
| 1857 | |||
| 1858 | // If there is no network, then delete the file | ||
| 1859 | // to avoid confusion. | ||
| 1860 |
3/4✓ Branch 0 taken 5601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 647 times.
✓ Branch 3 taken 4954 times.
|
5601 | if (systems.empty()) { |
| 1861 | // remove() returns 0 on success; a file that was never written is | ||
| 1862 | // not a failure. | ||
| 1863 |
4/6✓ Branch 0 taken 646 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 646 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 647 times.
|
647 | if (remove(filename.c_str()) != 0 && errno != ENOENT) { |
| 1864 | ✗ | LogWarn(VB_ALL, "Failed to remove file %s: %s\n", filename.c_str(), FPPstrerror(errno)); | |
| 1865 | } | ||
| 1866 |
1/2✓ Branch 0 taken 647 times.
✗ Branch 1 not taken.
|
647 | LogInfo(VB_ALL, "Not creating %s as no IP addresses found\n", filename.c_str()); |
| 1867 | 647 | return; | |
| 1868 | } | ||
| 1869 | |||
| 1870 |
1/2✓ Branch 0 taken 4954 times.
✗ Branch 1 not taken.
|
4954 | std::string addresses = ""; |
| 1871 |
3/4✓ Branch 0 taken 10180 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5226 times.
✓ Branch 3 taken 4954 times.
|
10180 | for (int x = 0; x < systems.size(); x++) { |
| 1872 |
3/4✓ Branch 0 taken 5226 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 272 times.
✓ Branch 3 taken 4954 times.
|
5226 | if (addresses != "") { |
| 1873 |
1/2✓ Branch 0 taken 272 times.
✗ Branch 1 not taken.
|
272 | addresses += ","; |
| 1874 | } | ||
| 1875 |
4/8✓ Branch 0 taken 5226 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5226 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5226 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5226 times.
✗ Branch 7 not taken.
|
5226 | addresses += systems[x]["address"].asString(); |
| 1876 | } | ||
| 1877 |
2/4✓ Branch 0 taken 4954 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4954 times.
✗ Branch 3 not taken.
|
4954 | Json::Value local = systems[0]; |
| 1878 |
1/2✓ Branch 0 taken 4954 times.
✗ Branch 1 not taken.
|
4954 | local.removeMember("address"); |
| 1879 |
2/4✓ Branch 0 taken 4954 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4954 times.
✗ Branch 3 not taken.
|
4954 | local["addresses"] = addresses; |
| 1880 | |||
| 1881 |
2/4✓ Branch 0 taken 4954 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4954 times.
✗ Branch 3 not taken.
|
4954 | SaveJsonToFile(local, filename); |
| 1882 |
6/6✓ Branch 0 taken 4954 times.
✓ Branch 1 taken 647 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 647 times.
✓ Branch 4 taken 4954 times.
✓ Branch 5 taken 647 times.
|
6895 | } |
| 1883 | |||
| 1884 | /* | ||
| 1885 | * | ||
| 1886 | */ | ||
| 1887 | 5846 | void MultiSync::Ping(int discover, bool broadcast) { | |
| 1888 |
1/2✓ Branch 0 taken 5846 times.
✗ Branch 1 not taken.
|
5846 | LogDebug(VB_SYNC, "MultiSync::Ping(%d, %d)\n", discover, broadcast); |
| 1889 | 5846 | time_t t = time(NULL); | |
| 1890 | 5846 | m_lastPingTime = (unsigned long)t; | |
| 1891 | |||
| 1892 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5846 times.
|
5846 | if (m_broadcastSock < 0) { |
| 1893 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send ping packet but control socket is not open.\n"); | |
| 1894 | ✗ | return; | |
| 1895 | } | ||
| 1896 |
1/2✓ Branch 0 taken 5846 times.
✗ Branch 1 not taken.
|
5846 | setupMulticastReceive(discover ? true : false); |
| 1897 | |||
| 1898 | // update the range for local systems so it's accurate | ||
| 1899 |
1/2✓ Branch 0 taken 5846 times.
✗ Branch 1 not taken.
|
5846 | auto ranges = GetOutputRangesSnapshot(true); |
| 1900 |
2/4✓ Branch 0 taken 5846 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5846 times.
✗ Branch 3 not taken.
|
5846 | std::string range = createRanges(*ranges, 120); |
| 1901 | |||
| 1902 | // Build every packet under m_systemsLock and send once it is released. | ||
| 1903 | // Dropping the lock mid-loop instead would leave the loop iterating | ||
| 1904 | // m_localSystems while a network change (FillLocalSystemInfo) rewrites it. | ||
| 1905 | 5846 | std::vector<std::vector<char>> packets; | |
| 1906 | { | ||
| 1907 |
1/2✓ Branch 0 taken 5846 times.
✗ Branch 1 not taken.
|
5846 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1908 |
2/2✓ Branch 0 taken 5674 times.
✓ Branch 1 taken 5846 times.
|
11520 | for (auto& sys : m_localSystems) { |
| 1909 |
1/2✓ Branch 0 taken 5674 times.
✗ Branch 1 not taken.
|
5674 | std::vector<char> outBuf(768, 0); |
| 1910 |
1/2✓ Branch 0 taken 5674 times.
✗ Branch 1 not taken.
|
5674 | sys.ranges = range; |
| 1911 |
2/4✓ Branch 0 taken 5674 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5674 times.
✗ Branch 3 not taken.
|
5674 | outBuf.resize(CreatePingPacket(sys, outBuf.data(), discover)); |
| 1912 |
1/2✓ Branch 0 taken 5674 times.
✗ Branch 1 not taken.
|
5674 | packets.push_back(std::move(outBuf)); |
| 1913 | 5674 | } | |
| 1914 | 5846 | } | |
| 1915 |
2/2✓ Branch 0 taken 5674 times.
✓ Branch 1 taken 5846 times.
|
11520 | for (auto& outBuf : packets) { |
| 1916 |
2/2✓ Branch 0 taken 5265 times.
✓ Branch 1 taken 409 times.
|
5674 | if (broadcast) { |
| 1917 |
1/2✓ Branch 0 taken 5265 times.
✗ Branch 1 not taken.
|
5265 | SendBroadcastPacket(outBuf.data(), outBuf.size()); |
| 1918 | } else { | ||
| 1919 |
1/2✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
|
409 | SendMulticastPacket(outBuf.data(), outBuf.size()); |
| 1920 | } | ||
| 1921 | } | ||
| 1922 | |||
| 1923 |
2/2✓ Branch 0 taken 2650 times.
✓ Branch 1 taken 3196 times.
|
5846 | if (discover) { |
| 1924 | 2650 | std::set<std::string> remotes; | |
| 1925 |
1/2✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
|
2650 | AddRemotesFromSetting("MultiSyncExtraRemotes", remotes); |
| 1926 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2650 times.
|
2662 | for (auto& remote : remotes) { |
| 1927 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | PingSingleRemote(remote.c_str(), 1); |
| 1928 | } | ||
| 1929 | 2650 | } | |
| 1930 | 5846 | } | |
| 1931 | 32442 | void MultiSync::PeriodicPing() { | |
| 1932 | 32442 | time_t t = time(NULL); | |
| 1933 |
2/2✓ Branch 0 taken 1647 times.
✓ Branch 1 taken 30795 times.
|
32442 | if (m_lastCheckTime == 0) { |
| 1934 | 1647 | m_lastCheckTime = (unsigned long)t; | |
| 1935 | } | ||
| 1936 | 32442 | unsigned long lpt = m_lastPingTime + 60 * 60; | |
| 1937 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 32426 times.
|
32442 | if (lpt < (unsigned long)t) { |
| 1938 | // once an hour, we'll send a ping letting everyone know we're still here | ||
| 1939 | // mark ourselves as seen | ||
| 1940 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1941 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 16 times.
|
34 | for (auto& sys : m_localSystems) { |
| 1942 | 18 | sys.lastSeen = (unsigned long)t; | |
| 1943 | } | ||
| 1944 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | lock.unlock(); |
| 1945 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | Ping(); |
| 1946 | 16 | } | |
| 1947 | // every minute we'll loop through real quick and check for remote instances | ||
| 1948 | // we haven't heard from in a while | ||
| 1949 | 32442 | lpt = m_lastCheckTime + 60; | |
| 1950 | 32442 | bool superLongGap = false; | |
| 1951 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 32384 times.
|
32442 | if (lpt < (unsigned long)t) { |
| 1952 | 58 | m_lastCheckTime = (unsigned long)t; | |
| 1953 | // anything we haven't heard from in 80 minutes we will re-ping to force | ||
| 1954 | 58 | unsigned long timeoutRePing = (unsigned long)t - 60 * 80; | |
| 1955 | // anything we haven't heard from in 2 hours we will remove. That would | ||
| 1956 | // have caused at least 4 pings to have been sent. If it has responded | ||
| 1957 | // to any of those 4, it's got to be down/gone. Remove it. | ||
| 1958 | 58 | unsigned long timeoutRemove = (unsigned long)t - 60 * 120; | |
| 1959 | // if we hadn't heard from them in 10 hours, it's likely a clock change | ||
| 1960 | // event, we'll resend a ping out to all to hopefully get everything | ||
| 1961 | // updated and new timestamps | ||
| 1962 | 58 | unsigned long timeoutRePingAll = (unsigned long)t - 60 * 600; | |
| 1963 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 1964 | 58 | bool unicastChanged = false; | |
| 1965 | // Collect the addresses (by value) and queue the HTTP probes after the | ||
| 1966 | // loop rather than from inside it. The probes are asynchronous now, but | ||
| 1967 | // the reason for the two-step is unchanged: a probe that resolves fast | ||
| 1968 | // reaches UpdateSystem, which can push_back onto m_remoteSystems (the | ||
| 1969 | // recursive mutex does not protect against our own thread) and | ||
| 1970 | // reallocate the vector out from under `it`. | ||
| 1971 | 58 | std::vector<std::string> httpPingAddresses; | |
| 1972 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 58 times.
|
70 | for (auto it = m_remoteSystems.begin(); it != m_remoteSystems.end();) { |
| 1973 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
|
12 | if (it->lastSeen < timeoutRemove) { |
| 1974 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogInfo(VB_SYNC, "Have not seen %s in over 2 hours, removing\n", it->address.c_str()); |
| 1975 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (it->lastSeen < timeoutRePingAll) { |
| 1976 | 1 | superLongGap = true; | |
| 1977 | } | ||
| 1978 | 2 | unicastChanged |= it->supportsUnicast; | |
| 1979 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | it = m_remoteSystems.erase(it); |
| 1980 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
|
10 | } else if (it->lastSeen < timeoutRePing) { |
| 1981 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (it->multiSync) { |
| 1982 | ✗ | PingSingleRemote(*it, 1); | |
| 1983 | } else { | ||
| 1984 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | httpPingAddresses.push_back(it->address); |
| 1985 | } | ||
| 1986 | 7 | ++it; | |
| 1987 | } else { | ||
| 1988 | 3 | ++it; | |
| 1989 | } | ||
| 1990 | } | ||
| 1991 | // Drop any removed remotes from the cached unicast destination list. | ||
| 1992 | // Snapshot the surviving targets under m_systemsLock, rebuild after | ||
| 1993 | // releasing it -- m_unicastUpdateLock is never acquired while | ||
| 1994 | // m_systemsLock is held. | ||
| 1995 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
58 | bool rebuildUnicast = m_sendUnicast && unicastChanged; |
| 1996 | 58 | std::vector<std::string> unicastAddrs; | |
| 1997 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (rebuildUnicast) { |
| 1998 | ✗ | for (auto& sys : m_remoteSystems) { | |
| 1999 | ✗ | if (sys.supportsUnicast) { | |
| 2000 | ✗ | unicastAddrs.push_back(sys.address); | |
| 2001 | } | ||
| 2002 | } | ||
| 2003 | } | ||
| 2004 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | lock.unlock(); |
| 2005 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (rebuildUnicast) { |
| 2006 | ✗ | UpdateUnicastDestinations(unicastAddrs); | |
| 2007 | } | ||
| 2008 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 56 times.
|
58 | if (!httpPingAddresses.empty()) { |
| 2009 | // HTTP probes of remotes we haven't heard from in a while. These | ||
| 2010 | // used to be blocking curl calls run on a detached thread, because | ||
| 2011 | // doing them inline on the fppd main loop -- the same thread that | ||
| 2012 | // drains the MultiSync control socket -- stalled sync-packet | ||
| 2013 | // processing for the length of the timeouts, which on a remote | ||
| 2014 | // showed up as the output freezing for a second or two and then | ||
| 2015 | // jumping to catch up. They now go through CurlManager, so there is | ||
| 2016 | // nothing to stall and no thread to keep off the loop. | ||
| 2017 | { | ||
| 2018 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::unique_lock<std::mutex> plock(m_httpProbeLock); |
| 2019 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | for (auto& address : httpPingAddresses) { |
| 2020 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | QueueHTTPPing(m_httpPingQueue, address); |
| 2021 | } | ||
| 2022 | 2 | } | |
| 2023 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | PumpHTTPPings(); |
| 2024 | } | ||
| 2025 | 58 | } | |
| 2026 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32441 times.
|
32442 | if (superLongGap) { |
| 2027 | 1 | Ping(1); | |
| 2028 | } | ||
| 2029 | |||
| 2030 | 32442 | CheckSystemInfoRefreshes(); | |
| 2031 | 32442 | } | |
| 2032 | |||
| 2033 | // How often a remote's HTTP-fetched detail is refreshed, how soon a failed | ||
| 2034 | // attempt is retried, and how many fetches may be outstanding at once. The | ||
| 2035 | // cap matters on a large show network: without it the first sweep after | ||
| 2036 | // discovery would open a connection to every remote at the same moment, from a | ||
| 2037 | // player that may be a single-core BeagleBone. The rest are simply picked up | ||
| 2038 | // by a later sweep. | ||
| 2039 | #define INFO_REFRESH_INTERVAL (30 * 60) | ||
| 2040 | #define INFO_RETRY_INTERVAL (5 * 60) | ||
| 2041 | #define INFO_SCAN_INTERVAL 5 | ||
| 2042 | #define INFO_MAX_IN_FLIGHT 4 | ||
| 2043 | |||
| 2044 | // Every fetch is delayed by a random slice of a window that grows with the size | ||
| 2045 | // of the known fleet. INFO_MAX_IN_FLIGHT bounds what one player sends, but the | ||
| 2046 | // dangerous direction is the other one: every peer sees the same discover ping, | ||
| 2047 | // so on a 100-instance show a single fppd restart would otherwise land ~200 HTTP | ||
| 2048 | // requests on the box that just came up -- the box least able to serve them, and | ||
| 2049 | // on a BeagleBone that is a real stall. A whole-show power-on is the same | ||
| 2050 | // pattern squared, with every box both hammering and being hammered. Budgeting | ||
| 2051 | // roughly one second of window per known system holds the aggregate arrival rate | ||
| 2052 | // at the target near two requests a second no matter how large the show is. | ||
| 2053 | #define INFO_JITTER_BASE 5 | ||
| 2054 | #define INFO_JITTER_MAX 300 | ||
| 2055 | |||
| 2056 | // The multisync page needs a fair amount of slow-changing detail about every | ||
| 2057 | // remote -- OS version, host description, background color, git branch/commit, | ||
| 2058 | // whether channel inputs/outputs are enabled, what cape is installed. It used | ||
| 2059 | // to fetch all of it from the browser, at least one HTTP request per remote per | ||
| 2060 | // page load, which is why the table visibly reflowed as the answers trickled | ||
| 2061 | // in. fppd already knows every remote and can collect it once per remote per | ||
| 2062 | // INFO_REFRESH_INTERVAL over the async CurlManager, so the UI gets it in the | ||
| 2063 | // very first GetSystems() response. | ||
| 2064 | // | ||
| 2065 | // Runs on the fppd main loop (from PeriodicPing). It must stay non-blocking: | ||
| 2066 | // the same loop feeds the sync output, which is why every fetch goes through | ||
| 2067 | // CurlManager. | ||
| 2068 | 32442 | void MultiSync::CheckSystemInfoRefreshes() { | |
| 2069 | 32442 | time_t now = time(nullptr); | |
| 2070 |
2/2✓ Branch 0 taken 29042 times.
✓ Branch 1 taken 3400 times.
|
32442 | if (now < m_nextInfoScan) { |
| 2071 | 29042 | return; | |
| 2072 | } | ||
| 2073 | 3400 | m_nextInfoScan = now + INFO_SCAN_INTERVAL; | |
| 2074 | |||
| 2075 | 3400 | std::vector<std::string> toFetch; | |
| 2076 | { | ||
| 2077 |
1/2✓ Branch 0 taken 3400 times.
✗ Branch 1 not taken.
|
3400 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 2078 | // We routinely discover ourselves as a "remote" -- over loopback, and | ||
| 2079 | // over any address that isn't one of the interface addresses in | ||
| 2080 | // m_localSystems (a global IPv6 address, typically). Those entries | ||
| 2081 | // merge into the local row in the UI, which already has everything | ||
| 2082 | // about the box serving the page, so probing them is pure waste. | ||
| 2083 | 3400 | std::set<std::string> localUUIDs; | |
| 2084 |
2/2✓ Branch 0 taken 3142 times.
✓ Branch 1 taken 3400 times.
|
6542 | for (auto& sys : m_localSystems) { |
| 2085 |
4/8✓ Branch 0 taken 3142 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3142 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3142 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3142 times.
|
3142 | if (!sys.uuid.empty() && sys.uuid != "Unknown") { |
| 2086 | ✗ | localUUIDs.insert(sys.uuid); | |
| 2087 | } | ||
| 2088 | } | ||
| 2089 |
2/2✓ Branch 0 taken 1539 times.
✓ Branch 1 taken 3400 times.
|
4939 | for (size_t idx = 0; idx < m_remoteSystems.size(); ++idx) { |
| 2090 | 1539 | MultiSyncSystem& sys = m_remoteSystems[idx]; | |
| 2091 | // Only full FPP instances: these are FPP's own API endpoints, and | ||
| 2092 | // anything at or above kSysTypeFalconController is a third-party | ||
| 2093 | // controller that would just 404 (or worse, be confused by) them. | ||
| 2094 |
4/4✓ Branch 0 taken 1040 times.
✓ Branch 1 taken 499 times.
✓ Branch 2 taken 107 times.
✓ Branch 3 taken 933 times.
|
1539 | if (sys.type == kSysTypeUnknown || sys.type >= kSysTypeFalconController) { |
| 2095 | 1536 | continue; | |
| 2096 | } | ||
| 2097 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 933 times.
|
933 | if (sys.infoFetchPending) { |
| 2098 | ✗ | continue; | |
| 2099 | } | ||
| 2100 |
2/4✓ Branch 0 taken 933 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 933 times.
|
933 | if (localUUIDs.find(sys.uuid) != localUUIDs.end()) { |
| 2101 | ✗ | continue; | |
| 2102 | } | ||
| 2103 | // Link-local addresses are reachable from here but not from a | ||
| 2104 | // browser (the IPv6 zone id is specific to this host), which is why | ||
| 2105 | // the multisync page drops those rows. Loopback never reaches this | ||
| 2106 | // list at all -- UpdateSystem() rejects it. | ||
| 2107 |
15/30✓ Branch 0 taken 933 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 933 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 932 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 932 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 932 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 932 times.
✓ Branch 12 taken 932 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 932 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 933 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 933 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 932 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
4663 | if (startsWith(sys.address, "169.254.") || startsWith(sys.address, "fe80:")) { |
| 2108 | 1 | continue; | |
| 2109 | } | ||
| 2110 | // A device with more than one NIC has one entry per address. Act | ||
| 2111 | // on it once and stamp every sibling entry the same way, otherwise | ||
| 2112 | // the next sweep would pick the siblings up separately; | ||
| 2113 | // ForEachRemoteMatching() fans the single answer back out to all of | ||
| 2114 | // them. | ||
| 2115 |
1/2✓ Branch 0 taken 932 times.
✗ Branch 1 not taken.
|
932 | std::string uuid = sys.uuid; |
| 2116 |
2/4✓ Branch 0 taken 932 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 932 times.
|
932 | if (uuid == "Unknown") { |
| 2117 | ✗ | uuid.clear(); | |
| 2118 | } | ||
| 2119 |
1/2✓ Branch 0 taken 932 times.
✗ Branch 1 not taken.
|
932 | std::string address = sys.address; |
| 2120 | 929 | auto stampSiblings = [&](const std::function<void(MultiSyncSystem&)>& apply) { | |
| 2121 |
2/2✓ Branch 0 taken 601130 times.
✓ Branch 1 taken 929 times.
|
602059 | for (auto& other : m_remoteSystems) { |
| 2122 |
8/8✓ Branch 0 taken 600201 times.
✓ Branch 1 taken 929 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 600190 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 930 times.
✓ Branch 7 taken 600200 times.
|
601130 | if (other.address == address || (!uuid.empty() && other.uuid == uuid)) { |
| 2123 |
1/2✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
|
930 | apply(other); |
| 2124 | } | ||
| 2125 | } | ||
| 2126 | 929 | }; | |
| 2127 | |||
| 2128 | // infoNextFetch == 0 means due but unscheduled: a remote we have | ||
| 2129 | // just discovered, or one InvalidateSystemInfo() marked stale after | ||
| 2130 | // its discover ping. A changed version string means the remote was | ||
| 2131 | // upgraded under us, which rewrites most of what we cached -- and on | ||
| 2132 | // a fleet upgrade that fires everywhere at once, so it earns the | ||
| 2133 | // same treatment. Either way, pick a jittered time and come back | ||
| 2134 | // for it on a later sweep instead of fetching right now. | ||
| 2135 |
5/6✓ Branch 0 taken 6 times.
✓ Branch 1 taken 926 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 926 times.
✓ Branch 5 taken 6 times.
|
932 | if (sys.infoNextFetch == 0 || sys.infoFetchedVersion != sys.version) { |
| 2136 | // Entry count, not device count: a multi-NIC box contributes | ||
| 2137 | // several, as do non-FPP controllers. That only ever widens | ||
| 2138 | // the window, which is the safe direction. | ||
| 2139 | 926 | int window = INFO_JITTER_BASE + (int)m_remoteSystems.size(); | |
| 2140 |
2/2✓ Branch 0 taken 768 times.
✓ Branch 1 taken 158 times.
|
926 | if (window > INFO_JITTER_MAX) { |
| 2141 | 768 | window = INFO_JITTER_MAX; | |
| 2142 | } | ||
| 2143 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926 | time_t when = now + (FPPrand() % window); |
| 2144 |
1/2✓ Branch 0 taken 926 times.
✗ Branch 1 not taken.
|
926 | stampSiblings([&](MultiSyncSystem& other) { |
| 2145 | 927 | other.infoNextFetch = when; | |
| 2146 | 927 | other.infoFetchedVersion = other.version; | |
| 2147 | 927 | }); | |
| 2148 | 926 | continue; | |
| 2149 | 926 | } | |
| 2150 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (now < sys.infoNextFetch) { |
| 2151 | 3 | continue; | |
| 2152 | } | ||
| 2153 | // Cap only what is actually sent. Scheduling above is free and has | ||
| 2154 | // to keep running even while the cap is reached, or a large fleet | ||
| 2155 | // would never get its jittered times assigned. Anything held back | ||
| 2156 | // here is simply picked up by the next sweep. | ||
| 2157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if ((int)toFetch.size() + m_infoFetchesInFlight >= INFO_MAX_IN_FLIGHT) { |
| 2158 | ✗ | continue; | |
| 2159 | } | ||
| 2160 | |||
| 2161 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | stampSiblings([&](MultiSyncSystem& other) { |
| 2162 | 3 | other.infoFetchPending = true; | |
| 2163 | 3 | other.infoFetchedVersion = other.version; | |
| 2164 | 3 | }); | |
| 2165 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | toFetch.push_back(address); |
| 2166 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 929 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 929 times.
|
1861 | } |
| 2167 | 3400 | } | |
| 2168 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3400 times.
|
3403 | for (auto& address : toFetch) { |
| 2169 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | FetchSystemInfo(address); |
| 2170 | } | ||
| 2171 | 3400 | } | |
| 2172 | |||
| 2173 | 69 | void MultiSync::InvalidateSystemInfo(const std::string& address) { | |
| 2174 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | ForEachRemoteMatching(address, [](MultiSyncSystem& sys) { |
| 2175 | // Due, but unscheduled: the next sweep gives it a jittered time. Never | ||
| 2176 | // fetch straight from here -- this runs for every peer that heard the | ||
| 2177 | // same discover ping, which is exactly the pile-on being avoided. | ||
| 2178 | 66 | sys.infoNextFetch = 0; | |
| 2179 | 66 | }); | |
| 2180 | 69 | } | |
| 2181 | |||
| 2182 | // One device, one identity. | ||
| 2183 | // | ||
| 2184 | // A box with several addresses gets an entry per address, and a real UUID only | ||
| 2185 | // ever reaches the entry that was actually probed for it -- UpdateSystem() | ||
| 2186 | // matches on the address. The others keep whatever they were given, which | ||
| 2187 | // since MAC-derived identities exist means a stand-in rather than nothing. Two | ||
| 2188 | // different identities for one device is worse than none: the UI keys a row on | ||
| 2189 | // the UUID and draws the device twice, and the statistics count it twice, which | ||
| 2190 | // defeats the deduplication the identity exists to provide. | ||
| 2191 | // | ||
| 2192 | // So once any entry knows a real UUID, every other entry for that device adopts | ||
| 2193 | // it. Guarded the way the UI guards its own hostname fallback: a hostname | ||
| 2194 | // claimed by more than one real UUID is not identifying a device at all -- two | ||
| 2195 | // controllers left on the default name -- so in that case nothing is touched. | ||
| 2196 | // | ||
| 2197 | // This is only about filling in for entries that have no identity of their own. | ||
| 2198 | // A real UUID is never overwritten by another. | ||
| 2199 | // Records identities one device reported for OTHER addresses. Some vendors | ||
| 2200 | // describe their neighbours but not themselves, so this is the only place those | ||
| 2201 | // devices' identities ever come from. | ||
| 2202 | // | ||
| 2203 | // The hints are kept, not applied once and dropped. Discovery reaches | ||
| 2204 | // addresses in whatever order it reaches them, so the neighbour describing a | ||
| 2205 | // device is very often probed BEFORE that device is found -- applying only to | ||
| 2206 | // what exists right now would silently lose exactly the identities that arrive | ||
| 2207 | // early. UpdateSystem() consults the map for every system it touches, so the | ||
| 2208 | // two orders behave the same. | ||
| 2209 | // | ||
| 2210 | // A hint never creates a system: a name in somebody's peer list is not evidence | ||
| 2211 | // that a device is on this network, and a system discovery has not found has no | ||
| 2212 | // business appearing in the list. | ||
| 2213 | 61 | void MultiSync::ApplyPeerUUIDs(const std::map<std::string, std::string>& peerUUIDs) { | |
| 2214 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 1 times.
|
61 | if (peerUUIDs.empty()) { |
| 2215 | 60 | return; | |
| 2216 | } | ||
| 2217 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 2218 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (const auto& [addr, uuid] : peerUUIDs) { |
| 2219 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | if (!addr.empty() && !uuid.empty()) { |
| 2220 | // One device's reply decides how many entries it lists, so a | ||
| 2221 | // device (or anything answering as one) could grow this for good. | ||
| 2222 | // Far more than any network's worth of devices. | ||
| 2223 |
2/8✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
|
3 | if (m_peerUUIDHints.size() >= 4096 && !m_peerUUIDHints.contains(addr)) { |
| 2224 | ✗ | continue; | |
| 2225 | } | ||
| 2226 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_peerUUIDHints[addr] = uuid; |
| 2227 | } | ||
| 2228 | } | ||
| 2229 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (auto& sys : m_remoteSystems) { |
| 2230 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | ApplyUUIDHint(sys); |
| 2231 | } | ||
| 2232 | 1 | } | |
| 2233 | |||
| 2234 | // Precedence matches MultiSyncSystem::update(): a device's own UUID always | ||
| 2235 | // wins, and a MAC-derived stand-in may only replace another stand-in. | ||
| 2236 | // | ||
| 2237 | // That a hint OVERRIDES an ARP-derived stand-in is deliberate, and it matters: | ||
| 2238 | // the two are not the same value. An ESP32 running on Ethernet uses base+3 as | ||
| 2239 | // its interface address, so ARP sees a MAC three higher than the one the device | ||
| 2240 | // reports for itself (measured on WLED and on two Baldricks; Genius, which | ||
| 2241 | // reports its interface address rather than the base, matches ARP exactly). | ||
| 2242 | // Both are stable identities for the device -- but they are DIFFERENT stable | ||
| 2243 | // identities, and letting a device carry whichever one its observer happened to | ||
| 2244 | // obtain would split it in two, which is the failure this whole path exists to | ||
| 2245 | // remove. So the vendor-reported value wins everywhere it is available, and | ||
| 2246 | // ARP stays the fallback for devices no detector could identify at all. | ||
| 2247 | 4981 | void MultiSync::ApplyUUIDHint(MultiSyncSystem& sys) { | |
| 2248 |
12/18✓ Branch 0 taken 543 times.
✓ Branch 1 taken 4438 times.
✓ Branch 2 taken 543 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 543 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 315 times.
✓ Branch 7 taken 228 times.
✓ Branch 8 taken 543 times.
✓ Branch 9 taken 4438 times.
✓ Branch 10 taken 543 times.
✓ Branch 11 taken 4438 times.
✓ Branch 12 taken 315 times.
✓ Branch 13 taken 4666 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
6067 | if (!sys.uuid.empty() && !startsWith(sys.uuid, MAC_UUID_PREFIX)) { |
| 2249 | 315 | return; | |
| 2250 | } | ||
| 2251 |
1/2✓ Branch 0 taken 4666 times.
✗ Branch 1 not taken.
|
4666 | auto it = m_peerUUIDHints.find(sys.address); |
| 2252 |
5/6✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4665 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 4665 times.
|
4666 | if (it != m_peerUUIDHints.end() && !it->second.empty()) { |
| 2253 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | sys.uuid = it->second; |
| 2254 | } | ||
| 2255 | } | ||
| 2256 | |||
| 2257 | 10808 | void MultiSync::ReconcileDeviceIdentity(const std::string& hostname, FPPMode fppMode) { | |
| 2258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10808 times.
|
10808 | if (hostname.empty()) { |
| 2259 | 10494 | return; | |
| 2260 | } | ||
| 2261 | // A player sending MultiSync pings as MASTER_MODE; update() stores PLAYER_MODE | ||
| 2262 |
2/2✓ Branch 0 taken 177 times.
✓ Branch 1 taken 10631 times.
|
10808 | if (fppMode == MASTER_MODE) { |
| 2263 | 177 | fppMode = PLAYER_MODE; | |
| 2264 | } | ||
| 2265 | 5310 | auto isStandIn = [](const std::string& u) { | |
| 2266 |
10/16✓ Branch 0 taken 859 times.
✓ Branch 1 taken 4451 times.
✓ Branch 2 taken 859 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 859 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 227 times.
✓ Branch 7 taken 632 times.
✓ Branch 8 taken 859 times.
✓ Branch 9 taken 4451 times.
✓ Branch 10 taken 859 times.
✓ Branch 11 taken 4451 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
7028 | return u.empty() || startsWith(u, MAC_UUID_PREFIX); |
| 2267 | }; | ||
| 2268 | |||
| 2269 | 10808 | std::string real; | |
| 2270 |
2/2✓ Branch 0 taken 2718108 times.
✓ Branch 1 taken 10806 times.
|
2728914 | for (auto& sys : m_remoteSystems) { |
| 2271 |
8/10✓ Branch 0 taken 4994 times.
✓ Branch 1 taken 2713114 times.
✓ Branch 2 taken 4994 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4994 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4676 times.
✓ Branch 7 taken 318 times.
✓ Branch 8 taken 2717790 times.
✓ Branch 9 taken 318 times.
|
2718108 | if (sys.hostname != hostname || sys.fppMode != fppMode || isStandIn(sys.uuid)) { |
| 2272 | 2717790 | continue; | |
| 2273 | } | ||
| 2274 |
2/2✓ Branch 0 taken 316 times.
✓ Branch 1 taken 2 times.
|
318 | if (real.empty()) { |
| 2275 |
1/2✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
|
316 | real = sys.uuid; |
| 2276 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (real != sys.uuid) { |
| 2277 | 2 | return; // hostname shared by more than one device | |
| 2278 | } | ||
| 2279 | } | ||
| 2280 |
2/2✓ Branch 0 taken 10492 times.
✓ Branch 1 taken 314 times.
|
10806 | if (real.empty()) { |
| 2281 | 10492 | return; | |
| 2282 | } | ||
| 2283 |
2/2✓ Branch 0 taken 1202 times.
✓ Branch 1 taken 314 times.
|
1516 | for (auto& sys : m_remoteSystems) { |
| 2284 |
8/10✓ Branch 0 taken 316 times.
✓ Branch 1 taken 886 times.
✓ Branch 2 taken 316 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 316 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 314 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1200 times.
|
1202 | if (sys.hostname == hostname && sys.fppMode == fppMode && isStandIn(sys.uuid)) { |
| 2285 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | sys.uuid = real; |
| 2286 | } | ||
| 2287 | } | ||
| 2288 |
2/2✓ Branch 0 taken 314 times.
✓ Branch 1 taken 10494 times.
|
10808 | } |
| 2289 | |||
| 2290 | 73 | void MultiSync::ForEachRemoteMatching(const std::string& address, | |
| 2291 | const std::function<void(MultiSyncSystem&)>& apply) { | ||
| 2292 |
1/2✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
|
73 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 2293 | 73 | std::string uuid; | |
| 2294 |
2/2✓ Branch 0 taken 79 times.
✓ Branch 1 taken 3 times.
|
82 | for (auto& sys : m_remoteSystems) { |
| 2295 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 9 times.
|
79 | if (sys.address == address) { |
| 2296 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | uuid = sys.uuid; |
| 2297 | 70 | break; | |
| 2298 | } | ||
| 2299 | } | ||
| 2300 |
2/4✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73 times.
|
73 | if (uuid == "Unknown") { |
| 2301 | ✗ | uuid.clear(); | |
| 2302 | } | ||
| 2303 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 73 times.
|
172 | for (auto& sys : m_remoteSystems) { |
| 2304 |
7/8✓ Branch 0 taken 29 times.
✓ Branch 1 taken 70 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 70 times.
✓ Branch 7 taken 29 times.
|
99 | if (sys.address == address || (!uuid.empty() && sys.uuid == uuid)) { |
| 2305 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | apply(sys); |
| 2306 | } | ||
| 2307 | } | ||
| 2308 | 73 | } | |
| 2309 | |||
| 2310 | 3 | void MultiSync::FetchSystemInfo(const std::string& address) { | |
| 2311 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string url = buildHttpURL(address, "/api/system/info"); |
| 2312 | 3 | ++m_infoFetchesInFlight; | |
| 2313 | // `address` is captured by value on purpose: m_remoteSystems is a vector of | ||
| 2314 | // values that UpdateSystem() push_back()s into, so any pointer or reference | ||
| 2315 | // to an entry can be dangling by the time this callback runs. Everything | ||
| 2316 | // below re-finds the entries by address instead. | ||
| 2317 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
9 | CurlManager::INSTANCE.addGet(url, [this, address](int rc, const std::string& resp) { |
| 2318 | 3 | --m_infoFetchesInFlight; | |
| 2319 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Json::Value v; |
| 2320 |
6/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
|
3 | if (rc != 200 || !LoadJsonFromString(resp, v, JsonRoot::Object)) { |
| 2321 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SYNC, "Could not fetch system info from %s (rc: %d)\n", address.c_str(), rc); |
| 2322 | 2 | time_t retryAt = time(nullptr) + INFO_RETRY_INTERVAL; | |
| 2323 |
1/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | ForEachRemoteMatching(address, [retryAt](MultiSyncSystem& sys) { |
| 2324 | 2 | sys.infoFetchPending = false; | |
| 2325 | // A zero here means InvalidateSystemInfo() ran while this fetch | ||
| 2326 | // was in flight -- the remote restarted mid-request, so what we | ||
| 2327 | // just read may already be wrong. Leave it zero and let the | ||
| 2328 | // sweep schedule a fresh attempt. | ||
| 2329 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (sys.infoNextFetch != 0) { |
| 2330 | 2 | sys.infoNextFetch = retryAt; | |
| 2331 | } | ||
| 2332 | 2 | }); | |
| 2333 | 2 | return; | |
| 2334 | } | ||
| 2335 | |||
| 2336 | 1 | MultiSyncSystemInfo info; | |
| 2337 | 1 | info.valid = true; | |
| 2338 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.platform = ReplyString(v, "Platform"); |
| 2339 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.variant = ReplyString(v, "Variant"); |
| 2340 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.subPlatform = ReplyString(v, "SubPlatform"); |
| 2341 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.osVersion = ReplyString(v, "OSVersion"); |
| 2342 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.osRelease = ReplyString(v, "OSRelease"); |
| 2343 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.kernel = ReplyString(v, "Kernel"); |
| 2344 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.hostDescription = ReplyString(v, "HostDescription"); |
| 2345 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.backgroundColor = ReplyString(v, "backgroundColor"); |
| 2346 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.branch = ReplyString(v, "Branch"); |
| 2347 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.localGitVersion = ReplyString(v, "LocalGitVersion"); |
| 2348 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.remoteGitVersion = ReplyString(v, "RemoteGitVersion"); |
| 2349 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | info.upgradeSource = ReplyString(v, "UpgradeSource"); |
| 2350 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | if (JsonHas(v, "channelInputsEnabled")) { |
| 2351 | ✗ | info.channelInputsEnabled = ReplyBool(v, "channelInputsEnabled", false) ? 1 : 0; | |
| 2352 | } | ||
| 2353 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | if (JsonHas(v, "channelOutputsEnabled")) { |
| 2354 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | info.channelOutputsEnabled = ReplyBool(v, "channelOutputsEnabled", false) ? 1 : 0; |
| 2355 | } | ||
| 2356 |
9/22✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
3 | if (JsonHas(v, "IPs") && v["IPs"].isArray()) { |
| 2357 |
8/14✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 1 times.
|
3 | for (const auto& ip : v["IPs"]) { |
| 2358 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if (ip.isString()) { |
| 2359 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | info.ips.push_back(ip.asString()); |
| 2360 | } | ||
| 2361 | } | ||
| 2362 | } | ||
| 2363 | |||
| 2364 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ForEachRemoteMatching(address, [&info](MultiSyncSystem& sys) { |
| 2365 | 1 | sys.systemInfo = info; | |
| 2366 | 1 | }); | |
| 2367 | |||
| 2368 | // Chain the cape fetch rather than issuing both at once: it reuses the | ||
| 2369 | // connection just established and halves the peak request count. | ||
| 2370 | // infoFetchPending stays set until it finishes so the sweep above does | ||
| 2371 | // not re-queue this remote in between. | ||
| 2372 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | FetchCapeInfo(address); |
| 2373 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | }); |
| 2374 | 3 | } | |
| 2375 | |||
| 2376 | 1 | void MultiSync::FetchCapeInfo(const std::string& address) { | |
| 2377 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | std::string url = buildHttpURL(address, "/api/cape"); |
| 2378 | 1 | ++m_infoFetchesInFlight; | |
| 2379 |
5/10✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
3 | CurlManager::INSTANCE.addGet(url, [this, address](int rc, const std::string& resp) { |
| 2380 | 1 | --m_infoFetchesInFlight; | |
| 2381 | 1 | MultiSyncCapeInfo cape; | |
| 2382 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | Json::Value v; |
| 2383 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | if (rc == 200 && LoadJsonFromString(resp, v, JsonRoot::Object)) { |
| 2384 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | cape = MultiSyncCapeInfo::fromCapeJSON(v); |
| 2385 | ✗ | } else if (rc == 404) { | |
| 2386 | // GetCapeInfo() answers 404 with {"id": "No Cape!"} when nothing is | ||
| 2387 | // installed. Cache that: it is an answer, not a failure. (An FPP | ||
| 2388 | // old enough to predate the route would 404 the same way and be | ||
| 2389 | // recorded as having no cape, which is what the UI shows for it | ||
| 2390 | // anyway.) | ||
| 2391 | ✗ | cape.valid = true; | |
| 2392 | ✗ | cape.present = false; | |
| 2393 | } else { | ||
| 2394 | // Anything else (connection failure, or an FPP old enough not to | ||
| 2395 | // have /api/cape at all) leaves capeInfo unset and untrusted. | ||
| 2396 | ✗ | LogDebug(VB_SYNC, "Could not fetch cape info from %s (rc: %d)\n", address.c_str(), rc); | |
| 2397 | } | ||
| 2398 | |||
| 2399 | // End of the chain, so this is where the next refresh is scheduled -- | ||
| 2400 | // the system info the caller already stored is good either way, so a | ||
| 2401 | // cape that could not be read doesn't earn the shorter retry interval. | ||
| 2402 | 1 | time_t nextAt = time(nullptr) + INFO_REFRESH_INTERVAL; | |
| 2403 |
1/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | ForEachRemoteMatching(address, [&cape, nextAt](MultiSyncSystem& sys) { |
| 2404 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (cape.valid) { |
| 2405 | 1 | sys.capeInfo = cape; | |
| 2406 | } | ||
| 2407 | 1 | sys.infoFetchPending = false; | |
| 2408 | // Zero means the remote sent a discover ping while this fetch was | ||
| 2409 | // in flight, i.e. it restarted mid-request and what we just stored | ||
| 2410 | // may already be stale. Don't paper over that with a 30 minute | ||
| 2411 | // interval; leave it due so the sweep reschedules. | ||
| 2412 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (sys.infoNextFetch != 0) { |
| 2413 | 1 | sys.infoNextFetch = nextAt; | |
| 2414 | } | ||
| 2415 | 1 | }); | |
| 2416 | 1 | }); | |
| 2417 | 1 | } | |
| 2418 | |||
| 2419 | // How many HTTP probes of unresponsive remotes may be outstanding at once. | ||
| 2420 | // Small on purpose: these run against boxes that are quite possibly down, so | ||
| 2421 | // most of them sit there burning the connect timeout, and the player doing the | ||
| 2422 | // probing may be a single-core BeagleBone. | ||
| 2423 | #define HTTP_PING_MAX_IN_FLIGHT 4 | ||
| 2424 | |||
| 2425 | // Starts queued probes until the cap is reached or the queue runs dry. Called | ||
| 2426 | // from PeriodicPing() on the main loop and again from each completion, which may | ||
| 2427 | // be on another thread -- see m_httpProbeLock. | ||
| 2428 | 496 | void MultiSync::PumpHTTPPings() { | |
| 2429 | while (true) { | ||
| 2430 | 496 | std::string address; | |
| 2431 | { | ||
| 2432 |
1/2✓ Branch 0 taken 496 times.
✗ Branch 1 not taken.
|
496 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 2433 |
6/6✓ Branch 0 taken 447 times.
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 288 times.
✓ Branch 3 taken 159 times.
✓ Branch 4 taken 337 times.
✓ Branch 5 taken 159 times.
|
496 | if (m_httpPingQueue.empty() || m_httpPingsInFlight >= HTTP_PING_MAX_IN_FLIGHT) { |
| 2434 | 674 | return; | |
| 2435 | } | ||
| 2436 |
1/2✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
|
159 | address = m_httpPingQueue.front(); |
| 2437 | 159 | m_httpPingQueue.pop_front(); | |
| 2438 | // Claimed here, under the same lock as the cap test, so a second | ||
| 2439 | // pumper cannot read a stale count and overshoot. | ||
| 2440 | 159 | ++m_httpPingsInFlight; | |
| 2441 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 337 times.
|
496 | } |
| 2442 |
1/2✓ Branch 0 taken 159 times.
✗ Branch 1 not taken.
|
159 | StartHTTPPing(address); |
| 2443 |
2/2✓ Branch 0 taken 159 times.
✓ Branch 1 taken 337 times.
|
655 | } |
| 2444 | } | ||
| 2445 | |||
| 2446 | // Probe one address now, outside the queue. MDNSManager calls this the moment | ||
| 2447 | // it resolves a host, and that probe must not be deferred behind a sweep -- but | ||
| 2448 | // it still has to be counted, or the cap above is measured against a number that | ||
| 2449 | // does not describe reality. (It is the entry point every caller outside this | ||
| 2450 | // file uses, which is why the accounting lives here rather than in the pump.) | ||
| 2451 | 26 | void MultiSync::PingSingleRemoteViaHTTP(const std::string& address) { | |
| 2452 | { | ||
| 2453 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 2454 | 26 | ++m_httpPingsInFlight; | |
| 2455 | 26 | } | |
| 2456 | 26 | StartHTTPPing(address); | |
| 2457 | 26 | } | |
| 2458 | |||
| 2459 | // Asks whatever is at `address` for its front page and hands the answer to the | ||
| 2460 | // controller detectors. Both halves are asynchronous, so this returns as soon | ||
| 2461 | // as the request is queued. The caller must already have claimed an in-flight | ||
| 2462 | // slot; whichever path below finishes the probe releases it. | ||
| 2463 | 185 | void MultiSync::StartHTTPPing(const std::string& address) { | |
| 2464 |
7/14✓ Branch 0 taken 185 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 185 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 185 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 185 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 185 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 185 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 185 times.
✗ Branch 13 not taken.
|
925 | CurlManager::INSTANCE.addGet(buildHttpURL(address), [this, address](int rc, const std::string& resp) { |
| 2465 | // The address may be queued for a re-ping again from here on: the | ||
| 2466 | // answer (or the failure) is in. | ||
| 2467 | { | ||
| 2468 |
1/2✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
|
183 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 2469 |
1/2✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
|
183 | s_httpPingPending.erase(address); |
| 2470 | 183 | } | |
| 2471 | // rc == 0 is a transfer that never got an HTTP response at all; any | ||
| 2472 | // status code means something answered, and the old blocking probe | ||
| 2473 | // likewise fed a non-200 body to the detectors rather than dropping it. | ||
| 2474 |
5/6✓ Branch 0 taken 153 times.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 153 times.
✓ Branch 4 taken 30 times.
✓ Branch 5 taken 153 times.
|
183 | if (rc == 0 || resp.empty()) { |
| 2475 | 30 | FinishHTTPPing(); | |
| 2476 | 30 | return; | |
| 2477 | } | ||
| 2478 |
3/6✓ Branch 0 taken 153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 153 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 153 times.
✗ Branch 5 not taken.
|
153 | NetworkController::DetectControllerViaHTML(address, resp, [this, address](NetworkController* nc) { |
| 2479 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 149 times.
|
153 | if (nc) { |
| 2480 | 4 | UpdateSystem(nc->typeId, nc->majorVersion, nc->minorVersion, | |
| 2481 | 4 | nc->systemMode, nc->ip, nc->hostname, nc->version, | |
| 2482 | 4 | nc->typeStr, nc->ranges, nc->uuid, false, nc->sendingMultiSync); | |
| 2483 | 4 | ApplyPeerUUIDs(nc->peerUUIDs); | |
| 2484 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | delete nc; |
| 2485 | } else { | ||
| 2486 |
4/10✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 149 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 149 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 149 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
1490 | UpdateSystem(kSysTypeUnknown, 0, 0, UNKNOWN_MODE, address, |
| 2487 |
1/2✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
|
149 | address, "Unknown", "Unknown", "0-0", "Unknown", false, false); |
| 2488 | } | ||
| 2489 | 153 | FinishHTTPPing(); | |
| 2490 | 153 | }); | |
| 2491 | }); | ||
| 2492 | 185 | } | |
| 2493 | |||
| 2494 | // Releases the in-flight slot and starts whatever is next. Kept separate | ||
| 2495 | // because the probe can end at either of two points above. | ||
| 2496 | 183 | void MultiSync::FinishHTTPPing() { | |
| 2497 | { | ||
| 2498 |
1/2✓ Branch 0 taken 183 times.
✗ Branch 1 not taken.
|
183 | std::unique_lock<std::mutex> lock(m_httpProbeLock); |
| 2499 | 183 | --m_httpPingsInFlight; | |
| 2500 | 183 | } | |
| 2501 | 183 | PumpHTTPPings(); | |
| 2502 | 183 | } | |
| 2503 | |||
| 2504 | // Answering a discover ping: one broadcast ping plus a unicast one to the | ||
| 2505 | // asker. This used to sleep up to 6ms on the main loop per discover ping | ||
| 2506 | // (so the remotes' answers are spread out) and answer every one, so a stream | ||
| 2507 | // of them stalled output and turned every packet into several. The answer | ||
| 2508 | // now goes out from a one-shot timer a few ms later, and every discover ping | ||
| 2509 | // that arrives while one is pending joins it: one broadcast, plus a unicast to | ||
| 2510 | // each distinct asker (bounded). | ||
| 2511 | static std::mutex s_discoverReplyLock; | ||
| 2512 | static std::set<std::string> s_discoverReplyTargets; | ||
| 2513 | static bool s_discoverReplyArmed = false; | ||
| 2514 | |||
| 2515 | 72 | void MultiSync::QueueDiscoverReply(const std::string& address, const std::string& srcIp) { | |
| 2516 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | std::lock_guard<std::mutex> lock(s_discoverReplyLock); |
| 2517 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 72 times.
|
216 | for (const std::string* a : { &address, &srcIp }) { |
| 2518 |
3/6✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 144 times.
✗ Branch 5 not taken.
|
144 | if (!a->empty() && s_discoverReplyTargets.size() < 64) { |
| 2519 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 | s_discoverReplyTargets.insert(*a); |
| 2520 | } | ||
| 2521 | } | ||
| 2522 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 17 times.
|
72 | if (s_discoverReplyArmed) { |
| 2523 | 55 | return; | |
| 2524 | } | ||
| 2525 | 17 | s_discoverReplyArmed = true; | |
| 2526 | // a slight random delay so all the remotes don't answer at the same time | ||
| 2527 |
4/8✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 17 times.
✗ Branch 7 not taken.
|
51 | Timers::INSTANCE.addTimer("MultiSyncDiscoverReply", GetTimeMS() + 1 + FPPrand() % 6, [this]() { |
| 2528 | 17 | std::set<std::string> targets; | |
| 2529 | { | ||
| 2530 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | std::lock_guard<std::mutex> lock(s_discoverReplyLock); |
| 2531 | 17 | targets.swap(s_discoverReplyTargets); | |
| 2532 | 17 | s_discoverReplyArmed = false; | |
| 2533 | 17 | } | |
| 2534 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | Ping(); |
| 2535 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 17 times.
|
57 | for (const auto& t : targets) { |
| 2536 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | PingSingleRemote(t.c_str(), 0); |
| 2537 | } | ||
| 2538 | 17 | }); | |
| 2539 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 55 times.
|
72 | } |
| 2540 | |||
| 2541 | 78 | void MultiSync::PingSingleRemote(const char* address, int discover) { | |
| 2542 | 78 | MultiSyncSystem sys; | |
| 2543 | |||
| 2544 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | sys.address = address; |
| 2545 | |||
| 2546 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | PingSingleRemote(sys, discover); |
| 2547 | 78 | } | |
| 2548 | |||
| 2549 | 78 | void MultiSync::PingSingleRemote(MultiSyncSystem& sys, int discover) { | |
| 2550 | char outBuf[512]; | ||
| 2551 | 78 | memset(outBuf, 0, sizeof(outBuf)); | |
| 2552 | int len; | ||
| 2553 | { | ||
| 2554 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 2555 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
|
78 | if (m_localSystems.empty()) { |
| 2556 | ✗ | return; | |
| 2557 | } | ||
| 2558 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | len = CreatePingPacket(m_localSystems[0], outBuf, discover); |
| 2559 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | } |
| 2560 |
1/2✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
|
78 | SendUnicastPacket(sys.address, outBuf, len); |
| 2561 | } | ||
| 2562 | 5752 | int MultiSync::CreatePingPacket(MultiSyncSystem& sysInfo, char* outBuf, int discover) { | |
| 2563 | 5752 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2564 | 5752 | InitControlPacket(cpkt); | |
| 2565 | |||
| 2566 | 5752 | cpkt->pktType = CTRL_PKT_PING; | |
| 2567 | 5752 | cpkt->extraDataLen = PING_V4_LEN; | |
| 2568 | |||
| 2569 | 5752 | unsigned char* ed = (unsigned char*)(outBuf + 7); | |
| 2570 | 5752 | memset(ed, 0, cpkt->extraDataLen); | |
| 2571 | |||
| 2572 | 5752 | ed[0] = 4; // ping version 4 | |
| 2573 |
2/2✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 3232 times.
|
5752 | ed[1] = discover > 0 ? 1 : 0; // 0 = ping, 1 = discover |
| 2574 | 5752 | ed[2] = sysInfo.type; | |
| 2575 | 5752 | ed[3] = (sysInfo.majorVersion & 0xFF00) >> 8; | |
| 2576 | 5752 | ed[4] = (sysInfo.majorVersion & 0x00FF); | |
| 2577 | 5752 | ed[5] = (sysInfo.minorVersion & 0xFF00) >> 8; | |
| 2578 | 5752 | ed[6] = (sysInfo.minorVersion & 0x00FF); | |
| 2579 | 5752 | ed[7] = sysInfo.fppMode; | |
| 2580 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 5608 times.
|
5752 | if (sysInfo.sendingMultiSync) { |
| 2581 | 144 | ed[7] |= 0x04; | |
| 2582 | } | ||
| 2583 | 5752 | ed[8] = sysInfo.ipa; | |
| 2584 | 5752 | ed[9] = sysInfo.ipb; | |
| 2585 | 5752 | ed[10] = sysInfo.ipc; | |
| 2586 | 5752 | ed[11] = sysInfo.ipd; | |
| 2587 | |||
| 2588 | 5752 | strncpy((char*)(ed + 12), sysInfo.hostname.c_str(), 64); | |
| 2589 | 5752 | strncpy((char*)(ed + 77), sysInfo.version.c_str(), 40); | |
| 2590 | 5752 | strncpy((char*)(ed + 118), sysInfo.model.c_str(), 40); | |
| 2591 | 5752 | strncpy((char*)(ed + 159), sysInfo.ranges.c_str(), 120); | |
| 2592 | // v4: appended after the whole v3 payload, which receivers that predate | ||
| 2593 | // it never read past. "Unknown" is getSetting()'s answer for no UUID. | ||
| 2594 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5750 times.
|
5752 | if (sysInfo.uuid != "Unknown") { |
| 2595 | 2 | strncpy((char*)(ed + PING_V3_LEN), sysInfo.uuid.c_str(), PING_UUID_MAX); | |
| 2596 | } | ||
| 2597 | 5752 | return sizeof(ControlPkt) + cpkt->extraDataLen; | |
| 2598 | } | ||
| 2599 | |||
| 2600 | // The most a sender may put after the ControlPkt header. Receivers read each | ||
| 2601 | // datagram into a MAX_MS_RCV_BUFSIZE buffer and drop anything that arrives | ||
| 2602 | // truncated, so a larger packet is sent but never acted on. Every sender | ||
| 2603 | // checks against this one limit and refuses (with an error) rather than send | ||
| 2604 | // something no remote will accept. | ||
| 2605 | static constexpr size_t MAX_MS_PAYLOAD = MAX_MS_RCV_BUFSIZE - sizeof(ControlPkt); | ||
| 2606 | |||
| 2607 | // The sync senders below write filename into a SyncPkt within a 2048-byte | ||
| 2608 | // outBuf; a filename that wouldn't fit in a packet must be rejected before the | ||
| 2609 | // strcpy rather than silently truncated or overflowed. sizeof(SyncPkt) | ||
| 2610 | // already counts the filename's terminating NUL. | ||
| 2611 | 9767 | static bool FitsInSyncPacket(const std::string& filename) { | |
| 2612 | 9767 | return (sizeof(SyncPkt) + filename.length()) <= MAX_MS_PAYLOAD; | |
| 2613 | } | ||
| 2614 | |||
| 2615 | 42 | void MultiSync::SendSeqOpenPacket(const std::string& filename) { | |
| 2616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (filename.empty()) { |
| 2617 | ✗ | return; | |
| 2618 | } | ||
| 2619 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (!FitsInSyncPacket(filename)) { |
| 2620 | ✗ | LogErr(VB_SYNC, "ERROR: SendSeqOpenPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2621 | ✗ | return; | |
| 2622 | } | ||
| 2623 | |||
| 2624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (m_controlSock < 0) { |
| 2625 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send start packet but sync socket is not open.\n"); | |
| 2626 | ✗ | return; | |
| 2627 | } | ||
| 2628 | |||
| 2629 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | LogDebug(VB_SYNC, "SendSeqOpenPacket('%s')\n", filename.c_str()); |
| 2630 |
3/4✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 42 times.
|
43 | for (auto a : getPluginsCopy()) { |
| 2631 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->SendSeqOpenPacket(filename); |
| 2632 | 42 | } | |
| 2633 | 42 | __atomic_store_n(&m_lastFrame, -1, __ATOMIC_RELAXED); | |
| 2634 | 42 | __atomic_store_n(&m_lastFrameSent, -1, __ATOMIC_RELAXED); | |
| 2635 | |||
| 2636 | char outBuf[2048]; | ||
| 2637 | 42 | bzero(outBuf, sizeof(outBuf)); | |
| 2638 | |||
| 2639 | 42 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2640 | 42 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2641 | |||
| 2642 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | InitControlPacket(cpkt); |
| 2643 | |||
| 2644 | 42 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2645 | 42 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2646 | |||
| 2647 | 42 | spkt->pktType = SYNC_PKT_OPEN; | |
| 2648 | 42 | spkt->fileType = SYNC_FILE_SEQ; | |
| 2649 | 42 | spkt->frameNumber = 0; | |
| 2650 | 42 | spkt->secondsElapsed = 0; | |
| 2651 | 42 | strcpy(spkt->filename, filename.c_str()); | |
| 2652 | |||
| 2653 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2654 | } | ||
| 2655 | |||
| 2656 | 37 | void MultiSync::SendSeqSyncStartPacket(const std::string& filename) { | |
| 2657 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (filename.empty()) { |
| 2658 | ✗ | return; | |
| 2659 | } | ||
| 2660 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (!FitsInSyncPacket(filename)) { |
| 2661 | ✗ | LogErr(VB_SYNC, "ERROR: SendSeqSyncStartPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2662 | ✗ | return; | |
| 2663 | } | ||
| 2664 | |||
| 2665 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (m_controlSock < 0) { |
| 2666 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send start packet but sync socket is not open.\n"); | |
| 2667 | ✗ | return; | |
| 2668 | } | ||
| 2669 | |||
| 2670 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | LogDebug(VB_SYNC, "SendSeqSyncStartPacket('%s')\n", filename.c_str()); |
| 2671 |
3/4✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 37 times.
|
38 | for (auto a : getPluginsCopy()) { |
| 2672 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->SendSeqSyncStartPacket(filename); |
| 2673 | 37 | } | |
| 2674 | 37 | __atomic_store_n(&m_lastFrame, -1, __ATOMIC_RELAXED); | |
| 2675 | 37 | __atomic_store_n(&m_lastFrameSent, -1, __ATOMIC_RELAXED); | |
| 2676 | |||
| 2677 | char outBuf[2048]; | ||
| 2678 | 37 | bzero(outBuf, sizeof(outBuf)); | |
| 2679 | |||
| 2680 | 37 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2681 | 37 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2682 | |||
| 2683 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | InitControlPacket(cpkt); |
| 2684 | |||
| 2685 | 37 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2686 | 37 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2687 | |||
| 2688 | 37 | spkt->pktType = SYNC_PKT_START; | |
| 2689 | 37 | spkt->fileType = SYNC_FILE_SEQ; | |
| 2690 | 37 | spkt->frameNumber = 0; | |
| 2691 | 37 | spkt->secondsElapsed = 0; | |
| 2692 | 37 | strcpy(spkt->filename, filename.c_str()); | |
| 2693 | |||
| 2694 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2695 | } | ||
| 2696 | |||
| 2697 | /* | ||
| 2698 | * | ||
| 2699 | */ | ||
| 2700 | 231 | void MultiSync::SendSeqSyncStopPacket(const std::string& filename) { | |
| 2701 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | if (filename.empty()) { |
| 2702 | ✗ | return; | |
| 2703 | } | ||
| 2704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | if (!FitsInSyncPacket(filename)) { |
| 2705 | ✗ | LogErr(VB_SYNC, "ERROR: SendSeqSyncStopPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2706 | ✗ | return; | |
| 2707 | } | ||
| 2708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
|
231 | if (m_controlSock < 0) { |
| 2709 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send stop packet but sync socket is not open.\n"); | |
| 2710 | ✗ | return; | |
| 2711 | } | ||
| 2712 |
1/2✓ Branch 0 taken 231 times.
✗ Branch 1 not taken.
|
231 | LogDebug(VB_SYNC, "SendSeqSyncStopPacket(%s)\n", filename.c_str()); |
| 2713 | |||
| 2714 |
3/4✓ Branch 0 taken 231 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 231 times.
|
232 | for (auto a : getPluginsCopy()) { |
| 2715 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->SendSeqSyncStopPacket(filename); |
| 2716 | 231 | } | |
| 2717 | |||
| 2718 | char outBuf[2048]; | ||
| 2719 | 231 | bzero(outBuf, sizeof(outBuf)); | |
| 2720 | |||
| 2721 | 231 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2722 | 231 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2723 | |||
| 2724 |
1/2✓ Branch 0 taken 231 times.
✗ Branch 1 not taken.
|
231 | InitControlPacket(cpkt); |
| 2725 | |||
| 2726 | 231 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2727 | 231 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2728 | |||
| 2729 | 231 | spkt->pktType = SYNC_PKT_STOP; | |
| 2730 | 231 | spkt->fileType = SYNC_FILE_SEQ; | |
| 2731 | 231 | spkt->frameNumber = 0; | |
| 2732 | 231 | spkt->secondsElapsed = 0; | |
| 2733 | 231 | strcpy(spkt->filename, filename.c_str()); | |
| 2734 | |||
| 2735 |
1/2✓ Branch 0 taken 231 times.
✗ Branch 1 not taken.
|
231 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2736 | |||
| 2737 | 231 | __atomic_store_n(&m_lastFrame, -1, __ATOMIC_RELAXED); | |
| 2738 | 231 | __atomic_store_n(&m_lastFrameSent, -1, __ATOMIC_RELAXED); | |
| 2739 | } | ||
| 2740 | |||
| 2741 | /* | ||
| 2742 | * | ||
| 2743 | */ | ||
| 2744 | 5733 | void MultiSync::SendSeqSyncPacket(const std::string& filename, int frames, float seconds) { | |
| 2745 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5733 times.
|
5733 | if (filename.empty()) { |
| 2746 | 4950 | return; | |
| 2747 | } | ||
| 2748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5733 times.
|
5733 | if (!FitsInSyncPacket(filename)) { |
| 2749 | ✗ | LogErr(VB_SYNC, "ERROR: SendSeqSyncPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2750 | ✗ | return; | |
| 2751 | } | ||
| 2752 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5733 times.
|
5733 | if (m_controlSock < 0) { |
| 2753 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send sync packet but sync socket is not open.\n"); | |
| 2754 | ✗ | return; | |
| 2755 | } | ||
| 2756 |
3/4✓ Branch 0 taken 5733 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 694 times.
✓ Branch 3 taken 5733 times.
|
6427 | for (auto a : getPluginsCopy()) { |
| 2757 |
1/2✓ Branch 0 taken 694 times.
✗ Branch 1 not taken.
|
694 | a->SendSeqSyncPacket(filename, frames, seconds); |
| 2758 | 5733 | } | |
| 2759 | // The output thread sends these while the sequence's open, start and | ||
| 2760 | // stop -- on the playlist's thread -- reset them, so every access is a | ||
| 2761 | // relaxed atomic one (the members are plain ints in a plugin-facing | ||
| 2762 | // header). | ||
| 2763 | 5733 | __atomic_store_n(&m_lastFrame, frames, __ATOMIC_RELAXED); | |
| 2764 | 5733 | int diff = frames - __atomic_load_n(&m_lastFrameSent, __ATOMIC_RELAXED); | |
| 2765 |
2/2✓ Branch 0 taken 4721 times.
✓ Branch 1 taken 1012 times.
|
5733 | if (frames > 32) { |
| 2766 | // after 32 frames, we send every 10 | ||
| 2767 | // that's either twice a second (50ms sequences) or 4 times (25ms) | ||
| 2768 |
2/2✓ Branch 0 taken 4215 times.
✓ Branch 1 taken 506 times.
|
4721 | if (diff < 10) { |
| 2769 | 4215 | return; | |
| 2770 | } | ||
| 2771 |
4/4✓ Branch 0 taken 1006 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 735 times.
✓ Branch 3 taken 271 times.
|
1012 | } else if (frames && diff < 4) { |
| 2772 | // under 32 frames, we send every 4 | ||
| 2773 | 735 | return; | |
| 2774 | } | ||
| 2775 | 783 | __atomic_store_n(&m_lastFrameSent, frames, __ATOMIC_RELAXED); | |
| 2776 | |||
| 2777 | // LogExcess: sent several times a second for the whole sequence, and a | ||
| 2778 | // LogDebug is always formatted into the crash ring. | ||
| 2779 |
1/2✓ Branch 0 taken 783 times.
✗ Branch 1 not taken.
|
783 | LogExcess(VB_SYNC, "SendSeqSyncPacket( '%s', %d, %.2f)\n", |
| 2780 | filename.c_str(), frames, seconds); | ||
| 2781 | char outBuf[2048]; | ||
| 2782 | 783 | bzero(outBuf, sizeof(outBuf)); | |
| 2783 | |||
| 2784 | 783 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2785 | 783 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2786 | |||
| 2787 |
1/2✓ Branch 0 taken 783 times.
✗ Branch 1 not taken.
|
783 | InitControlPacket(cpkt); |
| 2788 | |||
| 2789 | 783 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2790 | 783 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2791 | |||
| 2792 | 783 | spkt->pktType = SYNC_PKT_SYNC; | |
| 2793 | 783 | spkt->fileType = SYNC_FILE_SEQ; | |
| 2794 | 783 | spkt->frameNumber = frames; | |
| 2795 | 783 | spkt->secondsElapsed = seconds; | |
| 2796 | 783 | strcpy(spkt->filename, filename.c_str()); | |
| 2797 | |||
| 2798 |
1/2✓ Branch 0 taken 783 times.
✗ Branch 1 not taken.
|
783 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2799 | } | ||
| 2800 | |||
| 2801 | 19 | void MultiSync::SendMediaOpenPacket(const std::string& filename) { | |
| 2802 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (filename.empty()) { |
| 2803 | ✗ | return; | |
| 2804 | } | ||
| 2805 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (!FitsInSyncPacket(filename)) { |
| 2806 | ✗ | LogErr(VB_SYNC, "ERROR: SendMediaOpenPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2807 | ✗ | return; | |
| 2808 | } | ||
| 2809 | |||
| 2810 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (m_controlSock < 0) { |
| 2811 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send start packet but sync socket is not open.\n"); | |
| 2812 | ✗ | return; | |
| 2813 | } | ||
| 2814 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | LogDebug(VB_SYNC, "SendMediaOpenPacket('%s')\n", filename.c_str()); |
| 2815 | |||
| 2816 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
|
19 | for (auto a : getPluginsCopy()) { |
| 2817 | ✗ | a->SendMediaOpenPacket(filename); | |
| 2818 | 19 | } | |
| 2819 | |||
| 2820 | 19 | m_lastMediaHalfSecond = 0; | |
| 2821 | |||
| 2822 | char outBuf[2048]; | ||
| 2823 | 19 | bzero(outBuf, sizeof(outBuf)); | |
| 2824 | |||
| 2825 | 19 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2826 | 19 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2827 | |||
| 2828 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | InitControlPacket(cpkt); |
| 2829 | |||
| 2830 | 19 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2831 | 19 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2832 | |||
| 2833 | 19 | spkt->pktType = SYNC_PKT_OPEN; | |
| 2834 | 19 | spkt->fileType = SYNC_FILE_MEDIA; | |
| 2835 | 19 | spkt->frameNumber = 0; | |
| 2836 | 19 | spkt->secondsElapsed = 0; | |
| 2837 | 19 | strcpy(spkt->filename, filename.c_str()); | |
| 2838 | |||
| 2839 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2840 | } | ||
| 2841 | 1 | void MultiSync::SendMediaPreparePacket(const std::string& filename) { | |
| 2842 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
1 | if (filename.empty() || !FitsInSyncPacket(filename) || m_controlSock < 0) { |
| 2843 | ✗ | return; | |
| 2844 | } | ||
| 2845 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_SYNC, "SendMediaPreparePacket('%s')\n", filename.c_str()); |
| 2846 | |||
| 2847 | char outBuf[2048]; | ||
| 2848 | 1 | bzero(outBuf, sizeof(outBuf)); | |
| 2849 | 1 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2850 | 1 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2851 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | InitControlPacket(cpkt); |
| 2852 | 1 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2853 | 1 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2854 | 1 | spkt->pktType = SYNC_PKT_PREPARE; | |
| 2855 | 1 | spkt->fileType = SYNC_FILE_MEDIA; | |
| 2856 | 1 | spkt->frameNumber = 0; | |
| 2857 | 1 | spkt->secondsElapsed = 0; | |
| 2858 | 1 | strcpy(spkt->filename, filename.c_str()); | |
| 2859 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2860 | } | ||
| 2861 | |||
| 2862 | 19 | void MultiSync::SendMediaSyncStartPacket(const std::string& filename) { | |
| 2863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (filename.empty()) { |
| 2864 | ✗ | return; | |
| 2865 | } | ||
| 2866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (!FitsInSyncPacket(filename)) { |
| 2867 | ✗ | LogErr(VB_SYNC, "ERROR: SendMediaSyncStartPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2868 | ✗ | return; | |
| 2869 | } | ||
| 2870 | |||
| 2871 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (m_controlSock < 0) { |
| 2872 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send start packet but sync socket is not open.\n"); | |
| 2873 | ✗ | return; | |
| 2874 | } | ||
| 2875 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | LogDebug(VB_SYNC, "SendMediaSyncStartPacket('%s')\n", filename.c_str()); |
| 2876 | |||
| 2877 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
|
19 | for (auto a : getPluginsCopy()) { |
| 2878 | ✗ | a->SendMediaSyncStartPacket(filename); | |
| 2879 | 19 | } | |
| 2880 | |||
| 2881 | 19 | m_lastMediaHalfSecond = 0; | |
| 2882 | |||
| 2883 | char outBuf[2048]; | ||
| 2884 | 19 | bzero(outBuf, sizeof(outBuf)); | |
| 2885 | |||
| 2886 | 19 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2887 | 19 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2888 | |||
| 2889 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | InitControlPacket(cpkt); |
| 2890 | |||
| 2891 | 19 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2892 | 19 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2893 | |||
| 2894 | 19 | spkt->pktType = SYNC_PKT_START; | |
| 2895 | 19 | spkt->fileType = SYNC_FILE_MEDIA; | |
| 2896 | 19 | spkt->frameNumber = 0; | |
| 2897 | 19 | spkt->secondsElapsed = 0; | |
| 2898 | 19 | strcpy(spkt->filename, filename.c_str()); | |
| 2899 | |||
| 2900 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2901 | } | ||
| 2902 | |||
| 2903 | /* | ||
| 2904 | * | ||
| 2905 | */ | ||
| 2906 | 16 | void MultiSync::SendMediaSyncStopPacket(const std::string& filename) { | |
| 2907 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (filename.empty()) { |
| 2908 | ✗ | return; | |
| 2909 | } | ||
| 2910 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (!FitsInSyncPacket(filename)) { |
| 2911 | ✗ | LogErr(VB_SYNC, "ERROR: SendMediaSyncStopPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2912 | ✗ | return; | |
| 2913 | } | ||
| 2914 | |||
| 2915 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (m_controlSock < 0) { |
| 2916 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send stop packet but sync socket is not open.\n"); | |
| 2917 | ✗ | return; | |
| 2918 | } | ||
| 2919 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | LogDebug(VB_SYNC, "SendMediaSyncStopPacket(%s)\n", filename.c_str()); |
| 2920 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
|
16 | for (auto a : getPluginsCopy()) { |
| 2921 | ✗ | a->SendMediaSyncStopPacket(filename); | |
| 2922 | 16 | } | |
| 2923 | |||
| 2924 | char outBuf[2048]; | ||
| 2925 | 16 | bzero(outBuf, sizeof(outBuf)); | |
| 2926 | |||
| 2927 | 16 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2928 | 16 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2929 | |||
| 2930 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | InitControlPacket(cpkt); |
| 2931 | |||
| 2932 | 16 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2933 | 16 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2934 | |||
| 2935 | 16 | spkt->pktType = SYNC_PKT_STOP; | |
| 2936 | 16 | spkt->fileType = SYNC_FILE_MEDIA; | |
| 2937 | 16 | spkt->frameNumber = 0; | |
| 2938 | 16 | spkt->secondsElapsed = 0; | |
| 2939 | 16 | strcpy(spkt->filename, filename.c_str()); | |
| 2940 | |||
| 2941 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2942 | } | ||
| 2943 | |||
| 2944 | /* | ||
| 2945 | * | ||
| 2946 | */ | ||
| 2947 | 3669 | void MultiSync::SendMediaSyncPacket(const std::string& filename, float seconds) { | |
| 2948 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3669 times.
|
3669 | if (filename.empty()) { |
| 2949 | 3606 | return; | |
| 2950 | } | ||
| 2951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3669 times.
|
3669 | if (!FitsInSyncPacket(filename)) { |
| 2952 | ✗ | LogErr(VB_SYNC, "ERROR: SendMediaSyncPacket filename '%s' is too long to send\n", filename.c_str()); | |
| 2953 | ✗ | return; | |
| 2954 | } | ||
| 2955 | |||
| 2956 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3669 times.
|
3669 | if (m_controlSock < 0) { |
| 2957 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send sync packet but sync socket is not open.\n"); | |
| 2958 | ✗ | return; | |
| 2959 | } | ||
| 2960 | |||
| 2961 |
2/4✓ Branch 0 taken 3669 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3669 times.
|
3669 | for (auto a : getPluginsCopy()) { |
| 2962 | ✗ | a->SendMediaSyncPacket(filename, seconds); | |
| 2963 | 3669 | } | |
| 2964 | |||
| 2965 | 3669 | int curTS = (seconds * 2.0f); | |
| 2966 |
2/2✓ Branch 0 taken 3606 times.
✓ Branch 1 taken 63 times.
|
3669 | if (m_lastMediaHalfSecond == curTS) { |
| 2967 | // not time to send | ||
| 2968 | 3606 | return; | |
| 2969 | } | ||
| 2970 | 63 | m_lastMediaHalfSecond = curTS; | |
| 2971 | |||
| 2972 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | LogExcess(VB_SYNC, "SendMediaSyncPacket( '%s', %.2f)\n", |
| 2973 | filename.c_str(), seconds); | ||
| 2974 | |||
| 2975 | char outBuf[2048]; | ||
| 2976 | 63 | bzero(outBuf, sizeof(outBuf)); | |
| 2977 | |||
| 2978 | 63 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 2979 | 63 | SyncPkt* spkt = (SyncPkt*)(outBuf + sizeof(ControlPkt)); | |
| 2980 | |||
| 2981 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | InitControlPacket(cpkt); |
| 2982 | |||
| 2983 | 63 | cpkt->pktType = CTRL_PKT_SYNC; | |
| 2984 | 63 | cpkt->extraDataLen = sizeof(SyncPkt) + filename.length(); | |
| 2985 | |||
| 2986 | 63 | spkt->pktType = SYNC_PKT_SYNC; | |
| 2987 | 63 | spkt->fileType = SYNC_FILE_MEDIA; | |
| 2988 | 63 | spkt->frameNumber = 0; | |
| 2989 | 63 | spkt->secondsElapsed = seconds; | |
| 2990 | 63 | strcpy(spkt->filename, filename.c_str()); | |
| 2991 | |||
| 2992 |
1/2✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
|
63 | SendControlPacket(outBuf, sizeof(ControlPkt) + sizeof(SyncPkt) + filename.length()); |
| 2993 | } | ||
| 2994 | |||
| 2995 | 2 | void MultiSync::SendPluginData(const std::string& name, const uint8_t* data, int len) { | |
| 2996 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (name.empty()) { |
| 2997 | 1 | return; | |
| 2998 | } | ||
| 2999 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
4 | for (auto a : getPluginsCopy()) { |
| 3000 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | a->SendPluginData(name, data, len); |
| 3001 | 2 | } | |
| 3002 | |||
| 3003 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SYNC, "SendPluginData('%s')\n", name.c_str()); |
| 3004 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (m_controlSock < 0) { |
| 3005 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send plugin data packet but control socket is not open.\n"); | |
| 3006 | ✗ | return; | |
| 3007 | } | ||
| 3008 | |||
| 3009 | char outBuf[2048]; | ||
| 3010 | 2 | bzero(outBuf, sizeof(outBuf)); | |
| 3011 | |||
| 3012 | 2 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 3013 | 2 | CommandPkt* epkt = (CommandPkt*)(outBuf + sizeof(ControlPkt)); | |
| 3014 | |||
| 3015 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | InitControlPacket(cpkt); |
| 3016 | 2 | int nlen = strlen(name.c_str()) + 1; // add the null | |
| 3017 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if (len < 0 || ((size_t)nlen + (size_t)len) > MAX_MS_PAYLOAD) { |
| 3018 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_SYNC, "ERROR: Plugin data packet for '%s' (%d bytes) is too large to send\n", |
| 3019 | name.c_str(), len); | ||
| 3020 | 1 | return; | |
| 3021 | } | ||
| 3022 | 1 | cpkt->pktType = CTRL_PKT_PLUGIN; | |
| 3023 | 1 | cpkt->extraDataLen = len + nlen; | |
| 3024 | |||
| 3025 | 1 | strcpy(epkt->command, name.c_str()); | |
| 3026 | 1 | memcpy(&epkt->command[nlen], data, len); | |
| 3027 | |||
| 3028 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | SendControlPacket(outBuf, sizeof(ControlPkt) + len + nlen); |
| 3029 | } | ||
| 3030 | |||
| 3031 | /* | ||
| 3032 | * | ||
| 3033 | */ | ||
| 3034 | 86 | void MultiSync::SendBlankingDataPacket(void) { | |
| 3035 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | LogDebug(VB_SYNC, "SendBlankingDataPacket()\n"); |
| 3036 | |||
| 3037 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 86 times.
|
86 | if (m_controlSock < 0) { |
| 3038 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send blanking data packet but control socket is not open.\n"); | |
| 3039 | ✗ | return; | |
| 3040 | } | ||
| 3041 |
3/4✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 86 times.
|
90 | for (auto a : getPluginsCopy()) { |
| 3042 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | a->SendBlankingDataPacket(); |
| 3043 | 86 | } | |
| 3044 | char outBuf[2048]; | ||
| 3045 | 86 | bzero(outBuf, sizeof(outBuf)); | |
| 3046 | |||
| 3047 | 86 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 3048 | |||
| 3049 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | InitControlPacket(cpkt); |
| 3050 | |||
| 3051 | 86 | cpkt->pktType = CTRL_PKT_BLANK; | |
| 3052 | 86 | cpkt->extraDataLen = 0; | |
| 3053 | |||
| 3054 |
1/2✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
|
86 | SendControlPacket(outBuf, sizeof(ControlPkt)); |
| 3055 | } | ||
| 3056 | 12463 | std::vector<MultiSyncPlugin*> MultiSync::getPluginsCopy() { | |
| 3057 |
1/2✓ Branch 0 taken 12463 times.
✗ Branch 1 not taken.
|
12463 | std::unique_lock<std::mutex> lock(m_pluginsLock); |
| 3058 |
1/2✓ Branch 0 taken 12463 times.
✗ Branch 1 not taken.
|
24926 | return m_plugins; |
| 3059 | 12463 | } | |
| 3060 | 24003 | void MultiSync::addMultiSyncPlugin(MultiSyncPlugin* p) { | |
| 3061 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | std::unique_lock<std::mutex> lock(m_pluginsLock); |
| 3062 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | m_plugins.push_back(p); |
| 3063 | 24003 | } | |
| 3064 | 24003 | void MultiSync::removeMultiSyncPlugin(MultiSyncPlugin* p) { | |
| 3065 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | std::unique_lock<std::mutex> lock(m_pluginsLock); |
| 3066 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | auto a = std::find(m_plugins.begin(), m_plugins.end(), p); |
| 3067 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | if (a != m_plugins.end()) { |
| 3068 |
1/2✓ Branch 0 taken 24003 times.
✗ Branch 1 not taken.
|
24003 | m_plugins.erase(a); |
| 3069 | } | ||
| 3070 | 24003 | } | |
| 3071 | |||
| 3072 | /* | ||
| 3073 | * | ||
| 3074 | */ | ||
| 3075 | 3220 | void MultiSync::ShutdownSync(void) { | |
| 3076 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | LogDebug(VB_SYNC, "ShutdownSync()\n"); |
| 3077 | |||
| 3078 | // Idempotent, like WLEDAudioSync::Cleanup(): fppd's shutdown calls this and | ||
| 3079 | // ~MultiSync() calls it again at static-destruction time, by which point the | ||
| 3080 | // global SettingsConfig may already be gone -- locking its destroyed mutex | ||
| 3081 | // would throw out of a noexcept destructor. Unregistering is not a | ||
| 3082 | // barrier: listeners are called from a copy with no settings lock held, so | ||
| 3083 | // one may still be running ReloadSyncDestinations() on the settings-reload | ||
| 3084 | // thread, or be about to start. Close the gate and wait for those to | ||
| 3085 | // finish before the sockets below are closed. | ||
| 3086 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | if (!m_settingsListenersRemoved.exchange(true)) { |
| 3087 | 22540 | for (const char* s : { "MultiSyncRemotes", "MultiSyncExtraRemotes", | |
| 3088 | "MultiSyncBroadcast", "MultiSyncMulticast", "MultiSyncUnicast", | ||
| 3089 |
2/2✓ Branch 0 taken 19320 times.
✓ Branch 1 taken 3220 times.
|
25760 | "MultiSyncUnicastSubnets" }) { |
| 3090 |
3/6✓ Branch 0 taken 19320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19320 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19320 times.
✗ Branch 5 not taken.
|
77280 | unregisterSettingsListener("MultiSync", s); |
| 3091 | } | ||
| 3092 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | std::unique_lock<std::mutex> lock(s_listenerQuiesceLock); |
| 3093 | 3220 | s_listenersShutdown = true; | |
| 3094 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
6440 | s_listenerQuiesceCV.wait(lock, []() { return s_listenersInFlight == 0; }); |
| 3095 | 3220 | } | |
| 3096 | |||
| 3097 | { | ||
| 3098 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | std::unique_lock<std::mutex> pluginLock(m_pluginsLock); |
| 3099 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | auto plugins = m_plugins; |
| 3100 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | pluginLock.unlock(); |
| 3101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3220 times.
|
3220 | for (auto a : plugins) { |
| 3102 | ✗ | a->ShutdownSync(); | |
| 3103 | } | ||
| 3104 | 3220 | } | |
| 3105 | { | ||
| 3106 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | std::unique_lock<std::mutex> pluginLock(m_pluginsLock); |
| 3107 | 3220 | m_plugins.clear(); | |
| 3108 | 3220 | } | |
| 3109 | |||
| 3110 |
1/2✓ Branch 0 taken 3220 times.
✗ Branch 1 not taken.
|
3220 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3111 |
2/2✓ Branch 0 taken 2620 times.
✓ Branch 1 taken 600 times.
|
3220 | if (m_broadcastSock >= 0) { |
| 3112 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | close(m_broadcastSock); |
| 3113 | 2620 | m_broadcastSock = -1; | |
| 3114 | } | ||
| 3115 | |||
| 3116 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 3177 times.
|
3220 | if (m_controlSock >= 0) { |
| 3117 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | close(m_controlSock); |
| 3118 | 43 | m_controlSock = -1; | |
| 3119 | } | ||
| 3120 | |||
| 3121 |
2/2✓ Branch 0 taken 2620 times.
✓ Branch 1 taken 600 times.
|
3220 | if (m_twinklyDiscoverySock >= 0) { |
| 3122 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | EPollManager::INSTANCE.removeFileDescriptor(m_twinklyDiscoverySock); |
| 3123 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | close(m_twinklyDiscoverySock); |
| 3124 | 2620 | m_twinklyDiscoverySock = -1; | |
| 3125 | } | ||
| 3126 | |||
| 3127 |
2/2✓ Branch 0 taken 2620 times.
✓ Branch 1 taken 600 times.
|
3220 | if (m_receiveSock >= 0) { |
| 3128 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | close(m_receiveSock); |
| 3129 | 2620 | m_receiveSock = -1; | |
| 3130 | } | ||
| 3131 | 3220 | } | |
| 3132 | |||
| 3133 | /* | ||
| 3134 | * | ||
| 3135 | */ | ||
| 3136 | 2651 | int MultiSync::OpenBroadcastSocket(void) { | |
| 3137 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | LogDebug(VB_SYNC, "OpenBroadcastSocket()\n"); |
| 3138 | |||
| 3139 | 2651 | m_broadcastSock = OpenSocket(AF_INET, SOCK_DGRAM, 0); | |
| 3140 | |||
| 3141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
|
2651 | if (m_broadcastSock < 0) { |
| 3142 | ✗ | LogErr(VB_SYNC, "Error opening MultiSync broadcast socket\n"); | |
| 3143 | ✗ | WarningHolder::AddWarning(42, "MultiSync: could not open broadcast socket"); | |
| 3144 | ✗ | return 0; | |
| 3145 | } | ||
| 3146 | |||
| 3147 | 2651 | char loopch = 0; | |
| 3148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
|
2651 | if (setsockopt(m_broadcastSock, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&loopch, sizeof(loopch)) < 0) { |
| 3149 | ✗ | LogErr(VB_SYNC, "Error setting IP_MULTICAST_LOOP: \n", | |
| 3150 | FPPstrerror(errno)); | ||
| 3151 | ✗ | return 0; | |
| 3152 | } | ||
| 3153 | |||
| 3154 | 2651 | int broadcast = 1; | |
| 3155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
|
2651 | if (setsockopt(m_broadcastSock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) < 0) { |
| 3156 | ✗ | LogErr(VB_SYNC, "Error setting SO_BROADCAST: \n", FPPstrerror(errno)); | |
| 3157 | ✗ | return 0; | |
| 3158 | } | ||
| 3159 | |||
| 3160 | 2651 | return 1; | |
| 3161 | } | ||
| 3162 | |||
| 3163 | /* | ||
| 3164 | * | ||
| 3165 | */ | ||
| 3166 | 44 | int MultiSync::OpenControlSockets() { | |
| 3167 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | LogDebug(VB_SYNC, "OpenControlSockets()\n"); |
| 3168 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | std::unique_lock<std::mutex> openLock(s_controlSockOpenLock); |
| 3169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (m_controlSock >= 0) { |
| 3170 | ✗ | return 1; | |
| 3171 | } | ||
| 3172 | |||
| 3173 | // Set the socket up fully before publishing it, so a sender never sees a | ||
| 3174 | // half-configured one, and a failed setsockopt() doesn't leave it behind | ||
| 3175 | // as if the open had succeeded. | ||
| 3176 | 44 | int sock = OpenSocket(AF_INET, SOCK_DGRAM, 0); | |
| 3177 | |||
| 3178 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (sock < 0) { |
| 3179 | ✗ | LogErr(VB_SYNC, "Error opening MultiSync socket\n"); | |
| 3180 | ✗ | WarningHolder::AddWarning(42, "MultiSync: could not open control socket"); | |
| 3181 | ✗ | return 0; | |
| 3182 | } | ||
| 3183 | |||
| 3184 | 44 | char loopch = 0; | |
| 3185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&loopch, sizeof(loopch)) < 0) { |
| 3186 | ✗ | LogErr(VB_SYNC, "Error setting IP_MULTICAST_LOOP: %s\n", | |
| 3187 | FPPstrerror(errno)); | ||
| 3188 | ✗ | close(sock); | |
| 3189 | ✗ | return 0; | |
| 3190 | } | ||
| 3191 | |||
| 3192 | { | ||
| 3193 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3194 | 44 | m_controlSock = sock; | |
| 3195 | 44 | } | |
| 3196 | // The destination reload resolves hostnames, so don't make other threads | ||
| 3197 | // wanting the socket wait on it; they can use the socket already. | ||
| 3198 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | openLock.unlock(); |
| 3199 | |||
| 3200 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | ReloadSyncDestinations(); |
| 3201 | |||
| 3202 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | FillInInterfaces(); |
| 3203 | |||
| 3204 | 44 | return 1; | |
| 3205 | 44 | } | |
| 3206 | |||
| 3207 | 52 | void MultiSync::ReloadSyncDestinations() { | |
| 3208 | // Same lock UpdateUnicastDestinations() uses, for the same reason: the | ||
| 3209 | // resolve step below is slow and runs without m_socketLock, so two | ||
| 3210 | // overlapping reloads could otherwise finish out of order and leave the | ||
| 3211 | // older result in place. Holding it also keeps UpdateUnicastDestinations() | ||
| 3212 | // from reading m_destAddr for its dedupe set mid-swap. Nothing in this | ||
| 3213 | // function may take m_systemsLock while it is held; it is released before | ||
| 3214 | // the UpdateUnicastDestinations() call at the end, which snapshots the | ||
| 3215 | // remote list under m_systemsLock and then takes this lock itself. | ||
| 3216 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | std::unique_lock<std::mutex> updateLock(m_unicastUpdateLock); |
| 3217 | |||
| 3218 | 52 | std::set<std::string> remotes; | |
| 3219 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | AddRemotesFromSetting("MultiSyncRemotes", remotes); |
| 3220 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | AddRemotesFromSetting("MultiSyncExtraRemotes", remotes); |
| 3221 | |||
| 3222 | // Assign rather than |=: this runs again on every settings change, so a | ||
| 3223 | // method the user just turned off has to go back to false. | ||
| 3224 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | bool sendBroadcast = getSettingInt("MultiSyncBroadcast") != 0; |
| 3225 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | bool sendMulticast = getSettingInt("MultiSyncMulticast") != 0; |
| 3226 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | bool sendUnicast = getSettingInt("MultiSyncUnicast") != 0; |
| 3227 |
10/12✓ Branch 0 taken 12 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 50 times.
|
52 | if (remotes.empty() && !sendBroadcast && !sendMulticast && !sendUnicast && m_multiSyncEnabled) { |
| 3228 | // No explicit remotes or send method configured; default to multicast. | ||
| 3229 | // A list that names no host (only quotes or commas, which is how the | ||
| 3230 | // old UI saved an empty one) counts as no remotes. | ||
| 3231 | 2 | sendMulticast = true; | |
| 3232 | } | ||
| 3233 | |||
| 3234 | // Resolve into a local list first: getaddrinfo() below is an unbounded | ||
| 3235 | // network lookup and must not run while m_socketLock is held, since that | ||
| 3236 | // lock is taken by the send path on the output thread every frame. | ||
| 3237 | 52 | std::vector<struct sockaddr_in> newAddrs; | |
| 3238 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 52 times.
|
103 | for (auto& s : remotes) { |
| 3239 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | LogDebug(VB_SYNC, "Setting up Remote Sync for %s\n", s.c_str()); |
| 3240 | struct sockaddr_in newRemote; | ||
| 3241 | 51 | memset(&newRemote, 0, sizeof(newRemote)); | |
| 3242 | |||
| 3243 | 51 | newRemote.sin_family = AF_INET; | |
| 3244 | 51 | newRemote.sin_port = htons(FPP_CTRL_PORT); | |
| 3245 | |||
| 3246 | // A letter (or a space) means this is a hostname and has to be resolved; | ||
| 3247 | // anything else is a dotted-quad to parse directly. The test used to | ||
| 3248 | // read `... == s.end()`, i.e. "contains no letters", which is backwards: | ||
| 3249 | // hostnames took the inet_addr() path, came back INADDR_NONE, and were | ||
| 3250 | // then installed as a destination of 255.255.255.255 -- so every entry | ||
| 3251 | // that wasn't already an IP address quietly broadcast its sync packets. | ||
| 3252 |
4/6✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 454 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 454 times.
|
506 | bool isHostname = std::find_if(s.begin(), s.end(), [](char c) { return (isalpha(c) || (c == ' ')); }) != s.end(); |
| 3253 | 51 | bool valid = true; | |
| 3254 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 50 times.
|
51 | if (isHostname) { |
| 3255 | // Reentrant and cached, unlike gethostbyname(), which shares a | ||
| 3256 | // single static hostent across the process. | ||
| 3257 | 1 | uint32_t resolved = 0; | |
| 3258 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!ResolveHostToIPv4(s, resolved)) { |
| 3259 | ✗ | LogErr(VB_SYNC, | |
| 3260 | "Error looking up Remote hostname: %s\n", | ||
| 3261 | s.c_str()); | ||
| 3262 | ✗ | valid = false; | |
| 3263 | } else { | ||
| 3264 | 1 | newRemote.sin_addr.s_addr = resolved; | |
| 3265 | } | ||
| 3266 | } else { | ||
| 3267 | 50 | newRemote.sin_addr.s_addr = inet_addr(s.c_str()); | |
| 3268 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (newRemote.sin_addr.s_addr == INADDR_NONE) { |
| 3269 | ✗ | LogErr(VB_SYNC, "Error parsing Remote IP address: %s\n", s.c_str()); | |
| 3270 | ✗ | valid = false; | |
| 3271 | } | ||
| 3272 | } | ||
| 3273 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | if (valid) { |
| 3274 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | newAddrs.push_back(newRemote); |
| 3275 | } | ||
| 3276 | } | ||
| 3277 | |||
| 3278 | 52 | m_sendBroadcast = sendBroadcast; | |
| 3279 | 52 | m_sendMulticast = sendMulticast; | |
| 3280 | 52 | m_sendUnicast = sendUnicast; | |
| 3281 | |||
| 3282 | { | ||
| 3283 | // Swap the whole list in at once. Each mmsghdr points at its own | ||
| 3284 | // element of m_destAddr, so the two vectors must be rebuilt together | ||
| 3285 | // and never observed half-updated by SendControlPacketViaMsgs(). | ||
| 3286 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3287 | 52 | m_destAddr = std::move(newAddrs); | |
| 3288 | 52 | m_destMsgs.clear(); | |
| 3289 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | m_destMsgs.reserve(m_destAddr.size()); |
| 3290 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 52 times.
|
103 | for (size_t x = 0; x < m_destAddr.size(); x++) { |
| 3291 | struct mmsghdr msg; | ||
| 3292 | 51 | memset(&msg, 0, sizeof(msg)); | |
| 3293 | |||
| 3294 | 51 | msg.msg_hdr.msg_name = &m_destAddr[x]; | |
| 3295 | 51 | msg.msg_hdr.msg_namelen = sizeof(sockaddr_in); | |
| 3296 | 51 | msg.msg_hdr.msg_iov = &m_destIovec; | |
| 3297 | 51 | msg.msg_hdr.msg_iovlen = 1; | |
| 3298 | 51 | msg.msg_len = 0; | |
| 3299 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | m_destMsgs.push_back(msg); |
| 3300 | } | ||
| 3301 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | LogDebug(VB_SYNC, "%d Remote Sync systems configured\n", |
| 3302 | (int)m_destAddr.size()); | ||
| 3303 | |||
| 3304 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 50 times.
|
52 | if (!sendUnicast) { |
| 3305 | // "Send to ALL KNOWN remotes" is off, so drop that list rather than | ||
| 3306 | // leaving a stale copy behind for the next time it is turned on. | ||
| 3307 | 2 | m_unicastDestMsgs.clear(); | |
| 3308 | 2 | m_unicastDestAddr.clear(); | |
| 3309 | } | ||
| 3310 | 52 | } | |
| 3311 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | updateLock.unlock(); |
| 3312 | |||
| 3313 | // Rebuild the "all known remotes" list too: it dedupes itself against | ||
| 3314 | // m_destAddr, which just changed. Must run with both locks released -- | ||
| 3315 | // UpdateUnicastDestinations() snapshots the remote list under m_systemsLock | ||
| 3316 | // and then takes m_unicastUpdateLock and m_socketLock itself. | ||
| 3317 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2 times.
|
52 | if (sendUnicast) { |
| 3318 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
50 | UpdateUnicastDestinations(); |
| 3319 | } | ||
| 3320 | 52 | } | |
| 3321 | |||
| 3322 | // Malformed control packets come from whatever else is on the MultiSync port | ||
| 3323 | // (another program, an incompatible version), as fast as it sends them, and | ||
| 3324 | // each was logged with a hex dump: a line or more per packet. Log the first | ||
| 3325 | // few in each minute, then say how many more were ignored. | ||
| 3326 | static std::mutex badPacketLock; | ||
| 3327 | static long long badPacketWindowMS = 0; | ||
| 3328 | static int badPacketsLogged = 0; | ||
| 3329 | static int badPacketsSuppressed = 0; | ||
| 3330 | static constexpr int BAD_PACKETS_LOGGED_PER_MINUTE = 5; | ||
| 3331 | |||
| 3332 | 1216 | static bool ShouldLogBadPacket() { | |
| 3333 |
1/2✓ Branch 0 taken 1216 times.
✗ Branch 1 not taken.
|
1216 | std::lock_guard<std::mutex> l(badPacketLock); |
| 3334 |
1/2✓ Branch 0 taken 1216 times.
✗ Branch 1 not taken.
|
1216 | long long now = GetMonotonicTimeMS(); |
| 3335 |
3/4✓ Branch 0 taken 1212 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1212 times.
|
1216 | if (!badPacketWindowMS || now - badPacketWindowMS >= 60000) { |
| 3336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (badPacketsSuppressed) { |
| 3337 | ✗ | LogWarn(VB_SYNC, "%d more malformed MultiSync packets ignored in the last minute\n", badPacketsSuppressed); | |
| 3338 | } | ||
| 3339 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | badPacketWindowMS = now ? now : 1; |
| 3340 | 4 | badPacketsLogged = 0; | |
| 3341 | 4 | badPacketsSuppressed = 0; | |
| 3342 | } | ||
| 3343 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1196 times.
|
1216 | if (badPacketsLogged < BAD_PACKETS_LOGGED_PER_MINUTE) { |
| 3344 | 20 | badPacketsLogged++; | |
| 3345 | 20 | return true; | |
| 3346 | } | ||
| 3347 | 1196 | badPacketsSuppressed++; | |
| 3348 | 1196 | return false; | |
| 3349 | 1216 | } | |
| 3350 | |||
| 3351 | // Undelivered sync packets since the last log line about them, and when that | ||
| 3352 | // was (GetMonotonicTimeMS()). Guarded by m_socketLock; file-static rather | ||
| 3353 | // than members because MultiSync's layout is plugin ABI. A remote that is | ||
| 3354 | // gone stays gone: logging every failed packet wrote a line per sync packet | ||
| 3355 | // (several a second) to the SD card for the whole show. | ||
| 3356 | static int undeliveredSinceLog = 0; | ||
| 3357 | static long long undeliveredLoggedAt = 0; | ||
| 3358 | static constexpr long long UNDELIVERED_LOG_INTERVAL_MS = 60000; | ||
| 3359 | |||
| 3360 | // The same for the broadcast and multicast sends (ENOBUFS on Wi-Fi, an | ||
| 3361 | // interface that is down or firewalled): logged when it starts, then once a | ||
| 3362 | // minute with a count, rather than for every sync packet on every interface. | ||
| 3363 | // Callers hold m_socketLock. | ||
| 3364 | static int sendFailuresSinceLog = 0; | ||
| 3365 | static long long sendFailureLoggedAt = 0; | ||
| 3366 | |||
| 3367 | 232 | static void LogSendFailure(int err) { | |
| 3368 | 232 | sendFailuresSinceLog++; | |
| 3369 | 232 | long long now = GetMonotonicTimeMS(); | |
| 3370 |
3/4✓ Branch 0 taken 229 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 229 times.
|
232 | if (!sendFailureLoggedAt || now - sendFailureLoggedAt >= UNDELIVERED_LOG_INTERVAL_MS) { |
| 3371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | LogErr(VB_SYNC, "Error: Unable to send packet: %s (%d failed sends%s)\n", FPPstrerror(err), |
| 3372 | sendFailuresSinceLog, sendFailureLoggedAt ? " in the last minute" : ""); | ||
| 3373 | 3 | sendFailuresSinceLog = 0; | |
| 3374 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | sendFailureLoggedAt = now ? now : 1; |
| 3375 | } | ||
| 3376 | 232 | } | |
| 3377 | |||
| 3378 | // How long one sync send may keep retrying a destination whose socket buffer is | ||
| 3379 | // full, before skipping it. These sends run on the channel output thread ahead | ||
| 3380 | // of the frame's channel data, and under m_socketLock, which the main loop's | ||
| 3381 | // media sync sends also take -- so the bound covers both. See | ||
| 3382 | // SendControlPacketViaMsgs() for why a dropped sync packet is the cheap side. | ||
| 3383 | static constexpr long long SEND_BUDGET_MS = 2; | ||
| 3384 | |||
| 3385 | // One datagram, never blocking for longer than the budget left since startTime. | ||
| 3386 | // A blocking sendto() here once waited for good: Wi-Fi stopped transmitting | ||
| 3387 | // mid-show, the multicast socket's buffer filled, and the channel output thread | ||
| 3388 | // slept in sendto() holding m_socketLock while the main loop queued up behind | ||
| 3389 | // it -- all pixel output froze until a power cycle (issue #3072). | ||
| 3390 | // Returns 0, or the errno of the failed send. | ||
| 3391 | 9258 | static int SendDatagramBounded(int sock, const void* buf, int len, const struct sockaddr_in& addr, | |
| 3392 | long long startTime) { | ||
| 3393 | while (true) { | ||
| 3394 |
2/2✓ Branch 0 taken 7945 times.
✓ Branch 1 taken 1313 times.
|
9258 | if (sendto(sock, buf, len, MSG_DONTWAIT, (const struct sockaddr*)&addr, sizeof(addr)) >= 0) { |
| 3395 | 7945 | return 0; | |
| 3396 | } | ||
| 3397 | 1313 | int err = errno; | |
| 3398 |
4/6✓ Branch 0 taken 191 times.
✓ Branch 1 taken 1122 times.
✓ Branch 2 taken 191 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 191 times.
✗ Branch 5 not taken.
|
1313 | bool transient = err == EAGAIN || err == EWOULDBLOCK || err == ENOBUFS; |
| 3399 |
5/6✓ Branch 0 taken 1313 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 232 times.
✓ Branch 3 taken 1081 times.
✓ Branch 4 taken 232 times.
✓ Branch 5 taken 1081 times.
|
1313 | if (!transient || (GetMonotonicTimeMS() - startTime) >= SEND_BUDGET_MS) { |
| 3400 | 232 | return err; | |
| 3401 | } | ||
| 3402 |
1/2✓ Branch 0 taken 1081 times.
✗ Branch 1 not taken.
|
1081 | std::this_thread::sleep_for(std::chrono::microseconds(250)); |
| 3403 | 1081 | } | |
| 3404 | } | ||
| 3405 | |||
| 3406 | 2576 | void MultiSync::SendControlPacketViaMsgs(std::vector<struct mmsghdr>& msgs, struct iovec& iovec, void* outBuf, int len) { | |
| 3407 | // The msgs vector (and the sockaddrs its entries point at) may be rebuilt | ||
| 3408 | // concurrently by UpdateUnicastDestinations(), so read its size, point the | ||
| 3409 | // shared iovec at our buffer, and send all while holding m_socketLock. | ||
| 3410 |
1/2✓ Branch 0 taken 2576 times.
✗ Branch 1 not taken.
|
2576 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3411 | 2576 | int msgCount = msgs.size(); | |
| 3412 |
2/2✓ Branch 0 taken 1699 times.
✓ Branch 1 taken 877 times.
|
2576 | if (msgCount == 0) { |
| 3413 | 1699 | return; | |
| 3414 | } | ||
| 3415 | 877 | iovec.iov_base = outBuf; | |
| 3416 | 877 | iovec.iov_len = len; | |
| 3417 | |||
| 3418 | // sendmmsg stops at the first message it cannot send and reports how many | ||
| 3419 | // it did send, so each pass simply resumes at the destination that stopped | ||
| 3420 | // it. | ||
| 3421 | // | ||
| 3422 | // This runs on the channel output thread ahead of the frame's channel data, | ||
| 3423 | // so the whole call is bounded well inside a frame. The bound matters more | ||
| 3424 | // than it looks: a remote that has dropped off the LAN leaves its neighbour | ||
| 3425 | // entry unresolved, and the kernel then answers sends to it with EAGAIN | ||
| 3426 | // (not EHOSTUNREACH) for as long as it is gone - measured here at ~97% of | ||
| 3427 | // sends. Retrying that for long turns one dead remote into a per-frame | ||
| 3428 | // stall for every controller, which is exactly what the budget prevents. | ||
| 3429 | // A skipped sync packet is cheap by comparison: the next frame sends another. | ||
| 3430 | 877 | int outputCount = 0; | |
| 3431 | 877 | int undelivered = 0; | |
| 3432 | // monotonic: on the wall clock a step back during the budget kept this | ||
| 3433 | // loop retrying, on the channel output thread, for the size of the step | ||
| 3434 |
1/2✓ Branch 0 taken 877 times.
✗ Branch 1 not taken.
|
877 | long long startTime = GetMonotonicTimeMS(); |
| 3435 |
2/2✓ Branch 0 taken 909 times.
✓ Branch 1 taken 877 times.
|
1786 | while (outputCount < msgCount) { |
| 3436 |
1/2✓ Branch 0 taken 909 times.
✗ Branch 1 not taken.
|
909 | int sent = sendmmsg(m_controlSock, &msgs[outputCount], msgCount - outputCount, MSG_DONTWAIT); |
| 3437 |
2/2✓ Branch 0 taken 858 times.
✓ Branch 1 taken 51 times.
|
909 | if (sent > 0) { |
| 3438 | 858 | outputCount += sent; | |
| 3439 | 858 | continue; | |
| 3440 | } | ||
| 3441 |
4/8✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 51 times.
|
51 | bool transient = (sent == 0) || errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS; |
| 3442 |
2/8✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 51 times.
|
51 | if (transient && (GetMonotonicTimeMS() - startTime) < SEND_BUDGET_MS) { |
| 3443 | // Genuine buffer pressure clears in well under the budget. | ||
| 3444 | ✗ | std::this_thread::sleep_for(std::chrono::microseconds(250)); | |
| 3445 | ✗ | continue; | |
| 3446 | } | ||
| 3447 | // Either a hard error for this destination, or it is still refusing the | ||
| 3448 | // packet after the budget. Step past it rather than retrying or | ||
| 3449 | // bailing out entirely, so the remaining healthy remotes still get this | ||
| 3450 | // frame's packet - one unreachable remote must not desync the rest. | ||
| 3451 | 51 | ++outputCount; | |
| 3452 | 51 | ++undelivered; | |
| 3453 | } | ||
| 3454 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 826 times.
|
877 | if (undelivered) { |
| 3455 | 51 | int err = errno; | |
| 3456 | 51 | undeliveredSinceLog += undelivered; | |
| 3457 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | long long now = GetMonotonicTimeMS(); |
| 3458 |
3/4✓ Branch 0 taken 48 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
|
51 | if (!undeliveredLoggedAt || now - undeliveredLoggedAt >= UNDELIVERED_LOG_INTERVAL_MS) { |
| 3459 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | LogErr(VB_SYNC, "Error: Unable to send multisync packet: %s (%d/%d sent; %d undelivered %s)\n", |
| 3460 | FPPstrerror(err), msgCount - undelivered, msgCount, undeliveredSinceLog, | ||
| 3461 | undeliveredLoggedAt ? "in the last minute" : ""); | ||
| 3462 | 3 | undeliveredSinceLog = 0; | |
| 3463 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | undeliveredLoggedAt = now ? now : 1; |
| 3464 | } | ||
| 3465 | } | ||
| 3466 |
2/2✓ Branch 0 taken 877 times.
✓ Branch 1 taken 1699 times.
|
2576 | } |
| 3467 | |||
| 3468 | // A broadcast is looped back to this host's own sockets (multicast is not: | ||
| 3469 | // IP_MULTICAST_LOOP is off). An FPP command sent to all hosts is already run | ||
| 3470 | // locally by its sender, and plugin data is meant for the other hosts, so the | ||
| 3471 | // copy that comes back must not be dispatched a second time. Remember what | ||
| 3472 | // was just sent and drop the matching echo. Only those two types: other | ||
| 3473 | // local senders (scripts, tools, tests on this box) still get through. | ||
| 3474 | static std::mutex s_ownSendsLock; | ||
| 3475 | static std::deque<std::pair<size_t, long long>> s_ownSends; // hash, monotonic ms | ||
| 3476 | |||
| 3477 | 11825 | static bool IsEchoCandidate(const void* buf, int len) { | |
| 3478 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11825 times.
|
11825 | if (len < (int)sizeof(ControlPkt)) { |
| 3479 | ✗ | return false; | |
| 3480 | } | ||
| 3481 | 11825 | uint8_t type = ((const ControlPkt*)buf)->pktType; | |
| 3482 |
3/4✓ Branch 0 taken 11813 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11813 times.
|
11825 | return type == CTRL_PKT_FPPCOMMAND || type == CTRL_PKT_PLUGIN; |
| 3483 | } | ||
| 3484 | 18 | static size_t HashPacket(const void* buf, int len) { | |
| 3485 | 18 | return std::hash<std::string_view>{}(std::string_view((const char*)buf, len)); | |
| 3486 | } | ||
| 3487 | 9 | static void RememberOwnSend(const void* buf, int len) { | |
| 3488 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | long long now = GetMonotonicTimeMS(); |
| 3489 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | std::lock_guard<std::mutex> lock(s_ownSendsLock); |
| 3490 |
5/8✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
|
9 | while (!s_ownSends.empty() && (s_ownSends.size() >= 64 || now - s_ownSends.front().second > 2000)) { |
| 3491 | ✗ | s_ownSends.pop_front(); | |
| 3492 | } | ||
| 3493 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | s_ownSends.emplace_back(HashPacket(buf, len), now); |
| 3494 | 9 | } | |
| 3495 | 9 | static bool IsOwnEcho(const void* buf, int len) { | |
| 3496 | 9 | size_t h = HashPacket(buf, len); | |
| 3497 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | long long now = GetMonotonicTimeMS(); |
| 3498 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | std::lock_guard<std::mutex> lock(s_ownSendsLock); |
| 3499 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | for (auto it = s_ownSends.begin(); it != s_ownSends.end(); ++it) { |
| 3500 |
3/6✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
9 | if (it->first == h && now - it->second <= 2000) { |
| 3501 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | s_ownSends.erase(it); |
| 3502 | 9 | return true; | |
| 3503 | } | ||
| 3504 | } | ||
| 3505 | ✗ | return false; | |
| 3506 | 9 | } | |
| 3507 | |||
| 3508 | 1304 | void MultiSync::SendControlPacket(void* outBuf, int len) { | |
| 3509 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1304 times.
|
1304 | if (WillLog(LOG_EXCESSIVE, VB_SYNC)) { |
| 3510 | ✗ | LogExcess(VB_SYNC, "SendControlPacket()\n"); | |
| 3511 | ✗ | HexDump("Sending Control packet with contents:", outBuf, len, VB_SYNC); | |
| 3512 | } | ||
| 3513 | |||
| 3514 | // Statically-configured unicast remotes (MultiSyncRemotes/ExtraRemotes). | ||
| 3515 | 1304 | SendControlPacketViaMsgs(m_destMsgs, m_destIovec, outBuf, len); | |
| 3516 | |||
| 3517 | // All known FPP remotes in Remote mode (MultiSyncUnicast setting). | ||
| 3518 |
2/2✓ Branch 0 taken 1272 times.
✓ Branch 1 taken 32 times.
|
1304 | if (m_sendUnicast) { |
| 3519 | 1272 | SendControlPacketViaMsgs(m_unicastDestMsgs, m_unicastDestIovec, outBuf, len); | |
| 3520 | } | ||
| 3521 |
2/2✓ Branch 0 taken 398 times.
✓ Branch 1 taken 906 times.
|
1304 | if (m_sendMulticast) { |
| 3522 | 398 | SendMulticastPacket(outBuf, len); | |
| 3523 | } | ||
| 3524 |
2/2✓ Branch 0 taken 370 times.
✓ Branch 1 taken 934 times.
|
1304 | if (m_sendBroadcast) { |
| 3525 | 370 | SendBroadcastPacket(outBuf, len); | |
| 3526 | } | ||
| 3527 | 1304 | } | |
| 3528 | |||
| 3529 | 50 | void MultiSync::UpdateUnicastDestinations() { | |
| 3530 | // Snapshot the addresses to resolve while holding m_systemsLock only | ||
| 3531 | // briefly, then release it before the rebuild. The rebuild takes | ||
| 3532 | // m_unicastUpdateLock, which must never be acquired while m_systemsLock is | ||
| 3533 | // held (see the overload below), so the snapshot and the rebuild cannot | ||
| 3534 | // share a lock scope. | ||
| 3535 | 50 | std::vector<std::string> addrsToResolve; | |
| 3536 | { | ||
| 3537 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
50 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 3538 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 50 times.
|
54 | for (auto& sys : m_remoteSystems) { |
| 3539 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | if (sys.supportsUnicast) { |
| 3540 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | addrsToResolve.push_back(sys.address); |
| 3541 | } | ||
| 3542 | } | ||
| 3543 | 50 | } | |
| 3544 |
1/2✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
|
50 | UpdateUnicastDestinations(addrsToResolve); |
| 3545 | 50 | } | |
| 3546 | |||
| 3547 | 54 | void MultiSync::UpdateUnicastDestinations(const std::vector<std::string>& addrsToResolve) { | |
| 3548 | // Serialize rebuilds against each other -- DNS resolution below happens | ||
| 3549 | // without any other lock held, so without this, two overlapping calls could | ||
| 3550 | // interleave and the slower resolution could finish last and clobber a | ||
| 3551 | // newer result. Callers must not hold m_systemsLock here: ReloadSyncDestinations() | ||
| 3552 | // holds this lock and its tail reaches m_systemsLock through the no-arg | ||
| 3553 | // overload, so taking the two in the other order would deadlock. | ||
| 3554 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | std::unique_lock<std::mutex> updateLock(m_unicastUpdateLock); |
| 3555 | |||
| 3556 | // getaddrinfo() (via GetIPForHost()) is an unbounded, potentially slow | ||
| 3557 | // DNS/mDNS lookup, which is why the caller resolves from a snapshot rather | ||
| 3558 | // than iterating m_remoteSystems here: resolving under m_systemsLock used to | ||
| 3559 | // stall every other m_systemsLock caller (notably the frequently-polled | ||
| 3560 | // GetSystems()) for as long as the lookup took. GetIPForHost() itself is | ||
| 3561 | // reentrant/thread-safe, so it's fine to call without any MultiSync lock held. | ||
| 3562 | // Optional subnet filter: with one set, only remotes inside it are | ||
| 3563 | // unicast to. Empty (the default) means every known remote. If no | ||
| 3564 | // entry parses, the filter is treated as unset rather than silencing | ||
| 3565 | // every remote over a typo. | ||
| 3566 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | auto subnetFilter = ParseUnicastSubnetFilter(); |
| 3567 | 54 | std::vector<struct sockaddr_in> newAddrs; | |
| 3568 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 54 times.
|
62 | for (auto& address : addrsToResolve) { |
| 3569 | struct sockaddr_in addr; | ||
| 3570 | 8 | memset(&addr, 0, sizeof(addr)); | |
| 3571 | 8 | addr.sin_family = AF_INET; | |
| 3572 | 8 | addr.sin_port = htons(FPP_CTRL_PORT); | |
| 3573 | |||
| 3574 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | std::string ipAd = address; |
| 3575 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 | if (GetIPForHost(ipAd)) { |
| 3576 | 8 | addr.sin_addr.s_addr = inet_addr(ipAd.c_str()); | |
| 3577 | } else { | ||
| 3578 | ✗ | addr.sin_addr.s_addr = inet_addr(address.c_str()); | |
| 3579 | } | ||
| 3580 | // Skip anything that didn't resolve to a usable IPv4 address | ||
| 3581 | // (e.g. an IPv6-only peer); sockaddr_in can't represent it. | ||
| 3582 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | if (addr.sin_addr.s_addr == INADDR_NONE || addr.sin_addr.s_addr == 0) { |
| 3583 | ✗ | continue; | |
| 3584 | } | ||
| 3585 |
4/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
|
13 | if (!subnetFilter.empty() && |
| 3586 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
|
5 | std::none_of(subnetFilter.begin(), subnetFilter.end(), [&addr](const auto& f) { |
| 3587 | 5 | return (addr.sin_addr.s_addr & f.second) == f.first; | |
| 3588 | })) { | ||
| 3589 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_SYNC, "Not unicasting MultiSync to %s: outside MultiSyncUnicastSubnets\n", |
| 3590 | address.c_str()); | ||
| 3591 | 2 | continue; | |
| 3592 | } | ||
| 3593 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | newAddrs.push_back(addr); |
| 3594 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
|
8 | } |
| 3595 | |||
| 3596 | // Build the new sockaddr list, then swap it into place under m_socketLock. | ||
| 3597 | // m_socketLock is the innermost lock here and is never held while acquiring | ||
| 3598 | // m_systemsLock, matching the m_systemsLock -> m_socketLock order used by Ping(). | ||
| 3599 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3600 | // Skip any address already covered by the statically-configured remote list | ||
| 3601 | // (m_destAddr, rebuilt by ReloadSyncDestinations(), which holds the same | ||
| 3602 | // m_unicastUpdateLock we hold here while it swaps) so | ||
| 3603 | // a remote that is both individually selected for unicast AND picked up by | ||
| 3604 | // "all known remotes" only receives each packet once. The same set also | ||
| 3605 | // dedupes the all-known list against itself (e.g. a remote known under both | ||
| 3606 | // a hostname and an IP). | ||
| 3607 | 54 | std::set<uint32_t> seen; | |
| 3608 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 54 times.
|
106 | for (auto& s : m_destAddr) { |
| 3609 |
1/2✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
|
52 | seen.insert(s.sin_addr.s_addr); |
| 3610 | } | ||
| 3611 | 54 | m_unicastDestAddr.clear(); | |
| 3612 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | m_unicastDestAddr.reserve(newAddrs.size()); |
| 3613 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 54 times.
|
60 | for (auto& addr : newAddrs) { |
| 3614 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | if (seen.insert(addr.sin_addr.s_addr).second) { |
| 3615 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | m_unicastDestAddr.push_back(addr); |
| 3616 | } | ||
| 3617 | } | ||
| 3618 | 54 | m_unicastDestMsgs.clear(); | |
| 3619 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | m_unicastDestMsgs.reserve(m_unicastDestAddr.size()); |
| 3620 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 54 times.
|
60 | for (size_t x = 0; x < m_unicastDestAddr.size(); x++) { |
| 3621 | struct mmsghdr msg; | ||
| 3622 | 6 | memset(&msg, 0, sizeof(msg)); | |
| 3623 | 6 | msg.msg_hdr.msg_name = &m_unicastDestAddr[x]; | |
| 3624 | 6 | msg.msg_hdr.msg_namelen = sizeof(sockaddr_in); | |
| 3625 | 6 | msg.msg_hdr.msg_iov = &m_unicastDestIovec; | |
| 3626 | 6 | msg.msg_hdr.msg_iovlen = 1; | |
| 3627 | 6 | msg.msg_len = 0; | |
| 3628 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | m_unicastDestMsgs.push_back(msg); |
| 3629 | } | ||
| 3630 |
1/2✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
|
54 | LogDebug(VB_SYNC, "%d unicast MultiSync destinations (all known remotes)\n", |
| 3631 | (int)m_unicastDestMsgs.size()); | ||
| 3632 | 54 | } | |
| 3633 | 5635 | void MultiSync::SendBroadcastPacket(void* outBuf, int len) { | |
| 3634 |
2/4✓ Branch 0 taken 5635 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5635 times.
|
5635 | if (WillLog(LOG_EXCESSIVE, VB_SYNC)) { |
| 3635 | ✗ | HexDump("Sending Broadcast packet with contents:", outBuf, len, VB_SYNC); | |
| 3636 | } | ||
| 3637 | |||
| 3638 | 5635 | bool echoes = IsEchoCandidate(outBuf, len); | |
| 3639 |
1/2✓ Branch 0 taken 5635 times.
✗ Branch 1 not taken.
|
5635 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3640 |
1/2✓ Branch 0 taken 5635 times.
✗ Branch 1 not taken.
|
5635 | long long startTime = GetMonotonicTimeMS(); |
| 3641 |
2/2✓ Branch 0 taken 6565 times.
✓ Branch 1 taken 5635 times.
|
12200 | for (auto& a : m_interfaces) { |
| 3642 | struct sockaddr_in bda; | ||
| 3643 | 6565 | memset((void*)&bda, 0, sizeof(struct sockaddr_in)); | |
| 3644 | 6565 | bda.sin_family = AF_INET; | |
| 3645 | 6565 | bda.sin_port = htons(FPP_CTRL_PORT); | |
| 3646 | 6565 | bda.sin_addr.s_addr = a.second.broadcastAddress; | |
| 3647 | |||
| 3648 | // One datagram per interface, and each comes back to us: remember | ||
| 3649 | // each one, or the second interface's echo runs the command again. | ||
| 3650 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6556 times.
|
6565 | if (echoes) { |
| 3651 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | RememberOwnSend(outBuf, len); |
| 3652 | } | ||
| 3653 | |||
| 3654 |
3/4✓ Branch 0 taken 6565 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 6533 times.
|
6565 | if (int err = SendDatagramBounded(m_broadcastSock, outBuf, len, bda, startTime)) |
| 3655 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | LogSendFailure(err); |
| 3656 | } | ||
| 3657 | 5635 | } | |
| 3658 | 807 | void MultiSync::SendMulticastPacket(void* outBuf, int len) { | |
| 3659 |
1/2✓ Branch 0 taken 807 times.
✗ Branch 1 not taken.
|
807 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3660 |
1/2✓ Branch 0 taken 807 times.
✗ Branch 1 not taken.
|
807 | long long startTime = GetMonotonicTimeMS(); |
| 3661 |
2/2✓ Branch 0 taken 1612 times.
✓ Branch 1 taken 807 times.
|
2419 | for (auto& a : m_interfaces) { |
| 3662 | struct sockaddr_in bda; | ||
| 3663 | 1612 | memset((void*)&bda, 0, sizeof(struct sockaddr_in)); | |
| 3664 | 1612 | bda.sin_family = AF_INET; | |
| 3665 | 1612 | bda.sin_port = htons(FPP_CTRL_PORT); | |
| 3666 | 1612 | bda.sin_addr.s_addr = MULTISYNC_MULTICAST_ADD; | |
| 3667 | |||
| 3668 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 1384 times.
|
1612 | if (a.second.multicastSocket == -1) { |
| 3669 | // create the socket | ||
| 3670 | 228 | a.second.multicastSocket = OpenSocket(AF_INET, SOCK_DGRAM, 0); | |
| 3671 | |||
| 3672 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (a.second.multicastSocket < 0) { |
| 3673 | ✗ | LogErr(VB_SYNC, "Error opening Multicast socket for %s\n", a.second.interfaceName.c_str()); | |
| 3674 | } else { | ||
| 3675 | 228 | char loopch = 0; | |
| 3676 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (setsockopt(a.second.multicastSocket, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&loopch, sizeof(loopch)) < 0) { |
| 3677 | ✗ | LogErr(VB_SYNC, "Error setting IP_MULTICAST_LOOP for %s: %s\n", a.second.interfaceName.c_str(), FPPstrerror(errno)); | |
| 3678 | } | ||
| 3679 | #ifdef PLATFORM_OSX | ||
| 3680 | int idx = if_nametoindex(a.second.interfaceName.c_str()); | ||
| 3681 | if (setsockopt(a.second.multicastSocket, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)) < 0) { | ||
| 3682 | LogErr(VB_SYNC, "Error setting IP_MULTICAST Device for %s: %s\n", a.second.interfaceName.c_str(), FPPstrerror(errno)); | ||
| 3683 | } | ||
| 3684 | #else | ||
| 3685 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 227 times.
|
228 | if (setsockopt(a.second.multicastSocket, SOL_SOCKET, SO_BINDTODEVICE, a.second.interfaceName.c_str(), a.second.interfaceName.size()) < 0) { |
| 3686 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | LogErr(VB_SYNC, "Error setting IP_MULTICAST Device for %s: %s\n", a.second.interfaceName.c_str(), FPPstrerror(errno)); |
| 3687 | } | ||
| 3688 | #endif | ||
| 3689 | } | ||
| 3690 | } | ||
| 3691 | |||
| 3692 |
1/2✓ Branch 0 taken 1612 times.
✗ Branch 1 not taken.
|
1612 | if (a.second.multicastSocket >= 0) { |
| 3693 |
3/4✓ Branch 0 taken 1612 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
✓ Branch 3 taken 1412 times.
|
1612 | if (int err = SendDatagramBounded(a.second.multicastSocket, outBuf, len, bda, startTime)) |
| 3694 |
1/2✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
|
200 | LogSendFailure(err); |
| 3695 | } | ||
| 3696 | } | ||
| 3697 | 807 | } | |
| 3698 | 81 | void MultiSync::SendUnicastPacket(const std::string& address, void* outBuf, int len) { | |
| 3699 |
2/4✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 81 times.
|
81 | if (WillLog(LOG_EXCESSIVE, VB_SYNC)) { |
| 3700 | ✗ | LogExcess(VB_SYNC, "SendControlPacket()\n"); | |
| 3701 | ✗ | HexDump("Sending Control packet with contents:", outBuf, len, VB_SYNC); | |
| 3702 | } | ||
| 3703 | struct sockaddr_in dest_addr; | ||
| 3704 | 81 | memset(&dest_addr, 0, sizeof(dest_addr)); | |
| 3705 | 81 | dest_addr.sin_family = AF_INET; | |
| 3706 | |||
| 3707 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | std::string ipAd = address; |
| 3708 |
3/4✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73 times.
✓ Branch 3 taken 8 times.
|
81 | if (GetIPForHost(ipAd)) { |
| 3709 | 73 | dest_addr.sin_addr.s_addr = inet_addr(ipAd.c_str()); | |
| 3710 | } else { | ||
| 3711 | 8 | dest_addr.sin_addr.s_addr = inet_addr(address.c_str()); | |
| 3712 | } | ||
| 3713 | 81 | dest_addr.sin_port = htons(FPP_CTRL_PORT); | |
| 3714 |
1/2✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
|
81 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3715 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 70 times.
|
81 | if (m_controlSock >= 0) { |
| 3716 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | sendto(m_controlSock, outBuf, len, MSG_DONTWAIT, (struct sockaddr*)&dest_addr, sizeof(dest_addr)); |
| 3717 | } else { | ||
| 3718 | 70 | int uSock = OpenSocket(AF_INET, SOCK_DGRAM, 0); | |
| 3719 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (uSock < 0) { |
| 3720 | ✗ | LogErr(VB_SYNC, "Error opening Unicast socket\n"); | |
| 3721 | ✗ | return; | |
| 3722 | } | ||
| 3723 | |||
| 3724 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | sendto(uSock, outBuf, len, MSG_DONTWAIT, (struct sockaddr*)&dest_addr, sizeof(dest_addr)); |
| 3725 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | close(uSock); |
| 3726 | } | ||
| 3727 |
2/4✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
|
81 | } |
| 3728 | |||
| 3729 | 4189 | bool MultiSync::FillInInterfaces() { | |
| 3730 | struct ifaddrs *interfaces, *tmp; | ||
| 3731 | 4189 | getifaddrs(&interfaces); | |
| 3732 | 4189 | tmp = interfaces; | |
| 3733 | |||
| 3734 | 4189 | bool change = false; | |
| 3735 | // An interface can hold its 169.254 fallback and a DHCP/static address at | ||
| 3736 | // the same time. Only one is kept per interface, so prefer the routable | ||
| 3737 | // one, whatever order getifaddrs() lists them in. | ||
| 3738 | 4189 | std::set<std::string> haveRoutable; | |
| 3739 | |||
| 3740 |
1/2✓ Branch 0 taken 4189 times.
✗ Branch 1 not taken.
|
4189 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3741 | 4189 | std::map<std::string, std::string> before; | |
| 3742 |
2/2✓ Branch 0 taken 2730 times.
✓ Branch 1 taken 4189 times.
|
6919 | for (auto& [name, info] : m_interfaces) { |
| 3743 |
2/4✓ Branch 0 taken 2730 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2730 times.
✗ Branch 3 not taken.
|
2730 | before[name] = info.interfaceAddress; |
| 3744 | } | ||
| 3745 |
2/2✓ Branch 0 taken 22573 times.
✓ Branch 1 taken 4189 times.
|
26762 | while (tmp) { |
| 3746 |
4/4✓ Branch 0 taken 22571 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8723 times.
✓ Branch 3 taken 13848 times.
|
22573 | if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) { |
| 3747 | // Check if interface is UP and RUNNING before adding it | ||
| 3748 |
1/2✓ Branch 0 taken 8723 times.
✗ Branch 1 not taken.
|
8723 | if (isSupportedForMultisync("", tmp->ifa_name) && |
| 3749 |
6/6✓ Branch 0 taken 4529 times.
✓ Branch 1 taken 4194 times.
✓ Branch 2 taken 4525 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4525 times.
✓ Branch 5 taken 4198 times.
|
13248 | (tmp->ifa_flags & IFF_UP) && |
| 3750 |
1/2✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
|
4525 | (tmp->ifa_flags & IFF_RUNNING)) { |
| 3751 | // skip the usb* interfaces as we won't support multisync on those | ||
| 3752 | #ifdef PLATFORM_OSX | ||
| 3753 | struct sockaddr_in* ba = (struct sockaddr_in*)(tmp->ifa_dstaddr); | ||
| 3754 | #else | ||
| 3755 | 4525 | struct sockaddr_in* ba = (struct sockaddr_in*)(tmp->ifa_ifu.ifu_broadaddr); | |
| 3756 | #endif | ||
| 3757 | 4525 | struct sockaddr_in* sa = (struct sockaddr_in*)(tmp->ifa_addr); | |
| 3758 | 4525 | char abuf[INET_ADDRSTRLEN] = {0}; | |
| 3759 | 4525 | inet_ntop(AF_INET, &sa->sin_addr, abuf, sizeof(abuf)); | |
| 3760 |
8/30✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4525 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4525 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4525 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 4525 times.
✓ Branch 16 taken 4525 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 4525 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 4525 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
|
13575 | if (IsIPv4LinkLocal(abuf) && haveRoutable.contains(tmp->ifa_name)) { |
| 3761 | ✗ | tmp = tmp->ifa_next; | |
| 3762 | ✗ | continue; | |
| 3763 | } | ||
| 3764 |
3/6✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4525 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4525 times.
✗ Branch 5 not taken.
|
9050 | if (!IsIPv4LinkLocal(abuf)) { |
| 3765 |
2/4✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4525 times.
✗ Branch 3 not taken.
|
9050 | haveRoutable.insert(tmp->ifa_name); |
| 3766 | } | ||
| 3767 | |||
| 3768 |
2/4✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4525 times.
✗ Branch 3 not taken.
|
9050 | NetInterfaceInfo& info = m_interfaces[tmp->ifa_name]; |
| 3769 |
1/2✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
|
4525 | change |= info.interfaceName == ""; |
| 3770 |
1/2✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
|
4525 | info.interfaceName = tmp->ifa_name; |
| 3771 |
1/2✓ Branch 0 taken 4525 times.
✗ Branch 1 not taken.
|
4525 | info.interfaceAddress = abuf; |
| 3772 | 4525 | info.address = sa->sin_addr.s_addr; | |
| 3773 | 4525 | info.broadcastAddress = ba->sin_addr.s_addr; | |
| 3774 | } | ||
| 3775 |
1/2✓ Branch 0 taken 13848 times.
✗ Branch 1 not taken.
|
13848 | } else if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) { |
| 3776 | // FIXME for ipv6 multisync | ||
| 3777 | } | ||
| 3778 | 22573 | tmp = tmp->ifa_next; | |
| 3779 | } | ||
| 3780 | 4189 | freeifaddrs(interfaces); | |
| 3781 |
2/2✓ Branch 0 taken 5481 times.
✓ Branch 1 taken 4189 times.
|
9670 | for (auto& [name, info] : m_interfaces) { |
| 3782 |
1/2✓ Branch 0 taken 5481 times.
✗ Branch 1 not taken.
|
5481 | auto it = before.find(name); |
| 3783 |
4/4✓ Branch 0 taken 2730 times.
✓ Branch 1 taken 2751 times.
✓ Branch 2 taken 165 times.
✓ Branch 3 taken 2565 times.
|
5481 | change |= it == before.end() || it->second != info.interfaceAddress; |
| 3784 | } | ||
| 3785 | 4189 | return change; | |
| 3786 | 4189 | } | |
| 3787 | 804 | bool MultiSync::RemoveInterface(const std::string& interface) { | |
| 3788 |
1/2✓ Branch 0 taken 804 times.
✗ Branch 1 not taken.
|
804 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3789 |
1/2✓ Branch 0 taken 804 times.
✗ Branch 1 not taken.
|
804 | auto it = m_interfaces.find(interface); |
| 3790 |
2/2✓ Branch 0 taken 265 times.
✓ Branch 1 taken 539 times.
|
804 | if (it != m_interfaces.end()) { |
| 3791 |
1/2✓ Branch 0 taken 265 times.
✗ Branch 1 not taken.
|
265 | LogDebug(VB_SYNC, "Removing interface %s - %s\n", it->second.interfaceName.c_str(), it->second.interfaceAddress.c_str()); |
| 3792 | |||
| 3793 | struct ip_mreq mreq; | ||
| 3794 | 265 | memset(&mreq, 0, sizeof(mreq)); | |
| 3795 | 265 | mreq.imr_multiaddr.s_addr = inet_addr(MULTISYNC_MULTICAST_ADDRESS); | |
| 3796 | 265 | mreq.imr_interface.s_addr = it->second.address; | |
| 3797 | 265 | int rc = 0; | |
| 3798 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 247 times.
|
265 | if ((rc = setsockopt(m_receiveSock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq))) < 0) { |
| 3799 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | LogDebug(VB_SYNC, " Did not drop Multicast membership for interface %s - %s\n", it->second.interfaceName.c_str(), it->second.interfaceAddress.c_str()); |
| 3800 | } | ||
| 3801 |
1/2✓ Branch 0 taken 265 times.
✗ Branch 1 not taken.
|
265 | m_interfaces.erase(it); |
| 3802 | 265 | return true; | |
| 3803 | } | ||
| 3804 | 539 | return false; | |
| 3805 | 804 | } | |
| 3806 | |||
| 3807 | /* | ||
| 3808 | * | ||
| 3809 | */ | ||
| 3810 | 7061 | void MultiSync::InitControlPacket(ControlPkt* pkt) { | |
| 3811 | 7061 | bzero(pkt, sizeof(ControlPkt)); | |
| 3812 | |||
| 3813 | 7061 | pkt->fppd[0] = 'F'; | |
| 3814 | 7061 | pkt->fppd[1] = 'P'; | |
| 3815 | 7061 | pkt->fppd[2] = 'P'; | |
| 3816 | 7061 | pkt->fppd[3] = 'D'; | |
| 3817 | 7061 | pkt->pktType = 0; | |
| 3818 | 7061 | pkt->extraDataLen = 0; | |
| 3819 | 7061 | } | |
| 3820 | |||
| 3821 | /* | ||
| 3822 | * | ||
| 3823 | */ | ||
| 3824 | 2652 | int MultiSync::OpenReceiveSocket(void) { | |
| 3825 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | LogDebug(VB_SYNC, "OpenReceiveSocket()\n"); |
| 3826 | |||
| 3827 | int UniverseOctet[2]; | ||
| 3828 | int i; | ||
| 3829 | char strMulticastGroup[16]; | ||
| 3830 | |||
| 3831 | /* set up socket */ | ||
| 3832 | 2652 | m_receiveSock = OpenSocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); | |
| 3833 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2652 times.
|
2652 | if (m_receiveSock < 0) { |
| 3834 | ✗ | LogErr(VB_SYNC, "Error opening Receive socket; %s\n", FPPstrerror(errno)); | |
| 3835 | ✗ | WarningHolder::AddWarning(42, "MultiSync: could not open receive socket"); | |
| 3836 | ✗ | return 0; | |
| 3837 | } | ||
| 3838 |
1/2✓ Branch 0 taken 2652 times.
✗ Branch 1 not taken.
|
2652 | LogDebug(VB_SYNC, "Receive socket: %d\n", m_receiveSock); |
| 3839 | |||
| 3840 | // The default buffer (212992 bytes) holds about 166 datagrams -- each | ||
| 3841 | // costs ~1.3KB of it whatever its size -- so any stall of the main loop | ||
| 3842 | // (an output reload, a burst of pings from a large show) dropped sync and | ||
| 3843 | // ping packets in the kernel. 1MB (the kernel doubles it) holds ~1600. | ||
| 3844 | // A plain SO_RCVBUF is clamped to rmem_max, which only fppinit raises (to | ||
| 3845 | // 8MB): where it hasn't run, the request came back at the default. So | ||
| 3846 | // force it first, as the bridge sockets do (fppd runs as root). | ||
| 3847 | 2652 | int rcvBuf = 1024 * 1024; | |
| 3848 | 2652 | bool forced = false; | |
| 3849 | #ifdef SO_RCVBUFFORCE | ||
| 3850 | 2652 | forced = setsockopt(m_receiveSock, SOL_SOCKET, SO_RCVBUFFORCE, &rcvBuf, sizeof(rcvBuf)) == 0; | |
| 3851 | #endif | ||
| 3852 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 2652 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2652 times.
|
2652 | if (!forced && setsockopt(m_receiveSock, SOL_SOCKET, SO_RCVBUF, &rcvBuf, sizeof(rcvBuf)) < 0) { |
| 3853 | ✗ | LogWarn(VB_SYNC, "Error setting SO_RCVBUF on the receive socket; %s\n", FPPstrerror(errno)); | |
| 3854 | } | ||
| 3855 | |||
| 3856 | 2652 | bzero((char*)&m_receiveSrcAddr, sizeof(m_receiveSrcAddr)); | |
| 3857 | 2652 | m_receiveSrcAddr.sin_family = AF_INET; | |
| 3858 | 2652 | m_receiveSrcAddr.sin_addr.s_addr = htonl(INADDR_ANY); | |
| 3859 | 2652 | m_receiveSrcAddr.sin_port = htons(FPP_CTRL_PORT); | |
| 3860 | |||
| 3861 | 2652 | int optval = 1; | |
| 3862 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2652 times.
|
2652 | if (setsockopt(m_receiveSock, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0) { |
| 3863 | ✗ | LogErr(VB_SYNC, "Error turning on SO_REUSEPORT; %s\n", FPPstrerror(errno)); | |
| 3864 | ✗ | return 0; | |
| 3865 | } | ||
| 3866 | |||
| 3867 | // Bind the socket to address/port | ||
| 3868 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2651 times.
|
2652 | if (bind(m_receiveSock, (struct sockaddr*)&m_receiveSrcAddr, sizeof(m_receiveSrcAddr)) < 0) { |
| 3869 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | LogErr(VB_SYNC, "Error binding socket; %s\n", FPPstrerror(errno)); |
| 3870 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 | WarningHolder::AddWarning(42, "MultiSync: could not bind receive socket (port in use?)"); |
| 3871 | 1 | return 0; | |
| 3872 | } | ||
| 3873 | |||
| 3874 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
|
2651 | if (setsockopt(m_receiveSock, IPPROTO_IP, IP_PKTINFO, &optval, sizeof(optval)) < 0) { |
| 3875 | ✗ | LogErr(VB_SYNC, "Error calling setsockopt; %s\n", FPPstrerror(errno)); | |
| 3876 | ✗ | return 0; | |
| 3877 | } | ||
| 3878 | |||
| 3879 |
3/4✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 2590 times.
|
2651 | if (getFPPmode() == REMOTE_MODE) { |
| 3880 |
1/2✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
|
61 | int remoteOffsetInt = getSettingInt("remoteOffset"); |
| 3881 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 60 times.
|
61 | if (remoteOffsetInt) |
| 3882 | 1 | m_remoteOffset = (float)remoteOffsetInt * -0.001; | |
| 3883 | else | ||
| 3884 | 60 | m_remoteOffset = 0.0; | |
| 3885 | |||
| 3886 |
1/2✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
|
61 | LogDebug(VB_SYNC, "Using remoteOffset of %.3f\n", m_remoteOffset); |
| 3887 | } | ||
| 3888 | |||
| 3889 | 2651 | memset(rcvMsgs, 0, sizeof(rcvMsgs)); | |
| 3890 |
2/2✓ Branch 0 taken 31812 times.
✓ Branch 1 taken 2651 times.
|
34463 | for (int i = 0; i < MAX_MS_RCV_MSG; i++) { |
| 3891 | 31812 | rcvIovecs[i].iov_base = rcvBuffers[i]; | |
| 3892 | 31812 | rcvIovecs[i].iov_len = MAX_MS_RCV_BUFSIZE; | |
| 3893 | 31812 | rcvMsgs[i].msg_hdr.msg_iov = &rcvIovecs[i]; | |
| 3894 | 31812 | rcvMsgs[i].msg_hdr.msg_iovlen = 1; | |
| 3895 | 31812 | rcvMsgs[i].msg_hdr.msg_name = &rcvSrcAddr[i]; | |
| 3896 | 31812 | rcvMsgs[i].msg_hdr.msg_namelen = sizeof(struct sockaddr_storage); | |
| 3897 | 31812 | rcvMsgs[i].msg_hdr.msg_control = &rcvCmbuf[i]; | |
| 3898 | 31812 | rcvMsgs[i].msg_hdr.msg_controllen = 0x100; | |
| 3899 | } | ||
| 3900 | |||
| 3901 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | setupMulticastReceive(false); |
| 3902 | 2651 | return 1; | |
| 3903 | } | ||
| 3904 | 18678 | bool MultiSync::isSupportedForMultisync(const char* address, const char* intface) { | |
| 3905 |
7/8✓ Branch 0 taken 9955 times.
✓ Branch 1 taken 8723 times.
✓ Branch 2 taken 9942 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 4984 times.
✓ Branch 5 taken 4958 times.
✓ Branch 6 taken 4984 times.
✗ Branch 7 not taken.
|
18678 | if (strlen(address) > 3 && address[0] == '1' && address[1] == '2' && address[2] == '7') { |
| 3906 | // the entire 127.* subnet is localhost | ||
| 3907 | 4984 | return false; | |
| 3908 | } | ||
| 3909 |
5/8✓ Branch 0 taken 13694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9495 times.
✓ Branch 3 taken 4199 times.
✓ Branch 4 taken 9495 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 9495 times.
|
13694 | if (!strncmp(intface, "usb", 3) || !strcmp(intface, "lo") || !strncmp(intface, "tether", 6) || !strncmp(intface, "SoftAp", 6)) { |
| 3910 | 4199 | return false; | |
| 3911 | } | ||
| 3912 | 9495 | return true; | |
| 3913 | } | ||
| 3914 | |||
| 3915 | 9426 | void MultiSync::setupMulticastReceive(bool cycle) { | |
| 3916 |
1/2✓ Branch 0 taken 9426 times.
✗ Branch 1 not taken.
|
9426 | LogDebug(VB_SYNC, "setupMulticastReceive()\n"); |
| 3917 | // loop through all the interfaces and subscribe to the group | ||
| 3918 |
1/2✓ Branch 0 taken 9426 times.
✗ Branch 1 not taken.
|
9426 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 3919 |
2/2✓ Branch 0 taken 10015 times.
✓ Branch 1 taken 9426 times.
|
19441 | for (auto& a : m_interfaces) { |
| 3920 |
1/2✓ Branch 0 taken 10015 times.
✗ Branch 1 not taken.
|
10015 | LogDebug(VB_SYNC, " Adding interface %s - %s\n", a.second.interfaceName.c_str(), a.second.interfaceAddress.c_str()); |
| 3921 | struct ip_mreq mreq; | ||
| 3922 | 10015 | memset(&mreq, 0, sizeof(mreq)); | |
| 3923 | 10015 | mreq.imr_multiaddr.s_addr = inet_addr(MULTISYNC_MULTICAST_ADDRESS); | |
| 3924 | 10015 | mreq.imr_interface.s_addr = a.second.address; | |
| 3925 | 10015 | int rc = 0; | |
| 3926 |
2/2✓ Branch 0 taken 4329 times.
✓ Branch 1 taken 5686 times.
|
10015 | if (cycle) { |
| 3927 | 4329 | setsockopt(m_receiveSock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); | |
| 3928 | } | ||
| 3929 |
2/2✓ Branch 0 taken 3636 times.
✓ Branch 1 taken 6379 times.
|
10015 | if ((rc = setsockopt(m_receiveSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))) < 0) { |
| 3930 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3636 times.
|
3636 | if (m_broadcastSock < 0) { |
| 3931 | // first time through, log as warning, otherwise error is likely due to already being subscribed | ||
| 3932 | ✗ | LogWarn(VB_SYNC, " Could not setup Multicast Group for interface %s rc: %d\n", a.second.interfaceName.c_str(), rc); | |
| 3933 | } else { | ||
| 3934 |
1/2✓ Branch 0 taken 3636 times.
✗ Branch 1 not taken.
|
3636 | LogDebug(VB_SYNC, " Could not setup Multicast Group for interface %s rc: %d\n", a.second.interfaceName.c_str(), rc); |
| 3935 | } | ||
| 3936 | } | ||
| 3937 | } | ||
| 3938 | 9426 | } | |
| 3939 | |||
| 3940 | // True if a later message in this recvmmsg batch supersedes message i (same | ||
| 3941 | // sync file type and sync packet type), so only the newest need be acted on. | ||
| 3942 | // Entries are one per received message, with a null buffer for messages that | ||
| 3943 | // were not received or are too short to hold a ControlPkt, so the indexes line | ||
| 3944 | // up with the msg indexes the caller uses. Only packets long enough to hold | ||
| 3945 | // the SyncPkt that follows the header can be compared. | ||
| 3946 | 21929 | static bool shouldSkipPacket(int i, int num, const std::vector<std::pair<unsigned char*, int>>& rcvBuffers) { | |
| 3947 | 21929 | constexpr int MIN_SYNC_LEN = (int)(sizeof(ControlPkt) + sizeof(SyncPkt)); | |
| 3948 |
5/6✓ Branch 0 taken 21929 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5831 times.
✓ Branch 3 taken 16098 times.
✓ Branch 4 taken 5831 times.
✓ Branch 5 taken 16098 times.
|
21929 | if (rcvBuffers[i].first == nullptr || rcvBuffers[i].second < MIN_SYNC_LEN) { |
| 3949 | 5831 | return false; | |
| 3950 | } | ||
| 3951 | 16098 | ControlPkt* pkt = (ControlPkt*)(rcvBuffers[i].first); | |
| 3952 |
2/2✓ Branch 0 taken 11578 times.
✓ Branch 1 taken 4520 times.
|
16098 | if (pkt->pktType != CTRL_PKT_SYNC) { |
| 3953 | 11578 | return false; | |
| 3954 | } | ||
| 3955 | 4520 | SyncPkt* spkt = (SyncPkt*)(((char*)pkt) + sizeof(ControlPkt)); | |
| 3956 |
2/2✓ Branch 0 taken 1644 times.
✓ Branch 1 taken 3826 times.
|
5470 | for (int x = i + 1; x < num; x++) { |
| 3957 |
5/6✓ Branch 0 taken 1644 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 1566 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 1566 times.
|
1644 | if (rcvBuffers[x].first == nullptr || rcvBuffers[x].second < MIN_SYNC_LEN) { |
| 3958 | 78 | continue; | |
| 3959 | } | ||
| 3960 | 1566 | ControlPkt* npkt = (ControlPkt*)(rcvBuffers[x].first); | |
| 3961 |
2/2✓ Branch 0 taken 208 times.
✓ Branch 1 taken 1358 times.
|
1566 | if (npkt->pktType != CTRL_PKT_SYNC) { |
| 3962 | 208 | continue; | |
| 3963 | } | ||
| 3964 | 1358 | SyncPkt* snpkt = (SyncPkt*)(((char*)npkt) + sizeof(ControlPkt)); | |
| 3965 |
4/4✓ Branch 0 taken 873 times.
✓ Branch 1 taken 485 times.
✓ Branch 2 taken 694 times.
✓ Branch 3 taken 179 times.
|
1358 | if (spkt->fileType == snpkt->fileType && spkt->pktType == snpkt->pktType) { |
| 3966 | 694 | return true; | |
| 3967 | } | ||
| 3968 | } | ||
| 3969 | 3826 | return false; | |
| 3970 | } | ||
| 3971 | |||
| 3972 | /* | ||
| 3973 | * | ||
| 3974 | */ | ||
| 3975 | 6728 | void MultiSync::ProcessControlPacket(bool pingOnly) { | |
| 3976 | 6728 | LogExcess(VB_SYNC, "ProcessControlPacket()\n"); | |
| 3977 | |||
| 3978 | ControlPkt* pkt; | ||
| 3979 | |||
| 3980 | 6728 | int msgcnt = recvmmsg(m_receiveSock, rcvMsgs, MAX_MS_RCV_MSG, MSG_DONTWAIT, nullptr); | |
| 3981 | // Batches read per wakeup: the socket is level-triggered, so the rest is | ||
| 3982 | // read on the next pass. Draining until empty let a flood of packets keep | ||
| 3983 | // the main loop in here for as long as it lasted. | ||
| 3984 | 6728 | int batches = 1; | |
| 3985 |
2/2✓ Branch 0 taken 7710 times.
✓ Branch 1 taken 6728 times.
|
14438 | while (msgcnt > 0) { |
| 3986 | // One entry per received message, buffer and length, so that the | ||
| 3987 | // indexes shouldSkipPacket() walks are the same msg indexes used below. | ||
| 3988 | // Messages that failed or are too short for a ControlPkt get a null | ||
| 3989 | // placeholder rather than being left out of the vector. | ||
| 3990 | 7710 | std::vector<std::pair<unsigned char*, int>> v; | |
| 3991 |
1/2✓ Branch 0 taken 7710 times.
✗ Branch 1 not taken.
|
7710 | v.reserve(msgcnt); |
| 3992 |
2/2✓ Branch 0 taken 22059 times.
✓ Branch 1 taken 7710 times.
|
29769 | for (int msg = 0; msg < msgcnt; msg++) { |
| 3993 | 22059 | int len = rcvMsgs[msg].msg_len; | |
| 3994 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 21929 times.
|
22059 | if (len < (int)sizeof(ControlPkt)) { |
| 3995 |
1/2✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
|
130 | v.emplace_back(nullptr, 0); |
| 3996 | 130 | continue; | |
| 3997 | } | ||
| 3998 | 21929 | unsigned char* inBuf = rcvBuffers[msg]; | |
| 3999 | 21929 | inBuf[len] = 0; | |
| 4000 |
1/2✓ Branch 0 taken 21929 times.
✗ Branch 1 not taken.
|
21929 | v.emplace_back(inBuf, len); |
| 4001 | } | ||
| 4002 |
1/2✓ Branch 0 taken 7710 times.
✗ Branch 1 not taken.
|
7710 | LogExcess(VB_SYNC, "ProcessControlPacket msgcnt: %d\n", msgcnt); |
| 4003 |
2/2✓ Branch 0 taken 22059 times.
✓ Branch 1 taken 7710 times.
|
29769 | for (int msg = 0; msg < msgcnt; msg++) { |
| 4004 | 22059 | int len = rcvMsgs[msg].msg_len; | |
| 4005 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 22003 times.
|
22059 | if (len <= 0) { |
| 4006 | // an empty datagram: recvmmsg() itself succeeded (a failure | ||
| 4007 | // ends the batch), so there is no error to report | ||
| 4008 | 1744 | continue; | |
| 4009 | } | ||
| 4010 | 22003 | unsigned char* inBuf = rcvBuffers[msg]; | |
| 4011 | |||
| 4012 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 21929 times.
|
22003 | if (len < sizeof(ControlPkt)) { |
| 4013 |
3/4✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 72 times.
|
74 | if (ShouldLogBadPacket()) { |
| 4014 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogErr(VB_SYNC, "Error: Received control packet too short\n"); |
| 4015 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | HexDump("Received data:", (void*)inBuf, len, VB_SYNC); |
| 4016 | } | ||
| 4017 | 74 | continue; | |
| 4018 | } | ||
| 4019 |
2/2✓ Branch 0 taken 694 times.
✓ Branch 1 taken 21235 times.
|
21929 | if (shouldSkipPacket(msg, msgcnt, v)) { |
| 4020 |
1/2✓ Branch 0 taken 694 times.
✗ Branch 1 not taken.
|
694 | LogExcess(VB_SYNC, "Skipping sync packet %d/%d\n", msg, msgcnt); |
| 4021 | 694 | continue; | |
| 4022 | } | ||
| 4023 | |||
| 4024 | char tmpIP[INET_ADDRSTRLEN]; | ||
| 4025 | 21235 | inet_ntop(rcvSrcAddr[msg].ss_family, &(((struct sockaddr_in*)&rcvSrcAddr[msg])->sin_addr), tmpIP, INET_ADDRSTRLEN); | |
| 4026 |
1/2✓ Branch 0 taken 21235 times.
✗ Branch 1 not taken.
|
21235 | std::string sourceIP(tmpIP); |
| 4027 | 21235 | std::string hostname; | |
| 4028 | |||
| 4029 | // Both system lists have to be read under m_systemsLock: UpdateSystem() | ||
| 4030 | // runs on the HTTP/mDNS probe threads and can push_back onto | ||
| 4031 | // m_remoteSystems, reallocating it out from under this loop. The | ||
| 4032 | // stats map work below then runs under m_statsLock alone -- the two | ||
| 4033 | // locks are never held at the same time. | ||
| 4034 | 21235 | bool isLocal = false; | |
| 4035 | { | ||
| 4036 |
1/2✓ Branch 0 taken 21235 times.
✗ Branch 1 not taken.
|
21235 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 4037 |
2/2✓ Branch 0 taken 22131 times.
✓ Branch 1 taken 21235 times.
|
43366 | for (auto& sys : m_localSystems) { |
| 4038 |
2/2✓ Branch 0 taken 6190 times.
✓ Branch 1 taken 15941 times.
|
22131 | if (sys.address == sourceIP) { |
| 4039 | 6190 | isLocal = true; | |
| 4040 | } | ||
| 4041 | } | ||
| 4042 |
2/2✓ Branch 0 taken 15045 times.
✓ Branch 1 taken 6190 times.
|
21235 | if (!isLocal) { |
| 4043 |
2/2✓ Branch 0 taken 2711841 times.
✓ Branch 1 taken 15045 times.
|
2726886 | for (auto& sys : m_remoteSystems) { |
| 4044 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2711840 times.
|
2711841 | if (sys.address == sourceIP) |
| 4045 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | hostname = sys.hostname; |
| 4046 | } | ||
| 4047 | } | ||
| 4048 | 21235 | } | |
| 4049 | |||
| 4050 | 21235 | pkt = (ControlPkt*)inBuf; | |
| 4051 | |||
| 4052 |
2/2✓ Branch 0 taken 21129 times.
✓ Branch 1 taken 106 times.
|
21235 | if ((pkt->fppd[0] != 'F') || |
| 4053 |
1/2✓ Branch 0 taken 21129 times.
✗ Branch 1 not taken.
|
21129 | (pkt->fppd[1] != 'P') || |
| 4054 |
1/2✓ Branch 0 taken 21129 times.
✗ Branch 1 not taken.
|
21129 | (pkt->fppd[2] != 'P') || |
| 4055 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21129 times.
|
21129 | (pkt->fppd[3] != 'D')) { |
| 4056 |
3/4✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 100 times.
|
106 | if (ShouldLogBadPacket()) { |
| 4057 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | LogErr(VB_SYNC, "Error: Invalid Received Control Packet, missing 'FPPD' header\n"); |
| 4058 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | HexDump("Received data:", (void*)inBuf, len, VB_SYNC); |
| 4059 | } | ||
| 4060 | 106 | continue; | |
| 4061 | } | ||
| 4062 | |||
| 4063 |
2/2✓ Branch 0 taken 805 times.
✓ Branch 1 taken 20324 times.
|
21129 | if (len != (sizeof(ControlPkt) + pkt->extraDataLen)) { |
| 4064 |
3/4✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 795 times.
|
805 | if (ShouldLogBadPacket()) { |
| 4065 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | LogErr(VB_SYNC, "Error: Expected %d data bytes, received %d\n", |
| 4066 | pkt->extraDataLen, len - sizeof(ControlPkt)); | ||
| 4067 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | HexDump("Received data:", (void*)inBuf, len, VB_SYNC); |
| 4068 | } | ||
| 4069 | 805 | continue; | |
| 4070 | } | ||
| 4071 | |||
| 4072 |
2/4✓ Branch 0 taken 20324 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20324 times.
|
20324 | if (WillLog(LOG_EXCESSIVE, VB_SYNC)) { |
| 4073 | ✗ | HexDump("Received MultiSync packet with contents:", (void*)inBuf, len, VB_SYNC); | |
| 4074 | } | ||
| 4075 | |||
| 4076 | // Per-sender stats, created only for a well-formed packet (any | ||
| 4077 | // datagram from a new, possibly spoofed, source used to add one), | ||
| 4078 | // and only up to MAX_SYNC_STATS senders. Entries are never freed | ||
| 4079 | // (their pointers are used after m_statsLock is released), so a | ||
| 4080 | // sender past the cap simply isn't tracked. | ||
| 4081 | static constexpr size_t MAX_SYNC_STATS = 1024; | ||
| 4082 |
3/6✓ Branch 0 taken 20324 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20324 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20324 times.
✗ Branch 5 not taken.
|
60972 | MultiSyncStats tempStats("", ""); |
| 4083 | 20324 | MultiSyncStats* stats = &tempStats; | |
| 4084 |
2/2✓ Branch 0 taken 14134 times.
✓ Branch 1 taken 6190 times.
|
20324 | if (!isLocal) { |
| 4085 |
1/2✓ Branch 0 taken 14134 times.
✗ Branch 1 not taken.
|
14134 | std::unique_lock<std::recursive_mutex> slock(m_statsLock); |
| 4086 |
1/2✓ Branch 0 taken 14134 times.
✗ Branch 1 not taken.
|
14134 | auto a = m_syncStats.find(sourceIP); |
| 4087 |
2/2✓ Branch 0 taken 12887 times.
✓ Branch 1 taken 1247 times.
|
14134 | if (a != m_syncStats.end()) { |
| 4088 | 12887 | stats = (MultiSyncStats*)a->second; | |
| 4089 |
2/2✓ Branch 0 taken 1171 times.
✓ Branch 1 taken 76 times.
|
1247 | } else if (m_syncStats.size() < MAX_SYNC_STATS) { |
| 4090 |
5/12✓ Branch 0 taken 1171 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1171 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1171 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1171 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1171 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
1171 | stats = new MultiSyncStats(sourceIP, hostname); |
| 4091 |
1/2✓ Branch 0 taken 1171 times.
✗ Branch 1 not taken.
|
1171 | m_syncStats[sourceIP] = stats; |
| 4092 | } | ||
| 4093 | 14134 | stats->lastReceiveTime = time(NULL); | |
| 4094 | 14134 | } | |
| 4095 | |||
| 4096 |
8/10✓ Branch 0 taken 6190 times.
✓ Branch 1 taken 14134 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 6181 times.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 20315 times.
|
20324 | if (isLocal && IsEchoCandidate(inBuf, len) && IsOwnEcho(inBuf, len)) { |
| 4097 | 9 | continue; // our own broadcast, looped back (see IsOwnEcho) | |
| 4098 | } | ||
| 4099 | |||
| 4100 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 20315 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
20315 | if (!pingOnly || pkt->pktType == CTRL_PKT_PING) { |
| 4101 |
7/7✓ Branch 0 taken 31 times.
✓ Branch 1 taken 9235 times.
✓ Branch 2 taken 110 times.
✓ Branch 3 taken 10739 times.
✓ Branch 4 taken 29 times.
✓ Branch 5 taken 67 times.
✓ Branch 6 taken 104 times.
|
20315 | switch (pkt->pktType) { |
| 4102 | 31 | case CTRL_PKT_CMD: | |
| 4103 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | ProcessCommandPacket(pkt, len, stats); |
| 4104 | 31 | break; | |
| 4105 | 9235 | case CTRL_PKT_SYNC: | |
| 4106 |
3/4✓ Branch 0 taken 9235 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2628 times.
✓ Branch 3 taken 6607 times.
|
9235 | if (getFPPmode() == REMOTE_MODE) { |
| 4107 |
1/2✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
|
2628 | ProcessSyncPacket(pkt, len, stats); |
| 4108 | } | ||
| 4109 | 9235 | break; | |
| 4110 | 110 | case CTRL_PKT_BLANK: | |
| 4111 |
3/4✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 100 times.
|
110 | if (getFPPmode() == REMOTE_MODE) { |
| 4112 |
3/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10 times.
|
11 | for (auto a : getPluginsCopy()) { |
| 4113 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedBlankingDataPacket(); |
| 4114 | 10 | } | |
| 4115 | 10 | BumpStat(stats->pktBlank); | |
| 4116 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | sequence->SendBlankingData(); |
| 4117 | } | ||
| 4118 | 110 | break; | |
| 4119 | 10739 | case CTRL_PKT_PING: { | |
| 4120 | 10739 | struct sockaddr_in* inAddr = (struct sockaddr_in*)(&rcvSrcAddr[msg]); | |
| 4121 | 10739 | char ipbuf[INET_ADDRSTRLEN] = {0}; | |
| 4122 | 10739 | inet_ntop(AF_INET, &inAddr->sin_addr, ipbuf, sizeof(ipbuf)); | |
| 4123 |
1/2✓ Branch 0 taken 10739 times.
✗ Branch 1 not taken.
|
10739 | std::string ip = ipbuf; |
| 4124 |
1/2✓ Branch 0 taken 10739 times.
✗ Branch 1 not taken.
|
10739 | ProcessPingPacket(pkt, len, sourceIP, stats, ip); |
| 4125 | 10739 | break; | |
| 4126 | 10739 | } | |
| 4127 | 29 | case CTRL_PKT_PLUGIN: | |
| 4128 |
1/2✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
|
29 | ProcessPluginPacket(pkt, len, stats); |
| 4129 | 29 | break; | |
| 4130 | 67 | case CTRL_PKT_FPPCOMMAND: | |
| 4131 |
1/2✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
|
67 | ProcessFPPCommandPacket(pkt, len, stats); |
| 4132 | 67 | break; | |
| 4133 | } | ||
| 4134 | } | ||
| 4135 |
6/6✓ Branch 0 taken 20315 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 20315 times.
✓ Branch 3 taken 920 times.
✓ Branch 4 taken 20315 times.
✓ Branch 5 taken 920 times.
|
22164 | } |
| 4136 |
3/4✓ Branch 0 taken 7700 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 7700 times.
✗ Branch 3 not taken.
|
7710 | msgcnt = ++batches > 64 ? 0 : recvmmsg(m_receiveSock, rcvMsgs, MAX_MS_RCV_MSG, MSG_DONTWAIT, nullptr); |
| 4137 | 7710 | } | |
| 4138 | 6728 | } | |
| 4139 | |||
| 4140 | 51 | void MultiSync::OpenSyncedSequence(const std::string& filename) { | |
| 4141 | 51 | LogDebug(VB_SYNC, "OpenSyncedSequence(%s)\n", filename.c_str()); | |
| 4142 | |||
| 4143 |
3/4✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 51 times.
|
52 | for (auto a : getPluginsCopy()) { |
| 4144 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedSeqOpenPacket(filename); |
| 4145 | 51 | } | |
| 4146 | 51 | ResetMasterPosition(); | |
| 4147 | 51 | sequence->OpenSequenceFile(filename); | |
| 4148 | 51 | } | |
| 4149 | |||
| 4150 | 47 | void MultiSync::StartSyncedSequence(const std::string& filename) { | |
| 4151 | 47 | LogDebug(VB_SYNC, "StartSyncedSequence(%s)\n", filename.c_str()); | |
| 4152 | |||
| 4153 | 47 | ResetMasterPosition(); | |
| 4154 |
3/4✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 47 times.
|
48 | for (auto a : getPluginsCopy()) { |
| 4155 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedSeqSyncStartPacket(filename); |
| 4156 | 47 | } | |
| 4157 |
8/20✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 47 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 47 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 47 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 47 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 47 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
141 | if (!sequence->IsSequenceRunning(filename) && !sequence->IsSequenceRunning("fallback.fseq")) { |
| 4158 | 47 | sequence->StartSequence(filename, 0); | |
| 4159 | } | ||
| 4160 | 47 | } | |
| 4161 | |||
| 4162 | 33 | void MultiSync::StopSyncedSequence(const std::string& filename) { | |
| 4163 | 33 | LogDebug(VB_SYNC, "StopSyncedSequence(%s)\n", filename.c_str()); | |
| 4164 |
3/4✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 33 times.
|
34 | for (auto a : getPluginsCopy()) { |
| 4165 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedSeqSyncStopPacket(filename); |
| 4166 | 33 | } | |
| 4167 | 33 | sequence->CloseIfOpen(filename); | |
| 4168 | 33 | } | |
| 4169 | ✗ | void MultiSync::SyncStopAll() { | |
| 4170 | ✗ | LogDebug(VB_SYNC, "SyncStopAll()\n"); | |
| 4171 | ✗ | sequence->CloseSequenceFile(); | |
| 4172 | ✗ | if (!mediaOutput) { | |
| 4173 | ✗ | return; | |
| 4174 | } | ||
| 4175 | ✗ | CloseMediaOutput(); | |
| 4176 | } | ||
| 4177 | |||
| 4178 | 1 | void MultiSync::SyncPlaylistToMS(uint64_t ms, const std::string& pl, bool sendSyncPackets) { | |
| 4179 | 1 | SyncPlaylistToMS(ms, -1, pl, sendSyncPackets); | |
| 4180 | 1 | } | |
| 4181 | |||
| 4182 | 13 | void MultiSync::SyncPlaylistToMS(uint64_t ms, int pos, const std::string& pl, bool sendSyncPackets) { | |
| 4183 |
3/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 3 times.
|
13 | if (Player::INSTANCE.GetPlaylistName() != pl) { |
| 4184 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (pl == "") { |
| 4185 | ✗ | return; | |
| 4186 | } | ||
| 4187 |
2/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | Player::INSTANCE.Load(pl); |
| 4188 | } | ||
| 4189 | |||
| 4190 | 13 | int desiredpos = pos; | |
| 4191 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9 times.
|
13 | if (pos <= -1) { |
| 4192 | 4 | desiredpos = Player::INSTANCE.FindPosForMS(ms, pos == -2); | |
| 4193 | } | ||
| 4194 | |||
| 4195 | 13 | float seconds = ms; | |
| 4196 | 13 | seconds /= 1000; | |
| 4197 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (desiredpos >= 0) { |
| 4198 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
|
13 | if (m_controlSock < 0 && sendSyncPackets) { |
| 4199 | ✗ | OpenControlSockets(); | |
| 4200 | } | ||
| 4201 | |||
| 4202 | 13 | std::string seq, med; | |
| 4203 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | Player::INSTANCE.GetFilenamesForPos(desiredpos, seq, med); |
| 4204 |
3/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 8 times.
|
13 | if (seq != "") { |
| 4205 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (!sequence->IsSequenceRunning(seq)) { |
| 4206 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
|
5 | if (sequence->IsSequenceRunning()) { |
| 4207 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (sendSyncPackets) |
| 4208 | ✗ | SendSeqSyncStopPacket(sequence->GetSeqFilenameCopy()); | |
| 4209 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | sequence->CloseSequenceFile(); |
| 4210 | } | ||
| 4211 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | ResetMasterPosition(); |
| 4212 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | sequence->OpenSequenceFile(seq.c_str()); |
| 4213 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (sendSyncPackets) |
| 4214 | ✗ | SendSeqOpenPacket(seq); | |
| 4215 | 5 | int frame = ms / sequence->GetSeqStepTime(); | |
| 4216 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | sequence->StartSequence(seq.c_str(), frame); |
| 4217 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (sendSyncPackets) |
| 4218 | ✗ | SendSeqSyncStartPacket(seq); | |
| 4219 | } else { | ||
| 4220 | ✗ | int frame = ms / sequence->GetSeqStepTime(); | |
| 4221 | ✗ | SyncSyncedSequence(seq.c_str(), frame, seconds); | |
| 4222 | ✗ | if (sendSyncPackets) | |
| 4223 | ✗ | SendSeqSyncPacket(seq, frame, seconds); | |
| 4224 | } | ||
| 4225 | } | ||
| 4226 |
3/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 10 times.
|
13 | if (med != "") { |
| 4227 |
11/18✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
5 | if (mediaOutput && !MatchesRunningMediaFilename(med.c_str())) { |
| 4228 | // Stop the media that is playing, by its own name, as the | ||
| 4229 | // sequence branch above does. | ||
| 4230 | 1 | std::string running; | |
| 4231 | { | ||
| 4232 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::mutex> lock(mediaOutputLock); |
| 4233 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (mediaOutput) { |
| 4234 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | running = mediaOutput->m_mediaFilename; |
| 4235 | } | ||
| 4236 | 1 | } | |
| 4237 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!running.empty()) { |
| 4238 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | StopSyncedMedia(running); |
| 4239 | // StopSyncedMedia() matches by media name and can miss | ||
| 4240 | // the output's own; this is a no-op once it has closed it. | ||
| 4241 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CloseMediaOutput(); |
| 4242 | // CloseMediaOutput() sends the stop when MultiSync is on. | ||
| 4243 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | if (sendSyncPackets && !isMultiSyncEnabled()) |
| 4244 | ✗ | SendMediaSyncStopPacket(running); | |
| 4245 | } | ||
| 4246 | 1 | } | |
| 4247 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!mediaOutput) { |
| 4248 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | OpenSyncedMedia(med.c_str()); |
| 4249 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (sendSyncPackets) |
| 4250 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | SendMediaOpenPacket(med); |
| 4251 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | StartSyncedMedia(med.c_str()); |
| 4252 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (sendSyncPackets) |
| 4253 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | SendMediaSyncStartPacket(med); |
| 4254 | } | ||
| 4255 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | UpdateMasterMediaPosition(med.c_str(), seconds); |
| 4256 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (sendSyncPackets) |
| 4257 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | SendMediaSyncPacket(med, seconds); |
| 4258 | } | ||
| 4259 | 13 | } | |
| 4260 | } | ||
| 4261 | |||
| 4262 | /* | ||
| 4263 | * | ||
| 4264 | */ | ||
| 4265 | 930 | void MultiSync::SyncSyncedSequence(const std::string& filename, int frameNumber, float secondsElapsed) { | |
| 4266 | 930 | LogExcess(VB_SYNC, "SyncSyncedSequence('%s', %d, %.2f)\n", | |
| 4267 | filename.c_str(), frameNumber, secondsElapsed); | ||
| 4268 | |||
| 4269 |
3/4✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 930 times.
|
931 | for (auto a : getPluginsCopy()) { |
| 4270 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedSeqSyncPacket(filename, frameNumber, secondsElapsed); |
| 4271 | 930 | } | |
| 4272 |
12/20✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 212 times.
✓ Branch 3 taken 718 times.
✓ Branch 4 taken 212 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 212 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 212 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 212 times.
✓ Branch 11 taken 718 times.
✓ Branch 12 taken 212 times.
✓ Branch 13 taken 718 times.
✓ Branch 14 taken 212 times.
✓ Branch 15 taken 718 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1354 | if (!sequence->IsSequenceRunning(filename) && !sequence->IsSequenceRunning("fallback.fseq")) { |
| 4273 | 212 | sequence->StartSequence(filename, frameNumber); | |
| 4274 | } | ||
| 4275 |
2/2✓ Branch 0 taken 722 times.
✓ Branch 1 taken 208 times.
|
930 | if (sequence->IsSequenceRunning(filename)) { |
| 4276 | 722 | double framePosition = frameNumber; | |
| 4277 |
2/2✓ Branch 0 taken 720 times.
✓ Branch 1 taken 2 times.
|
722 | if (secondsElapsed > 0.0001f) { |
| 4278 | // recalculate the frame number based on the seconds, which carry | ||
| 4279 | // remoteOffset: kept whole, the lights would move by the offset | ||
| 4280 | // rounded to a frame (+30 ms at 20 fps moved them 50 ms). | ||
| 4281 | 720 | framePosition = secondsElapsed * 1000.0 / sequence->GetSeqStepTime(); | |
| 4282 | 720 | frameNumber = std::round(framePosition); | |
| 4283 | } | ||
| 4284 | 722 | UpdateMasterPosition(frameNumber, framePosition); | |
| 4285 | } | ||
| 4286 | 930 | } | |
| 4287 | |||
| 4288 | 45 | void MultiSync::OpenSyncedMedia(const std::string& filename) { | |
| 4289 | 45 | LogDebug(VB_SYNC, "OpenSyncedMedia(%s)\n", filename.c_str()); | |
| 4290 | |||
| 4291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (mediaOutput) { |
| 4292 | ✗ | LogDebug(VB_SYNC, "Start media %s received while playing media %s\n", | |
| 4293 | filename.c_str(), mediaOutput->m_mediaFilename.c_str()); | ||
| 4294 | |||
| 4295 | ✗ | CloseMediaOutput(); | |
| 4296 | } | ||
| 4297 |
3/4✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 45 times.
|
46 | for (auto a : getPluginsCopy()) { |
| 4298 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedMediaOpenPacket(filename); |
| 4299 | 45 | } | |
| 4300 | |||
| 4301 | 45 | m_lastSyncedMediaPacketMS = (uint64_t)GetTimeMS(); | |
| 4302 | 45 | OpenMediaOutput(filename); | |
| 4303 | 45 | } | |
| 4304 | |||
| 4305 | 3 | void MultiSync::PrepareSyncedMedia(const std::string& filename) { | |
| 4306 | 3 | LogDebug(VB_SYNC, "PrepareSyncedMedia(%s)\n", filename.c_str()); | |
| 4307 | 3 | PrepareRemoteMediaOutput(filename); | |
| 4308 | 3 | } | |
| 4309 | |||
| 4310 | 46 | void MultiSync::StartSyncedMedia(const std::string& filename, float secondsElapsed) { | |
| 4311 | 46 | LogDebug(VB_SYNC, "StartSyncedMedia(%s, %.2f)\n", filename.c_str(), secondsElapsed); | |
| 4312 |
3/4✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 46 times.
|
47 | for (auto a : getPluginsCopy()) { |
| 4313 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedMediaSyncStartPacket(filename); |
| 4314 | 46 | } | |
| 4315 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 41 times.
|
46 | int msTime = (secondsElapsed > 0.0f) ? (int)(secondsElapsed * 1000.0f) : 0; |
| 4316 | 46 | m_lastSyncedMediaPacketMS = (uint64_t)GetTimeMS(); | |
| 4317 | 46 | StartMediaOutput(filename, msTime); | |
| 4318 | 46 | } | |
| 4319 | |||
| 4320 | /* | ||
| 4321 | * | ||
| 4322 | */ | ||
| 4323 | 41 | void MultiSync::StopSyncedMedia(const std::string& filename) { | |
| 4324 | 41 | LogDebug(VB_SYNC, "StopSyncedMedia(%s)\n", filename.c_str()); | |
| 4325 |
3/4✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 41 times.
|
42 | for (auto a : getPluginsCopy()) { |
| 4326 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedMediaSyncStopPacket(filename); |
| 4327 | 41 | } | |
| 4328 | |||
| 4329 | 41 | m_lastSyncedMediaPacketMS = 0; | |
| 4330 | |||
| 4331 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 34 times.
|
41 | if (!mediaOutput) { |
| 4332 | 7 | return; | |
| 4333 | } | ||
| 4334 | |||
| 4335 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | if (MatchesRunningMediaFilename(filename)) { |
| 4336 | 34 | LogDebug(VB_SYNC, "Stopping synced media: %s\n", mediaOutput->m_mediaFilename.c_str()); | |
| 4337 | 34 | CloseMediaOutput(); | |
| 4338 | } | ||
| 4339 | } | ||
| 4340 | |||
| 4341 | /* | ||
| 4342 | * Close a synced media output that has run to its end while the player has | ||
| 4343 | * gone away (issue #2727: a wedged-decoder restart on the player left both | ||
| 4344 | * remotes holding an EOS'd pipeline forever -- slot still active, /dev/video10 | ||
| 4345 | * and dmabufs still held -- while the UI happily reported "playing"). | ||
| 4346 | * | ||
| 4347 | * The trigger is deliberately NOT "sync packets went quiet". A remote's media | ||
| 4348 | * free-runs on its own clock, so a network glitch mid-clip is harmless: the | ||
| 4349 | * clip keeps playing and UpdateMasterMediaPosition nudges it back when packets | ||
| 4350 | * resume. Tearing that down on packet silence would turn a glitch into a | ||
| 4351 | * visible outage. The unrecoverable state is a clip that has ENDED with the | ||
| 4352 | * player gone -- nothing but a sync packet can ever move it forward again. | ||
| 4353 | * | ||
| 4354 | * The normal end-of-clip-to-next-clip gap on a remote is ~13ms, so the default | ||
| 4355 | * grace of 10s is ~750x the real-world gap; a glitch straddling a clip boundary | ||
| 4356 | * costs at most the last frame going away early, and the next START packet | ||
| 4357 | * opens a fresh output as usual. | ||
| 4358 | */ | ||
| 4359 | 9255 | void MultiSync::CheckSyncedMediaIdleTimeout() { | |
| 4360 | 9255 | uint64_t last = m_lastSyncedMediaPacketMS; | |
| 4361 |
2/2✓ Branch 0 taken 8820 times.
✓ Branch 1 taken 435 times.
|
9255 | if (last == 0) { |
| 4362 | 9254 | return; // no synced media open | |
| 4363 | } | ||
| 4364 | // 0 disables the watchdog | ||
| 4365 |
1/2✓ Branch 0 taken 435 times.
✗ Branch 1 not taken.
|
435 | int timeoutSec = getSettingInt("RemoteSyncedMediaIdleTimeout", 10); |
| 4366 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 336 times.
|
435 | if (timeoutSec <= 0) { |
| 4367 | 99 | return; | |
| 4368 | } | ||
| 4369 |
3/4✓ Branch 0 taken 336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 335 times.
✓ Branch 3 taken 1 times.
|
336 | if (((uint64_t)GetTimeMS() - last) < (uint64_t)(timeoutSec * 1000)) { |
| 4370 | 335 | return; | |
| 4371 | } | ||
| 4372 | |||
| 4373 | 1 | std::string filename; | |
| 4374 | { | ||
| 4375 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::mutex> lock(mediaOutputLock); |
| 4376 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!mediaOutput) { |
| 4377 | ✗ | m_lastSyncedMediaPacketMS = 0; | |
| 4378 | ✗ | return; | |
| 4379 | } | ||
| 4380 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (mediaOutput->IsPlaying()) { |
| 4381 | ✗ | return; // still playing -- free-running through a sync gap is fine | |
| 4382 | } | ||
| 4383 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | filename = mediaOutput->m_mediaFilename; |
| 4384 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } |
| 4385 | |||
| 4386 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_SYNC, "Synced media '%s' finished and no sync packet received in %d seconds " |
| 4387 | "- player appears to have gone away, closing media output\n", | ||
| 4388 | filename.c_str(), timeoutSec); | ||
| 4389 | 1 | m_lastSyncedMediaPacketMS = 0; | |
| 4390 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CloseMediaOutput(); |
| 4391 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } |
| 4392 | |||
| 4393 | /* | ||
| 4394 | * | ||
| 4395 | */ | ||
| 4396 | 1370 | void MultiSync::SyncSyncedMedia(const std::string& filename, int frameNumber, float secondsElapsed) { | |
| 4397 | 1370 | LogExcess(VB_SYNC, "SyncSyncedMedia('%s', %d, %.2f)\n", | |
| 4398 | filename.c_str(), frameNumber, secondsElapsed); | ||
| 4399 |
3/4✓ Branch 0 taken 1370 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1370 times.
|
1371 | for (auto a : getPluginsCopy()) { |
| 4400 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedMediaSyncPacket(filename, secondsElapsed); |
| 4401 | 1370 | } | |
| 4402 | |||
| 4403 | 1370 | m_lastSyncedMediaPacketMS = (uint64_t)GetTimeMS(); | |
| 4404 | 1370 | UpdateMasterMediaPosition(filename, secondsElapsed); | |
| 4405 | 1370 | } | |
| 4406 | |||
| 4407 | /* | ||
| 4408 | * | ||
| 4409 | */ | ||
| 4410 | // A file name from a sync packet, as a name relative to the media folder it is | ||
| 4411 | // looked up in, or false if it can't be one. Masters send what they play: a | ||
| 4412 | // name, a path below the folder, or -- for a random media item -- the full | ||
| 4413 | // path on the master. That full path is cut down to what follows its | ||
| 4414 | // music/videos/sequences folder, which also makes it work on a remote whose | ||
| 4415 | // media directory is elsewhere. Anything else absolute, and any "..", is | ||
| 4416 | // refused: the name is network input, and a remote opened whatever existing | ||
| 4417 | // file it named. | ||
| 4418 | 2625 | static bool SyncFilenameToMediaRelative(std::string& name, uint8_t fileType) { | |
| 4419 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2625 times.
|
2625 | if (name.empty()) { |
| 4420 | ✗ | return false; | |
| 4421 | } | ||
| 4422 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 2596 times.
|
2625 | if (name[0] == '/') { |
| 4423 | static const char* const seqDirs[] = { "/sequences/", nullptr }; | ||
| 4424 | static const char* const mediaDirs[] = { "/music/", "/videos/", nullptr }; | ||
| 4425 | 29 | bool found = false; | |
| 4426 |
5/6✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 13 times.
|
74 | for (const char* const* d = (fileType == SYNC_FILE_SEQ) ? seqDirs : mediaDirs; *d && !found; d++) { |
| 4427 | 45 | size_t pos = name.find(*d); | |
| 4428 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 32 times.
|
45 | if (pos != std::string::npos) { |
| 4429 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | name = name.substr(pos + strlen(*d)); |
| 4430 | 13 | found = true; | |
| 4431 | } | ||
| 4432 | } | ||
| 4433 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 13 times.
|
29 | if (!found) { |
| 4434 | 16 | return false; | |
| 4435 | } | ||
| 4436 | } | ||
| 4437 | 2609 | size_t start = 0; | |
| 4438 |
2/2✓ Branch 0 taken 2609 times.
✓ Branch 1 taken 2595 times.
|
5204 | while (start <= name.size()) { |
| 4439 | 2609 | size_t end = name.find('/', start); | |
| 4440 |
2/2✓ Branch 0 taken 2595 times.
✓ Branch 1 taken 14 times.
|
2609 | if (end == std::string::npos) { |
| 4441 | 2595 | end = name.size(); | |
| 4442 | } | ||
| 4443 |
5/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2595 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 2595 times.
|
2609 | if (name.compare(start, end - start, "..") == 0 && end - start == 2) { |
| 4444 | 14 | return false; | |
| 4445 | } | ||
| 4446 | 2595 | start = end + 1; | |
| 4447 | } | ||
| 4448 |
2/4✓ Branch 0 taken 2595 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2595 times.
✗ Branch 3 not taken.
|
2595 | return !name.empty() && name.back() != '/'; |
| 4449 | } | ||
| 4450 | |||
| 4451 | 2628 | void MultiSync::ProcessSyncPacket(ControlPkt* pkt, int len, MultiSyncStats* stats) { | |
| 4452 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2625 times.
|
2628 | if (pkt->extraDataLen < sizeof(SyncPkt)) { |
| 4453 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (ShouldLogBadPacket()) { |
| 4454 | ✗ | LogErr(VB_SYNC, "Error: Invalid length of received sync packet\n"); | |
| 4455 | ✗ | HexDump("Received data:", (void*)pkt, len, VB_SYNC); | |
| 4456 | } | ||
| 4457 | 3 | BumpStat(stats->pktError); | |
| 4458 | 33 | return; | |
| 4459 | } | ||
| 4460 | |||
| 4461 | { | ||
| 4462 | // Read by GetSyncStats() on an API thread; m_statsLock is the lock the | ||
| 4463 | // two sides share. Do not reach for m_systemsLock while holding it. | ||
| 4464 |
1/2✓ Branch 0 taken 2625 times.
✗ Branch 1 not taken.
|
2625 | std::unique_lock<std::recursive_mutex> slock(m_statsLock); |
| 4465 |
1/2✓ Branch 0 taken 2625 times.
✗ Branch 1 not taken.
|
2625 | m_syncMaster = stats->sourceIP; |
| 4466 | 2625 | } | |
| 4467 | |||
| 4468 | 2625 | SyncPkt* spkt = (SyncPkt*)(((char*)pkt) + sizeof(ControlPkt)); | |
| 4469 | |||
| 4470 | // filename is a flexible char[1]: read it no further than the packet goes, | ||
| 4471 | // terminated or not. | ||
| 4472 | 2625 | size_t nameMax = pkt->extraDataLen - offsetof(SyncPkt, filename); | |
| 4473 |
1/2✓ Branch 0 taken 2625 times.
✗ Branch 1 not taken.
|
3593 | std::string filename(spkt->filename, strnlen(spkt->filename, nameMax)); |
| 4474 | 2625 | float secondsIn = spkt->secondsElapsed; | |
| 4475 | |||
| 4476 | // LogExcess: every sync packet on a remote (10+/s), and a LogDebug is | ||
| 4477 | // always formatted into the crash ring. | ||
| 4478 |
2/4✓ Branch 0 taken 2625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2625 times.
✗ Branch 3 not taken.
|
2625 | LogExcess(VB_SYNC, "ProcessSyncPacket() filename: %s type: %d filetype: %d frameNumber: %d secondsElapsed: %0.2f\n", |
| 4479 | TruncateForLog(filename).c_str(), spkt->pktType, spkt->fileType, spkt->frameNumber, secondsIn); | ||
| 4480 | |||
| 4481 |
3/4✓ Branch 0 taken 2625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 2595 times.
|
2625 | if (!SyncFilenameToMediaRelative(filename, spkt->fileType)) { |
| 4482 | // A master sends one of these several times a second; say it once. | ||
| 4483 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
30 | static std::string s_lastRefused; |
| 4484 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 26 times.
|
30 | if (filename != s_lastRefused) { |
| 4485 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | s_lastRefused = filename; |
| 4486 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | LogWarn(VB_SYNC, "Ignoring sync packets from %s for '%s': not a name in the media folders\n", |
| 4487 | stats->sourceIP.c_str(), TruncateForLog(filename).c_str()); | ||
| 4488 | } | ||
| 4489 | 30 | BumpStat(stats->pktError); | |
| 4490 | 30 | return; | |
| 4491 | } | ||
| 4492 | // A NaN passes every "< 0" test and the int conversions downstream are | ||
| 4493 | // undefined for it, as for anything past INT_MAX milliseconds. | ||
| 4494 |
6/6✓ Branch 0 taken 2584 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2577 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 2577 times.
|
2595 | if (!std::isfinite(secondsIn) || secondsIn < 0.0f) { |
| 4495 | 18 | secondsIn = 0.0f; | |
| 4496 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 2532 times.
|
2577 | } else if (secondsIn > 86400.0f) { |
| 4497 | 45 | secondsIn = 86400.0f; | |
| 4498 | } | ||
| 4499 | // The same bound for the frame number, at the fastest frame rate (1 ms): | ||
| 4500 | // it is unsigned on the wire and an int from here on, so 2^31 and up went | ||
| 4501 | // negative, and the frameNumber - 1 downstream overflowed at INT_MIN. | ||
| 4502 | 2595 | uint32_t wireFrame = spkt->frameNumber; | |
| 4503 | 2595 | const int frameNumber = (int)std::min<uint32_t>(wireFrame, 86400u * 1000u); | |
| 4504 | |||
| 4505 | 2595 | float secondsElapsed = 0.0; | |
| 4506 | |||
| 4507 |
2/2✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 1531 times.
|
2595 | if (spkt->fileType == SYNC_FILE_SEQ) { |
| 4508 |
5/5✓ Branch 0 taken 51 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 930 times.
✓ Branch 4 taken 3 times.
|
1064 | switch (spkt->pktType) { |
| 4509 | 51 | case SYNC_PKT_OPEN: | |
| 4510 |
1/2✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
|
51 | OpenSyncedSequence(filename); |
| 4511 | 51 | BumpStat(stats->pktSyncSeqOpen); | |
| 4512 | 51 | break; | |
| 4513 | 47 | case SYNC_PKT_START: | |
| 4514 |
1/2✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
|
47 | StartSyncedSequence(filename); |
| 4515 | 47 | BumpStat(stats->pktSyncSeqStart); | |
| 4516 | 47 | break; | |
| 4517 | 33 | case SYNC_PKT_STOP: | |
| 4518 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | StopSyncedSequence(filename); |
| 4519 | 33 | BumpStat(stats->pktSyncSeqStop); | |
| 4520 | 33 | break; | |
| 4521 | 930 | case SYNC_PKT_SYNC: | |
| 4522 | 930 | secondsElapsed = secondsIn - m_remoteOffset; | |
| 4523 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
|
930 | if (secondsElapsed < 0) |
| 4524 | ✗ | secondsElapsed = 0.0; | |
| 4525 | |||
| 4526 |
1/2✓ Branch 0 taken 930 times.
✗ Branch 1 not taken.
|
930 | SyncSyncedSequence(filename, |
| 4527 | frameNumber, secondsElapsed); | ||
| 4528 | 930 | BumpStat(stats->pktSyncSeqSync); | |
| 4529 | 930 | break; | |
| 4530 | } | ||
| 4531 |
2/2✓ Branch 0 taken 1501 times.
✓ Branch 1 taken 30 times.
|
1531 | } else if (spkt->fileType == SYNC_FILE_MEDIA) { |
| 4532 |
6/6✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 1370 times.
✓ Branch 5 taken 3 times.
|
1501 | switch (spkt->pktType) { |
| 4533 | 42 | case SYNC_PKT_OPEN: | |
| 4534 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | OpenSyncedMedia(filename); |
| 4535 | 42 | BumpStat(stats->pktSyncMedOpen); | |
| 4536 | 42 | break; | |
| 4537 | 3 | case SYNC_PKT_PREPARE: | |
| 4538 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | PrepareSyncedMedia(filename); |
| 4539 | 3 | break; | |
| 4540 | 43 | case SYNC_PKT_START: | |
| 4541 | 43 | secondsElapsed = secondsIn - m_remoteOffset; | |
| 4542 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (secondsElapsed < 0) |
| 4543 | ✗ | secondsElapsed = 0.0; | |
| 4544 | |||
| 4545 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | StartSyncedMedia(filename, secondsElapsed); |
| 4546 | 43 | BumpStat(stats->pktSyncMedStart); | |
| 4547 | 43 | break; | |
| 4548 | 40 | case SYNC_PKT_STOP: | |
| 4549 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | StopSyncedMedia(filename); |
| 4550 | 40 | BumpStat(stats->pktSyncMedStop); | |
| 4551 | 40 | break; | |
| 4552 | 1370 | case SYNC_PKT_SYNC: | |
| 4553 | 1370 | secondsElapsed = secondsIn - m_remoteOffset; | |
| 4554 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1370 times.
|
1370 | if (secondsElapsed < 0) |
| 4555 | ✗ | secondsElapsed = 0.0; | |
| 4556 | |||
| 4557 |
1/2✓ Branch 0 taken 1370 times.
✗ Branch 1 not taken.
|
1370 | SyncSyncedMedia(filename, |
| 4558 | frameNumber, secondsElapsed); | ||
| 4559 | 1370 | BumpStat(stats->pktSyncMedSync); | |
| 4560 | 1370 | break; | |
| 4561 | } | ||
| 4562 | } | ||
| 4563 |
2/2✓ Branch 0 taken 2595 times.
✓ Branch 1 taken 30 times.
|
2625 | } |
| 4564 | |||
| 4565 | /* | ||
| 4566 | * | ||
| 4567 | */ | ||
| 4568 | 31 | void MultiSync::ProcessCommandPacket(ControlPkt* pkt, int len, MultiSyncStats* stats) { | |
| 4569 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | LogDebug(VB_SYNC, "ProcessCommandPacket()\n"); |
| 4570 | |||
| 4571 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 25 times.
|
31 | if (pkt->extraDataLen < sizeof(CommandPkt)) { |
| 4572 |
3/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
|
6 | if (ShouldLogBadPacket()) { |
| 4573 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogErr(VB_SYNC, "Error: Invalid length of received command packet\n"); |
| 4574 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | HexDump("Received data:", (void*)pkt, len, VB_SYNC); |
| 4575 | } | ||
| 4576 | 6 | BumpStat(stats->pktError); | |
| 4577 | 6 | return; | |
| 4578 | } | ||
| 4579 | |||
| 4580 | 25 | BumpStat(stats->pktCommand); | |
| 4581 | |||
| 4582 | 25 | CommandPkt* cpkt = (CommandPkt*)(((char*)pkt) + sizeof(ControlPkt)); | |
| 4583 | |||
| 4584 | // CommandPkt is a flexible char[1] with no length field of its own, so the | ||
| 4585 | // command text is only as terminated as the sender chose to make it. Bound | ||
| 4586 | // the read by the packet's own extraDataLen before handing it to the log | ||
| 4587 | // (which is remote-supplied and unbounded, hence TruncateForLog too). | ||
| 4588 |
3/6✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
|
50 | LogDebug(VB_COMMAND, "Legacy command \"%s\" received from remote host %s (%s)\n", |
| 4589 | TruncateForLog(std::string(cpkt->command, strnlen(cpkt->command, pkt->extraDataLen))).c_str(), | ||
| 4590 | stats->hostname.c_str(), stats->sourceIP.c_str()); | ||
| 4591 | |||
| 4592 | char response[1500]; | ||
| 4593 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | char* r2 = ProcessCommand(cpkt->command, response); |
| 4594 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (r2) { |
| 4595 | ✗ | free(r2); | |
| 4596 | } | ||
| 4597 | } | ||
| 4598 | |||
| 4599 | /* | ||
| 4600 | * | ||
| 4601 | */ | ||
| 4602 | 10739 | void MultiSync::ProcessPingPacket(ControlPkt* pkt, int len, const std::string& srcIp, MultiSyncStats* stats, const std::string& incomingIp) { | |
| 4603 |
1/2✓ Branch 0 taken 10739 times.
✗ Branch 1 not taken.
|
10739 | LogDebug(VB_SYNC, "ProcessPingPacket()\n"); |
| 4604 | |||
| 4605 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 10697 times.
|
10739 | if (pkt->extraDataLen < 169) { // v1 packet length |
| 4606 |
2/4✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
|
42 | if (ShouldLogBadPacket()) { |
| 4607 | ✗ | LogErr(VB_SYNC, "ERROR: Invalid length of received Ping packet\n"); | |
| 4608 | ✗ | HexDump("Received data:", (void*)pkt, len, VB_SYNC); | |
| 4609 | } | ||
| 4610 | 42 | BumpStat(stats->pktError); | |
| 4611 | 156 | return; | |
| 4612 | } | ||
| 4613 | |||
| 4614 | 10697 | unsigned char* extraData = (unsigned char*)(((char*)pkt) + sizeof(ControlPkt)); | |
| 4615 | |||
| 4616 | 10697 | unsigned char pingVersion = extraData[0]; | |
| 4617 | |||
| 4618 |
4/4✓ Branch 0 taken 72 times.
✓ Branch 1 taken 10625 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 6 times.
|
10697 | if ((pingVersion == 1) && (pkt->extraDataLen > 169)) { |
| 4619 |
2/4✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 66 times.
|
66 | if (ShouldLogBadPacket()) { |
| 4620 | ✗ | LogErr(VB_SYNC, "ERROR: Ping v1 packet too long: %d\n", pkt->extraDataLen); | |
| 4621 | ✗ | HexDump("Received data:", (void*)pkt, len, VB_SYNC); | |
| 4622 | } | ||
| 4623 | 66 | BumpStat(stats->pktError); | |
| 4624 | 66 | return; | |
| 4625 | } | ||
| 4626 |
4/4✓ Branch 0 taken 72 times.
✓ Branch 1 taken 10559 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 24 times.
|
10631 | if ((pingVersion == 2) && (pkt->extraDataLen > 214)) { |
| 4627 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
|
48 | if (ShouldLogBadPacket()) { |
| 4628 | ✗ | LogErr(VB_SYNC, "ERROR: Ping v2 packet too long %d\n", pkt->extraDataLen); | |
| 4629 | ✗ | HexDump("Received data:", (void*)pkt, len, VB_SYNC); | |
| 4630 | } | ||
| 4631 | 48 | BumpStat(stats->pktError); | |
| 4632 | 48 | return; | |
| 4633 | } | ||
| 4634 | 10583 | int discover = extraData[1]; | |
| 4635 | |||
| 4636 | 10583 | MultiSyncSystemType type = (MultiSyncSystemType)extraData[2]; | |
| 4637 | |||
| 4638 | 10583 | unsigned int majorVersion = ((unsigned int)extraData[3] << 8) | extraData[4]; | |
| 4639 | 10583 | unsigned int minorVersion = ((unsigned int)extraData[5] << 8) | extraData[6]; | |
| 4640 | |||
| 4641 | 10583 | FPPMode systemMode = (FPPMode)extraData[7]; | |
| 4642 | |||
| 4643 | 10583 | bool isInstance = true; | |
| 4644 | 10583 | std::string address; | |
| 4645 |
5/8✓ Branch 0 taken 9 times.
✓ Branch 1 taken 10574 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
|
10583 | if (extraData[8] == 0 && extraData[9] == 0 && extraData[10] == 0 && extraData[11] == 0) { |
| 4646 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | if (discover) { |
| 4647 | // No ip address in packet, this is a ping/discovery packet | ||
| 4648 | // from something (xLights?) that is just trying to | ||
| 4649 | // get a list of FPP instances, we won't record this | ||
| 4650 | 7 | isInstance = false; | |
| 4651 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | address = "0.0.0.0"; |
| 4652 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (!incomingIp.empty()) { |
| 4653 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | address = incomingIp; |
| 4654 | } else { | ||
| 4655 | ✗ | isInstance = false; | |
| 4656 | ✗ | address = "0.0.0.0"; | |
| 4657 | } | ||
| 4658 | } else { | ||
| 4659 | char addrStr[16]; | ||
| 4660 | 10574 | memset(addrStr, 0, sizeof(addrStr)); | |
| 4661 | 10574 | snprintf(addrStr, 16, "%d.%d.%d.%d", extraData[8], extraData[9], | |
| 4662 | 10574 | extraData[10], extraData[11]); | |
| 4663 |
1/2✓ Branch 0 taken 10574 times.
✗ Branch 1 not taken.
|
10574 | address = addrStr; |
| 4664 | } | ||
| 4665 | |||
| 4666 | char tmpStr[128]; | ||
| 4667 | // Bounded copy of a packet string field. The packet tail is not guaranteed | ||
| 4668 | // to be NUL-terminated and may be longer than tmpStr, so clamp to both the | ||
| 4669 | // field's own size and the destination buffer to avoid a stack overflow / | ||
| 4670 | // over-read. | ||
| 4671 | 52549 | auto copyField = [&](int fieldOffset) -> std::string { | |
| 4672 | 52549 | int avail = (int)pkt->extraDataLen - fieldOffset; | |
| 4673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52549 times.
|
52549 | if (avail < 0) { |
| 4674 | ✗ | avail = 0; | |
| 4675 | } | ||
| 4676 | 52549 | int toCopy = std::min(avail, (int)(sizeof(tmpStr) - 1)); | |
| 4677 | 52549 | memset(tmpStr, 0, sizeof(tmpStr)); | |
| 4678 | 52549 | memcpy(tmpStr, (char*)(extraData + fieldOffset), toCopy); | |
| 4679 |
1/2✓ Branch 0 taken 52549 times.
✗ Branch 1 not taken.
|
105098 | return std::string(tmpStr); |
| 4680 | 10583 | }; | |
| 4681 |
1/2✓ Branch 0 taken 10583 times.
✗ Branch 1 not taken.
|
10583 | std::string hostname = copyField(12); |
| 4682 |
1/2✓ Branch 0 taken 10583 times.
✗ Branch 1 not taken.
|
10583 | std::string version = copyField(77); |
| 4683 |
1/2✓ Branch 0 taken 10583 times.
✗ Branch 1 not taken.
|
10583 | std::string typeStr = copyField(118); |
| 4684 | // End of v1 packet fields | ||
| 4685 | |||
| 4686 | 10583 | std::string ranges; | |
| 4687 |
2/2✓ Branch 0 taken 10547 times.
✓ Branch 1 taken 36 times.
|
10583 | if ((pkt->extraDataLen) > 169) { |
| 4688 |
1/2✓ Branch 0 taken 10547 times.
✗ Branch 1 not taken.
|
10547 | ranges = copyField(166 - 7); |
| 4689 | } | ||
| 4690 | |||
| 4691 | 10583 | bool isLocal = false; | |
| 4692 | { | ||
| 4693 | // Only m_interfaces needs m_socketLock; released before UpdateSystem() | ||
| 4694 | // below so it isn't held across a call that can re-enter m_socketLock | ||
| 4695 | // via UpdateUnicastDestinations() (m_socketLock is non-recursive). | ||
| 4696 |
1/2✓ Branch 0 taken 10583 times.
✗ Branch 1 not taken.
|
10583 | std::unique_lock<std::mutex> lock(m_socketLock); |
| 4697 |
2/2✓ Branch 0 taken 11825 times.
✓ Branch 1 taken 10583 times.
|
22408 | for (auto& a : m_interfaces) { |
| 4698 |
2/2✓ Branch 0 taken 5839 times.
✓ Branch 1 taken 5986 times.
|
11825 | if (address == a.second.interfaceAddress) { |
| 4699 | 5839 | isLocal = true; | |
| 4700 | } | ||
| 4701 | } | ||
| 4702 | 10583 | } | |
| 4703 | |||
| 4704 | // v4: the sender's SystemUUID, so every address a device pings from can be | ||
| 4705 | // tied to the one device without an HTTP round trip. Gated on length | ||
| 4706 | // rather than version, so anything that appends further still carries it. | ||
| 4707 | 10583 | std::string pktUUID; | |
| 4708 |
2/2✓ Branch 0 taken 10253 times.
✓ Branch 1 taken 330 times.
|
10583 | if (pkt->extraDataLen >= PING_V4_LEN) { |
| 4709 |
2/4✓ Branch 0 taken 10253 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10253 times.
✗ Branch 3 not taken.
|
10253 | pktUUID = copyField(PING_V3_LEN).substr(0, PING_UUID_MAX); |
| 4710 |
3/4✓ Branch 0 taken 10253 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 10246 times.
|
15421 | if (std::any_of(pktUUID.begin(), pktUUID.end(), [](unsigned char c) { return !isgraph(c); })) { |
| 4711 | 7 | pktUUID.clear(); | |
| 4712 | } | ||
| 4713 | } | ||
| 4714 | |||
| 4715 |
2/2✓ Branch 0 taken 10576 times.
✓ Branch 1 taken 7 times.
|
10583 | if (isInstance) { |
| 4716 |
9/14✓ Branch 0 taken 5839 times.
✓ Branch 1 taken 4737 times.
✓ Branch 2 taken 5839 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4649 times.
✓ Branch 5 taken 88 times.
✓ Branch 6 taken 4649 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 88 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4649 times.
✓ Branch 11 taken 5927 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
15225 | std::string uuid = isLocal ? getSetting("SystemUUID") : (pktUUID.empty() ? "Unknown" : pktUUID); |
| 4717 | 10576 | multiSync->UpdateSystem(type, majorVersion, minorVersion, | |
| 4718 | systemMode, address, hostname, version, | ||
| 4719 | typeStr, ranges, uuid, true, | ||
| 4720 |
1/2✓ Branch 0 taken 10576 times.
✗ Branch 1 not taken.
|
10576 | systemMode & 0x04 ? true : false); |
| 4721 | |||
| 4722 | // A discover ping is what an instance sends as its fppd starts (fppd.cpp | ||
| 4723 | // calls Discover() during startup), and a restart is exactly when most | ||
| 4724 | // of what we cache about a peer changes -- channel inputs/outputs, host | ||
| 4725 | // description, background color, anything else that needed a restart to | ||
| 4726 | // take effect. Clearing the fetch timestamp makes the next sweep re-ask | ||
| 4727 | // within INFO_SCAN_INTERVAL instead of serving up to | ||
| 4728 | // INFO_REFRESH_INTERVAL of stale detail. The cached values themselves | ||
| 4729 | // are left in place so the UI doesn't blank out mid-refetch. | ||
| 4730 | // | ||
| 4731 | // This cannot amplify into a fetch storm: a discover ping is only ever | ||
| 4732 | // answered with plain (non-discover) pings, so one restart invalidates | ||
| 4733 | // one system on each peer. xLights' discovery ping is also a discover | ||
| 4734 | // ping, but it carries no address and so never reaches this branch. | ||
| 4735 |
4/4✓ Branch 0 taken 2819 times.
✓ Branch 1 taken 7757 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 2750 times.
|
10576 | if (discover && !isLocal) { |
| 4736 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | multiSync->InvalidateSystemInfo(address); |
| 4737 | } | ||
| 4738 | 10576 | } | |
| 4739 |
2/2✓ Branch 0 taken 2826 times.
✓ Branch 1 taken 7757 times.
|
10583 | if (discover) { |
| 4740 |
6/6✓ Branch 0 taken 77 times.
✓ Branch 1 taken 2749 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 72 times.
✓ Branch 5 taken 2754 times.
|
2826 | if ((hostname != m_hostname) && !isLocal) { |
| 4741 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | QueueDiscoverReply(address, srcIp); |
| 4742 | } | ||
| 4743 | } | ||
| 4744 | |||
| 4745 | 10583 | BumpStat(stats->pktPing); | |
| 4746 | 10583 | } | |
| 4747 | |||
| 4748 | 29 | void MultiSync::ProcessPluginPacket(ControlPkt* pkt, int plen, MultiSyncStats* stats) { | |
| 4749 | 29 | LogDebug(VB_SYNC, "ProcessPluginPacket()\n"); | |
| 4750 | 29 | CommandPkt* cpkt = (CommandPkt*)(((char*)pkt) + sizeof(ControlPkt)); | |
| 4751 | 29 | int len = pkt->extraDataLen; | |
| 4752 | 29 | char* pn = &cpkt->command[0]; | |
| 4753 | // The plugin name must be NUL-terminated within the extra data. An | ||
| 4754 | // unterminated name would otherwise run strlen() out to the terminator the | ||
| 4755 | // receive loop writes one byte past the datagram, making nlen larger than | ||
| 4756 | // the data actually present and leaving a negative len for the plugins -- | ||
| 4757 | // which they take as a size_t and read far past the buffer. | ||
| 4758 | 29 | int nlen = (int)strnlen(pn, (size_t)len); | |
| 4759 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 5 times.
|
29 | if (nlen >= len) { |
| 4760 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (ShouldLogBadPacket()) { |
| 4761 | ✗ | LogErr(VB_SYNC, "Error: plugin packet name is not terminated within %d bytes of data\n", len); | |
| 4762 | } | ||
| 4763 | 24 | BumpStat(stats->pktError); | |
| 4764 | 24 | return; | |
| 4765 | } | ||
| 4766 | 5 | nlen++; // include the terminator | |
| 4767 | 5 | len -= nlen; | |
| 4768 | 5 | uint8_t* data = (uint8_t*)&cpkt->command[nlen]; | |
| 4769 | |||
| 4770 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
|
7 | for (auto a : getPluginsCopy()) { |
| 4771 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
6 | a->ReceivedPluginData(pn, data, len); |
| 4772 | 5 | } | |
| 4773 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | PluginManager::INSTANCE.multiSyncData(pn, data, len); |
| 4774 | |||
| 4775 | 5 | BumpStat(stats->pktPlugin); | |
| 4776 | } | ||
| 4777 | |||
| 4778 | 13 | static bool MyHostMatches(const std::string& host, const std::string& hostName, std::vector<MultiSyncSystem>& localSystems) { | |
| 4779 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | std::vector<std::string> names = split(host, ','); |
| 4780 |
3/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 9 times.
|
13 | if (std::find(names.begin(), names.end(), hostName) != names.end()) { |
| 4781 | 4 | return true; | |
| 4782 | } | ||
| 4783 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 8 times.
|
19 | for (auto& h : names) { |
| 4784 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 10 times.
|
25 | for (auto& ls : localSystems) { |
| 4785 |
5/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 14 times.
|
15 | if (h == ls.address || h == ls.hostname) { |
| 4786 | 1 | return true; | |
| 4787 | } | ||
| 4788 | } | ||
| 4789 | } | ||
| 4790 | 8 | return false; | |
| 4791 | 13 | } | |
| 4792 | |||
| 4793 | 67 | void MultiSync::ProcessFPPCommandPacket(ControlPkt* pkt, int len, MultiSyncStats* stats) { | |
| 4794 | // The caller has already checked len == sizeof(ControlPkt) + extraDataLen, | ||
| 4795 | // so the packet's own data ends at `end`. Every field below has to be | ||
| 4796 | // parsed strictly against that bound: a truncated or crafted packet whose | ||
| 4797 | // strings are not terminated inside it would otherwise be read out of the | ||
| 4798 | // stale contents of this reusable receive buffer -- and, for the last row of | ||
| 4799 | // that array, past the end of it -- and the result handed to CommandManager. | ||
| 4800 | 67 | const char* b = (const char*)pkt; | |
| 4801 | 67 | const char* end = b + sizeof(ControlPkt) + pkt->extraDataLen; | |
| 4802 | 67 | const char* pos = b + sizeof(ControlPkt); | |
| 4803 | |||
| 4804 | 1880 | auto readString = [&pos, end](std::string& out) { | |
| 4805 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1868 times.
|
1880 | if (pos >= end) { |
| 4806 | 12 | return false; | |
| 4807 | } | ||
| 4808 | 1868 | size_t avail = (size_t)(end - pos); | |
| 4809 | 1868 | size_t slen = strnlen(pos, avail); | |
| 4810 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1844 times.
|
1868 | if (slen == avail) { |
| 4811 | // ran to the end of the packet without finding a terminator | ||
| 4812 | 24 | return false; | |
| 4813 | } | ||
| 4814 | 1844 | out.assign(pos, slen); | |
| 4815 | 1844 | pos += slen + 1; | |
| 4816 | 1844 | return true; | |
| 4817 | 67 | }; | |
| 4818 | |||
| 4819 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 61 times.
|
67 | if (pos >= end) { |
| 4820 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if (ShouldLogBadPacket()) { |
| 4821 | ✗ | LogErr(VB_SYNC, "Error: truncated FPP Command packet\n"); | |
| 4822 | } | ||
| 4823 | 6 | BumpStat(stats->pktError); | |
| 4824 | 42 | return; | |
| 4825 | } | ||
| 4826 | // Unsigned: as a signed char an argument count above 127 reads as negative | ||
| 4827 | // and silently skips the whole argument list. | ||
| 4828 | 61 | uint8_t numArgs = (uint8_t)*pos++; | |
| 4829 | |||
| 4830 | 61 | std::string host; | |
| 4831 | 61 | std::string cmd; | |
| 4832 |
8/10✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 43 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 37 times.
✓ Branch 8 taken 24 times.
✓ Branch 9 taken 37 times.
|
61 | if (!readString(host) || !readString(cmd)) { |
| 4833 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | if (ShouldLogBadPacket()) { |
| 4834 | ✗ | LogErr(VB_SYNC, "Error: truncated FPP Command packet\n"); | |
| 4835 | } | ||
| 4836 | 24 | BumpStat(stats->pktError); | |
| 4837 | 24 | return; | |
| 4838 | } | ||
| 4839 | |||
| 4840 | 37 | std::vector<std::string> args; | |
| 4841 |
2/2✓ Branch 0 taken 1776 times.
✓ Branch 1 taken 25 times.
|
1801 | for (uint8_t x = 0; x < numArgs; x++) { |
| 4842 | 1776 | std::string arg; | |
| 4843 |
3/4✓ Branch 0 taken 1776 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 1764 times.
|
1776 | if (!readString(arg)) { |
| 4844 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
12 | if (ShouldLogBadPacket()) { |
| 4845 | ✗ | LogErr(VB_SYNC, "Error: FPP Command packet claims %d arguments but only holds %d\n", | |
| 4846 | (int)numArgs, (int)args.size()); | ||
| 4847 | } | ||
| 4848 | 12 | BumpStat(stats->pktError); | |
| 4849 | 12 | return; | |
| 4850 | } | ||
| 4851 |
1/2✓ Branch 0 taken 1764 times.
✗ Branch 1 not taken.
|
1764 | args.push_back(std::move(arg)); |
| 4852 |
2/2✓ Branch 0 taken 1764 times.
✓ Branch 1 taken 12 times.
|
1776 | } |
| 4853 | bool matches; | ||
| 4854 |
3/4✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 10 times.
|
25 | if (host == "") { |
| 4855 | 15 | matches = true; | |
| 4856 | } else { | ||
| 4857 | // Copy m_localSystems under m_systemsLock and release it before | ||
| 4858 | // evaluating/running -- MyHostMatches only needs a snapshot, and this | ||
| 4859 | // function must not hold m_systemsLock across CommandManager::run() or | ||
| 4860 | // the plugin callbacks below. | ||
| 4861 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 4862 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::vector<MultiSyncSystem> localSystems = m_localSystems; |
| 4863 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | lock.unlock(); |
| 4864 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | matches = MyHostMatches(host, m_hostname, localSystems); |
| 4865 | 10 | } | |
| 4866 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
|
25 | if (matches) { |
| 4867 | 20 | BumpStat(stats->pktFPPCommand); | |
| 4868 | // Remote-supplied and unbounded - truncate. (The args are covered by | ||
| 4869 | // CommandManager::run()'s own log line below.) | ||
| 4870 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | LogDebug(VB_COMMAND, "Command \"%s\" received from remote host %s (%s)\n", |
| 4871 | TruncateForLog(cmd).c_str(), stats->hostname.c_str(), stats->sourceIP.c_str()); | ||
| 4872 |
3/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 20 times.
|
21 | for (auto a : getPluginsCopy()) { |
| 4873 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | a->ReceivedFPPCommandPacket(cmd, args); |
| 4874 | 20 | } | |
| 4875 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | CommandManager::INSTANCE.run(cmd, args); |
| 4876 | } | ||
| 4877 |
6/6✓ Branch 0 taken 25 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 25 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 25 times.
✓ Branch 5 taken 36 times.
|
109 | } |
| 4878 | |||
| 4879 | 11 | void MultiSync::SendFPPCommandPacket(const std::string& host, const std::string& cmd, const std::vector<std::string>& args) { | |
| 4880 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (m_controlSock < 0) { |
| 4881 | ✗ | OpenControlSockets(); | |
| 4882 | } | ||
| 4883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (m_controlSock < 0) { |
| 4884 | ✗ | OpenControlSockets(); | |
| 4885 | ✗ | LogErr(VB_SYNC, "ERROR: Tried to send FPP Command packet but sync socket is not open.\n"); | |
| 4886 | 1 | return; | |
| 4887 | } | ||
| 4888 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | LogDebug(VB_SYNC, "SendFPPCommandPacket\n"); |
| 4889 |
2/4✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
|
11 | for (auto a : getPluginsCopy()) { |
| 4890 | ✗ | a->SendFPPCommandPacket(host, cmd, args); | |
| 4891 | 11 | } | |
| 4892 | // The argument count goes out as one byte, so more than 255 would wrap and | ||
| 4893 | // the remote would read a different command than this host runs. | ||
| 4894 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | if (args.size() > 255) { |
| 4895 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | LogErr(VB_SYNC, "ERROR: FPP Command \"%s\" has %d arguments, more than a MultiSync packet can carry\n", |
| 4896 | TruncateForLog(cmd).c_str(), (int)args.size()); | ||
| 4897 | 1 | return; | |
| 4898 | } | ||
| 4899 | // Payload: arg count, then host, cmd and each arg NUL-terminated. Sized | ||
| 4900 | // up front so a command too large for one packet is refused as a whole | ||
| 4901 | // rather than sent truncated (or dropped by every receiver) while this | ||
| 4902 | // host runs it in full. | ||
| 4903 | 10 | size_t payloadLen = 1 + host.length() + 1 + cmd.length() + 1; | |
| 4904 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 10 times.
|
68 | for (auto& a : args) { |
| 4905 | 58 | payloadLen += a.length() + 1; | |
| 4906 | } | ||
| 4907 | 10 | const bool fits = payloadLen <= MAX_MS_PAYLOAD; | |
| 4908 | |||
| 4909 | char outBuf[2048]; | ||
| 4910 | static_assert(sizeof(ControlPkt) + MAX_MS_PAYLOAD <= sizeof(outBuf), "outBuf must hold the largest packet"); | ||
| 4911 | 10 | bzero(outBuf, sizeof(outBuf)); | |
| 4912 | |||
| 4913 | 10 | ControlPkt* cpkt = (ControlPkt*)outBuf; | |
| 4914 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | InitControlPacket(cpkt); |
| 4915 | 10 | cpkt->pktType = CTRL_PKT_FPPCOMMAND; | |
| 4916 | |||
| 4917 | 10 | int pos = sizeof(ControlPkt); | |
| 4918 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
|
10 | if (fits) { |
| 4919 | 69 | auto appendField = [&](const std::string& v) { | |
| 4920 | 69 | memcpy(&outBuf[pos], v.c_str(), v.length() + 1); | |
| 4921 | 69 | pos += v.length() + 1; | |
| 4922 | 78 | }; | |
| 4923 | 9 | outBuf[pos++] = (unsigned char)args.size(); | |
| 4924 | 9 | appendField(host); | |
| 4925 | 9 | appendField(cmd); | |
| 4926 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 9 times.
|
60 | for (auto& a : args) { |
| 4927 | 51 | appendField(a); | |
| 4928 | } | ||
| 4929 | } | ||
| 4930 | 10 | cpkt->extraDataLen = pos - sizeof(ControlPkt); | |
| 4931 | |||
| 4932 | // SendFPPCommandPacket can run on API/command threads, so m_localSystems | ||
| 4933 | // must not be read without m_systemsLock; take a snapshot for both | ||
| 4934 | // MyHostMatches() calls below rather than locking per-call. | ||
| 4935 | 10 | std::vector<MultiSyncSystem> localSystems; | |
| 4936 | { | ||
| 4937 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | std::unique_lock<std::recursive_mutex> lock(m_systemsLock); |
| 4938 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | localSystems = m_localSystems; |
| 4939 | 10 | } | |
| 4940 | |||
| 4941 |
6/8✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 7 times.
|
10 | if (host != "" && host.find(",") == std::string::npos) { |
| 4942 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (MyHostMatches(host, m_hostname, localSystems)) { |
| 4943 | // only targetting myself, just run and don't send the packet | ||
| 4944 | ✗ | LogDebug(VB_COMMAND, "Command \"%s\" self-targeted, running locally without sending\n", cmd.c_str()); | |
| 4945 | ✗ | CommandManager::INSTANCE.run(cmd, args); | |
| 4946 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } else if (!fits) { |
| 4947 | ✗ | LogErr(VB_SYNC, "ERROR: FPP Command \"%s\" (%d bytes) is too large for a MultiSync packet, not sent\n", | |
| 4948 | TruncateForLog(cmd).c_str(), (int)payloadLen); | ||
| 4949 | } else { | ||
| 4950 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | SendUnicastPacket(host, outBuf, pos); |
| 4951 | } | ||
| 4952 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
|
7 | } else if (!fits) { |
| 4953 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | LogErr(VB_SYNC, "ERROR: FPP Command \"%s\" (%d bytes) is too large for a MultiSync packet, not sent or run\n", |
| 4954 | TruncateForLog(cmd).c_str(), (int)payloadLen); | ||
| 4955 | } else { | ||
| 4956 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | SendControlPacket(outBuf, pos); |
| 4957 | // Run it here directly: multicast and unicast don't loop back, and the | ||
| 4958 | // broadcast copies that do are dropped as our own (IsOwnEcho). | ||
| 4959 |
3/10✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
|
6 | if (host == "" || MyHostMatches(host, m_hostname, localSystems)) { |
| 4960 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | LogDebug(VB_COMMAND, "Command \"%s\" broadcast includes this host, running locally too\n", cmd.c_str()); |
| 4961 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | CommandManager::INSTANCE.run(cmd, args); |
| 4962 | } | ||
| 4963 | } | ||
| 4964 | 10 | } | |
| 4965 | |||
| 4966 | 21495 | MultiSyncStats::MultiSyncStats(std::string ip, std::string host) : | |
| 4967 | 21495 | sourceIP(ip), | |
| 4968 |
1/2✓ Branch 0 taken 21495 times.
✗ Branch 1 not taken.
|
21495 | hostname(host), |
| 4969 | 21495 | pktCommand(0), | |
| 4970 | 21495 | pktSyncSeqOpen(0), | |
| 4971 | 21495 | pktSyncSeqStart(0), | |
| 4972 | 21495 | pktSyncSeqStop(0), | |
| 4973 | 21495 | pktSyncSeqSync(0), | |
| 4974 | 21495 | pktSyncMedOpen(0), | |
| 4975 | 21495 | pktSyncMedStart(0), | |
| 4976 | 21495 | pktSyncMedStop(0), | |
| 4977 | 21495 | pktSyncMedSync(0), | |
| 4978 | 21495 | pktBlank(0), | |
| 4979 | 21495 | pktPing(0), | |
| 4980 | 21495 | pktPlugin(0), | |
| 4981 | 21495 | pktFPPCommand(0), | |
| 4982 | 21495 | pktError(0) { | |
| 4983 | 21495 | lastReceiveTime = time(NULL); | |
| 4984 | 21495 | } | |
| 4985 | |||
| 4986 | 2130 | Json::Value MultiSyncStats::toJSON() { | |
| 4987 |
1/2✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
|
2130 | Json::Value result; |
| 4988 | |||
| 4989 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["sourceIP"] = sourceIP; |
| 4990 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["hostname"] = hostname; |
| 4991 | |||
| 4992 | char timeStr[34]; | ||
| 4993 | 2130 | memset(timeStr, 0, sizeof(timeStr)); | |
| 4994 | struct tm tm; | ||
| 4995 | 2130 | localtime_r(&lastReceiveTime, &tm); | |
| 4996 | 2130 | snprintf(timeStr, sizeof(timeStr), "%4d-%.2d-%.2d %.2d:%.2d:%.2d", | |
| 4997 | 2130 | 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, | |
| 4998 | tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
| 4999 | |||
| 5000 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["lastReceiveTime"] = timeStr; |
| 5001 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktCommand"] = __atomic_load_n(&pktCommand, __ATOMIC_RELAXED); |
| 5002 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncSeqOpen"] = __atomic_load_n(&pktSyncSeqOpen, __ATOMIC_RELAXED); |
| 5003 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncSeqStart"] = __atomic_load_n(&pktSyncSeqStart, __ATOMIC_RELAXED); |
| 5004 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncSeqStop"] = __atomic_load_n(&pktSyncSeqStop, __ATOMIC_RELAXED); |
| 5005 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncSeqSync"] = __atomic_load_n(&pktSyncSeqSync, __ATOMIC_RELAXED); |
| 5006 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncMedOpen"] = __atomic_load_n(&pktSyncMedOpen, __ATOMIC_RELAXED); |
| 5007 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncMedStart"] = __atomic_load_n(&pktSyncMedStart, __ATOMIC_RELAXED); |
| 5008 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncMedStop"] = __atomic_load_n(&pktSyncMedStop, __ATOMIC_RELAXED); |
| 5009 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktSyncMedSync"] = __atomic_load_n(&pktSyncMedSync, __ATOMIC_RELAXED); |
| 5010 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktBlank"] = __atomic_load_n(&pktBlank, __ATOMIC_RELAXED); |
| 5011 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktPing"] = __atomic_load_n(&pktPing, __ATOMIC_RELAXED); |
| 5012 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktPlugin"] = __atomic_load_n(&pktPlugin, __ATOMIC_RELAXED); |
| 5013 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktFPPCommand"] = __atomic_load_n(&pktFPPCommand, __ATOMIC_RELAXED); |
| 5014 |
2/4✓ Branch 0 taken 2130 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2130 times.
✗ Branch 3 not taken.
|
2130 | result["pktError"] = __atomic_load_n(&pktError, __ATOMIC_RELAXED); |
| 5015 | |||
| 5016 | 2130 | return result; | |
| 5017 | ✗ | } | |
| 5018 |