LicenseLibrary.h 3.2 KB
Newer Older
J
jinhai 已提交
1 2 3 4
#pragma once

#include "LicenseFile.h"
#include "SecretFile.h"
Y
yangwei.yao 已提交
5
#include "GPUInfoFile.h"
J
jinhai 已提交
6 7 8

#include "utils/Error.h"

Y
yangwei.yao 已提交
9 10 11 12
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

J
jinhai 已提交
13 14 15 16 17 18 19 20 21 22
#include <vector>
#include <map>


namespace zilliz {
namespace vecwise {
namespace server {

class LicenseLibrary {
 public:
J
jinhai 已提交
23 24 25 26
    // Part 0: File check
    static bool
    IsFileExistent(const std::string& path);

J
jinhai 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    // Part 1: Get GPU Info
    static ServerError
    GetDeviceCount(int &device_count);

    static ServerError
    GetUUID(int device_count, std::vector<std::string> &uuid_array);

    static ServerError
    GetUUIDMD5(int device_count, std::vector<std::string> &uuid_array, std::vector<std::string> &md5_array);


    static ServerError
    GetUUIDSHA256(const int &device_count,
                  std::vector<std::string> &uuid_array,
                  std::vector<std::string> &sha_array);

    // Part 2: Handle License File
    static ServerError
    LicenseFileSerialization(const std::string &path,
                             int device_count,
                             const std::map<int, std::string> &uuid_encrption_map, int64_t remaining_hour);

    static ServerError
    LicenseFileDeserialization(const std::string &path,
                               int &device_count,
                               std::map<int, std::string> &uuid_encrption_map,
                               int64_t &remaining_hour);

    static ServerError
    SecretFileSerialization(const std::string &path,
                            const time_t &update_time,
                            const off_t &file_size,
                            const std::string &file_md5);

    static ServerError
    SecretFileDeserialization(const std::string &path, time_t &update_time, off_t &file_size, std::string &file_md5);

    // Part 3: File attribute: UpdateTime Time/ Size/ MD5
    static ServerError
    GetFileUpdateTimeAndSize(const std::string &path, time_t &update_time, off_t &file_size);

    static ServerError
    GetFileMD5(const std::string &path, std::string &filemd5);

    // Part 4: GPU Info File Serialization/Deserialization
Y
yangwei.yao 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    static ServerError
    GPUinfoFileSerialization(const std::string &path,
                             int device_count,
                             const std::map<int, std::string> &uuid_encrption_map);
    static ServerError
    GPUinfoFileDeserialization(const std::string &path,
                               int &device_count,
                               std::map<int, std::string> &uuid_encrption_map);

    // Part 5: Integrity check and Legality check
    static ServerError
    IntegrityCheck(const std::string &license_file_path, const std::string &secret_file_path);

    static ServerError
    LegalityCheck(const std::string &license_file_path);

    // Part 6: Timer
    static ServerError
    AlterFile(const std::string &license_file_path,
              const std::string &secret_file_path,
              const boost::system::error_code &ec,
              boost::asio::deadline_timer *pt);

    static ServerError
    StartCountingDown(const std::string &license_file_path, const std::string &secret_file_path);

J
jinhai 已提交
98 99 100 101 102 103 104 105 106

 private:
    static constexpr int sha256_length_ = 32;
};


}
}
}