📄 transportselector.cxx
字号:
{
cid = msg->header(h_Routes).front().uri().param(p_cid).convertUnsignedLong();
msg->header(h_Routes).front().uri().remove(p_cid);
}
else if (msg->header(h_RequestLine).uri().exists(p_cid))
{
cid = msg->header(h_RequestLine).uri().param(p_cid).convertUnsignedLong();
msg->header(h_RequestLine).uri().remove(p_cid);
}
target.connectionId=cid;
}
// !bwc! We might find a match by the cid, or maybe using the
// tuple itself.
Connection* conn = findConnection(target);
if(conn) // !bwc! Woohoo! Home free!
{
return conn->transport();
}
else if(target.getType()==TLS)
{
return findTlsTransport(msg->getTlsDomain(), target.ipVersion());
}
else if(target.getType()==DTLS)
{
return findTlsTransport(msg->getTlsDomain(), target.ipVersion());
}
}
}
else // !bwc! Easy as pie.
{
return target.transport;
}
// !bwc! No luck here. Maybe findTransportBySource will end up working.
return 0;
}
Transport*
TransportSelector::findTransportBySource(Tuple& search)
{
DebugLog(<< "findTransportBySource(" << search << ")");
if (search.getPort() != 0)
{
//0. When we are sending to a loopback address, the kernel makes an
//(effectively) arbitrary choice of which loopback address to send
//from. (Since any loopback address can be used to send to any other
//loopback address) This choice may not agree with our idea of what
//address we should be sending from, so we need to just choose the
//loopback address we like, and ignore what the kernel told us to do.
if( search.isLoopback() )
{
ExactTupleMap::const_iterator i;
for (i=mExactTransports.begin();i != mExactTransports.end();i++)
{
DebugLog(<<"search: " << search << " elem: " << i->first);
if(i->first.ipVersion()==V4)
{
//Compare only the first byte (the 127)
if(i->first.isEqualWithMask(search,8,false))
{
search=i->first;
DebugLog(<<"Match!");
return i->second;
}
}
#ifdef USE_IPV6
else if(i->first.ipVersion()==V6)
{
//What to do?
}
#endif
else
{
assert(0);
}
}
}
// 1. search for matching port on a specific interface
{
ExactTupleMap::const_iterator i = mExactTransports.find(search);
if (i != mExactTransports.end())
{
DebugLog(<< "findTransport (exact) => " << *(i->second));
return i->second;
}
}
// 2. search for specific port on ANY interface
{
AnyInterfaceTupleMap::const_iterator i = mAnyInterfaceTransports.find(search);
if (i != mAnyInterfaceTransports.end())
{
DebugLog(<< "findTransport (any interface) => " << *(i->second));
return i->second;
}
}
}
else
{
//0. When we are sending to a loopback address, the kernel makes an
//(effectively) arbitrary choice of which loopback address to send
//from. (Since any loopback address can be used to send to any other
//loopback address) This choice may not agree with our idea of what
//address we should be sending from, so we need to just choose the
//loopback address we like, and ignore what the kernel told us to do.
if( search.isLoopback() )
{
ExactTupleMap::const_iterator i;
for (i=mExactTransports.begin();i != mExactTransports.end();i++)
{
DebugLog(<<"search: " << search << " elem: " << i->first);
if(i->first.ipVersion()==V4)
{
//Compare only the first byte (the 127)
if(i->first.isEqualWithMask(search,8,true))
{
search=i->first;
DebugLog(<<"Match!");
return i->second;
}
}
#ifdef USE_IPV6
else if(i->first.ipVersion()==V6)
{
//What to do?
}
#endif
else
{
assert(0);
}
}
}
// 1. search for ANY port on specific interface
{
AnyPortTupleMap::const_iterator i = mAnyPortTransports.find(search);
if (i != mAnyPortTransports.end())
{
DebugLog(<< "findTransport (any port, specific interface) => " << *(i->second));
return i->second;
}
}
// 2. search for ANY port on ANY interface
{
//CerrLog(<< "Trying AnyPortAnyInterfaceTupleMap " << mAnyPortAnyInterfaceTransports.size());
AnyPortAnyInterfaceTupleMap::const_iterator i = mAnyPortAnyInterfaceTransports.find(search);
if (i != mAnyPortAnyInterfaceTransports.end())
{
DebugLog(<< "findTransport (any port, any interface) => " << *(i->second));
return i->second;
}
}
}
DebugLog (<< "Exact interface / Specific port: " << Inserter(mExactTransports));
DebugLog (<< "Any interface / Specific port: " << Inserter(mAnyInterfaceTransports));
DebugLog (<< "Exact interface / Any port: " << Inserter(mAnyPortTransports));
DebugLog (<< "Any interface / Any port: " << Inserter(mAnyPortAnyInterfaceTransports));
WarningLog(<< "Can't find matching transport " << search);
return 0;
}
Transport*
TransportSelector::findTlsTransport(const Data& domainname,resip::IpVersion version)
{
if(version==V4)
{
DebugLog (<< "Searching for TLS transport for domain='"
<< domainname << "'" << " have " << mV4TlsTransports.size());
// If no domainname specified and there is only 1 TLS transport, use it.
if (domainname == Data::Empty && mV4TlsTransports.size() == 1)
{
DebugLog (<< "Found default TLS transport for domain=" << mV4TlsTransports.begin()->first);
return mV4TlsTransports.begin()->second;
}
if (mV4TlsTransports.count(domainname))
{
DebugLog (<< "Found TLS transport for domain=" << mV4TlsTransports.begin()->first);
return mV4TlsTransports[domainname];
}
// don't know which one to use
DebugLog (<< "No TLS transport found");
return 0;
}
else if(version==V6)
{
#ifdef USE_IPV6
DebugLog (<< "Searching for TLS transport for domain='"
<< domainname << "'" << " have " << mV6TlsTransports.size());
// If no domainname specified and there is only 1 TLS transport, use it.
if (domainname == Data::Empty && mV6TlsTransports.size() == 1)
{
DebugLog (<< "Found default TLS transport for domain=" << mV6TlsTransports.begin()->first);
return mV6TlsTransports.begin()->second;
}
if (mV6TlsTransports.count(domainname))
{
DebugLog (<< "Found TLS transport for domain=" << mV6TlsTransports.begin()->first);
return mV6TlsTransports[domainname];
}
#endif
// don't know which one to use
DebugLog (<< "No TLS transport found");
return 0;
}
else
{
assert(0);
return 0;
}
}
Transport*
TransportSelector::findDtlsTransport(const Data& domainname,resip::IpVersion version)
{
#ifdef USE_DTLS
if(version==V4)
{
DebugLog (<< "Searching for DTLS transport for domain='" << domainname << "'");
// If no domainname specified and there is only 1 TLS transport, use it.
if (domainname == Data::Empty && mV4DtlsTransports.size() == 1)
{
DebugLog (<< "Found default DTLS transport for domain=" << mV4DtlsTransports.begin()->first);
return (Transport*)mV4DtlsTransports.begin()->second;
}
if (mV4DtlsTransports.count(domainname))
{
DebugLog (<< "Found DTLS transport for domain=" << mV4DtlsTransports.begin()->first);
return (Transport*)mV4DtlsTransports[domainname];
}
}
else if(version==V6)
{
#ifdef USE_IPV6
DebugLog (<< "Searching for DTLS transport for domain='" << domainname << "'");
// If no domainname specified and there is only 1 TLS transport, use it.
if (domainname == Data::Empty && mV6DtlsTransports.size() == 1)
{
DebugLog (<< "Found default DTLS transport for domain=" << mV6DtlsTransports.begin()->first);
return (Transport*)mV6DtlsTransports.begin()->second;
}
if (mV6DtlsTransports.count(domainname))
{
DebugLog (<< "Found DTLS transport for domain=" << mV6DtlsTransports.begin()->first);
return (Transport*)mV6DtlsTransports[domainname];
}
#endif
}
else
{
assert(0);
}
#endif
// don't know which one to use
DebugLog (<< "No DTLS transport found");
return 0;
}
unsigned int
TransportSelector::getTimeTillNextProcessMS()
{
if (mDns.requiresProcess())
{
return 50;
}
else
{
return INT_MAX;
}
}
void
TransportSelector::registerBlacklistListener(int rrType, DnsStub::BlacklistListener* listener)
{
mDns.registerBlacklistListener(rrType, listener);
}
void TransportSelector::unregisterBlacklistListener(int rrType, DnsStub::BlacklistListener* listener)
{
mDns.unregisterBlacklistListener(rrType, listener);
}
/* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by Vovida
* Networks, Inc. and many individuals on behalf of Vovida Networks,
* Inc. For more information on Vovida Networks, Inc., please see
* <http://www.vovida.org/>.
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -