XRootD
Loading...
Searching...
No Matches
XrdNetRegistry Class Reference

#include <XrdNetRegistry.hh>

+ Collaboration diagram for XrdNetRegistry:

Public Member Functions

 XrdNetRegistry ()
 
 ~XrdNetRegistry ()
 

Static Public Member Functions

static const char * GetAddrs (const std::string &hSpec, std::vector< XrdNetAddr > &aVec, int *ordn=0, XrdNetUtils::AddrOpts opts=XrdNetUtils::allIPMap, int pNum=XrdNetUtils::PortInSpec)
 
static bool Register (const char *hName, const char *hList, std::string *eText=0, bool rotate=false)
 
static bool Register (const char *hName, const char *hList[], int hLNum, std::string *eText=0, bool rotate=false)
 

Static Public Attributes

static const char pfx = '%'
 Registry names must start with this character.
 

Detailed Description

Definition at line 39 of file XrdNetRegistry.hh.

Constructor & Destructor Documentation

◆ XrdNetRegistry()

XrdNetRegistry::XrdNetRegistry ( )
inline

Definition at line 107 of file XrdNetRegistry.hh.

107{}

◆ ~XrdNetRegistry()

XrdNetRegistry::~XrdNetRegistry ( )
inline

Definition at line 108 of file XrdNetRegistry.hh.

108{}

Member Function Documentation

◆ GetAddrs()

const char * XrdNetRegistry::GetAddrs ( const std::string &  hSpec,
std::vector< XrdNetAddr > &  aVec,
int *  ordn = 0,
XrdNetUtils::AddrOpts  opts = XrdNetUtils::allIPMap,
int  pNum = XrdNetUtils::PortInSpec 
)
static

Return addresses associated with a registered name.

Parameters
hSpecReference to address specification & must start with "pfx".
aVecReference to the vector to contain addresses.
ordnPointer to where the partition ordinal is to be stored.
optsOptions on what to return (see XrdNetUtils).
pNumPort number argument (see XrdNetUtils), ignored for now.
Returns
Success: 0 is returned. When ordn is not nil, the number of IPv4 entries (for order46) or IPv6 (for order64) entries that appear in the front of the vector. If ordering is not specified, the value is set to the size of the vector. Failure: the error message text describing the error and aVec is cleared (i.e. has no elements).

Definition at line 110 of file XrdNetRegistry.cc.

113{
114 regEntry *reP;
115 unsigned int refs;
116
117// Find the entry
118//
119 XrdSysMutexHelper mHelp(regMutex);
120 if (!(reP = regEntry::Find(hSpec.c_str())))
121 {aVec.clear();
122 return "pseudo host not registered";
123 }
124
125// Hold this entry as we don't want to hold the global lock doing DNS lookups.
126//
127 if (reP->rotate) refs = reP->refs++;
128 else refs = 0;
129 reP->Hold(true);
130 mHelp.UnLock();
131
132// Resolve the the host specification (at least one must be resolvable)
133//
134 XrdNetUtils::GetAddrs(reP->hVec, aVec, ordn, opts, refs, true);
135
136// Drop the hold on the entry and return result
137//
138 reP->Hold(false);
139 if (aVec.size() == 0) return "registry entry unresolvable";
140 return 0;
141}
struct myOpts opts
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)

References XrdNetUtils::GetAddrs(), opts, and XrdSysMutexHelper::UnLock().

Referenced by XrdNetUtils::GetAddrs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Register() [1/2]

bool XrdNetRegistry::Register ( const char *  hName,
const char *  hList,
std::string *  eText = 0,
bool  rotate = false 
)
static

Register a pseuo-hostname to be associated with a string of hosts.

