mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-11 08:06:41 +02:00
improve unique host ID creation
This commit is contained in:
parent
fa3f78b08d
commit
5bf78eb874
5 changed files with 22 additions and 8 deletions
|
@ -182,9 +182,12 @@ void Controller::worker()
|
||||||
{
|
{
|
||||||
clientConnection_->start();
|
clientConnection_->start();
|
||||||
|
|
||||||
msg::Hello hello(clientConnection_->getMacAddress(), instance_);
|
/// Say hello to the server
|
||||||
|
string macAddress = clientConnection_->getMacAddress();
|
||||||
|
msg::Hello hello(macAddress, ::getHostId(macAddress), instance_);
|
||||||
clientConnection_->send(&hello);
|
clientConnection_->send(&hello);
|
||||||
|
|
||||||
|
/// Do initial time sync with the server
|
||||||
msg::Time timeReq;
|
msg::Time timeReq;
|
||||||
for (size_t n=0; n<50 && active_; ++n)
|
for (size_t n=0; n<50 && active_; ++n)
|
||||||
{
|
{
|
||||||
|
@ -197,6 +200,7 @@ void Controller::worker()
|
||||||
}
|
}
|
||||||
logO << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f << "\n";
|
logO << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f << "\n";
|
||||||
|
|
||||||
|
/// Main loop
|
||||||
while (active_)
|
while (active_)
|
||||||
{
|
{
|
||||||
for (size_t n=0; n<10 && active_; ++n)
|
for (size_t n=0; n<10 && active_; ++n)
|
||||||
|
|
|
@ -39,7 +39,8 @@
|
||||||
/// Forwards PCM data to the audio player
|
/// Forwards PCM data to the audio player
|
||||||
/**
|
/**
|
||||||
* Sets up a connection to the server (using ClientConnection)
|
* Sets up a connection to the server (using ClientConnection)
|
||||||
* Sets up the audio decoder and player. Decodes audio feeds PCM to the audio stream buffer
|
* Sets up the audio decoder and player.
|
||||||
|
* Decodes audio (message_type::kWireChunk) and feeds PCM to the audio stream buffer
|
||||||
* Does timesync with the server
|
* Does timesync with the server
|
||||||
*/
|
*/
|
||||||
class Controller : public MessageReceiver
|
class Controller : public MessageReceiver
|
||||||
|
|
|
@ -308,10 +308,12 @@ static std::string getMacAddress(int sock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static std::string getClientId(const std::string defaultId = "")
|
static std::string getHostId(const std::string defaultId = "")
|
||||||
{
|
{
|
||||||
std::string result = defaultId;
|
std::string result = defaultId;
|
||||||
if (!result.empty())
|
/// the Android API will return "02:00:00:00:00:00" for WifiInfo.getMacAddress().
|
||||||
|
/// Maybe this could also happen with native code
|
||||||
|
if (!result.empty() && (result != "02:00:00:00:00:00") && (result != "00:00:00:00:00:00"))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
@ -320,6 +322,7 @@ static std::string getClientId(const std::string defaultId = "")
|
||||||
return result;
|
return result;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// The host name should be unique enough in a LAN
|
||||||
return getHostName();
|
return getHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Hello(const std::string& macAddress, size_t instance) : JsonMessage(message_type::kHello)
|
Hello(const std::string& macAddress, const std::string& id, size_t instance) : JsonMessage(message_type::kHello)
|
||||||
{
|
{
|
||||||
msg["MAC"] = macAddress;
|
msg["MAC"] = macAddress;
|
||||||
msg["HostName"] = ::getHostName();
|
msg["HostName"] = ::getHostName();
|
||||||
|
@ -44,6 +44,7 @@ public:
|
||||||
msg["OS"] = ::getOS();
|
msg["OS"] = ::getOS();
|
||||||
msg["Arch"] = ::getArch();
|
msg["Arch"] = ::getArch();
|
||||||
msg["Instance"] = instance;
|
msg["Instance"] = instance;
|
||||||
|
msg["ID"] = id;
|
||||||
msg["SnapStreamProtocolVersion"] = 2;
|
msg["SnapStreamProtocolVersion"] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +92,14 @@ public:
|
||||||
return get("SnapStreamProtocolVersion", 1);
|
return get("SnapStreamProtocolVersion", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getClientId() const
|
std::string getId() const
|
||||||
{
|
{
|
||||||
std::string id = getMacAddress();
|
return get("ID", getMacAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getUniqueId() const
|
||||||
|
{
|
||||||
|
std::string id = getId();
|
||||||
int instance = getInstance();
|
int instance = getInstance();
|
||||||
if (instance != 1)
|
if (instance != 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -467,7 +467,7 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
{
|
{
|
||||||
msg::Hello helloMsg;
|
msg::Hello helloMsg;
|
||||||
helloMsg.deserialize(baseMessage, buffer);
|
helloMsg.deserialize(baseMessage, buffer);
|
||||||
connection->clientId = helloMsg.getClientId();
|
connection->clientId = helloMsg.getUniqueId();
|
||||||
logO << "Hello from " << connection->clientId << ", host: " << helloMsg.getHostName() << ", v" << helloMsg.getVersion()
|
logO << "Hello from " << connection->clientId << ", host: " << helloMsg.getHostName() << ", v" << helloMsg.getVersion()
|
||||||
<< ", ClientName: " << helloMsg.getClientName() << ", OS: " << helloMsg.getOS() << ", Arch: " << helloMsg.getArch()
|
<< ", ClientName: " << helloMsg.getClientName() << ", OS: " << helloMsg.getOS() << ", Arch: " << helloMsg.getArch()
|
||||||
<< ", Protocol version: " << helloMsg.getProtocolVersion() << "\n";
|
<< ", Protocol version: " << helloMsg.getProtocolVersion() << "\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue