2022-02-22 20:33:45 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2018-06-20 23:44:47 +08:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
|
|
|
#include "communication/client.hpp"
|
|
|
|
#include "io/network/endpoint.hpp"
|
2021-01-21 22:47:56 +08:00
|
|
|
#include "utils/logging.hpp"
|
2018-06-20 23:44:47 +08:00
|
|
|
#include "utils/timer.hpp"
|
|
|
|
|
|
|
|
DEFINE_string(address, "127.0.0.1", "Server address");
|
|
|
|
DEFINE_int32(port, 54321, "Server port");
|
|
|
|
DEFINE_string(cert_file, "", "Certificate file to use.");
|
|
|
|
DEFINE_string(key_file, "", "Key file to use.");
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
bool EchoMessage(memgraph::communication::Client &client, const std::string &data) {
|
2018-06-20 23:44:47 +08:00
|
|
|
uint16_t size = data.size();
|
|
|
|
if (!client.Write(reinterpret_cast<const uint8_t *>(&size), sizeof(size))) {
|
2021-01-21 22:47:56 +08:00
|
|
|
spdlog::warn("Couldn't send data size!");
|
2018-06-20 23:44:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!client.Write(data)) {
|
2021-01-21 22:47:56 +08:00
|
|
|
spdlog::warn("Couldn't send data!");
|
2018-06-20 23:44:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
client.ClearData();
|
|
|
|
if (!client.Read(size)) {
|
2021-01-21 22:47:56 +08:00
|
|
|
spdlog::warn("Couldn't receive data!");
|
2018-06-20 23:44:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-18 22:32:43 +08:00
|
|
|
if (std::string(reinterpret_cast<const char *>(client.GetData()), size) != data) {
|
2021-01-21 22:47:56 +08:00
|
|
|
spdlog::warn("Received data isn't equal to sent data!");
|
2018-06-20 23:44:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::SSLInit sslInit;
|
2018-06-20 23:44:47 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::io::network::Endpoint endpoint(FLAGS_address, FLAGS_port);
|
2018-06-20 23:44:47 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::ClientContext context(FLAGS_key_file, FLAGS_cert_file);
|
|
|
|
memgraph::communication::Client client(&context);
|
2018-06-20 23:44:47 +08:00
|
|
|
|
|
|
|
if (!client.Connect(endpoint)) return 1;
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
while (true) {
|
|
|
|
std::string s;
|
|
|
|
std::getline(std::cin, s);
|
|
|
|
if (s == "") break;
|
|
|
|
if (!EchoMessage(client, s)) {
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send server shutdown signal. The call will fail, we don't care.
|
|
|
|
EchoMessage(client, "");
|
|
|
|
|
|
|
|
return success ? 0 : 1;
|
|
|
|
}
|