cache.cpp 3.7 KB

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