|
reSIProcate/DialogUsageManager
9694
|
#include <KeepAliveManager.hxx>

Classes | |
| struct | NetworkAssociationInfo |
Public Types | |
| typedef std::map< Tuple, NetworkAssociationInfo, Tuple::FlowKeyCompare > | NetworkAssociationMap |
Public Member Functions | |
| KeepAliveManager () | |
| virtual | ~KeepAliveManager () |
| void | setDialogUsageManager (DialogUsageManager *dum) |
| virtual void | add (const Tuple &target, int keepAliveInterval, bool targetSupportsOutbound) |
| virtual void | remove (const Tuple &target) |
| virtual void | process (KeepAliveTimeout &timeout) |
| virtual void | process (KeepAlivePongTimeout &timeout) |
| virtual void | receivedPong (const Tuple &flow) |
Static Public Attributes | |
| static int | mKeepAlivePongTimeoutMs = 10000 |
Protected Attributes | |
| DialogUsageManager * | mDum |
| NetworkAssociationMap | mNetworkAssociations |
| unsigned int | mCurrentId |
Definition at line 14 of file KeepAliveManager.hxx.
| typedef std::map<Tuple, NetworkAssociationInfo, Tuple::FlowKeyCompare> resip::KeepAliveManager::NetworkAssociationMap |
Definition at line 36 of file KeepAliveManager.hxx.
| resip::KeepAliveManager::KeepAliveManager | ( | ) | [inline] |
Definition at line 38 of file KeepAliveManager.hxx.
: mCurrentId(0) {}
| virtual resip::KeepAliveManager::~KeepAliveManager | ( | ) | [inline, virtual] |
Definition at line 39 of file KeepAliveManager.hxx.
{}
| void KeepAliveManager::add | ( | const Tuple & | target, |
| int | keepAliveInterval, | ||
| bool | targetSupportsOutbound | ||
| ) | [virtual] |
Definition at line 18 of file KeepAliveManager.cxx.
References DebugLog, resip::KeepAliveManager::NetworkAssociationInfo::id, resip::Helper::jitterValue(), resip::KeepAliveManager::NetworkAssociationInfo::keepAliveInterval, resip::KeepAliveManager::NetworkAssociationInfo::pongReceivedForLastPing, resip::SipStack::post(), resip::KeepAliveManager::NetworkAssociationInfo::refCount, and resip::KeepAliveManager::NetworkAssociationInfo::supportsOutbound.
{
assert(mDum);
NetworkAssociationMap::iterator it = mNetworkAssociations.find(target);
if (it == mNetworkAssociations.end())
{
DebugLog(<< "First keep alive for id=" << mCurrentId << ": " << target << ", interval="
<< keepAliveInterval << "s, supportsOutbound=" << (targetSupportsOutbound ? "true" : "false"));
NetworkAssociationInfo info;
info.refCount = 1;
info.keepAliveInterval = keepAliveInterval;
info.id = mCurrentId;
info.supportsOutbound = targetSupportsOutbound;
info.pongReceivedForLastPing = false;
mNetworkAssociations.insert(NetworkAssociationMap::value_type(target, info));
KeepAliveTimeout t(target, mCurrentId);
SipStack &stack = mDum->getSipStack();
if(targetSupportsOutbound)
{
// Used randomized timeout between 80% and 100% of keepalivetime
stack.post(t, Helper::jitterValue(keepAliveInterval, 80, 100), mDum);
}
else
{
stack.post(t, keepAliveInterval, mDum);
}
++mCurrentId;
}
else
{
it->second.refCount++;
if(keepAliveInterval < it->second.keepAliveInterval || targetSupportsOutbound) // if targetSupportsOutbound, then always update the interval, as value may be from Flow-Timer header
{
// ?slg? only allow value to be shortened??? What if 2 different profiles
// with different keepAliveTime settings are sharing this network association?
it->second.keepAliveInterval = keepAliveInterval;
}
if(targetSupportsOutbound)
{
// allow this to be updated to true only. If any usage get's an indication of
// outbound support on this flow, then we accept it
it->second.supportsOutbound = targetSupportsOutbound;
}
DebugLog(<< "Association added for keep alive id=" << it->second.id << ": " << target
<< ", interval=" << it->second.keepAliveInterval << "s, supportsOutbound="
<< (it->second.supportsOutbound ? "true" : "false")
<< ", refCount=" << it->second.refCount);
}
}

