Public Member Functions | Private Attributes | List of all members
gov::fnal::cd::rms::util::UUIDGenerator Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-16/rms/cxx/include/util/UUIDGenerator.h"

Public Member Functions

 UUIDGenerator (std::string nodeName)
 
const std::string getUUIDHex ()
 
const char * getUUID ()
 

Private Attributes

struct timeval _previousTime
 
int _overrunCounter
 
std::string _nodeName
 
unsigned char _nodeNameHash [20]
 
unsigned char _clockSequence [2]
 

Detailed Description

This class generates time based type 1 UUIDs, as specified in RFC4122.

Author
Kurt Biery
Steve Foulkes
Version
Revision
1.1.1.1.18.1
Date
2019/09/27 00:07:32

Definition at line 42 of file UUIDGenerator.h.

Constructor & Destructor Documentation

gov::fnal::cd::rms::util::UUIDGenerator::UUIDGenerator ( std::string  nodeName)

UUID constructor. Takes the nodename, and generates the hash. Also sets up the clock sequence.

Parameters
nodeNameThe name of the node generating the UUIDs. This should be unique.

Definition at line 23 of file UUIDGenerator.cpp.

References _clockSequence, _nodeName, _nodeNameHash, _previousTime, msf_helper::generator, sha1_forRMS_finish(), sha1_forRMS_starts(), and sha1_forRMS_update().

23  {
24  _nodeName = nodeName;
26  unsigned int randomNumber;
27 
28  gettimeofday(&_previousTime, NULL);
29 
30  sha1_forRMS_starts(&ctx);
31  sha1_forRMS_update(&ctx, (unsigned char *)_nodeName.c_str(),
32  _nodeName.size());
34 
35  boost::minstd_rand generator(_previousTime.tv_usec);
36  boost::uniform_int<> uniformDistribution(0, 65536);
37  boost::variate_generator<boost::minstd_rand&, boost::uniform_int<> >
38  uniformDistributionGenerator(generator, uniformDistribution);
39 
40  randomNumber = uniformDistributionGenerator() & 0xffff;
41 
42  _clockSequence[0] = randomNumber & 0xff;
43  _clockSequence[1] = (randomNumber >> 8) & 0xff;
44 
45  return;
46 }
void sha1_forRMS_update(sha1_forRMS_context *ctx, unsigned char *input, int ilen)
SHA-1 process buffer.
Definition: Sha1.cpp:232
SHA-1 context structure.
Definition: Sha1.h:14
void sha1_forRMS_starts(sha1_forRMS_context *ctx)
SHA-1 context setup.
Definition: Sha1.cpp:60
void sha1_forRMS_finish(sha1_forRMS_context *ctx, unsigned char output[20])
SHA-1 final digest.
Definition: Sha1.cpp:285

Member Function Documentation

const char * gov::fnal::cd::rms::util::UUIDGenerator::getUUID ( )

Get a UUID from the generator.

Returns
A universal unique identifier.

Definition at line 129 of file UUIDGenerator.cpp.

References _clockSequence, _nodeNameHash, _overrunCounter, _previousTime, and MECModelEnuComparisons::i.

Referenced by gov::fnal::cd::rms::provider::EpicsMessenger::sendMessage().

129  {
130  char *uuid;
131  struct timeval currentTime;
132  unsigned long timeHigh;
133  unsigned long timeLow;
134  unsigned long version = 0x1;
135 
136  gettimeofday(&currentTime, NULL);
137 
138  if (_previousTime.tv_sec == currentTime.tv_sec &&
139  _previousTime.tv_usec == currentTime.tv_usec) {
140  _overrunCounter++;
141  }
142  else {
143  _overrunCounter = 0;
144  }
145 
146  timeHigh = currentTime.tv_sec;
147  timeLow = (currentTime.tv_usec << 10) | (_overrunCounter & 0x3ff);
148 
149  timeHigh = timeHigh | (version << 28);
150 
151  uuid = new char[16];
152 
153  uuid[8] = _clockSequence[0];
154  uuid[9] = _clockSequence[1];
155 
156  memcpy(uuid, &timeLow, sizeof(unsigned int));
157  memcpy(uuid + (4 * sizeof(char)), &timeHigh, sizeof(unsigned int));
158 
159  for (int i = 10; i < 16; i++) {
160  uuid[i] = _nodeNameHash[i];
161  }
162 
163  // 10-Sep-2009, KAB - ensure that the first byte is not NULL.
164  // This is needed because we don't always bother with a UUID in single-
165  // fragment messages on the Java side, and the way that we tell if
166  // a UUID is empty on the C++ side is to check for a NULL first byte.
167  // So, we need to avoid the case in which the full UUID is not NULL
168  // but appears to be because its first byte is NULL.
169  if (uuid[0] == '\0') {uuid[0] = '\1';}
170 
171  return uuid;
172 }
const XML_Char * version
Definition: expat.h:187
const std::string gov::fnal::cd::rms::util::UUIDGenerator::getUUIDHex ( )

