Skip to content

Commit

Permalink
Merge "Send subscriber discovery client ip address" into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 19, 2015
2 parents bdf4223 + 63f391e commit c6e6c43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/discovery/client/discovery_client.cc
Expand Up @@ -169,11 +169,19 @@ DiscoveryServiceClient::DiscoveryServiceClient(EventManager *evm,
this, _1)),
shutdown_(false),
subscriber_name_(client_name),
heartbeat_interval_(DiscoveryServiceClient::kHeartBeatInterval) {
heartbeat_interval_(DiscoveryServiceClient::kHeartBeatInterval),
local_addr_("127.0.0.1") {
}

void DiscoveryServiceClient::Init() {
http_client_->Init();

boost::system::error_code ec;
boost::asio::ip::tcp::socket socket(*evm_->io_service());
socket.connect(ds_endpoint_, ec);
if (ec == 0) {
local_addr_ = socket.local_endpoint().address().to_string();
}
}

void DiscoveryServiceClient::Shutdown() {
Expand Down Expand Up @@ -619,16 +627,8 @@ void DiscoveryServiceClient::Subscribe(std::string serviceName,
subscriber_name_;
pugi->AddChildNode("client", client_id);
pugi->ReadNode(serviceName); //Reset parent
pugi->AddChildNode("remote-addr", local_addr_);

//Retrieve ip address
ip::udp::resolver resolver(*evm_->io_service());
ip::udp::resolver::query query(ip::udp::v4(), ip::host_name(error), "");
ip::udp::resolver::iterator endpoint_iter = resolver.resolve(query, error);
if (!error) {
ip::udp::endpoint ep = *endpoint_iter++;
pugi->AddChildNode("remote-addr", ep.address().to_string());
}

stringstream ss;
impl->PrintDoc(ss);

Expand Down
1 change: 1 addition & 0 deletions src/discovery/client/discovery_client.h
Expand Up @@ -214,6 +214,7 @@ class DiscoveryServiceClient {
bool shutdown_;
std::string subscriber_name_;
int heartbeat_interval_;
std::string local_addr_;
};

#endif // __DISCOVERY_SERVICE_CLIENT_H__

0 comments on commit c6e6c43

Please sign in to comment.