Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/DSManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class DiscoveryServerManager
tinyxml2::XMLElement* snapshot);
void loadEnvironmentChange(
tinyxml2::XMLElement* snapshot);
void loadAPIChange(
tinyxml2::XMLElement* change);
void MapServerInfo(
tinyxml2::XMLElement* server);

Expand Down
5 changes: 5 additions & 0 deletions include/IDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ static const std::string s_sChange("change");
static const std::string s_sVariable("variable");
static const std::string s_sKey("key");
static const std::string s_sValue("value");
static const std::string s_sAPIChange("serverchange");
static const std::string s_sPrefix("prefix");
static const std::string s_sRemoteServer("RemoteServer");
static const std::string s_sAddress("address");
static const std::string s_sPort("port");

// specific Snapshot schema string literals
static const std::string s_sDS_Snapshots("DS_Snapshots");
Expand Down
35 changes: 35 additions & 0 deletions include/LJ.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,41 @@ class DelayedEnvironmentModification
DiscoveryServerManager& ) override;
};

class DelayedServerListChange
: public LateJoinerData // Delayed Server List Change via API
{
std::string prefix;
RemoteServerAttributes attributes;

public:

DelayedServerListChange(
const std::chrono::steady_clock::time_point tp,
std::string client_prefix,
RemoteServerAttributes attr)
: LateJoinerData(tp)
, prefix(client_prefix)
, attributes(attr)
{
}

~DelayedServerListChange() override
{
}

DelayedServerListChange() = delete;
DelayedServerListChange(
const DelayedServerListChange&) = default;
DelayedServerListChange(
DelayedServerListChange&&) = default;
DelayedServerListChange& operator =(
const DelayedServerListChange&) = default;
DelayedServerListChange& operator =(
DelayedServerListChange&&) = default;

void operator ()(
DiscoveryServerManager& ) override;
};
} // fastrtps
} // discovery_server

Expand Down
21 changes: 21 additions & 0 deletions resources/xsd/discovery-server.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,20 @@
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="RemoteServerChangeType">
<xs:attribute name="prefix" type="stringType" use="required" />
<xs:attribute name="addess" type="stringType" use="required" />
<xs:attribute name="port" type="uint32Type" use="required" />
</xs:complexType>

<xs:complexType name="ServerListChangeType">
<xs:sequence>
<xs:element name="RemoteServer" type="RemoteServerChangeType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="time" type="uint32Type" use="required" />
<xs:attribute name="prefix" type="stringType" use="required" />
</xs:complexType>

<xs:element name="DS">
<xs:complexType>
<xs:all>
Expand Down Expand Up @@ -1069,6 +1083,13 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="serverchange" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="change" type="ServerListChangeType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="user_shutdown" type="xs:boolean" default="true" use="optional" />
<xs:attribute name="prefix_validation" type="xs:boolean" default="true" use="optional" />
Expand Down
59 changes: 59 additions & 0 deletions src/DSManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ DiscoveryServerManager::DiscoveryServerManager(
change = change->NextSiblingElement(s_sChange.c_str());
}
}
tinyxml2::XMLElement* serverchange = child->FirstChildElement(s_sAPIChange.c_str());
if (serverchange)
{
tinyxml2::XMLElement* change = serverchange->FirstChildElement(s_sChange.c_str());
while (change != nullptr)
{
loadAPIChange(change);
change = change->NextSiblingElement(s_sChange.c_str());
}
}

}
}
Expand Down Expand Up @@ -1740,6 +1750,55 @@ void DiscoveryServerManager::loadEnvironmentChange(
events.push_back(new DelayedEnvironmentModification(time, key, value));
}

void DiscoveryServerManager::loadAPIChange(
tinyxml2::XMLElement* change)
{
std::lock_guard<std::recursive_mutex> lock(management_mutex);

// snapshots are created for debugging purposes
// time is mandatory
const char* time_str = change->Attribute(s_sTime.c_str());

if (time_str == nullptr)
{
LOG_ERROR(s_sTime << " is a mandatory attribute of " << s_sChange << " tag");
return;
}

const char* client_prefix = change->Attribute(s_sPrefix.c_str());
if (client_prefix == nullptr)
{
LOG_ERROR(s_sPrefix << " is a mandatory attribute of " << s_sChange << " tag");
return;
}

std::chrono::steady_clock::time_point time(getTime());
{
int aux;
std::istringstream(time_str) >> aux;
time += std::chrono::seconds(aux);
}

RemoteServerAttributes remote_server_att;

tinyxml2::XMLElement* remote_server = change->FirstChildElement(s_sRemoteServer.c_str());
while (remote_server != nullptr)
{
std::string address(remote_server->Attribute(s_sAddress.c_str()));
uint32_t port(remote_server->IntAttribute(s_sPort.c_str()));

remote_server_att.ReadguidPrefix(remote_server->Attribute(s_sPrefix.c_str()));
Locator locator;
IPLocator::setIPv4(locator, address);
locator.port = port;
remote_server_att.metatrafficUnicastLocatorList.push_back(locator);
remote_server = remote_server->NextSiblingElement(s_sRemoteServer.c_str());
}

// Add the event
events.push_back(new DelayedServerListChange(time, client_prefix, remote_server_att));
}

void DiscoveryServerManager::MapServerInfo(
tinyxml2::XMLElement* server)
{
Expand Down
21 changes: 21 additions & 0 deletions src/LJ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "LJ.h"

#include <fstream>
#include <sstream>

#include "log/DSLog.h"
#include "DSManager.h"
Expand Down Expand Up @@ -173,3 +174,23 @@ void DelayedEnvironmentModification::operator ()(
return;
}
}

void DelayedServerListChange::operator ()(
DiscoveryServerManager& man) /*override*/
{
GuidPrefix_t participant_prefix;
std::istringstream(prefix) >> participant_prefix;
GUID_t participant_guid (participant_prefix, ENTITYID_RTPSParticipant);
DomainParticipant* participant = man.getParticipant(participant_guid);

if (nullptr != participant)
{
DomainParticipantQos qos = participant->get_qos();
qos.wire_protocol().builtin.discovery_config.m_DiscoveryServers.push_back(attributes);
participant->set_qos(qos);
}
else
{
LOG_ERROR("Tried to modify Discovery Servers list of undiscovered participant: " << participant_guid);
}
}
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ if(fastrtps_VERSION VERSION_GREATER_EQUAL "2.4.0")
list(APPEND TEST_LIST
test_36_dns_environment_variable_setup
test_37_dns_fast_discovery_server_tool

test_50_environment_modification
test_51_discovery_server_list_api
)
endif()

Expand Down
Loading