Skip to content

Commit

Permalink
SipDialog: Randomize session timer interval a bit (#403)
Browse files Browse the repository at this point in the history
Make it +-5 sec from half the input interval.

This should improve potential glare conditions.
  • Loading branch information
orgads authored Jan 17, 2025
1 parent 7a20c24 commit bc294d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/client-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ namespace drachtio {

void ClientController::start() {
DR_LOG(log_debug) << "Client controller thread id: " << std::this_thread::get_id() ;
srand (time(NULL));
std::thread t(&ClientController::threadFunc, this) ;
m_thread.swap( t ) ;

Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ THE SOFTWARE.
#define DRACHTIO_MAIN

#include "controller.hpp"
#include <stdlib.h>
#include <time.h>

using namespace drachtio ;

Expand All @@ -38,6 +40,7 @@ void handleSigPipe( int signal ) {
}

int main( int argc, char *argv[] ) {
srand(time(NULL));

try {
theOneAndOnlyController = new DrachtioController( argc, argv ) ;
Expand Down
5 changes: 4 additions & 1 deletion src/sip-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ namespace drachtio {
DR_LOG(log_info) << "SipDialog::setSessionTimer: " << getCallId() << " Session expires has been set to " << nSecs << " seconds and refresher is " << (areWeRefresher() ? "us" : "them") ;

/* if we are the refresher, then we want the timer to go off halfway through the interval */
if( areWeRefresher() ) m_nSessionTimerDuration /= 2 ;
if( areWeRefresher() ) {
m_nSessionTimerDuration /= 2 ;
m_nSessionTimerDuration += (rand() % 10000) - 5000 ;
}
m_timerSessionRefresh = su_timer_create( su_root_task(theOneAndOnlyController->getRoot()), m_nSessionTimerDuration ) ;

m_ppSelf = new std::weak_ptr<SipDialog>( shared_from_this() ) ;
Expand Down

0 comments on commit bc294d4

Please sign in to comment.