Add SendMetadata methods to Server.

This commit is contained in:
Sadie Powell 2024-07-23 23:28:37 +01:00
parent 5d2f760e4d
commit 4175ba7833
4 changed files with 39 additions and 0 deletions

View File

@ -84,4 +84,17 @@ public:
* @return True if this server is a silent service, false otherwise.
*/
bool IsSilentService() const { return silentservice; }
/** Send metadata related to this server to the target server.
* @param key The name of the metadata (e.g. foo-bar).
* @param data The network representation of the metadata.
*/
virtual void SendMetadata(const std::string& key, const std::string& data) const;
/** Send metadata related to an extensible to the target server.
* @param ext The extensible to send metadata for.
* @param key The name of the metadata (e.g. foo-bar).
* @param data The network representation of the metadata.
*/
virtual void SendMetadata(const Extensible* ext, const std::string& key, const std::string& data) const;
};

View File

@ -291,3 +291,15 @@ void TreeServer::RemoveHash()
Utils->sidlist.erase(GetId());
Utils->serverlist.erase(GetName());
}
void TreeServer::SendMetadata(const std::string& key, const std::string& data) const
{
if (!GetRoute())
GetRoute()->GetSocket()->WriteLine(CommandMetadata::Builder(key, data));
}
void TreeServer::SendMetadata(const Extensible* ext, const std::string& key, const std::string& data) const
{
if (!GetRoute())
GetRoute()->GetSocket()->WriteLine(CommandMetadata::Builder(ext, key, data));
}

View File

@ -97,6 +97,10 @@ public:
*/
TreeServer();
void SendMetadata(const std::string& key, const std::string& data) const override;
void SendMetadata(const Extensible* ext, const std::string& key, const std::string& data) const override;
/** When we create a new server, we call this constructor to initialize it.
* This constructor initializes the server's Route and Parent, and sets up
* its ping counters so that it will be pinged one minute from now.

View File

@ -161,3 +161,13 @@ const std::string& Server::GetPublicName() const
return ServerInstance->Config->HideServer;
return GetName();
}
void Server::SendMetadata(const std::string& key, const std::string& data) const
{
// Do nothing for the local server.
}
void Server::SendMetadata(const Extensible* ext, const std::string& key, const std::string& data) const
{
// Do nothing for the local server.
}