Archived

This forum has been archived. Please start a new discussion on GitHub.

IceGrid Location

I created the following code to lookup an ice service record in DNS to find a Locator automatically instead of hand-coding the Locator into the config file. This would be an excellent addition to the Ice client code to automatically try to find a Locator if it isn't specified with an environment variable or in a config file. It would also make deploying Ice clients that much easier as no site-specific information would need to be changed from a default installation. Additionally, changing the location of the Locator is as simple as modifying an SRV entry on the DNS server.
#include <iostream>
#include <windows.h>
#include <Windns.h>

#pragma comment (lib, "dnsapi.lib")

using namespace std;

int main(void) {
	cout << "Locating Ice Grid..." << endl;
	PDNS_RECORD results;
	DWORD apicall = DnsQuery(
		"_ice._tcp",         // The Ice TCP service locator record
		DNS_TYPE_SRV,        // Request the SRV record type
		DNS_QUERY_STANDARD,  // Using a standard DNS query
		0,                   // Use the default DNS servers
		&results,            // Pointer to our result set
		0);                  // Reserved
	if (apicall) return apicall;
	
	PDNS_RECORD result = results;
	while (result->pNext) {
		PDNS_SRV_DATA record = &result->Data.SRV;
		cout
			<< "Locator=tcp"
			<< " -h " << record->pNameTarget
			<< " -p " << record->wPort
			<< endl;
		result = result->pNext;
	}
	DnsRecordListFree(results, DnsFreeRecordList);
	return 0;
}

Comments

  • benoit
    benoit Rennes, France
    Hi Eric,

    Note that you could easily put this code into an Ice plugin and set the communicator default locator to the value retrieved from the DNS. You would then just have to configure your Ice components to load this plugin!

    Cheers,
    Benoit.