[go: up one dir, main page]

Menu

[r73]: / gmp / prec.h  Maximize  Restore  History

Download this file

115 lines (90 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*****************************************************************************
Copyright © 2006, 2007, The Board of Trustees of the University of Illinois.
All Rights Reserved.
Group Messaging Protocol (GMP)
National Center for Data Mining (NCDM)
University of Illinois at Chicago
http://www.ncdm.uic.edu/
GMP is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
GMP is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
/*****************************************************************************
written by
Yunhong Gu [gu@lac.uic.edu], last updated 01/25/2007
*****************************************************************************/
#ifndef __PEER_RECORD_H__
#define __PEER_RECORD_H__
#ifndef WIN32
#include <pthread.h>
#else
#include <udt.h>
#include <common.h>
#endif
#include <set>
#include <string>
using namespace std;
namespace cb
{
struct CPeerRecord
{
string m_strIP;
int m_iPort;
int m_iSession;
int32_t m_iID;
int64_t m_llTimeStamp;
int m_iRTT;
};
struct CFPeerRec
{
bool operator()(const CPeerRecord* p1, const CPeerRecord* p2) const
{
if (p1->m_strIP == p2->m_strIP)
{
if (p1->m_iPort == p2->m_iPort)
return (p1->m_iSession > p2->m_iSession);
return (p1->m_iPort > p2->m_iPort);
}
return (p1->m_strIP > p2->m_strIP);
}
};
struct CFPeerRecByIP
{
bool operator()(const CPeerRecord* p1, const CPeerRecord* p2) const
{
return (p1->m_strIP > p2->m_strIP);
}
};
struct CFPeerRecByTS
{
bool operator()(const CPeerRecord* p1, const CPeerRecord* p2) const
{
return (p1->m_llTimeStamp > p2->m_llTimeStamp);
}
};
class CPeerManagement
{
public:
CPeerManagement();
~CPeerManagement();
public:
void insert(const string& ip, const int& port, const int& session, const int32_t& id = -1, const int& rtt = -1);
int getRTT(const string& ip);
int getLastID(const string& ip, const int& port, const int& session);
void clearRTT(const string& ip);
private:
set<CPeerRecord*, CFPeerRec> m_sPeerRec;
set<CPeerRecord*, CFPeerRecByTS> m_sPeerRecByTS;
multiset<CPeerRecord*, CFPeerRecByIP> m_sPeerRecByIP;
pthread_mutex_t m_PeerRecLock;
private:
static const unsigned int m_uiRecLimit = 500;
};
}; // namespace
#endif