Skip to content

Commit

Permalink
Merge pull request #229 from singnet/issue-166-link-creation-client
Browse files Browse the repository at this point in the history
[#das166] Link Creation client
  • Loading branch information
eddiebrissow authored Jan 29, 2025
2 parents 5e18cf8 + 780df6c commit 7c14d3c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@ cc_binary(
],
)


cc_binary(
name = "link_creation_agent_client",
srcs = [],
defines = ["BAZEL_BUILD"],
linkstatic = 1,
deps = [
"//main:link_creation_agent_client_main_lib",
],
)
5 changes: 4 additions & 1 deletion src/cpp/link_creation_agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ build_docs:
build:
cd ../../ && bash scripts/build.sh && cd -

run:
run_server:
cd ../../ && bash scripts/container_tty.sh ./bin/link_creation_server ${OPTIONS} && cd -

run_client:
cd ../../ && bash scripts/container_tty.sh ./bin/link_creation_agent_client ${OPTIONS} && cd -


tests:
cd ../../ && bash scripts/unit_tests.sh && cd -
9 changes: 8 additions & 1 deletion src/cpp/link_creation_agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ requests_buffer_file = ./buffer
* das_client_id: IP + port of DAS to add links
* requests_buffer_file: path to request buffer, where are stored all requests that repeat


#### Running client

```
make run_client OPTIONS="localhost:1010 localhost:9080 LINK_TEMPLATE Expression 3 NODE Symbol Similarity VARIABLE V1 VARIABLE V2 LINK_CREATE Similarity 2 1 VARIABLE V1 VARIABLE V2 CUSTOM_FIELD truth_value 2 CUSTOM_FIELD mean 2 count 10 avg 0.9 confidence 0.9 10 0 test false"
```

If successful, you should see a message like this:

```
Starting server
SynchronousGRPC listening on localhost:9080
SynchronousGRPC listening on localhost:9001
SynchronousGRPC listening on localhost:9090
```
```
18 changes: 16 additions & 2 deletions src/cpp/link_creation_agent/das_link_creation_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ using namespace link_creation_agent;
using namespace std;
using namespace distributed_algorithm_node;

LinkCreationNode::LinkCreationNode(const string& node_id) : StarNode(node_id) {}
LinkCreationNode::LinkCreationNode(const string& node_id) : StarNode(node_id) {
is_server = true;
}

LinkCreationNode::LinkCreationNode(const string& node_id, const string& server_id) : StarNode(node_id, server_id) {
is_server = false;
}

LinkCreationNode::~LinkCreationNode() {
shutting_down = true;
Expand Down Expand Up @@ -33,6 +39,12 @@ shared_ptr<Message> LinkCreationNode::message_factory(string& command, vector<st
return make_shared<DummyMessage>(command, args);
}


void LinkCreationNode::send_message(vector<string> args) {
cout << "Sending message" << endl;
send(CREATE_LINK, args, server_id);
}

LinkCreationRequest::LinkCreationRequest(string command, vector<string>& args) {
this->command = command;
this->args = args;
Expand All @@ -42,4 +54,6 @@ void LinkCreationRequest::act(shared_ptr<MessageFactory> node) {
auto link_node = dynamic_pointer_cast<LinkCreationNode>(node);
string request;
link_node->add_request(this->args);
}
}


12 changes: 12 additions & 0 deletions src/cpp/link_creation_agent/das_link_creation_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class LinkCreationNode : public StarNode {
* @param node_id ID of this node in the network.
*/
LinkCreationNode(const string& node_id);
/**
* @brief Client constructor
* @param node_id ID of this node in the network.
* @param server_id ID of a server.
*/
LinkCreationNode(const string& node_id, const string& server_id);;

/**
* Destructor
*/
Expand Down Expand Up @@ -45,10 +52,13 @@ class LinkCreationNode : public StarNode {
*/
virtual shared_ptr<Message> message_factory(string& command, vector<string>& args);

void send_message(vector<string> args);

private:
Queue<vector<string>> request_queue;
const string CREATE_LINK = "create_link"; // DAS Node command
bool shutting_down = false;
bool is_server = true;
};

/**
Expand All @@ -60,6 +70,8 @@ class LinkCreationRequest : public Message {
vector<string> args;
LinkCreationRequest(string command, vector<string>& args);
void act(shared_ptr<MessageFactory> node);
string server_id;
string client_id;
};

/**
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/main/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ cc_library(
],
)

cc_library(
name = "link_creation_agent_client_main_lib",
srcs = ["link_creation_agent_client_main.cc"],
deps = [
"//link_creation_agent:link_creation_agent_lib",

],
)
44 changes: 44 additions & 0 deletions src/cpp/main/link_creation_agent_client_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <signal.h>

#include <cstring>
#include <iostream>
#include <string>

#include "das_link_creation_node.h"
using namespace link_creation_agent;
using namespace std;

void ctrl_c_handler(int) {
std::cout << "Stopping client..." << std::endl;
std::cout << "Done." << std::endl;
exit(0);
}


int main(int argc, char* argv[]) {
string help = R""""(
Usage: link_creation_agent CLIENT_HOST:CLIENT_PORT SERVER_HOST:SERVER_PORT REQUEST+
Requests must be in the following format:
QUERY, LINK_TEMPLATE, MAX_RESULTS, REPEAT, CONTEXT, UPDATE_ATTENTION_BROKER
MAX_RESULTS and REPEAT are optional, the default value for MAX_RESULTS is 1000 and for REPEAT is 1
)"""";

if ((argc < 4)) {
cerr << help << endl;
}
signal(SIGINT, &ctrl_c_handler);

string client_id = string(argv[1]);
string server_id = string(argv[2]);

vector<string> request;
for (int i = 3; i < argc; i++) {
request.push_back(argv[i]);
}

auto client = new LinkCreationNode(client_id, server_id);
client->send_message(request);

return 0;
}
2 changes: 2 additions & 0 deletions src/scripts/bazel_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ BAZELISK_BUILD_CMD="${BAZELISK_CMD} build --jobs ${JOBS} --enable_bzlmod"
cd $CPP_WORKSPACE_DIR \
&& $BAZELISK_BUILD_CMD //:link_creation_server \
&& mv bazel-bin/link_creation_server $BIN_DIR \
&& $BAZELISK_BUILD_CMD //:link_creation_agent_client \
&& mv bazel-bin/link_creation_agent_client $BIN_DIR \
&& $BAZELISK_BUILD_CMD //:word_query \
&& mv bazel-bin/word_query $BIN_DIR \
&& $BAZELISK_BUILD_CMD //:attention_broker_service \
Expand Down

0 comments on commit 7c14d3c

Please sign in to comment.