XRootD
Loading...
Searching...
No Matches
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
38
39class XrdNetAddrInfo;
40
42{
43public:
44
45//------------------------------------------------------------------------------
51//------------------------------------------------------------------------------
52
53void Add(XrdNetAddrInfo *hAddr, const char *hName);
54
55//------------------------------------------------------------------------------
62//------------------------------------------------------------------------------
63
64char *Find(XrdNetAddrInfo *hAddr);
65
66//------------------------------------------------------------------------------
70//------------------------------------------------------------------------------
71static
72void 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
91private:
92
93static const int LoadMax = 80;
94
95struct anItem
96 {union {long long aV6[2];
97 int aV4[4];
98 char aVal[16]; // Enough for IPV4 or IPV6
99 };
100 anItem *Next;
101 char *hName;
102 time_t expTime; // Expiration time
103unsigned int aHash; // Hash value
104 int aLen; // Actual length 4 or 16
105
106inline 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
120void Expand();
121int GenKey(anItem &Item, XrdNetAddrInfo *hAddr);
122anItem *Locate(anItem &Item);
123
124static int keepTime;
125
126XrdSysMutex myMutex;
127anItem **nashtable;
128int prevtablesize;
129int nashtablesize;
130int nashnum;
131int Threshold;
132};
133#endif
static void SetKT(int ktval)
void Add(XrdNetAddrInfo *hAddr, const char *hName)
char * Find(XrdNetAddrInfo *hAddr)
XrdNetCache(int psize=987, int csize=1597)