Made configurable the number of times to transmit a request or a final response when retransmission is required.

git-svn-id: http://yate.null.ro/svn/yate/trunk@4556 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2011-08-22 14:11:51 +00:00
parent 80cd472913
commit df8ec5d64d
5 changed files with 66 additions and 3 deletions

View File

@ -131,6 +131,22 @@
; This parameter is applied on reload
;ssl_key_file=
; sip_req_trans_count: integer: The number of times to transmit a sip request
; when retransmission is required (e.g. on non reliable transports)
; This parameter is applied on reload
; Minimum allowed value is 2, maximum allowed value is 10
; Defaults to 5 if missing, invalid or out of bounds
;sip_req_trans_count=5
; sip_rsp_trans_count: integer: The number of times to transmit a final response
; to a sip request when retransmission is required
; Retransmission is required for all responses to INVITE requests on non reliable
; transports or 2xx responses over reliable transports
; This parameter is applied on reload
; Minimum allowed value is 2, maximum allowed value is 10
; Defaults to 6 if missing, invalid or out of bounds
;sip_rsp_trans_count=6
; printmsg: boolean: Print SIP messages to output
; This parameter is applied on reload
; Defaults to yes

View File

@ -169,7 +169,8 @@ SIPEvent::~SIPEvent()
SIPEngine::SIPEngine(const char* userAgent)
: Mutex(true,"SIPEngine"),
m_t1(500000), m_t4(5000000), m_maxForwards(70),
m_t1(500000), m_t4(5000000), m_reqTransCount(5), m_rspTransCount(6),
m_maxForwards(70),
m_cseq(0), m_flags(0), m_lazyTrying(false),
m_userAgent(userAgent), m_nc(0), m_nonce_time(0),
m_nonce_mutex(false,"SIPEngine::nonce")

View File

@ -317,7 +317,8 @@ void SIPTransaction::setResponse(SIPMessage* message)
if (changeState(Retrans)) {
bool reliable = message->getParty() && message->getParty()->isReliable();
bool retrans = !reliable || message->code < 300;
setTimeout(m_engine->getTimer(retrans ? 'G' : 'H',reliable),retrans ? 6 : 1);
setTimeout(m_engine->getTimer(retrans ? 'G' : 'H',reliable),
retrans ? m_engine->getRspTransCount() : 1);
}
}
else {
@ -584,7 +585,7 @@ SIPEvent* SIPTransaction::getClientEvent(int state, int timeout)
if (changeState(Trying)) {
bool reliable = e->getParty() && e->getParty()->isReliable();
if (!reliable)
setTimeout(m_engine->getTimer(isInvite() ? 'A' : 'E'),5);
setTimeout(m_engine->getTimer(isInvite() ? 'A' : 'E'),m_engine->getReqTransCount());
else
setTimeout(m_engine->getTimer(isInvite() ? 'B' : 'F',true),1);
}

View File

@ -1192,6 +1192,22 @@ public:
*/
u_int64_t getTimer(char which, bool reliable = false) const;
/**
* Get the number of times to send a SIP request.
* This value applies only when retransmission is required
* @return The number of times to send a SIP request
*/
inline unsigned int getReqTransCount() const
{ return m_reqTransCount; }
/**
* Get the number of times to send a response to a SIP request.
* This value applies only when retransmission is required
* @return The number of times to send a response to a SIP request
*/
inline unsigned int getRspTransCount() const
{ return m_rspTransCount; }
/**
* Get the default value of the Max-Forwards header for this engine
* @return The maximum number of hops the request is allowed to pass
@ -1325,6 +1341,8 @@ protected:
u_int64_t m_t1;
u_int64_t m_t4;
int m_reqTransCount;
int m_rspTransCount;
unsigned int m_maxForwards;
int m_cseq;
int m_flags;

View File

@ -523,6 +523,8 @@ class YateSIPEngine : public SIPEngine
{
public:
YateSIPEngine(YateSIPEndPoint* ep);
// Initialize the engine
void initialize(NamedList* params);
virtual bool buildParty(SIPMessage* message);
virtual bool checkUser(const String& username, const String& realm, const String& nonce,
const String& method, const String& uri, const String& response,
@ -1123,6 +1125,16 @@ static unsigned int getMaxpkt(int val, int defVal)
return 524;
}
// Retrieve an integer value from a list
// Check bounds. Return default value if out of bounds
static inline int checkIntValue(NamedList& params, const String& param, int def, int min, int max)
{
int tmp = params.getIntValue(param,def);
if (tmp >= min && tmp <= max)
return tmp;
return def;
}
// Skip tabs, spaces, CR and LF from buffer start
// Return true if the buffer changed
static bool skipSpaces(String& buf, bool crlf = true)
@ -3416,6 +3428,19 @@ YateSIPEngine::YateSIPEngine(YateSIPEndPoint* ep)
addAllowed(meth);
}
}
initialize(s_cfg.getSection("general"));
}
// Initialize the engine
void YateSIPEngine::initialize(NamedList* params)
{
NamedList dummy("");
if (!params)
params = &dummy;
m_reqTransCount = checkIntValue(*params,"sip_req_trans_count",5,2,10);
m_rspTransCount = checkIntValue(*params,"sip_rsp_trans_count",6,2,10);
DDebug(this,DebugAll,"Initialized sip_req_trans_count=%d sip_rsp_trans_count=%d",
m_reqTransCount,m_rspTransCount);
}
SIPTransaction* YateSIPEngine::forkInvite(SIPMessage* answer, SIPTransaction* trans)
@ -7368,6 +7393,8 @@ void SIPDriver::initialize()
if (s_cfg.getBoolValue("general","generate"))
Engine::install(new SipHandler);
}
else
m_endpoint->engine()->initialize(s_cfg.getSection("general"));
// Unsafe globals
s_globalMutex.lock();
s_realm = s_cfg.getValue("general","realm","Yate");