Parameters
hNameThe pseudo-hostname which must start with 'pfx'.
hListA string of comma separated "host:port" entries to register. If the name starts with 'pfx' then it assumed to be a single name where hName is to become its alias. Alias rules are: 1) hName must not exist, 2) the target must exist, and 3) if the target is an alias hName becomes an alias of it's target (i.e. its parent).
eTextWhen not null, the reason for the registration failure.
rotateWhen true, the returned host list will be rotated +1 relative to the previously returned list of hosts.
Returns
True upon success and false otherwise.
Note
The expanded list is returned when GetAddrs() is called with hName.

Definition at line 179 of file XrdNetRegistry.cc.

181{
182 char *comma, *hosts = strdup(hList);
183 std::vector<const char*> hVec;
184
185// Make sure we have valid parameters
186//
187 if (!hName || *hName != pfx || !hList)
188 {if (eText) *eText = "invalid calling arguments";
189 return 0;
190 }
191
192// Check for alias creation
193//
194 if (*hList == pfx) return SetAlias(hName, hList, eText);
195
196// Construct a vector of contacts
197//
198 hVec.reserve(16);
199 hVec.push_back(hosts);
200 comma = hosts;
201 while((comma = index(comma, ',')))
202 {*comma++ = 0;
203 hVec.push_back(comma);
204 }
205
206// Verify that each element has a colon in it
207//
208 for (int i = 0; i < (int)hVec.size(); i++)
209 {if (!index(hVec[i], ':'))
210 {if (eText)
211 {*eText = "port missing for '";
212 *eText += hVec[i]; *eText += "'";
213 }
214 free(hosts);
215 return false;
216 }
217 }
218
219// Register this contact
220//
221 bool aOK = Register(hName, hVec.data(), (int)hVec.size(), eText, rotate);
222
223// Cleanup and return result
224//
225 free(hosts);
226 return aOK;
227}
static bool Register(const char *hName, const char *hList[], int hLNum, std::string *eText=0, bool rotate=false)
static const char pfx
Registry names must start with this character.

References pfx, and Register().

+ Here is the call graph for this function:

◆ Register() [2/2]

bool XrdNetRegistry::Register ( const char *  hName,
const char *  hList[],
int  hLNum,
std::string *  eText = 0,
bool  rotate = false 
)
static

Register a pseuo-hostname to be associated with a list of hosts.

Parameters
hNameThe pseudo-hostname which must start with 'pfx'.
hListA list of "host:port" entries to register as hName.
hLNumThe number of entries in hList.
eTextWhen not null, the reason for the registration failure.
rotateWhen true, the returned host list will be rotated +1 relative to the previously returned list of hosts.
Returns
True upon success and false otherwise.
Note
The expanded list is returned when GetAddrs() is called with hName.

Definition at line 147 of file XrdNetRegistry.cc.

150{
151 regEntry *reP;
152
153// Make sure we have valid parameters
154//
155 if (!hName || *hName != pfx || !hList || hLNum <= 0)
156 {if (eText) *eText = "invalid calling arguments";
157 return false;
158 }
159
160// Run through the list resolving all of the addresses. When registering, all
161// of them must be resolvable. When running at least one must be resolvable.
162//
163 for (int i = 0; i < hLNum; i++) if (!Resolve(hList[i], eText)) return false;
164
165// Do replacement or addition
166//
167 regMutex.Lock();
168 if ((reP = regEntry::Find(hName))) reP->Update(hList, hLNum, rotate);
169 else regEntry::Add(new regEntry(hName, hList, hLNum, rotate));
170 regMutex.UnLock();
171
172// All done
173//
174 return true;
175}

References pfx.

Referenced by XrdSsiClientProvider::GetService(), and Register().

+ Here is the caller graph for this function:

Member Data Documentation

◆ pfx

const char XrdNetRegistry::pfx = '%'
static

Registry names must start with this character.

Definition at line 43 of file XrdNetRegistry.hh.

Referenced by XrdNetUtils::GetAddrs(), XrdSsiClientProvider::GetService(), Register(), and Register().


The documentation for this class was generated from the following files: