Resolve the hostname of a MGCP endpoint only when first needed.

git-svn-id: http://voip.null.ro/svn/yate@4972 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2012-03-22 14:01:24 +00:00
parent f1a062da01
commit 529737a967
5 changed files with 62 additions and 25 deletions

View File

@ -142,9 +142,10 @@
; A value of -1 uses default 2427 but doesn't add at end of ID
;port=2427
; address: ipaddress: IP address of the gateway, if present will override
; resolving the host name and will immediately make the span operational
; without waiting for a remote RSIP
; address: ipaddress: IP address of the gateway
; If present will override resolving the host name and will immediately make
; the span operational without waiting for a remote RSIP
; A boolean true value will resolve the host to an address at startup
;address=
; version: string: Protocol name and version to use initially, if left blank

View File

@ -115,4 +115,16 @@ void MGCPEndpointId::set(const char* endpoint, const char* host, int port, bool
m_id << ":" << m_port;
}
// Resolve the Ep Info host on first demand
const SocketAddr& MGCPEpInfo::address()
{
if (m_resolve) {
m_resolve = false;
DDebug(DebugInfo,"Resolving MGCP host '%s'",host().c_str());
m_address.host(host());
}
return m_address;
}
/* vi: set ts=8 sw=4 sts=4 noet: */

View File

@ -608,9 +608,9 @@ public:
* @param addPort Add :port at end of id only if port is not zero
*/
inline MGCPEpInfo(const char* endpoint, const char* host, int port, bool addPort = true)
: MGCPEndpointId(endpoint,host,port,addPort), address(AF_INET) {
address.host(host);
address.port(port);
: MGCPEndpointId(endpoint,host,port,addPort),
m_address(AF_INET), m_resolve(true) {
m_address.port(port);
}
/**
@ -621,14 +621,33 @@ public:
{ return id(); }
/**
* The IP address and port of this endpoint
* Retrieve the current address for this endpoint information
* @return Address and port of this endpoint info
*/
SocketAddr address;
inline const SocketAddr& address() const
{ return m_address; }
/**
* Retrieve the address for this endpoint information, resolve name if needed
* @return Address and port of this endpoint info
*/
const SocketAddr& address();
/**
* Set a new socket address in the endpoint info
* @param addr New address and port to set in the endpoint
*/
inline void address(const SocketAddr& addr)
{ m_resolve = false; m_address = addr; }
/**
* An alias name of the remote endpoint, may be empty
*/
String alias;
private:
SocketAddr m_address;
bool m_resolve;
};
/**

View File

@ -656,7 +656,7 @@ bool MGCPWrapper::rtpMessage(Message& msg)
copyRename(mm->params,"x-autoaddr",msg,"autoaddr");
copyRename(mm->params,"x-anyssrc",msg,"anyssrc");
}
mm = sendSync(mm,ep->address);
mm = sendSync(mm,ep->address());
if (!mm)
return false;
if (m_connId.null())
@ -679,7 +679,7 @@ void MGCPWrapper::clearConn()
return;
MGCPMessage* mm = new MGCPMessage(s_engine,"DLCX",ep->toString());
addParams(mm);
s_engine->sendCommand(mm,ep->address);
s_engine->sendCommand(mm,ep->address());
}
// Populate a MGCP message with basic identification parameters
@ -794,7 +794,7 @@ bool MGCPWrapper::sendDTMF(const String& tones)
tmp << "D/" << tones.at(i);
}
mm->params.setParam("O",tmp);
return s_engine->sendCommand(mm,ep->address) != 0;
return s_engine->sendCommand(mm,ep->address()) != 0;
}
void MGCPWrapper::gotDTMF(char tone)
@ -833,7 +833,7 @@ bool MGCPWrapper::nativeConnect(DataEndpoint* peer)
MGCPMessage* mm = new MGCPMessage(s_engine,"MDCX",ep->toString());
addParams(mm);
mm->params.setParam("Z2",other->connId());
return s_engine->sendCommand(mm,ep->address) != 0;
return s_engine->sendCommand(mm,ep->address()) != 0;
}
@ -1061,12 +1061,16 @@ bool MGCPSpan::init(const NamedList& params)
Debug(&splugin,DebugNote,"MGCPSpan '%s' first circuit=%s",
id().safe(),first.c_str());
m_version = config->getValue(YSTRING("version"));
const char* addr = config->getValue(YSTRING("address"));
if (addr) {
MGCPEpInfo* ep = s_endpoint->find(epId().id());
const String* addr = config->getParam(YSTRING("address"));
if (!TelEngine::null(addr) && addr->toBoolean(true)) {
const MGCPEpInfo* ep = s_endpoint->find(epId().id());
if (ep) {
SocketAddr a(ep->address);
a.host(addr);
SocketAddr a(ep->address().family());
if (addr->toBoolean(false))
a.host(ep->host());
else
a.host(addr);
a.port(ep->port());
operational(a);
}
}
@ -1099,11 +1103,12 @@ void MGCPSpan::operational(bool active)
// Set the operational state and copy GW address
void MGCPSpan::operational(const SocketAddr& address)
{
if (address.valid() && address.host())
m_address = address.host();
MGCPEpInfo* ep = s_endpoint->find(epId().id());
if (ep && !(m_operational && ep->address.valid()))
ep->address = address;
if (address.host().null() || (address.host() == YSTRING("0.0.0.0")))
return;
m_address = address.host();
const MGCPEpInfo* ep = s_endpoint->find(epId().id());
if (ep && !(m_operational && ep->address().valid()))
const_cast<MGCPEpInfo*>(ep)->address(address);
operational(true);
}
@ -1558,7 +1563,7 @@ bool MGCPCircuit::sendAsync(MGCPMessage* mm, bool notify)
return false;
MGCPEpInfo* ep = s_endpoint->find(mySpan()->epId().id());
if (ep) {
MGCPTransaction* tr = s_engine->sendCommand(mm,ep->address);
MGCPTransaction* tr = s_engine->sendCommand(mm,ep->address());
if (tr) {
if (notify)
tr->userData(static_cast<GenObject*>(this));
@ -1587,7 +1592,7 @@ RefPointer<MGCPMessage> MGCPCircuit::sendSync(MGCPMessage* mm)
Thread::idle();
}
u_int64_t t2 = Time::msecNow();
MGCPTransaction* tr = s_engine->sendCommand(mm,ep->address);
MGCPTransaction* tr = s_engine->sendCommand(mm,ep->address());
s_mutex.lock();
tr->userData(static_cast<GenObject*>(this));
m_tr = tr;

View File

@ -700,7 +700,7 @@ void MGCPPlugin::initialize()
mm->params.addParam("x-standby",String::boolText(s_standby));
mm->params.addParam("x-started",s_started);
}
s_engine->sendCommand(mm,ca->address);
s_engine->sendCommand(mm,ca->address());
}
}
else