| 1 |
/***************************************************************************** |
| 2 |
Copyright (c) 2001 - 2009, The Board of Trustees of the University of Illinois. |
| 3 |
All rights reserved. |
| 4 |
|
| 5 |
Redistribution and use in source and binary forms, with or without |
| 6 |
modification, are permitted provided that the following conditions are |
| 7 |
met: |
| 8 |
|
| 9 |
* Redistributions of source code must retain the above |
| 10 |
copyright notice, this list of conditions and the |
| 11 |
following disclaimer. |
| 12 |
|
| 13 |
* Redistributions in binary form must reproduce the |
| 14 |
above copyright notice, this list of conditions |
| 15 |
and the following disclaimer in the documentation |
| 16 |
and/or other materials provided with the distribution. |
| 17 |
|
| 18 |
* Neither the name of the University of Illinois |
| 19 |
nor the names of its contributors may be used to |
| 20 |
endorse or promote products derived from this |
| 21 |
software without specific prior written permission. |
| 22 |
|
| 23 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 24 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 25 |
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 26 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 27 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 28 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 29 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
*****************************************************************************/ |
| 35 |
|
| 36 |
/***************************************************************************** |
| 37 |
written by |
| 38 |
Yunhong Gu, last updated 05/05/2009 |
| 39 |
*****************************************************************************/ |
| 40 |
|
| 41 |
#include "platform_sys.h" |
| 42 |
|
| 43 |
#include <cstring> |
| 44 |
#include "cache.h" |
| 45 |
#include "core.h" |
| 46 |
|
| 47 |
using namespace std; |
| 48 |
|
| 49 |
srt::CInfoBlock& srt::CInfoBlock::copyFrom(const CInfoBlock& obj) |
| 50 |
{ |
| 51 |
std::copy(obj.m_piIP, obj.m_piIP + 4, m_piIP); |
| 52 |
m_iIPversion = obj.m_iIPversion; |
| 53 |
m_ullTimeStamp = obj.m_ullTimeStamp; |
| 54 |
m_iSRTT = obj.m_iSRTT; |
| 55 |
m_iBandwidth = obj.m_iBandwidth; |
| 56 |
m_iLossRate = obj.m_iLossRate; |
| 57 |
m_iReorderDistance = obj.m_iReorderDistance; |
| 58 |
m_dInterval = obj.m_dInterval; |
| 59 |
m_dCWnd = obj.m_dCWnd; |
| 60 |
|
| 61 |
return *this; |
| 62 |
} |
| 63 |
|
| 64 |
bool srt::CInfoBlock::operator==(const CInfoBlock& obj) const |
| 65 |
{ |
| 66 |
if (m_iIPversion != obj.m_iIPversion) |
| 67 |
return false; |
| 68 |
|
| 69 |
else if (m_iIPversion == AF_INET) |
| 70 |
return (m_piIP[0] == obj.m_piIP[0]); |
| 71 |
|
| 72 |
for (int i = 0; i < 4; ++i) |
| 73 |
{ |
| 74 |
if (m_piIP[i] != obj.m_piIP[i]) |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
srt::CInfoBlock* srt::CInfoBlock::clone() |
| 82 |
{ |
| 83 |
CInfoBlock* obj = new CInfoBlock; |
| 84 |
|
| 85 |
std::copy(m_piIP, m_piIP + 4, obj->m_piIP); |
| 86 |
obj->m_iIPversion = m_iIPversion; |
| 87 |
obj->m_ullTimeStamp = m_ullTimeStamp; |
| 88 |
obj->m_iSRTT = m_iSRTT; |
| 89 |
obj->m_iBandwidth = m_iBandwidth; |
| 90 |
obj->m_iLossRate = m_iLossRate; |
| 91 |
obj->m_iReorderDistance = m_iReorderDistance; |
| 92 |
obj->m_dInterval = m_dInterval; |
| 93 |
obj->m_dCWnd = m_dCWnd; |
| 94 |
|
| 95 |
return obj; |
| 96 |
} |
| 97 |
|
| 98 |
int srt::CInfoBlock::getKey() |
| 99 |
{ |
| 100 |
if (m_iIPversion == AF_INET) |
| 101 |
return m_piIP[0]; |
| 102 |
|
| 103 |
return m_piIP[0] + m_piIP[1] + m_piIP[2] + m_piIP[3]; |
| 104 |
} |
| 105 |
|
| 106 |
void srt::CInfoBlock::convert(const sockaddr_any& addr, uint32_t aw_ip[4]) |
| 107 |
{ |
| 108 |
if (addr.family() == AF_INET) |
| 109 |
{ |
| 110 |
aw_ip[0] = addr.sin.sin_addr.s_addr; |
| 111 |
aw_ip[1] = aw_ip[2] = aw_ip[3] = 0; |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
memcpy((aw_ip), addr.sin6.sin6_addr.s6_addr, sizeof addr.sin6.sin6_addr.s6_addr); |
| 116 |
} |
| 117 |
} |