Get a human readable UUID from the generator.

Returns
A universal unique identifier.

Definition at line 53 of file UUIDGenerator.cpp.

References _clockSequence, _nodeNameHash, _overrunCounter, _previousTime, MECModelEnuComparisons::i, calib::j, fillBadChanDBTables::result, and string.

Referenced by gov::fnal::cd::rms::provider::DDSConnection::getUUID(), and gov::fnal::cd::rms::provider::RmsConnection::getUUID().

53  {
54  unsigned char uuid[16];
55  unsigned char uuidHex[37];
56  struct timeval currentTime;
57  unsigned long timeHigh;
58  unsigned long timeLow;
59  unsigned long version = 0x1;
60  int i = 0;
61  int j = 0;
62 
63  gettimeofday(&currentTime, NULL);
64 
65  if (_previousTime.tv_sec == currentTime.tv_sec &&
66  _previousTime.tv_usec == currentTime.tv_usec) {
68  }
69  else {
70  _overrunCounter = 0;
71  }
72 
73  timeHigh = currentTime.tv_sec;
74  timeLow = (currentTime.tv_usec << 10) | (_overrunCounter & 0x3ff);
75 
76  timeHigh = timeHigh | (version << 28);
77 
78  uuid[8] = _clockSequence[0];
79  uuid[9] = _clockSequence[1];
80 
81  memcpy(uuid, &timeLow, sizeof(unsigned int));
82  memcpy(uuid + (4 * sizeof(char)), &timeHigh, sizeof(unsigned int));
83 
84  for (int i = 10; i < 16; i++) {
85  uuid[i] = _nodeNameHash[i];
86  }
87 
88  unsigned int upper, lower;
89 
90  for (i = 0; i < 16; i++) {
91  upper = (uuid[i] >> 4) & 0x0f;
92  lower = uuid[i] & 0x0f;
93 
94  if (j == 8 || j == 13 || j == 18 || j == 23) {
95  uuidHex[j] = '-';
96  j++;
97  }
98 
99  if (upper < 10) {
100  uuidHex[j] = upper + 48;
101  }
102  else {
103  uuidHex[j] = upper + 87;
104  }
105 
106  j++;
107 
108  if (lower < 10) {
109  uuidHex[j] = lower + 48;
110  }
111  else {
112  uuidHex[j] = lower + 87;
113  }
114 
115  j++;
116  }
117 
118  uuidHex[36] = '\0';
119  const std::string result((const char*)uuidHex);
120 
121  return result;
122 }
const double j
Definition: BetheBloch.cxx:29
const XML_Char * version
Definition: expat.h:187
enum BeamMode string

Member Data Documentation

unsigned char gov::fnal::cd::rms::util::UUIDGenerator::_clockSequence[2]
private

The clock sequence, a 16 bit random number

Definition at line 75 of file UUIDGenerator.h.

Referenced by getUUID(), getUUIDHex(), and UUIDGenerator().

std::string gov::fnal::cd::rms::util::UUIDGenerator::_nodeName
private

The name of the node that is generating the UUIDs. This should be unique.

Definition at line 65 of file UUIDGenerator.h.

Referenced by UUIDGenerator().

unsigned char gov::fnal::cd::rms::util::UUIDGenerator::_nodeNameHash[20]
private

An SHA1 hash of the nodename

Definition at line 70 of file UUIDGenerator.h.

Referenced by getUUID(), getUUIDHex(), and UUIDGenerator().

int gov::fnal::cd::rms::util::UUIDGenerator::_overrunCounter
private

This is used to differentiate UUIDs that are generated within the same clock tick

Definition at line 59 of file UUIDGenerator.h.

Referenced by getUUID(), and getUUIDHex().

struct timeval gov::fnal::cd::rms::util::UUIDGenerator::_previousTime
private

The time at which the last UUID was generated.

Definition at line 53 of file UUIDGenerator.h.

Referenced by getUUID(), getUUIDHex(), and UUIDGenerator().


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