1.4.10 updates
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <shared/License.h>
|
||||
#include <shared/LicenseRequest.h>
|
||||
#include <event2/thread.h>
|
||||
#include "shared/LicenseServerClient.h"
|
||||
|
||||
#include <random>
|
||||
#include <ed25519/ed25519.h>
|
||||
#include <misc/base64.h>
|
||||
@@ -49,8 +51,8 @@ int main(int ac, char** av){
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Intermediate: " << base64::encode(error) << endl;
|
||||
|
||||
#endif
|
||||
#if 0
|
||||
auto license = v2::License::read(intermediate_key.data(), intermediate_key.size(), errc);
|
||||
|
||||
license->push_entry<v2::hierarchy::Server>(system_clock::now(), system_clock::now() + hours{24 * 365 * 1000}, "TeaSpeak Official server", "contact@teaspeak.de");
|
||||
@@ -60,6 +62,7 @@ int main(int ac, char** av){
|
||||
__asm__("nop");
|
||||
cout << "Errc: " << errc << endl;
|
||||
cout << "Write: " << base64::encode(error) << endl;
|
||||
#endif
|
||||
#if 0
|
||||
std::array<uint8_t, 32> private_key, public_key;
|
||||
|
||||
@@ -84,7 +87,6 @@ int main(int ac, char** av){
|
||||
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
srand(system_clock::now().time_since_epoch().count());
|
||||
cout << "Generating new license" << endl;
|
||||
@@ -121,29 +123,56 @@ int main(int ac, char** av){
|
||||
auto data = make_shared<LicenseRequestData>();
|
||||
data->license = license;
|
||||
data->info = make_shared<ServerInfo>();
|
||||
while(true) {
|
||||
LicenceRequest request(data, serv_addr);
|
||||
try {
|
||||
cout << "Requesting license" << endl;
|
||||
auto info = request.requestInfo().waitAndGet(nullptr);
|
||||
if(!info) {
|
||||
cout << "Invalid result! Error: " << (request.exception() ? "yes => " + string(request.exception()->what()) : "no") << endl;
|
||||
throw *request.exception();
|
||||
}
|
||||
cout << "Got result!" << endl;
|
||||
cout << "Valid: " << info->license_valid << endl;
|
||||
if(info->license) {
|
||||
cout << "License:" << endl;
|
||||
cout << " Type: " << info->license->type << endl;
|
||||
cout << " User name: " << info->license->username << endl;
|
||||
cout << " First name: " << info->license->first_name << endl;
|
||||
cout << " Last name: " << info->license->last_name << endl;
|
||||
cout << " EMail: " << info->license->email << endl;
|
||||
} else cout << "License: none";
|
||||
} catch (const std::exception& ex){
|
||||
cerr << "Could not load info after throwing: " << endl << ex.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
LicenceRequest request(data, serv_addr);
|
||||
try {
|
||||
cout << "Requesting license" << endl;
|
||||
auto info = request.requestInfo().waitAndGet(nullptr);
|
||||
if(!info) {
|
||||
cout << "Invalid result! Error: " << (request.exception() ? "yes => " + string(request.exception()->what()) : "no") << endl;
|
||||
throw *request.exception();
|
||||
}
|
||||
cout << "Got result!" << endl;
|
||||
cout << "Valid: " << info->license_valid << endl;
|
||||
if(info->license) {
|
||||
cout << "License:" << endl;
|
||||
cout << " Type: " << info->license->type << endl;
|
||||
cout << " User name: " << info->license->username << endl;
|
||||
cout << " First name: " << info->license->first_name << endl;
|
||||
cout << " Last name: " << info->license->last_name << endl;
|
||||
cout << " EMail: " << info->license->email << endl;
|
||||
} else cout << "License: none";
|
||||
} catch (const std::exception& ex){
|
||||
cerr << "Could not load info after throwing: " << endl << ex.what() << endl;
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
sockaddr_in serv_addr{};
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
||||
serv_addr.sin_addr.s_addr = ((in_addr*) gethostbyname("localhost")->h_addr)->s_addr;
|
||||
serv_addr.sin_port = htons(27786);
|
||||
|
||||
client::LicenseServerClient client{serv_addr, 3};
|
||||
client.callback_connected = [&]{
|
||||
std::cout << "Connected" << std::endl;
|
||||
client.disconnect("client closed", std::chrono::system_clock::now() + std::chrono::seconds{5});
|
||||
};
|
||||
client.callback_message = [&](auto type, const void* buffer, size_t length) {
|
||||
std::cout << "Received an message" << std::endl;
|
||||
};
|
||||
client.callback_disconnected = [&](bool expected, const std::string& reason) {
|
||||
std::cout << "Received disconnect (expected: " << expected << "): " << reason << std::endl;
|
||||
};
|
||||
|
||||
if(!client.start_connection(error)) {
|
||||
std::cout << "Failed to start connection" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds{2});
|
||||
client.disconnect("client closed", std::chrono::system_clock::now() + std::chrono::seconds{5});
|
||||
std::cout << "Disconnect result: " << client.await_disconnect() << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user