// Multiple servers found
+
+ /*
+
// Special case: If there are two servers returned and they only differ by IP version and IP, select one and connect automatically
if ( (numServers == 2)
&& !vdpc[0].name.compare(vdpc[1].name) // if the names are the same...
&& (vdpc[0].port == vdpc[1].port) // and the port number is the same...
&& (vdpc[0].ipVersion != vdpc[1].ipVersion) // and the IP versions DO NOT match...
- /* and the IPs don't match - they can't if ipVersions are different */
+ / * and the IPs don't match - they can't if ipVersions are different * /
)
{
int which = 6;
continue; // restart discovery
}
+ */
+
+
// Now numServers > 1
VServerSelect* vs = new VServerSelect(vdpc, this); // deleted by handleCommand returning BoxStack::DELETE_ME
#include <algorithm>
#include "log.h"
+#include "config.h"
#include "wol.h"
#include "vdpc.h"
bool VDPC::init()
{
+ logger = LogNT::getInstance();
+
AddServerCallback addFunc( [this] (int ipVersion, const char* ip, const char* name, USHORT port, ULONG version)
{
std::lock_guard<std::mutex> lg(serversLock);
do
{
- LogNT::getInstance()->debug(TAG, "Sending broadcasts");
+ logger->debug(TAG, "Sending broadcasts");
#ifdef IPV4
vdpc4.sendRequest();
#endif
waitCond.wait_for(ul, std::chrono::milliseconds(1500), [this]{ return stopNow == true; });
- LogNT::getInstance()->debug(TAG, "go() wait finished");
+ logger->debug(TAG, "go() wait finished");
if (stopNow) break;
if (servers.size() == 0) Wol::getInstance()->doWakeUp();
vdpc6.stop();
#endif
+ filterServers();
+
std::sort(servers.begin(), servers.end(), ServerSorter());
return servers.size();
}
return servers[index];
}
+void VDPC::filterServers()
+{
+ // If the same VDR instance has replied on both IPv4 and IPv6,
+ // remove one based on the config option server-discovery.prefer-ipv
+
+ // It is assumed that we can only get a maximum of two responses from
+ // the same server. The only way this doesn't happen is if two different
+ // VDR-vompservers are running with the same server name in the config.
+ // This is not supported. Results will not be as you would expect.
+
+ Config* config = Config::getInstance();
+ int which = 6;
+ config->getInt("server-discovery", "prefer-ipv", which);
+ logger->debug(TAG, "Auto select IPv{}", which);
+
+ bool removed;
+ do
+ {
+ removed = false;
+
+ for(auto i = servers.begin(); i != servers.end(); i++)
+ {
+ for(auto j = i + 1; j != servers.end(); j++)
+ {
+ if (i->name == j->name)
+ {
+ if (i->ipVersion != which)
+ {
+
+ logger->debug(TAG, "{} found twice, removing {}", i->name, i->ipVersion);
+
+ servers.erase(i);
+ removed = true;
+ break;
+ }
+
+ if (j->ipVersion != which)
+ {
+
+ logger->debug(TAG, "{} found twice, removing {}", j->name, j->ipVersion);
+
+ servers.erase(j);
+ removed = true;
+ break;
+ }
+ }
+ }
+
+ if (removed) break;
+ }
+
+ } while (removed);
+}
+
+
#ifdef IPV4
// ======================================= VDPC4