Skip to content

Commit

Permalink
Unique ID: UUID (vesoft-inc#595)
Browse files Browse the repository at this point in the history
* uuid

* uuid

Co-authored-by: jakevin <30525741+jackwener@users.noreply.github.com>
  • Loading branch information
nebula-bots and jackwener authored Feb 11, 2022
1 parent a36eb17 commit 025ab10
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/common/id/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ nebula_add_library(
Snowflake.cpp
)

nebula_add_library(
uuid_obj OBJECT
UUID.cpp
)

nebula_add_subdirectory(test)
20 changes: 20 additions & 0 deletions src/common/id/UUID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include "common/id/UUID.h"

namespace nebula {

boost::uuids::uuid UUIDV4::getId() {
boost::uuids::uuid uuid = boost::uuids::random_generator()();
return uuid;
}

std::string UUIDV4::getIdStr() {
boost::uuids::uuid uuid = getId();
return boost::uuids::to_string(uuid);
}

} // namespace nebula
28 changes: 28 additions & 0 deletions src/common/id/UUID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

/*
* UUID v1: time-based and mac-based
* UUID v2: DCE security
* UUID v3: name-based MD5
* UUID v4: random
* UUID v5: name-based SHA-1
* boost implements uuid v4 and v5(is deprecated due to security concerns)
*/
namespace nebula {

// the probability to find a duplicate within version-4 UUIDs is one in a billion.
// the computed is in: https://en.wikipedia.org/wiki/Universally_unique_identifier
class UUIDV4 {
public:
static boost::uuids::uuid getId();

static std::string getIdStr();
};
} // namespace nebula

0 comments on commit 025ab10

Please sign in to comment.