Skip to content
Open
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
21 changes: 12 additions & 9 deletions src/Discovery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ namespace gz
this->hostInterfaces = determineInterfaces();
}

// Update the wire version if GZ_TRANSPORT_TOPIC_STATISTICS is set.
std::string gzStats;
if (env("GZ_TRANSPORT_TOPIC_STATISTICS", gzStats) && gzStats == "1")
this->wireVersion += 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be sure that Discovery is constructed only once?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's constructed twice, one for msgs and one for services here.

Are you thinking on race conditions? If so, they're constructed in sequence, so I think we should be good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm concerned that the since wireVersion is a static variable, every construction of the same template type would increment the wire version. I guess I'm not sure why it needs to be static at all if each instance will end up computing the wireVersion anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason to make it static is to preserve ABI.


#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData;
Expand Down Expand Up @@ -1568,15 +1573,7 @@ namespace gz
/// \return The discovery version.
private: uint8_t Version() const
{
static std::string gzStats;
static int topicStats;

if (env("GZ_TRANSPORT_TOPIC_STATISTICS", gzStats) && !gzStats.empty())
{
topicStats = (gzStats == "1");
}

return this->kWireVersion + (topicStats * 100);
return this->wireVersion;
}

/// \brief Register a new network interface in the discovery system.
Expand Down Expand Up @@ -1653,8 +1650,14 @@ namespace gz

/// \brief Wire protocol version. Bump up the version number if you modify
/// the wire protocol (for discovery or message/service exchange).
/// Note: Deprecated: Use wireVersion instead.
private: static const uint8_t kWireVersion = 10;

/// \brief Wire protocol version. Bump up the version number if you modify
/// the wire protocol (for discovery or message/service exchange).
/// \TODO(caguero): Remove static in Gazebo K.
private: static inline uint8_t wireVersion;

/// \brief Port used to broadcast the discovery messages.
private: int port;

Expand Down
Loading