From c7ba2112bb27fbc4e4d144154ebfc0640060a83b Mon Sep 17 00:00:00 2001 From: "yangwei.yao" Date: Sat, 11 May 2019 14:08:30 +0800 Subject: [PATCH] 05.11 Former-commit-id: 22e7d5214db47ac228d50989b01e3a5e71a719d4 --- cpp/CMakeLists.txt | 2 +- cpp/src/license/BoostArchive.h | 133 +++++++ cpp/src/license/License.cpp | 371 +++++++++++++++++++ cpp/src/license/License.h | 81 ++++ cpp/src/license/LicenseCreateTime.cpp | 51 +++ cpp/src/license/LicenseCreateuuidshafile.cpp | 31 ++ cpp/src/license/LicenseGenerator.cpp | 2 +- cpp/src/license/LicensePublic.cpp | 284 ++++++++++++++ cpp/src/license/LicensePublic.h | 68 ++++ cpp/src/license/LicenseRun.cpp | 13 + cpp/src/utils/Error.h | 1 + cpp/unittest/license/CMakeLists.txt | 22 +- cpp/unittest/license/license_tests.cpp | 174 ++++++++- 13 files changed, 1218 insertions(+), 15 deletions(-) create mode 100644 cpp/src/license/BoostArchive.h create mode 100644 cpp/src/license/License.cpp create mode 100644 cpp/src/license/License.h create mode 100644 cpp/src/license/LicenseCreateTime.cpp create mode 100644 cpp/src/license/LicenseCreateuuidshafile.cpp create mode 100644 cpp/src/license/LicensePublic.cpp create mode 100644 cpp/src/license/LicensePublic.h create mode 100644 cpp/src/license/LicenseRun.cpp diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index e6f65de4..d249baf1 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -69,7 +69,7 @@ link_directories(${VECWISE_THIRD_PARTY_BUILD}/lib64) # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party) add_subdirectory(src) -add_subdirectory(test_client) +#add_subdirectory(test_client) if (BUILD_UNIT_TEST) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unittest) diff --git a/cpp/src/license/BoostArchive.h b/cpp/src/license/BoostArchive.h new file mode 100644 index 00000000..4074cc07 --- /dev/null +++ b/cpp/src/license/BoostArchive.h @@ -0,0 +1,133 @@ +// +// Created by zilliz on 19-5-10. +// + +#ifndef VECWISE_ENGINE_BOOSTARCHIVE_H +#define VECWISE_ENGINE_BOOSTARCHIVE_H +#include +#include +#include +#include +#include + +using std::list; +using std::ifstream; +using std::ofstream; +using std::string; +using std::map; + +template +class BoostArchive +{ +public: + typedef T entity_type; + typedef boost::archive::binary_iarchive InputArchive; + typedef boost::archive::binary_oarchive OutputArchive; + + BoostArchive(const string & archive_file_path) + : _file_path_name(archive_file_path) + , _p_ofs(NULL) + , _p_output_archive(NULL) + , _entity_nums(0) + { + load_arvhive_info(); + } + ~BoostArchive() + { + close_output(); + } + //存储一个对象,序列化 + void store(const entity_type & entity); + + //反序列化, 提取所有对象 + bool restore(list & entitys); + + size_t size() const + { + return _entity_nums; + } + +private: + void save_archive_info() //保存已序列化的对象个数信息 + { + ofstream ofs; + ofs.open(get_archive_info_file_path(),std::ios::out | std::ios::trunc); + if (ofs.is_open()) + { + ofs << _entity_nums; + } + ofs.close(); + } + + void load_arvhive_info()//读取已序列化的对象个数信息 + { + ifstream ifs; + ifs.open(get_archive_info_file_path(),std::ios_base::in); + if (ifs.is_open() && !ifs.eof()) + { + int enity_num = 0; + ifs >> enity_num; + _entity_nums = enity_num; + } + ifs.close(); + } + + string get_archive_info_file_path() + { + return "/tmp/vecwise_engine.meta"; + } + + void close_output() + { + if (NULL != _p_output_archive) + { + delete _p_output_archive; + _p_output_archive = NULL; + save_archive_info(); + } + if (NULL != _p_ofs) + { + delete _p_ofs; + _p_ofs = NULL; + } + } + +private: + size_t _entity_nums; + string _file_path_name; + ofstream * _p_ofs; + OutputArchive * _p_output_archive; +}; + +template +bool BoostArchive::restore( list & entitys ) +{ + close_output(); + load_arvhive_info(); + ifstream ifs(_file_path_name); + if (ifs) + { + InputArchive ia(ifs); + for (size_t cnt = 0; cnt < _entity_nums; ++cnt) + { + entity_type entity; + ia & entity; + entitys.push_back(entity); + } + return true; + } + return false; +} + +template +void BoostArchive::store( const entity_type & entity ) +{ + if (NULL == _p_output_archive) + { + _p_ofs = new ofstream(_file_path_name); + _p_output_archive = new OutputArchive(*_p_ofs); + } + (*_p_output_archive) & entity; + ++_entity_nums; +} +#endif //VECWISE_ENGINE_BOOSTARCHIVE_H diff --git a/cpp/src/license/License.cpp b/cpp/src/license/License.cpp new file mode 100644 index 00000000..193a322e --- /dev/null +++ b/cpp/src/license/License.cpp @@ -0,0 +1,371 @@ +#include "License.h" + +namespace zilliz { +namespace vecwise { +namespace server { + +ServerError +LicenseSave(const std::string& path,const int& deviceCount,const std::vector& shas) +{ + std::ofstream file(path); + + boost::archive::binary_oarchive oa(file); + oa << deviceCount; + for(int i=0;i& shas) +{ + std::ifstream file(path); + + boost::archive::binary_iarchive ia(file); + ia >> deviceCount; + std::string sha; + for(int i=0;i> sha; + shas.push_back(sha); + } + file.close(); + return SERVER_SUCCESS; +} + +ServerError +Licensefileread(const std::string& path) +{ + std::ifstream fileread; + fileread.open(path,std::ios::in); + if(!fileread) + { + printf("Can't open file\n"); + return SERVER_UNEXPECTED_ERROR; + } + fileread.close(); + return SERVER_SUCCESS; +} + +ServerError +Licensefileread (const std::string& path,std::ifstream& fileread){ + fileread.open(path,std::ios::in); + if(!fileread) + { + printf("Can't open file\n"); + return SERVER_UNEXPECTED_ERROR; + } + return SERVER_SUCCESS; +} + +ServerError +Licensefilewrite (const std::string& path,std::ofstream& filewrite) { + filewrite.open(path,std::ios::out); + if(!filewrite) + { + printf("Can't write file\n"); + return SERVER_UNEXPECTED_ERROR; + } + return SERVER_SUCCESS; +} + +ServerError +LicenseGetCount(int &deviceCount) +{ + nvmlReturn_t result = nvmlInit(); + if (NVML_SUCCESS != result) + { + printf("Failed to initialize NVML: %s\n", nvmlErrorString(result)); + return SERVER_UNEXPECTED_ERROR; + } + cudaError_t error_id = cudaGetDeviceCount(&deviceCount); + if (error_id != cudaSuccess) + { + printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id)); + printf("Result = FAIL\n"); + return SERVER_UNEXPECTED_ERROR; + } + return SERVER_SUCCESS; +} + +ServerError +LicenseGetuuid(int& deviceCount, std::vector& uuids) +{ + nvmlReturn_t result = nvmlInit(); + if (NVML_SUCCESS != result) + { + printf("Failed to initialize NVML: %s\n", nvmlErrorString(result)); + return SERVER_UNEXPECTED_ERROR; + } + cudaError_t error_id = cudaGetDeviceCount(&deviceCount); + if (error_id != cudaSuccess) + { + printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id, cudaGetErrorString(error_id)); + printf("Result = FAIL\n"); + return SERVER_UNEXPECTED_ERROR; + } + + if (deviceCount == 0) + { + printf("There are no available device(s) that support CUDA\n"); + return SERVER_UNEXPECTED_ERROR; + } + + for (int dev = 0; dev < deviceCount; ++dev) + { + nvmlDevice_t device; + result = nvmlDeviceGetHandleByIndex(dev, &device); + printf("device id: %d\n", dev); + if (NVML_SUCCESS != result) + { + printf("Failed to get handle for device %i: %s\n", dev, nvmlErrorString(result)); + return SERVER_UNEXPECTED_ERROR; + } + + char* uuid = (char*)malloc(80); + unsigned int length = 80; + nvmlReturn_t err = nvmlDeviceGetUUID(device, uuid, length); + if(err != NVML_SUCCESS) { + printf("nvmlDeviceGetUUID error: %d\n", err); + return SERVER_UNEXPECTED_ERROR; + } + + printf("\n device: %d, uuid = %s \n", dev, uuid); + uuids.push_back(std::string(uuid)); + free(uuid); + uuid = NULL; + } + return SERVER_SUCCESS; +} + +ServerError +LicenseGetuuidmd5(const int& deviceCount,std::vector& uuids,std::vector& md5s) +{ + MD5_CTX ctx; + unsigned char outmd[16]; + char temp[2]; + std::string md5=""; + for(int dev=0;dev& uuids,std::vector& shas) +{ + SHA256_CTX ctx; + unsigned char outmd[32]; + char temp[2]; + std::string sha=""; + for(int dev=0;dev uuids; + LicenseGetuuid(deviceCount,uuids); + std::vector shas; + LicenseGetuuidsha(deviceCount,uuids,shas); + + + int deviceCountcheck; + std::vector shascheck; + LicenseLoad(path,deviceCountcheck,shascheck); + + if(deviceCount!=deviceCountcheck) + { + printf("deviceCount is wrong\n"); + return SERVER_UNEXPECTED_ERROR; + } + for(int i=0;i> filemd5; + ia >> last_time; + file.close(); + return SERVER_SUCCESS; +} + +ServerError +LicenseIntegritycheck(const std::string& path,const std::string& path2) + { + std::string filemd5; + LicenseGetfilemd5(path,filemd5); + time_t last_time; + LicenseGetfiletime(path,last_time); + + time_t last_timecheck; + std::string filemd5check; + LicensefileLoad(path2,filemd5check,last_timecheck); + + if(filemd5!=filemd5check) + { + printf("This file has been modified\n"); + return SERVER_UNEXPECTED_ERROR; + } + if(last_time!=last_timecheck) + { + printf("last_time is wrong\n"); + return SERVER_UNEXPECTED_ERROR; + } + + return SERVER_SUCCESS; + } + +ServerError +LicenseValidate(const std::string& path) { + + + return SERVER_SUCCESS; +} + + + +} +} +} \ No newline at end of file diff --git a/cpp/src/license/License.h b/cpp/src/license/License.h new file mode 100644 index 00000000..6f67edb6 --- /dev/null +++ b/cpp/src/license/License.h @@ -0,0 +1,81 @@ +#pragma once + +#include "utils/Error.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "boost/archive/binary_oarchive.hpp" +#include "boost/archive/binary_iarchive.hpp" + +#include +#include +#include +#include + + +namespace zilliz { +namespace vecwise { +namespace server { + + +ServerError +LicenseSave(const std::string& path,const int& deviceCount,const std::vector& shas); + +ServerError +LicenseLoad(const std::string& path,int& deviceCount,std::vector& shas); + +ServerError +Licensefileread (const std::string& path,std::ifstream& fileread); + +ServerError +Licensefilewrite (const std::string& path,std::ofstream& filewrite); + +ServerError +LicenseGetuuid(int& deviceCount, std::vector& uuids); + +ServerError +LicenseGetuuidmd5(const int& deviceCount,std::vector& uuids,std::vector& md5s); + +ServerError +LicenseGetfilemd5(const std::string& path,std::string& filemd5); + +ServerError +LicenseGetuuidsha(const int& deviceCount,std::vector& uuids,std::vector& shas); + +ServerError +LicenseIntegritycheck(const std::string& path,const std::string& path2); + +ServerError +LicenseGetfiletime(const std::string& path,time_t& last_time); + +ServerError +LicenseLegalitycheck(const std::string& path); + +ServerError +LicensefileSave(const std::string& path,const std::string& path2); + +ServerError +LicensefileLoad(const std::string& path2,std::string& filemd5,time_t& last_time); + + +ServerError +LicenseGetfilesize(const std::string& path,off_t& file_size); + +ServerError +LicenseValidate(const std::string& path); + +ServerError +Licensefileread(const std::string& path); + +ServerError +LicenseGetCount(int &deviceCount); +} +} +} + + diff --git a/cpp/src/license/LicenseCreateTime.cpp b/cpp/src/license/LicenseCreateTime.cpp new file mode 100644 index 00000000..7683fae2 --- /dev/null +++ b/cpp/src/license/LicenseCreateTime.cpp @@ -0,0 +1,51 @@ +// +// Created by zilliz on 19-5-11. +// + +#include +#include +#include + +#include "utils/Error.h" +#include "license/License.h" +#include "license/LicensePublic.h" + +using namespace zilliz::vecwise; + +//TEST(LicenseTest, LICENSE_TEST) { +// +// std::string path1 = "/tmp/vecwise_engine.sha"; +// std::string path2 = "/tmp/vecwise_engine.license"; +// std::cout << "This is create licenseTime " << std::endl; +// +// server::ServerError err; +// int deviceCount=0; +// +// std::vector shas; +// err = server::LicenseLoad(path1,deviceCount,shas); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// std::map uuidEncryption; +// std::cout<< "deviceCount : " << deviceCount << std::endl; +// for(int i=0;i> RemainingTime ; +// +// err = server::LiSave(path2,deviceCount,uuidEncryption,RemainingTime); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// int64_t RemainingTimecheck; +// std::map uuidEncryptioncheck; +// int deviceCountcheck; +// err = server::LiLoad(path2,deviceCountcheck,uuidEncryptioncheck,RemainingTimecheck); +// +// printf("\n deviceCountcheck = %d\n",deviceCountcheck); +// std::cout<< "RemainingTimecheck: " << RemainingTimecheck<< std::endl; +// std::cout<< "success" << std::endl; +// +//} \ No newline at end of file diff --git a/cpp/src/license/LicenseCreateuuidshafile.cpp b/cpp/src/license/LicenseCreateuuidshafile.cpp new file mode 100644 index 00000000..93179ba7 --- /dev/null +++ b/cpp/src/license/LicenseCreateuuidshafile.cpp @@ -0,0 +1,31 @@ +// +// Created by zilliz on 19-5-11. +// +#include +#include + +#include "utils/Error.h" +#include "license/License.h" +using namespace zilliz::vecwise; + +// +//TEST(LicenseTest, LICENSE_TEST) { +// +// std::string path1 = "/tmp/vecwise_engine.sha"; +// std::cout << "This is create uuidshafile " << std::endl; +// +// server::ServerError err; +// int deviceCount=0; +// std::vector uuids; +// +// err = server::LicenseGetuuid(deviceCount,uuids); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// std::vector shas; +// err = server::LicenseGetuuidsha(deviceCount,uuids,shas); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// err = server::LicenseSave(path1,deviceCount,shas); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +//} \ No newline at end of file diff --git a/cpp/src/license/LicenseGenerator.cpp b/cpp/src/license/LicenseGenerator.cpp index f82e948c..278c1329 100644 --- a/cpp/src/license/LicenseGenerator.cpp +++ b/cpp/src/license/LicenseGenerator.cpp @@ -1,6 +1,6 @@ #include - int main() { std::cout << "This is license generator" << std::endl; + return 0; } \ No newline at end of file diff --git a/cpp/src/license/LicensePublic.cpp b/cpp/src/license/LicensePublic.cpp new file mode 100644 index 00000000..65346744 --- /dev/null +++ b/cpp/src/license/LicensePublic.cpp @@ -0,0 +1,284 @@ +// +// Created by zilliz on 19-5-10. +// + +#include "LicensePublic.h" +#include "license/License.h" +//#include "BoostArchive.h" +#define RTime 100 + +using std::string; +using std::map; +namespace zilliz { +namespace vecwise { +namespace server { + +// GET /tmp/vecwise_engine.license +class Licensedata1 +{ +public: + Licensedata1() + :_deviceCount(0) + ,_RemainingTime(RTime) + {} + + Licensedata1(const int& deviceCount,const map& uuidEncryption) + :_deviceCount(deviceCount) + ,_uuidEncryption(uuidEncryption) + ,_RemainingTime(RTime) + {} + + Licensedata1(const int& deviceCount,const map& uuidEncryption,const int64_t& RemainingTime) + :_deviceCount(deviceCount) + ,_uuidEncryption(uuidEncryption) + ,_RemainingTime(RemainingTime) + {} + + int GetdeviceCount() + { + return _deviceCount; + } + map GetuuidEncryption() + { + return _uuidEncryption; + } + int64_t GetRemainingTime() + { + return _RemainingTime; + } + +private: + friend class boost::serialization::access; + template + void serialize(Archive &ar, const unsigned int version) + { + ar & _deviceCount; + ar & _uuidEncryption; + ar & _RemainingTime; + } + +public: + int _deviceCount; + map _uuidEncryption; + int64_t _RemainingTime; +}; + + +class STLlicensedata +{ +private: + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int version) + { + ar & m_licensedata; + } + +public: + Licensedata1* m_licensedata; +}; + + +ServerError +LiSave(const string& path,const int& deviceCount,const map& uuidEncryption) +{ + std::ofstream file(path); + boost::archive::binary_oarchive oa(file); + oa.register_type(); + STLlicensedata stllicensedata; + + Licensedata1 *p = new Licensedata1(deviceCount,uuidEncryption); + stllicensedata.m_licensedata = p; + oa << stllicensedata; + + delete p; + file.close(); + return SERVER_SUCCESS; +} + +ServerError +LiSave(const string& path,const int& deviceCount,const map& uuidEncryption, const int64_t& RemainingTime) +{ + std::ofstream file(path); + boost::archive::binary_oarchive oa(file); + oa.register_type(); + STLlicensedata stllicensedata; + + Licensedata1 *p = new Licensedata1(deviceCount,uuidEncryption,RemainingTime); + stllicensedata.m_licensedata = p; + oa << stllicensedata; + + delete p; + file.close(); + return SERVER_SUCCESS; +} + +ServerError +LiLoad(const string& path,int& deviceCount,map& uuidEncryption,int64_t& RemainingTime) +{ + std::ifstream file(path); + boost::archive::binary_iarchive ia(file); + ia.register_type(); + STLlicensedata stllicensedata; + ia >> stllicensedata; + deviceCount = stllicensedata.m_licensedata->GetdeviceCount(); + uuidEncryption = stllicensedata.m_licensedata->GetuuidEncryption(); + RemainingTime = stllicensedata.m_licensedata->GetRemainingTime(); + file.close(); + return SERVER_SUCCESS; +} + + +// GET /tmp/vecwise_engine2.license + +class Licensefiledata +{ +public: + Licensefiledata() + :_update_time(0) + ,_file_size(0) + ,_filemd5("") + {} + + Licensefiledata(const time_t& update_time,const off_t& file_size,const string& filemd5) + :_update_time(update_time) + ,_file_size(file_size) + ,_filemd5(filemd5) + {} + + time_t Getupdate_time() + { + return _update_time; + } + off_t Getfile_size() + { + return _file_size; + } + string Getfilemd5() + { + return _filemd5; + } + +private: + friend class boost::serialization::access; + template + void serialize(Archive &ar, const unsigned int version) + { + ar & _update_time; + ar & _file_size; + ar & _filemd5; + } + +public: + time_t _update_time; + off_t _file_size; + string _filemd5; +}; + + +class STLlicensefiledata +{ +private: + friend class boost::serialization::access; + template + void serialize(Archive& ar, const unsigned int version) + { + ar & m_licensefiledata; + } + +public: + Licensefiledata* m_licensefiledata; +}; + + +ServerError +LifileSave(const string& path,const time_t& update_time,const off_t& file_size,const string& filemd5) +{ + std::ofstream file(path); + boost::archive::binary_oarchive oa(file); + oa.register_type(); + STLlicensefiledata stllicensefiledata; + + Licensefiledata *p = new Licensefiledata(update_time,file_size,filemd5); + stllicensefiledata.m_licensefiledata = p; + oa << stllicensefiledata; + + delete p; + file.close(); + return SERVER_SUCCESS; +} + +ServerError +LifileLoad(const string& path,time_t& update_time,off_t& file_size,string& filemd5) + { + std::ifstream file(path); + boost::archive::binary_iarchive ia(file); + ia.register_type(); + STLlicensefiledata stllicensefiledata; + ia >> stllicensefiledata; + update_time = stllicensefiledata.m_licensefiledata->Getupdate_time(); + file_size = stllicensefiledata.m_licensefiledata->Getfile_size(); + filemd5 = stllicensefiledata.m_licensefiledata->Getfilemd5(); + file.close(); + return SERVER_SUCCESS; + } + + +void Alterfile(const string &path1, const string &path2 ,const boost::system::error_code &ec, boost::asio::deadline_timer* pt) +{ + int deviceCount; + map uuidEncryption; + int64_t RemainingTime; + LiLoad(path1,deviceCount,uuidEncryption,RemainingTime); + + std::cout<< "RemainingTime: " << RemainingTime < uuidEncryptioncheck; + int64_t RemainingTimecheck; + LiLoad(path1,deviceCountcheck,uuidEncryptioncheck,RemainingTimecheck); + + std::cout<< "RemainingTimecheck: " << RemainingTimecheck <expires_at(pt->expires_at() + boost::posix_time::hours(1)) ; + pt->async_wait(boost::bind(Alterfile,path1,path2, boost::asio::placeholders::error, pt)); + +} +void Runtime(const string &path1, const string &path2 ) +{ + boost::asio::io_service io; + boost::asio::deadline_timer t(io, boost::posix_time::hours(1)); + t.async_wait(boost::bind(Alterfile,path1,path2, boost::asio::placeholders::error, &t)); + io.run(); + return;; +} + +} +} +} \ No newline at end of file diff --git a/cpp/src/license/LicensePublic.h b/cpp/src/license/LicensePublic.h new file mode 100644 index 00000000..ea2e439d --- /dev/null +++ b/cpp/src/license/LicensePublic.h @@ -0,0 +1,68 @@ +// +// Created by zilliz on 19-5-10. +// + +#pragma once + +#include "utils/Error.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace zilliz { +namespace vecwise { +namespace server { + +class BoostArchive; +class Licensedata1; + + +class Licensefiledata; +class STLlicensefiledata; + + +ServerError +LiSave(const std::string& path,const int& deviceCount,const std::map& uuidEncryption); + +ServerError +LiLoad(const std::string& path,int& deviceCount,std::map& uuidEncryption,int64_t& RemainingTime); + +ServerError +LifileSave(const std::string& path,const time_t& update_time,const off_t& file_size,const std::string& filemd5); + +ServerError +LifileLoad(const std::string& path,time_t& update_time,off_t& file_size,std::string& filemd5); + +ServerError +LiSave(const std::string& path,const int& deviceCount,const std::map& uuidEncryption, const int64_t& RemainingTime); + +void Alterfile(const std::string &path1, const std::string &path2 ,const boost::system::error_code &ec, boost::asio::deadline_timer* pt); +void Runtime(const std::string &path1, const std::string &path2 ); + +// void Print(const boost::system::error_code &ec,boost::asio::deadline_timer* pt, int * pcount ); +// void Run(); + +} +} +} \ No newline at end of file diff --git a/cpp/src/license/LicenseRun.cpp b/cpp/src/license/LicenseRun.cpp new file mode 100644 index 00000000..660fd5fa --- /dev/null +++ b/cpp/src/license/LicenseRun.cpp @@ -0,0 +1,13 @@ +// +// Created by zilliz on 19-5-11. +// +#include +#include +#include + +#include "utils/Error.h" +#include "license/License.h" +#include "license/LicensePublic.h" +using namespace zilliz::vecwise; + + diff --git a/cpp/src/utils/Error.h b/cpp/src/utils/Error.h index 83da0cea..88e697ec 100644 --- a/cpp/src/utils/Error.h +++ b/cpp/src/utils/Error.h @@ -31,6 +31,7 @@ constexpr ServerError SERVER_INVALID_ARGUMENT = ToGlobalServerErrorCode(0x004); constexpr ServerError SERVER_FILE_NOT_FOUND = ToGlobalServerErrorCode(0x005); constexpr ServerError SERVER_NOT_IMPLEMENT = ToGlobalServerErrorCode(0x006); constexpr ServerError SERVER_BLOCKING_QUEUE_EMPTY = ToGlobalServerErrorCode(0x007); +constexpr ServerError SERVER_LICENSE_VALIDATION_FAIL = ToGlobalServerErrorCode(0x008); class ServerException : public std::exception { public: diff --git a/cpp/unittest/license/CMakeLists.txt b/cpp/unittest/license/CMakeLists.txt index dd742d66..92eef5d5 100644 --- a/cpp/unittest/license/CMakeLists.txt +++ b/cpp/unittest/license/CMakeLists.txt @@ -11,34 +11,32 @@ aux_source_directory(../../src/cache cache_srcs) aux_source_directory(../../src/wrapper wrapper_src) include_directories(/usr/local/cuda/include) -link_directories("/usr/local/cuda/lib64") +link_directories(/usr/local/cuda) +link_directories(/usr/local/cuda/lib64) +link_directories(/usr/lib/x86_64-linux-gnu) +link_directories(/usr/lib/nvidia-415) set(require_files - ../../src/server/ServerConfig.cpp - ../../src/utils/CommonUtil.cpp - ../../src/utils/TimeRecorder.cpp ../../src/license/License.cpp - ) + ../../src/license/LicensePublic.cpp + ../../src/license/LicenseCreateuuidshafile.cpp + ) set(db_test_src - ${unittest_srcs} - ${config_files} - ${cache_srcs} - ${db_srcs} - ${wrapper_src} ${require_files} license_tests.cpp) cuda_add_executable(license_test ${db_test_src}) set(db_libs - faiss + nvidia-ml cudart cublas - sqlite3 boost_system boost_filesystem lz4 + crypto + boost_serialization ) target_link_libraries(license_test ${unittest_libs} ${db_libs}) diff --git a/cpp/unittest/license/license_tests.cpp b/cpp/unittest/license/license_tests.cpp index 798160f6..4ee6898d 100644 --- a/cpp/unittest/license/license_tests.cpp +++ b/cpp/unittest/license/license_tests.cpp @@ -5,12 +5,184 @@ //////////////////////////////////////////////////////////////////////////////// #include #include "license/License.h" +#include "license/LicensePublic.h" #include "utils/Error.h" + using namespace zilliz::vecwise; TEST(LicenseTest, LICENSE_TEST) { + std::string path1 = "/tmp/vecwise_engine.license"; - server::ServerError err = server::LicenseValidate(path1); + std::string path2 = "/tmp/vecwise_engine2.license"; + std::cout << "This is run " << std::endl; + + server::ServerError err; + + err = server::Licensefileread(path1); + if(err!=server::SERVER_SUCCESS) + { + exit(1); + } + + int deviceCount=0; + std::vector uuids; + + err = server::LicenseGetuuid(deviceCount,uuids); + ASSERT_EQ(err, server::SERVER_SUCCESS); + + std::vector shas; + err = server::LicenseGetuuidsha(deviceCount,uuids,shas); ASSERT_EQ(err, server::SERVER_SUCCESS); + + err = server::LicenseSave(path1,deviceCount,shas); + ASSERT_EQ(err, server::SERVER_SUCCESS); + } + +//TEST(LicenseTest, LICENSE_TEST) { +// std::string path1 = "/tmp/vecwise_engine.license"; +// std::string path2 = "/tmp/vecwise_engine2.license"; +// +// server::ServerError err; +// server::Runtime(path1,path2); + + +// time_t update_time; +// off_t file_size; +// std::string filemd5; +// +// time_t update_timecheck; +// off_t file_sizecheck; +// std::string filemd5check; +// +// err = server::LicenseGetfiletime(path1,update_time); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// err = server::LicenseGetfilesize(path1,file_size); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// err = server::LicenseGetfilemd5(path1,filemd5); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// err = server::LifileSave(path2,update_time,file_size,filemd5); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// err = server::LifileLoad(path2,update_timecheck,file_sizecheck,filemd5check); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// +// std::cout<< "update_time : " << update_time < uuids; +// +// deviceCount = 2; +// uuids.push_back("121"); +// uuids.push_back("324"); +// err = server::LicenseGetuuid(deviceCount,uuids); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// printf("\n deviceCount = %d\n",deviceCount); +// +// std::vector uuidmd5s; +// err = server::LicenseGetuuidmd5(deviceCount,uuids,uuidmd5s); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// printf(" md5s \n"); +// for(int i=0;i uuidshas; +// err = server::LicenseGetuuidsha(deviceCount,uuids,uuidshas); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// std::map uuidEncryption; +// for(int i=0;i uuidEncryptioncheck; +// err = server::LiLoad(path1,deviceCountcheck,uuidEncryptioncheck,RemainingTime); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// printf("----- checking ----\n"); +// printf("\n deviceCount = %d\n",deviceCountcheck); +// for(auto it : uuidEncryptioncheck) +// { +// std::cout<< "uuidshas : " << it.second << std::endl; +// } +// std::cout<< "RemainingTime :" << RemainingTime << std::endl; +// +// printf(" shas \n"); +// for(int i=0;i uuidshascheck; +// +// err = server::LicenseLoad(path1,deviceCountcheck,uuidshascheck); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// std::cout<<" deviceCountcheck :" << deviceCountcheck << std::endl; +// std::cout<<" uuidshascheck :" << uuidshascheck[0] << std::endl; +// +// +// std::string filemd5; +// err = server::LicenseGetfilemd5(path1,filemd5); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// std::cout<<" filemd5 :" << filemd5 << std::endl; +// +// err= server::LicensefileSave(path1,path2); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// time_t last_timecheck; +// std::string filemd5check; +// err= server::LicensefileLoad(path2,filemd5check,last_timecheck); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// std::cout<<" filemd5check :" << filemd5check << std::endl; +// +// time_t last_time; +// err = server::LicenseGetfiletime(path1,last_time); +// ASSERT_EQ(err, server::SERVER_SUCCESS); +// +// std::cout<<" last_time : " << last_time << std::endl; +// std::cout<<" last_timecheck :" << last_timecheck << std::endl; +// +// err = server::LicenseIntegritycheck(path1,path2); +// ASSERT_EQ(err, server::SERVER_SUCCESS); + +//} -- GitLab