On Mon, 2009-12-07 at 09:10 -0500, Scott Lawrence wrote:
> Could/should we modify things so that if all else is equal, the local
> host is preferred over alternative SRV targets? Do we have enough
> information now in SipTransaction to do that?
It turns out that the change is pretty easy down in SipSrvLookup.cpp.
Please have a look at the attached patch to check my logic and the unit
test cases I added for it (crucible is being upgraded now, and it's not
so great for reviewing patches like this that are small widely-spaced
changes unless the change is checked in).
I think that this is only really useful in the proxy (it's the only
thing that routinely spirals), but there it might well be significant,
especially if we start using names in route headers more (which,
ideally, we should). If the host name is not set, this change should
have no effect at all (and I verified that by running the unit test
without the name setting code added).
At the moment, the proxy doesn't seem to actually have a specific
configuration directive that configures its own host name, so that would
have to be added to take advantage of this, but that's trivial.
diff --git a/sipXtackLib/include/net/SipSrvLookup.h b/sipXtackLib/include/net/SipSrvLookup.h
index 1d1da85..1c1ba53 100644
--- a/sipXtackLib/include/net/SipSrvLookup.h
+++ b/sipXtackLib/include/net/SipSrvLookup.h
@@ -160,6 +160,12 @@ public:
* configuration.
*/
+ /// Sets our own hostname - if priorities are equal, our own name sorts above other alternatives
+ static void setOwnHostname(const char* hostname);
+
+ /// Is the passed host name the same as that passed to setOwnHostname?
+ static bool isOwnHostname(const char* hostname);
+
/// Sets the timing parameters for DNS SRV queries.
static void setDnsSrvTimeouts(int initialTimeoutInSecs,
/**< Timeout in seconds for first query,
@@ -217,6 +223,9 @@ protected:
/// The array of option values.
static int options[OptionCodeLast+1];
+ /// Our own hostname
+ static UtlString mOwnHostname;
+
/// Sets the timeout parameter for DNS SRV queries. Default is 3
static int mTimeout;
diff --git a/sipXtackLib/src/net/SipSrvLookup.cpp b/sipXtackLib/src/net/SipSrvLookup.cpp
index ca6adb6..8148ca3 100644
--- a/sipXtackLib/src/net/SipSrvLookup.cpp
+++ b/sipXtackLib/src/net/SipSrvLookup.cpp
@@ -241,6 +241,9 @@ int SipSrvLookup::options[OptionCodeLast+1] = {
};
/// Sets the timeout parameter for DNS SRV queries. Default is 3
+UtlString SipSrvLookup::mOwnHostname;
+
+/// Sets the timeout parameter for DNS SRV queries. Default is 3
int SipSrvLookup::mTimeout = 3;
/// Sets the number of retries for DNS SRV queries. Default is 2
@@ -500,6 +503,20 @@ void SipSrvLookup::setOption(OptionCode option, int value)
options[option] = value;
}
+void SipSrvLookup::setOwnHostname(const char* hostname)
+{
+ // Seize the lock, to ensure atomic effect.
+ OsLock lock(sMutex);
+
+ mOwnHostname = hostname;
+}
+
+bool SipSrvLookup::isOwnHostname(const char* hostname)
+{
+ return mOwnHostname.compareTo(hostname, UtlString::ignoreCase) == 0;
+}
+
+
//! Sets the DNS SRV times. Defaults: timeout=5, retries=4
void SipSrvLookup::setDnsSrvTimeouts(int initialTimeoutInSecs, int retries)
{
@@ -1034,6 +1051,18 @@ int server_compare(const void* a, const void* b,
{
result = -1;
}
+ /*
+ * Next, if our own hostname is set, the check to see of one of these is
+ * our own name - if so, it is preferred regardless of the weights.
+ */
+ else if (SipSrvLookup::isOwnHostname(s1->host))
+ {
+ result = -1;
+ }
+ else if (SipSrvLookup::isOwnHostname(s2->host))
+ {
+ result = 1;
+ }
// Next compare the scores derived from the weights.
// With the new scheme for computing scores, lower score values should
// sort to the beginning of the list, that is, should compare less than
diff --git a/sipXtackLib/src/test/Makefile.am b/sipXtackLib/src/test/Makefile.am
index 99890c6..a6575c4 100644
--- a/sipXtackLib/src/test/Makefile.am
+++ b/sipXtackLib/src/test/Makefile.am
@@ -1,6 +1,6 @@
## All tests under this GNU variable should run relatively quickly
## and of course require no setup
-TESTS = testsuite
+TESTS = sandbox
check_PROGRAMS = testsuite sandbox
@@ -75,4 +75,4 @@ EXTRA_DIST = \
sandbox_LDADD = $(testsuite_LDADD)
sandbox_CXXFLAGS = $(testsuite_CXXFLAGS)
-sandbox_SOURCES =
+sandbox_SOURCES = net/SipSrvLookupTest.cpp
diff --git a/sipXtackLib/src/test/net/SipSrvLookupTest.cpp b/sipXtackLib/src/test/net/SipSrvLookupTest.cpp
index 96ae914..cde71dc 100644
--- a/sipXtackLib/src/test/net/SipSrvLookupTest.cpp
+++ b/sipXtackLib/src/test/net/SipSrvLookupTest.cpp
@@ -536,11 +536,38 @@ public:
"2.1.4.0:8004,1,0.930,1,TCP\n"
"" },
+ // Test to see that our own name _does_ override weights
+ { "test30", "sip", OsSocket::UNKNOWN, -1, NULL,
+ "2.1.8.1:5060,1,0.244,1,TCP\n"
+ "2.1.8.1:5060,1,0.225,1,UDP\n"
+ "2.1.8.2:5060,1000,0.000,1,UDP\n"
+ "2.1.8.3:5060,100,0.009,1,TCP\n"
+ "" },
+
+ // Test to see that our own name _does_not override priorities
+ { "test31", "sip", OsSocket::UNKNOWN, -1, NULL,
+ "2.1.8.2:5060,1000,0.000,1,UDP\n"
+ "2.1.8.3:5060,100,0.009,1,TCP\n"
+ "2.1.8.1:5060,1,0.244,2,TCP\n"
+ "2.1.8.1:5060,1,0.225,2,UDP\n"
+ "" },
+
+ // Test to see that name preference works among low-priority alternatives
+ { "test32", "sip", OsSocket::UNKNOWN, -1, NULL,
+ "2.1.8.2:5060,1,0.174,1,UDP\n"
+ "2.1.8.1:5060,1,0.244,2,TCP\n"
+ "2.1.8.1:5060,1,0.225,2,UDP\n"
+ "2.1.8.3:5060,100,0.009,2,TCP\n"
+ "" },
+
};
// Flag for whether any test cases have failed.
int failure_seen = 0;
+ // Set our own host name to testself.example.com
+ SipSrvLookup::setOwnHostname("testself.example.com");
+
// Set up the option values we desire for all tests.
SipSrvLookup::setOption(SipSrvLookup::OptionCodeSortAnswers, 1);
SipSrvLookup::setOption(SipSrvLookup::OptionCodeSortServers, 1);
diff --git a/sipXtackLib/src/test/net/SipSrvLookupTest.named.zone b/sipXtackLib/src/test/net/SipSrvLookupTest.named.zone
index 1eac663..7aeef23 100644
--- a/sipXtackLib/src/test/net/SipSrvLookupTest.named.zone
+++ b/sipXtackLib/src/test/net/SipSrvLookupTest.named.zone
@@ -3,7 +3,7 @@
$TTL 86400
$ORIGIN .
@ 1D IN SOA @ worley.ariadne.com. (
- 2005060702 ; serial
+ 2009120904 ; serial
24H ; refresh
1H ; retry
1W ; expire
@@ -90,8 +90,22 @@ _sip._udp.test29 1D IN SRV 1 10 8003 test4.example.com.
_sip._tcp.test29 1D IN SRV 1 100 8002 test4.example.com.
_sip._tcp.test29 1D IN SRV 1 1 8004 test4.example.com.
-;; Records used by more than one test.
+_sip._udp.test30 1D IN SRV 1 1 5060 testself.example.com.
+_sip._tcp.test30 1D IN SRV 1 1 5060 testself.example.com.
+_sip._udp.test30 1D IN SRV 1 1000 5060 testother2.example.com.
+_sip._tcp.test30 1D IN SRV 1 100 5060 testother3.example.com.
+
+_sip._udp.test31 1D IN SRV 2 1 5060 testself.example.com.
+_sip._tcp.test31 1D IN SRV 2 1 5060 testself.example.com.
+_sip._udp.test31 1D IN SRV 1 1000 5060 testother2.example.com.
+_sip._tcp.test31 1D IN SRV 1 100 5060 testother3.example.com.
+
+_sip._udp.test32 1D IN SRV 1 1 5060 testother2.example.com.
+_sip._udp.test32 1D IN SRV 2 1 5060 testself.example.com.
+_sip._tcp.test32 1D IN SRV 2 1 5060 testself.example.com.
+_sip._tcp.test32 1D IN SRV 2 100 5060 testother3.example.com.
+;; Records used by more than one test.
test4.example.com 1D IN A 2.1.4.0
test5.example.com 1D IN A 2.1.5.0
test6a.example.com 1D IN A 2.1.6.0
@@ -99,3 +113,7 @@ test6b.example.com 1D IN A 2.1.6.1
test6udp.example.com 1D IN A 2.1.6.0
test6tcp.example.com 1D IN A 2.1.6.1
test7.example.com 1D IN A 2.1.7.0
+
+testself.example.com 1D IN A 2.1.8.1
+testother2.example.com 1D IN A 2.1.8.2
+testother3.example.com 1D IN A 2.1.8.3
_______________________________________________
sipx-dev mailing list [email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev
sipXecs IP PBX -- http://www.sipfoundry.org/