| void KeepAliveManager::process | ( | KeepAliveTimeout & | timeout | ) | [virtual] |
Definition at line 88 of file KeepAliveManager.cxx.
References DebugLog, resip::InteropHelper::getOutboundVersion(), resip::KeepAliveTimeout::id(), resip::Helper::jitterValue(), resip::SipStack::post(), resip::SipStack::postMS(), resip::SipStack::sendTo(), resip::KeepAliveTimeout::target(), resip::TCP, and resip::TLS.
{
assert(mDum);
static KeepAliveMessage msg;
NetworkAssociationMap::iterator it = mNetworkAssociations.find(timeout.target());
if (it != mNetworkAssociations.end() && timeout.id() == it->second.id)
{
SipStack &stack = mDum->getSipStack();
DebugLog(<< "Refreshing keepalive for id=" << it->second.id << ": " << it->first
<< ", interval=" << it->second.keepAliveInterval << "s, supportsOutbound="
<< (it->second.supportsOutbound ? "true" : "false")
<< ", refCount=" << it->second.refCount);
if(InteropHelper::getOutboundVersion()>=8 && it->second.supportsOutbound && mKeepAlivePongTimeoutMs > 0)
{
// Assert if keep alive interval is too short in order to properly detect
// missing pong responses - ie. interval must be greater than 10s
assert((it->second.keepAliveInterval*1000) > mKeepAlivePongTimeoutMs);
// Start pong timeout if transport is TCP based (note: pong processing of Stun messaging is currently not implemented)
if(it->first.getType() == TCP || it->first.getType() == TLS)
{
DebugLog( << "Starting pong timeout for keepalive id " << it->second.id);
KeepAlivePongTimeout t(it->first, it->second.id);
stack.postMS(t, mKeepAlivePongTimeoutMs, mDum);
}
}
it->second.pongReceivedForLastPing = false; // reset flag
stack.sendTo(msg, timeout.target(), mDum);
KeepAliveTimeout t(it->first, it->second.id);
if(it->second.supportsOutbound)
{
// Used randomized timeout between 80% and 100% of keepalivetime
stack.post(t, Helper::jitterValue(it->second.keepAliveInterval, 80, 100), mDum);
}
else
{
stack.post(t, it->second.keepAliveInterval, mDum);
}
}
}

| void KeepAliveManager::process | ( | KeepAlivePongTimeout & | timeout | ) | [virtual] |
Definition at line 132 of file KeepAliveManager.cxx.
References resip::KeepAlivePongTimeout::id(), InfoLog, and resip::KeepAlivePongTimeout::target().
{
assert(mDum);
NetworkAssociationMap::iterator it = mNetworkAssociations.find(timeout.target());
if (it != mNetworkAssociations.end() && timeout.id() == it->second.id)
{
if(!it->second.pongReceivedForLastPing)
{
// Timeout expecting pong response
InfoLog(<< "Timed out expecting pong response for keep alive id=" << it->second.id << ": " << it->first);
mDum->getSipStack().terminateFlow(it->first);
}
}
}

| void KeepAliveManager::receivedPong | ( | const Tuple & | flow | ) | [virtual] |
Definition at line 148 of file KeepAliveManager.cxx.
References DebugLog.
{
NetworkAssociationMap::iterator it = mNetworkAssociations.find(flow);
if (it != mNetworkAssociations.end())
{
DebugLog(<< "Received pong response for keep alive id=" << it->second.id << ": " << it->first);
it->second.pongReceivedForLastPing = true;
}
}
| void KeepAliveManager::remove | ( | const Tuple & | target | ) | [virtual] |
Definition at line 70 of file KeepAliveManager.cxx.
References DebugLog.
{
NetworkAssociationMap::iterator it = mNetworkAssociations.find(target);
if (it != mNetworkAssociations.end())
{
if (0 == --it->second.refCount)
{
DebugLog(<< "Last association removed for keep alive id=" << it->second.id << ": " << target);
mNetworkAssociations.erase(it);
}
else
{
DebugLog(<< "Association removed for keep alive id=" << it->second.id << ": " << target << ", refCount=" << it->second.refCount);
}
}
}
| void resip::KeepAliveManager::setDialogUsageManager | ( | DialogUsageManager * | dum | ) | [inline] |
unsigned int resip::KeepAliveManager::mCurrentId [protected] |
Definition at line 50 of file KeepAliveManager.hxx.
DialogUsageManager* resip::KeepAliveManager::mDum [protected] |
Definition at line 48 of file KeepAliveManager.hxx.
Referenced by setDialogUsageManager().
int KeepAliveManager::mKeepAlivePongTimeoutMs = 10000 [static] |
Definition at line 18 of file KeepAliveManager.hxx.
Definition at line 49 of file KeepAliveManager.hxx.
1.7.5.1