xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdNetCache.hh
Go to the documentation of this file.
1 #ifndef __XRDNETCACHE_HH__
2 #define __XRDNETCACHE_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d N e t C a c h e . h h */
6 /* */
7 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <cstring>
34 #include <ctime>
35 #include <sys/types.h>
36 
37 #include "XrdSys/XrdSysPthread.hh"
38 
39 class XrdNetAddrInfo;
40 
42 {
43 public:
44 
45 //------------------------------------------------------------------------------
51 //------------------------------------------------------------------------------
52 
53 void Add(XrdNetAddrInfo *hAddr, const char *hName);
54 
55 //------------------------------------------------------------------------------
62 //------------------------------------------------------------------------------
63 
64 char *Find(XrdNetAddrInfo *hAddr);
65 
66 //------------------------------------------------------------------------------
70 //------------------------------------------------------------------------------
71 static
72 void SetKT(int ktval) {keepTime = ktval;}
73 
74 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 
82  XrdNetCache(int psize = 987, int csize = 1597);
83 
84 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 
89  ~XrdNetCache() {} // Never gets deleted
90 
91 private:
92 
93 static const int LoadMax = 80;
94 
95 struct anItem
96  {union {long long aV6[2];
97  int aV4[4];
98  char aVal[16]; // Enough for IPV4 or IPV6
99  };
101  char *hName;
102  time_t expTime; // Expiration time
103 unsigned int aHash; // Hash value
104  int aLen; // Actual length 4 or 16
105 
106 inline int operator!=(const anItem &oth)
107  {return aLen != oth.aLen || aHash != oth.aHash
108  || memcmp(aVal, oth.aVal, aLen);
109  }
110 
111  anItem() : Next(0), hName(0), aLen(0) {}
112 
113  anItem(anItem &Item, const char *hn, int kt)
114  : Next(0), hName(strdup(hn)), expTime(time(0)+kt),
115  aHash(Item.aHash), aLen(Item.aLen)
116  {memcpy(aVal, Item.aVal, Item.aLen);}
117  ~anItem() {if (hName) free(hName);}
118  };
119 
120 void Expand();
121 int GenKey(anItem &Item, XrdNetAddrInfo *hAddr);
122 anItem *Locate(anItem &Item);
123 
124 static int keepTime;
125 
132 };
133 #endif
anItem * Next
Definition: XrdNetCache.hh:100
int operator!=(const anItem &oth)
Definition: XrdNetCache.hh:106
int nashtablesize
Definition: XrdNetCache.hh:129
Definition: XrdNetCache.hh:95
int aV4[4]
Definition: XrdNetCache.hh:97
time_t expTime
Definition: XrdNetCache.hh:102
int Threshold
Definition: XrdNetCache.hh:131
~anItem()
Definition: XrdNetCache.hh:117
int nashnum
Definition: XrdNetCache.hh:130
char * hName
Definition: XrdNetCache.hh:101
long long aV6[2]
Definition: XrdNetCache.hh:96
anItem ** nashtable
Definition: XrdNetCache.hh:127
XrdNetCache(int psize=987, int csize=1597)
static const int LoadMax
Definition: XrdNetCache.hh:93
Definition: XrdSysPthread.hh:164
int GenKey(anItem &Item, XrdNetAddrInfo *hAddr)
char * Find(XrdNetAddrInfo *hAddr)
void Expand()
anItem * Locate(anItem &Item)
static int keepTime
Definition: XrdNetCache.hh:124
Definition: XrdNetCache.hh:41
Definition: XrdNetAddrInfo.hh:53
int prevtablesize
Definition: XrdNetCache.hh:128
anItem()
Definition: XrdNetCache.hh:111
int aLen
Definition: XrdNetCache.hh:104
unsigned int aHash
Definition: XrdNetCache.hh:103
~XrdNetCache()
Definition: XrdNetCache.hh:89
char aVal[16]
Definition: XrdNetCache.hh:98
void Add(XrdNetAddrInfo *hAddr, const char *hName)
XrdSysMutex myMutex
Definition: XrdNetCache.hh:126
static void SetKT(int ktval)
Definition: XrdNetCache.hh:72
anItem(anItem &Item, const char *hn, int kt)
Definition: XrdNetCache.hh:113