mirror of
https://github.com/fairwaves/openbts-2.8.git
synced 2025-11-02 13:03:14 +00:00
Fixes #711 in private. We now check RTP ports before allocation, to ensure they're not already in use.
git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@3225 19bc5d8c-e614-43d4-8b26-e1612bc8e597
This commit is contained in:
@@ -72,17 +72,20 @@ using namespace Control;
|
||||
*/
|
||||
unsigned allocateRTPPorts()
|
||||
{
|
||||
// FIXME -- We need a real port allocator.
|
||||
const unsigned base = gConfig.getNum("RTP.Start");
|
||||
const unsigned range = gConfig.getNum("RTP.Range");
|
||||
const unsigned top = base+range;
|
||||
static Mutex lock;
|
||||
// Pick a random starting point.
|
||||
static unsigned port = base + 2*(random()%(range/2));
|
||||
unsigned retVal;
|
||||
lock.lock();
|
||||
unsigned retVal = port;
|
||||
port += 2;
|
||||
if (port>=top) port=base;
|
||||
//This is a little hacky as RTPAvail is O(n)
|
||||
do {
|
||||
retVal = port;
|
||||
port += 2;
|
||||
if (port>=top) port=base;
|
||||
} while (!gTransactionTable.RTPAvailable(retVal));
|
||||
lock.unlock();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -805,5 +805,19 @@ TransactionEntry* TransactionTable::findLongestCall()
|
||||
|
||||
|
||||
|
||||
/* linear, we should move the actual search into this structure */
|
||||
bool TransactionTable::RTPAvailable(short rtpPort)
|
||||
{
|
||||
ScopedLock lock(mLock);
|
||||
clearDeadEntries();
|
||||
bool avail = true;
|
||||
for (TransactionMap::iterator itr = mTable.begin(); itr!=mTable.end(); ++itr) {
|
||||
if (itr->second->mSIP.RTPPort() == rtpPort){
|
||||
avail = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
|
||||
// vim: ts=4 sw=4
|
||||
|
||||
@@ -337,6 +337,12 @@ class TransactionTable {
|
||||
*/
|
||||
TransactionEntry* findLongestCall();
|
||||
|
||||
/**
|
||||
Return the availability of this particular RTP port
|
||||
@return True if Port is available, False otherwise
|
||||
*/
|
||||
bool RTPAvailable(short rtpPort);
|
||||
|
||||
/**
|
||||
Remove an entry from the table and from gSIPMessageMap.
|
||||
@param wID The transaction ID to search.
|
||||
|
||||
Reference in New Issue
Block a user