In a recent patch, I added a --domain option related to DNS SRV support. Unfortunately, that overwrote the --daemon option. This patch removes the --domain option and adds a new --srv option which I actually like more than the previous --domain option anyway. So, now you have:
1) matahari-qmf-<agent>d
Determine the local domain. If found, do a DNS SRV lookup on it. If results are found, connect to that. When all else fails, connect to localhost.
2) matahari-qmf-<agent>d --broker russellbryant.net
Do a DNS A/AAAA lookup on russellbryant.net and connect to that.
3) matahari-qmf-<agent>d --broker russellbryant.net --srv
Do a DNS SRV lookup on russellbryant.net. If a result is found, use that. If not, do an A/AAAA lookup on russellbryant.net and use that.
Signed-off-by: Russell Bryant rbryant@redhat.com --- src/lib/mh_agent.cpp | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp index 27d7aa1..ef2d305 100644 --- a/src/lib/mh_agent.cpp +++ b/src/lib/mh_agent.cpp @@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n"); - printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n" - "\t For this option to take effect, the broker option must not\n" - "\t be provided.\n"); + printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n"); printf("\t-u | --username value username to use for authentication purposes.\n"); printf("\t-P | --password value password to use for authentication purposes.\n"); printf("\t-s | --service value service name to use for authentication purposes.\n"); @@ -205,12 +203,18 @@ mh_connect(qpid::types::Variant::Map mh_options, qpid::types::Variant::Map amqp_ int backoff = 0; char *target = NULL;
- if(mh_options.count("servername") == 0) { + if (!mh_options.count("servername") || mh_options.count("srv")) { + /* + * Do an SRV lookup either because no broker was specified at all, + * or because a broker domain was given and the --srv option was + * used specifically requesting an SRV lookup. + */ + /* Is _ssl valid here as a protocol? _udp? */ std::stringstream fqdn;
- if (mh_options.count("domain")) { - fqdn << "_matahari._tcp." << mh_options["domain"]; + if (mh_options.count("servername")) { + fqdn << "_matahari._tcp." << mh_options["servername"]; } else { fqdn << "_matahari._tcp." << mh_domainname(); } @@ -226,13 +230,15 @@ mh_connect(qpid::types::Variant::Map mh_options, qpid::types::Variant::Map amqp_
while (true) { std::stringstream url; - if(mh_options.count("servername") > 0) { - url << "amqp:" << mh_options["protocol"] << ":" << mh_options["servername"] << ":" << mh_options["serverport"] ; - } else if (target) { - /* Try DNS */ + + if (target) { + /* Use the result of a DNS SRV lookup. */ url << "amqp:" << mh_options["protocol"] << ":" << target << ":" << mh_options["serverport"] ; + } else if (mh_options.count("servername")) { + /* Use the explicitly specified broker hostname or IP address. */ + url << "amqp:" << mh_options["protocol"] << ":" << mh_options["servername"] << ":" << mh_options["serverport"] ; } else { - /* Try localhost */ + /* If nothing else, try localhost */ url << "amqp:" << mh_options["protocol"] << ":localhost:" << mh_options["serverport"] ; }
@@ -281,7 +287,7 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari
/* Force local-only handling */ mh_add_option('b', required_argument, "broker", NULL, NULL, NULL); - mh_add_option('d', required_argument, "domain", NULL, NULL, NULL); + mh_add_option('S', no_argument, "srv", NULL, NULL, NULL); mh_add_option('p', required_argument, "port", NULL, NULL, NULL); #ifdef MH_SSL mh_add_option('N', required_argument, "ssl-cert-name", NULL, NULL, NULL); @@ -306,8 +312,8 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari
if (RegistryRead(HKEY_LOCAL_MACHINE, L"SYSTEM\CurrentControlSet\services\Matahari", - L"domain", &value) == 0) { - options["domain"] = value; + L"srv", &value) == 0) { + options["srv"] = value; value = NULL; }
@@ -395,8 +401,8 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari mh_err("Broker '%s' is not resolvable - ignoring", optarg); } break; - case 'd': - options["domain"] = optarg; + case 'S': + options["srv"] = 1; break; #ifdef MH_SSL case 'N':
On 23/08/11 16:20, Russell Bryant wrote:
In a recent patch, I added a --domain option related to DNS SRV support. Unfortunately, that overwrote the --daemon option. This patch removes the --domain option and adds a new --srv option which I actually like more than the previous --domain option anyway. So, now you have:
matahari-qmf-<agent>d
Determine the local domain. If found, do a DNS SRV lookup on it. If results are found, connect to that. When all else fails, connect to localhost.
matahari-qmf-<agent>d --broker russellbryant.net
Do a DNS A/AAAA lookup on russellbryant.net and connect to that.
matahari-qmf-<agent>d --broker russellbryant.net --srv
Do a DNS SRV lookup on russellbryant.net. If a result is found, use that. If not, do an A/AAAA lookup on russellbryant.net and use that.
Signed-off-by: Russell Bryantrbryant@redhat.com
src/lib/mh_agent.cpp | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/lib/mh_agent.cpp b/src/lib/mh_agent.cpp index 27d7aa1..ef2d305 100644 --- a/src/lib/mh_agent.cpp +++ b/src/lib/mh_agent.cpp @@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n");
- printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n"
"\t For this option to take effect, the broker option must not\n"
"\t be provided.\n");
- printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n");
Should be "--srv value"
printf("\t-u | --username value username to use for authentication purposes.\n"); printf("\t-P | --password value password to use for authentication purposes.\n"); printf("\t-s | --service value service name to use for authentication purposes.\n");
@@ -205,12 +203,18 @@ mh_connect(qpid::types::Variant::Map mh_options, qpid::types::Variant::Map amqp_ int backoff = 0; char *target = NULL;
- if(mh_options.count("servername") == 0) {
- if (!mh_options.count("servername") || mh_options.count("srv")) {
/*
* Do an SRV lookup either because no broker was specified at all,
* or because a broker domain was given and the --srv option was
* used specifically requesting an SRV lookup.
*/
/* Is _ssl valid here as a protocol? _udp? */ std::stringstream fqdn;
if (mh_options.count("domain")) {
fqdn<< "_matahari._tcp."<< mh_options["domain"];
if (mh_options.count("servername")) {
fqdn<< "_matahari._tcp."<< mh_options["servername"]; } else { fqdn<< "_matahari._tcp."<< mh_domainname(); }
@@ -226,13 +230,15 @@ mh_connect(qpid::types::Variant::Map mh_options, qpid::types::Variant::Map amqp_
while (true) { std::stringstream url;
if(mh_options.count("servername")> 0) {
url<< "amqp:"<< mh_options["protocol"]<< ":"<< mh_options["servername"]<< ":"<< mh_options["serverport"] ;
} else if (target) {
/* Try DNS */
if (target) {
/* Use the result of a DNS SRV lookup. */ url<< "amqp:"<< mh_options["protocol"]<< ":"<< target<< ":"<< mh_options["serverport"] ;
} else if (mh_options.count("servername")) {
/* Use the explicitly specified broker hostname or IP address. */
url<< "amqp:"<< mh_options["protocol"]<< ":"<< mh_options["servername"]<< ":"<< mh_options["serverport"] ; } else {
/* Try localhost */
/* If nothing else, try localhost */ url<< "amqp:"<< mh_options["protocol"]<< ":localhost:"<< mh_options["serverport"] ; }
@@ -281,7 +287,7 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari
/* Force local-only handling */ mh_add_option('b', required_argument, "broker", NULL, NULL, NULL);
- mh_add_option('d', required_argument, "domain", NULL, NULL, NULL);
- mh_add_option('S', no_argument, "srv", NULL, NULL, NULL); mh_add_option('p', required_argument, "port", NULL, NULL, NULL); #ifdef MH_SSL mh_add_option('N', required_argument, "ssl-cert-name", NULL, NULL, NULL);
@@ -306,8 +312,8 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari
if (RegistryRead(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\services\\Matahari",
L"domain",&value) == 0) {
options["domain"] = value;
L"srv",&value) == 0) {
options["srv"] = value; value = NULL; }
@@ -395,8 +401,8 @@ mh_parse_options(const char *proc_name, int argc, char **argv, qpid::types::Vari mh_err("Broker '%s' is not resolvable - ignoring", optarg); } break;
case 'd':
options["domain"] = optarg;
case 'S':
#ifdef MH_SSL case 'N':options["srv"] = 1; break;
On 08/23/2011 10:26 AM, Zane Bitter wrote:
On 23/08/11 16:20, Russell Bryant wrote:
@@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n");
- printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n"
"\t For this option to take effect, the broker option must not\n"
"\t be provided.\n");
- printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n");
Should be "--srv value"
It is currently defined as not taking an argument.
On 23/08/11 17:44, Russell Bryant wrote:
On 08/23/2011 10:26 AM, Zane Bitter wrote:
On 23/08/11 16:20, Russell Bryant wrote:
@@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n");
- printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n"
"\t For this option to take effect, the broker option must not\n"
"\t be provided.\n");
- printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n");
Should be "--srv value"
It is currently defined as not taking an argument.
Ah, my bad. I should have read that big comment-y thing at the top.
It seems slightly odd that --broker is sometimes a host and sometimes a domain, but OK.
On 08/23/2011 01:33 PM, Zane Bitter wrote:
On 23/08/11 17:44, Russell Bryant wrote:
On 08/23/2011 10:26 AM, Zane Bitter wrote:
On 23/08/11 16:20, Russell Bryant wrote:
@@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n");
- printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n"
"\t For this option to take effect, the broker option must not\n"
"\t be provided.\n");
- printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n");
Should be "--srv value"
It is currently defined as not taking an argument.
Ah, my bad. I should have read that big comment-y thing at the top.
It seems slightly odd that --broker is sometimes a host and sometimes a domain, but OK.
Not to me... it's similar to how other applications that use SRV work. It usually happens behind the scenes, though. It would be even better to:
1) Determine if the --broker is an IP address and if so, use it.
2) If it's a hostname, first try an SRV lookup. If that fails, fall back to an A/AAAA lookup.
but I don't think it's strictly necessary to implement that.
As a random example of another application that uses SRV records, take Pidgin (the IM client). Let's say you want to add your gmail account as a Jabber/XMPP account. All you have to do is say that your account is <you>@gmail.com. From there, it's going to first try an SRV lookup on gmail.com (which will succeed), and that's how it knows where to connect.
$ dig -t SRV _jabber._tcp.gmail.com
My personal domain, russellbryant.net, is hosted on google apps, so it also supports jabber. However, I don't have the proper SRV record set up, so if I try to set up that as an account in Pidgin the same way, it won't work. It ends up trying to connect to "russellbryant.net", which is not Google's XMPP server. I have to set an additional option that specifies the specific server to connect to, and then it works.
On 23/08/11 21:06, Russell Bryant wrote:
On 08/23/2011 01:33 PM, Zane Bitter wrote:
On 23/08/11 17:44, Russell Bryant wrote:
On 08/23/2011 10:26 AM, Zane Bitter wrote:
On 23/08/11 16:20, Russell Bryant wrote:
@@ -174,9 +174,7 @@ int print_help(int code, const char *name, const char *arg, void *userdata) printf("\t-h | --help print this help message.\n"); printf("\t-b | --broker value specify broker host name..\n"); printf("\t-p | --port value specify broker port.\n");
- printf("\t-d | --domain value Specify domain to connect to (Use DNS SRV to determine host).\n"
"\t For this option to take effect, the broker option must not\n"
"\t be provided.\n");
- printf("\t-S | --srv Enable DNS SRV lookup for the specified broker.\n");
Should be "--srv value"
It is currently defined as not taking an argument.
Ah, my bad. I should have read that big comment-y thing at the top.
It seems slightly odd that --broker is sometimes a host and sometimes a domain, but OK.
Not to me... it's similar to how other applications that use SRV work. It usually happens behind the scenes, though. It would be even better to:
1) Determine if the --broker is an IP address and if so, use it. 2) If it's a hostname, first try an SRV lookup. If that fails, fall back to an A/AAAA lookup.
but I don't think it's strictly necessary to implement that.
As a random example of another application that uses SRV records, take Pidgin (the IM client). Let's say you want to add your gmail account as a Jabber/XMPP account. All you have to do is say that your account is <you>@gmail.com. From there, it's going to first try an SRV lookup on gmail.com (which will succeed), and that's how it knows where to connect.
$ dig -t SRV _jabber._tcp.gmail.com
My personal domain, russellbryant.net, is hosted on google apps, so it also supports jabber. However, I don't have the proper SRV record set up, so if I try to set up that as an account in Pidgin the same way, it won't work. It ends up trying to connect to "russellbryant.net", which is not Google's XMPP server. I have to set an additional option that specifies the specific server to connect to, and then it works.
In that case I think you may have a bug, because servername is not set unless the servername itself is resolvable as a hostname:
rc = getaddrinfo(arg, NULL, &hints, &res); if (rc == 0) { (*options)["servername"] = arg; } else { mh_err("Broker '%s' is not resolvable - ignoring", arg); }
If that is a bug, I'll fix it because I'm changing this code anyway.
On 08/25/2011 12:04 PM, Zane Bitter wrote:
In that case I think you may have a bug, because servername is not set unless the servername itself is resolvable as a hostname:
rc = getaddrinfo(arg, NULL,&hints,&res); if (rc == 0) { (*options)["servername"] = arg; } else { mh_err("Broker '%s' is not resolvable - ignoring", arg); }
I guess in theory that's the case ... I would just remove this check. However, the likelihood that example.com has no A/AAAA records but does have SRV records for a particular service is pretty small.
matahari@lists.fedorahosted.org