-
Notifications
You must be signed in to change notification settings - Fork 0
capnp router implementation: rpc client server comm #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| /cmake-build-debug/ | ||
| /cmake-build-release/ | ||
| .idea | ||
| .vscode/ | ||
| build/ | ||
| test/bizlogic/python/__pycache__/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
|
|
||
|
|
||
| add_subdirectory(rule_engine/abstract) | ||
| add_subdirectory(rule_engine/python) | ||
| add_subdirectory(cluster) | ||
| add_subdirectory(network) | ||
|
|
||
| add_executable(node main.cpp) | ||
|
|
||
|
|
||
| target_link_libraries(node PRIVATE cluster python_rule_engine) | ||
| target_link_libraries(node PRIVATE cluster python_rule_engine network) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #FetchContent_Declare( | ||
| # gRPC | ||
| # GIT_REPOSITORY https://github.com/grpc/grpc | ||
| # GIT_TAG v1.54.0 | ||
| #) | ||
|
|
||
| add_library(network) | ||
|
|
||
| target_sources( | ||
| network | ||
|
|
||
| PUBLIC | ||
| FILE_SET cxx_modules TYPE CXX_MODULES FILES | ||
| router.cppm | ||
| ) | ||
|
|
||
| add_subdirectory(rpc) | ||
|
|
||
| target_link_libraries( | ||
| network | ||
| rpc | ||
| ) |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| module; | ||
| #include <iostream> | ||
| #include <thread> | ||
| #include <cstring> | ||
| #include <cstdlib> | ||
| #include <unistd.h> | ||
| #include <sys/socket.h> | ||
| #include <netinet/in.h> | ||
| #include <sys/types.h> | ||
| #include <sys/wait.h> | ||
| import rpc.client; | ||
| import rpc.server; | ||
|
|
||
| export module network.router; | ||
|
|
||
| export void test_network() | ||
| { | ||
| pid_t serverProcess = fork(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to run two processes to recieve and send messages? Is there any way we can do this with only one process? |
||
|
|
||
| if (serverProcess < 0) { | ||
| perror("Error in forking server process"); | ||
| exit(1); | ||
| } else if (serverProcess == 0) { | ||
| start_server("localhost:8081"); | ||
| } else { | ||
| std::thread clientThread(start_client, "localhost:8081"); | ||
|
|
||
| int status; | ||
| waitpid(serverProcess, &status, 0); //kill the server process manually on the terminal. Currently the server will run forever | ||
| clientThread.join(); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| set(RPC_SRCS | ||
| src/rpc_client.cppm | ||
| src/rpc_server.cppm | ||
| ) | ||
|
|
||
| set(CAPNPC_SRCS | ||
| schema/message_intf.capnp | ||
| ) | ||
|
|
||
| set(GLOBAL_INCLUDES | ||
| include/rpc_defs.cppm | ||
| ) | ||
|
|
||
| foreach(schema ${CAPNPC_SRCS}) | ||
| add_custom_command( | ||
| OUTPUT "${schema}.c++" "${schema}.h" | ||
| COMMAND capnp compile -oc++ "${schema}" | ||
| DEPENDS ${schema} | ||
| WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
| COMMENT "Compiling Cap'n Proto schema: ${schema}" | ||
| ) | ||
| list(APPEND CAPNPC_CXX_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${schema}.c++") | ||
| endforeach() | ||
|
|
||
| add_library(rpc) | ||
| include_directories(schema) | ||
| target_sources( | ||
| rpc | ||
| PUBLIC | ||
| ${CAPNPC_CXX_SOURCES} | ||
| ) | ||
| target_sources( | ||
| rpc | ||
| PUBLIC | ||
| FILE_SET cxx_modules | ||
| TYPE CXX_MODULES | ||
| FILES | ||
| ${GLOBAL_INCLUDES} | ||
| ${RPC_SRCS} | ||
|
|
||
| ) | ||
| target_link_libraries( | ||
| rpc | ||
| PRIVATE | ||
| capnp | ||
| kj | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| module; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best not to separate include and src directories. Since we use modules, just use the directory hierarchy as the module hierarchy |
||
| #include <iostream> | ||
| #include <kj/common.h> | ||
| #include <vector> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| export module rpc_defs; | ||
|
|
||
| export namespace uaf | ||
| { | ||
| typedef unsigned char byte; | ||
| enum class StatusCode : std::uint16_t | ||
| { | ||
| STATUS_NONE, | ||
| STATUS_ERROR, | ||
| STATUS_ERROR_WITH_DATA, | ||
| STATUS_SUCCESS, | ||
| STATUS_SUCCESS_WITH_DATA | ||
| }; | ||
|
|
||
| struct ResultDefStruct | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does't really like using the type in the name. Isn't |
||
| { | ||
| uaf::StatusCode status; | ||
| std::vector<kj::byte> data; | ||
|
|
||
| ResultDefStruct(StatusCode status, std::vector<kj::byte> &&data) : status(status), data(std::move(data)) | ||
| { | ||
| } | ||
|
|
||
| ResultDefStruct(ResultDefStruct &&other) noexcept | ||
| : status(other.status), data(std::move(other.data)) {} | ||
|
|
||
| ResultDefStruct &operator=(ResultDefStruct &&other) noexcept | ||
| { | ||
| if (this != &other) | ||
| { | ||
| status = other.status; | ||
| data = std::move(other.data); | ||
| } | ||
| return *this; | ||
| } | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| @0x9c4f255fd44cfc76; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we move this somewhere outside the root src dir? |
||
| interface MessageDefInterface | ||
| { | ||
| struct MessageDef { | ||
| id @0 : Text; | ||
| message @1 : Data; | ||
| } | ||
|
|
||
| interface ResultDef { | ||
| getStatus @0 () -> (status : UInt16); | ||
| getData @1 () -> (data : Data); | ||
| } | ||
|
|
||
| schedule @0 (messageDefObj : MessageDef) -> (resultDefObj : ResultDef); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you linked these with
target_link_librariesas well. Why do we need to add these to linker flags?