Skip to content
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

feat: add meta proto service for service discovery #543

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4c3eb9f
Add meta proto service for service discovery
oguzcanoguz Jan 25, 2024
cdc8fb3
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
adb0092
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
f15b249
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
d5d9dc2
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
cf77db0
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
9622fe2
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
b6cc192
Update protobuf/meta_services/ServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
bbc7075
Update protobuf/meta_services/test/TestServiceDiscoveryEcho.cpp
oguzcanoguz Jan 25, 2024
b9239e9
Apply suggestions from code review
oguzcanoguz Jan 25, 2024
2850b82
Add service changed notification to ServviceDiscovery
oguzcanoguz Jan 29, 2024
151e119
Merge remote-tracking branch 'origin/main' into feature/proto_service…
oguzcanoguz Apr 23, 2024
e8ca6d6
ServiceDiscoveryEcho refactor header
oguzcanoguz Apr 23, 2024
2dadfb7
Implement StartMethod and NotifyServiceChanges in ServiceDiscoveryEcho
oguzcanoguz Apr 25, 2024
2e575b3
Refactor ServiceDiscoveryTest
oguzcanoguz Apr 26, 2024
0db7aa5
Fix function static storage in ServiceDiscoveryEcho
oguzcanoguz Apr 26, 2024
ca8bdaa
Solve functio storage problem in ServiceDiscoveryTest
oguzcanoguz Apr 26, 2024
914754e
Make EchoConsole accept recursive directories for protobuf files
oguzcanoguz Apr 30, 2024
a2dd642
Start with PeerServiceDiscoverer
oguzcanoguz May 1, 2024
f0fc274
PeerServiceDiscovererTest: Add iterative service discovery
oguzcanoguz May 3, 2024
a8a24b8
PeerServiceDiscovererTest contd
oguzcanoguz May 6, 2024
df27790
Merge commit 'e9afc63890f512f66b28fe2b409de5b9fe471934'
oguzcanoguz Jun 7, 2024
0068cc6
Start with providing id range in NotifyServicesChanged
oguzcanoguz Aug 19, 2024
3685020
Add notifying service changes with a range
oguzcanoguz Sep 6, 2024
5db6745
Make service changes amnesiac
oguzcanoguz Sep 6, 2024
d5519bd
remove ServiceDiscoveryStarted from PeerServiceDiscovery
oguzcanoguz Oct 4, 2024
067ec70
Refactor PeerServiceDiscovererObserver
oguzcanoguz Oct 4, 2024
9118a61
PeerServiceDiscoverer: Start service discovery on construction
oguzcanoguz Oct 4, 2024
abfa695
PeerServiceDiscoverer: Handle service updated notification
oguzcanoguz Oct 4, 2024
e2c95a7
PeerServiceDiscovererTest: WIP Streamlining services changed tests
oguzcanoguz Oct 11, 2024
5a0a2be
Refactor PeerServiceDiscovery tests
oguzcanoguz Oct 28, 2024
a89a492
PeerServiceDiscovery: Discovery can end with a service or no service
oguzcanoguz Nov 1, 2024
6543e14
Start with a test echo server that can be run in devcontainer
oguzcanoguz Nov 4, 2024
a30b880
fix cmakelists
oguzcanoguz Nov 5, 2024
a471b1d
Try to instantiate PeerServiceDiscovery in echo console
oguzcanoguz Nov 11, 2024
62a871f
Fix: Use echo only when the connection observer is attached to a conn…
oguzcanoguz Nov 13, 2024
50d9170
ServiceDiscoveryEcho: Optimize FirstServiceSupported
oguzcanoguz Nov 13, 2024
138fc45
Merge branch 'temp' into feature/proto_service_discovery
oguzcanoguz Nov 13, 2024
161fcb6
trace discovered services
oguzcanoguz Nov 14, 2024
f65605a
Start working on attaching EchoConsole to Echo as a Service
oguzcanoguz Nov 15, 2024
6ad3bb7
TestConsoleService preparation
oguzcanoguz Dec 9, 2024
ba3f652
Merge commit '6c84af5324c79219059d1066cc5ce3aad8f2b927' into feature/…
oguzcanoguz Dec 16, 2024
d3a528f
Fix build error
oguzcanoguz Dec 16, 2024
52afcbd
Remove incorrect include (breaks embedded build)
oguzcanoguz Dec 16, 2024
922f501
Make echo_console only list available services
oguzcanoguz Dec 16, 2024
5410260
Fix lots of stuff to make EchoConsole to discover services of RefProd
oguzcanoguz Dec 17, 2024
8052a28
Remove temporary tracing
oguzcanoguz Dec 19, 2024
9f9594a
Merge branch 'main' into feature/proto_service_discovery
oguzcanoguz Jan 9, 2025
1194ba5
Make ServiceForwarderAll use a reserved svc id and assert this stays …
oguzcanoguz Jan 10, 2025
fd44ae0
Fix the existing ServiceDiscovery tests, more tests need to be added
oguzcanoguz Jan 10, 2025
d6d4b06
ServiceDiscoveryEcho clean
oguzcanoguz Jan 10, 2025
8324508
TestServiceDiscoveryEcho: Add test for clashing responses
oguzcanoguz Jan 10, 2025
10f3094
Clean up echo_console a bit
oguzcanoguz Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions infra/syntax/CppFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,18 @@ namespace application

void Undef::PrintSource(google::protobuf::io::Printer& printer, const std::string& scope) const
{}

StaticAssert::StaticAssert(const std::string& condition, const std::string& message)
: Entity(true, false)
, condition(condition)
, message(message)
{}

void StaticAssert::PrintHeader(google::protobuf::io::Printer& printer) const
{
printer.Print("static_assert($condition$, \"$message$\");\n", "condition", condition, "message", message);
}

void StaticAssert::PrintSource(google::protobuf::io::Printer& printer, const std::string& scope) const
{}
}
14 changes: 14 additions & 0 deletions infra/syntax/CppFormatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ namespace application
private:
std::string name;
};

class StaticAssert
: public Entity
{
public:
explicit StaticAssert(const std::string& condition, const std::string& message);

void PrintHeader(google::protobuf::io::Printer& printer) const override;
void PrintSource(google::protobuf::io::Printer& printer, const std::string& scope) const override;

private:
std::string condition;
std::string message;
};
}

#endif
15 changes: 15 additions & 0 deletions infra/syntax/test/TestCppFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,18 @@ TEST_F(CppFormatterTest, Undef_prints_no_source)
declaration.PrintSource(*printer, "scope");
ExpectPrinted("");
}

TEST_F(CppFormatterTest, StaticAssert_prints_header)
{
application::StaticAssert declaration("condition", "message");
declaration.PrintHeader(*printer);
ExpectPrinted(R"(static_assert(condition, "message");
)");
}

TEST_F(CppFormatterTest, StaticAssert_prints_no_source)
{
application::StaticAssert declaration("condition", "message");
declaration.PrintSource(*printer, "scope");
ExpectPrinted("");
}
1 change: 1 addition & 0 deletions protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(echo)
add_subdirectory(protoc_echo_plugin)
add_subdirectory(protoc_echo_plugin_csharp)
add_subdirectory(protoc_echo_plugin_java)
add_subdirectory(meta_services)
14 changes: 14 additions & 0 deletions protobuf/echo/Echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

namespace services
{
ServiceId::ServiceId(uint32_t id)
: id(id)
{}

Service::Service(Echo& echo, uint32_t serviceId)
: ServiceId(serviceId)
, infra::Observer<Service, Echo>(echo)
{}

uint32_t ServiceIdAccess::GetId(const ServiceId& serviceId)
{
return serviceId.id;
}

void Service::MethodDone()
{
Rpc().ServiceDone();
Expand Down
34 changes: 30 additions & 4 deletions protobuf/echo/Echo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,46 @@
#include "protobuf/echo/EchoErrorPolicy.hpp"
#include "protobuf/echo/Proto.hpp"
#include "protobuf/echo/Serialization.hpp"
#include <cstdint>

namespace services
{
class Echo;
class ServiceId;
class Service;
class ServiceProxy;

class Service
: public infra::Observer<Service, Echo>
class ServiceIdAccess
{
public:
static uint32_t GetId(const ServiceId& serviceId);
};

class ServiceId
{
friend class ServiceIdAccess;

public:
using infra::Observer<Service, Echo>::Observer;
ServiceId(uint32_t id);

virtual bool AcceptsService(uint32_t id) const = 0;
virtual bool AcceptsService(uint32_t id) const
{
return id == this->id;
}

public:
static constexpr uint32_t reservedServiceId = 0;

private:
const uint32_t id;
};

class Service
: public ServiceId
, public infra::Observer<Service, Echo>
{
public:
Service(Echo& echo, uint32_t serviceId);

void MethodDone();
virtual infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const EchoErrorPolicy& errorPolicy) = 0;
Expand Down
18 changes: 9 additions & 9 deletions protobuf/echo/ServiceForwarder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "protobuf/echo/ServiceForwarder.hpp"
#include "protobuf/echo/Echo.hpp"
#include <cstdint>

namespace services
{
ServiceForwarderBase::ServiceForwarderBase(Echo& echo, Echo& forwardTo)
: Service(echo)
ServiceForwarderBase::ServiceForwarderBase(Echo& echo, uint32_t id, Echo& forwardTo)
: Service(echo, id)
, ServiceProxy(forwardTo, 0)
{}

Expand Down Expand Up @@ -83,18 +85,16 @@ namespace services
contentsReader = nullptr;
}

ServiceForwarderAll::ServiceForwarderAll(Echo& echo, Echo& forwardTo)
: ServiceForwarderBase(echo, ServiceId::reservedServiceId, forwardTo)
{}

bool ServiceForwarderAll::AcceptsService(uint32_t id) const
{
return true;
}

ServiceForwarder::ServiceForwarder(Echo& echo, uint32_t id, Echo& forwardTo)
: ServiceForwarderBase(echo, forwardTo)
, serviceId(id)
: ServiceForwarderBase(echo, id, forwardTo)
{}

bool ServiceForwarder::AcceptsService(uint32_t id) const
{
return serviceId == id;
}
}
13 changes: 6 additions & 7 deletions protobuf/echo/ServiceForwarder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PROTOBUF_ECHO_SERVICE_FORWARDER_HPP

#include "protobuf/echo/Echo.hpp"
#include <cstdint>

namespace services
{
Expand All @@ -12,7 +13,7 @@ namespace services
, private MethodSerializer
{
public:
ServiceForwarderBase(Echo& echo, Echo& forwardTo);
ServiceForwarderBase(Echo& echo, uint32_t id, Echo& forwardTo);

// Implementation of Service
infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const EchoErrorPolicy& errorPolicy) override;
Expand Down Expand Up @@ -44,21 +45,19 @@ namespace services
: public ServiceForwarderBase
{
public:
using ServiceForwarderBase::ServiceForwarderBase;
ServiceForwarderAll(Echo& echo, Echo& forwardTo);

bool AcceptsService(uint32_t id) const override;

private:
static constexpr uint8_t invalidServiceId = 0;
};

class ServiceForwarder
: public ServiceForwarderBase
{
public:
ServiceForwarder(Echo& echo, uint32_t id, Echo& forwardTo);

bool AcceptsService(uint32_t id) const override;

private:
uint32_t serviceId;
};
}

Expand Down
13 changes: 5 additions & 8 deletions protobuf/echo/test_doubles/ServiceStub.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "protobuf/echo/test_doubles/ServiceStub.hpp"
#include <cstdint>

namespace services
{
Expand Down Expand Up @@ -50,15 +51,10 @@ namespace services
return value;
}

ServiceStub::ServiceStub(Echo& echo)
: Service(echo)
ServiceStub::ServiceStub(Echo& echo, uint32_t serviceId)
: Service(echo, serviceId)
{}

bool ServiceStub::AcceptsService(uint32_t id) const
{
return id == serviceId;
}

infra::SharedPtr<MethodDeserializer> ServiceStub::StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy)
{
switch (methodId)
Expand All @@ -84,8 +80,9 @@ namespace services
}
}

ServiceStubProxy::ServiceStubProxy(services::Echo& echo)
ServiceStubProxy::ServiceStubProxy(services::Echo& echo, uint32_t serviceId)
: services::ServiceProxy(echo, maxMessageSize)
, serviceId(serviceId)
{}

void ServiceStubProxy::Method(uint32_t value)
Expand Down
14 changes: 8 additions & 6 deletions protobuf/echo/test_doubles/ServiceStub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "protobuf/echo/Echo.hpp"
#include "gmock/gmock.h"
#include <cstdint>

namespace services
{
Expand Down Expand Up @@ -64,9 +65,7 @@ namespace services
: public services::Service
{
public:
ServiceStub(Echo& echo);

bool AcceptsService(uint32_t id) const override;
ServiceStub(Echo& echo, uint32_t serviceId = defaultServiceId);

MOCK_METHOD(void, Method, (uint32_t value));
MOCK_METHOD(void, MethodNoParameter, ());
Expand All @@ -76,7 +75,7 @@ namespace services
infra::SharedPtr<MethodDeserializer> StartMethod(uint32_t serviceId, uint32_t methodId, uint32_t size, const services::EchoErrorPolicy& errorPolicy) override;

public:
static const uint32_t serviceId = 1;
static constexpr uint32_t defaultServiceId = 1;
static const uint32_t idMethod = 1;
static const uint32_t idMethodNoParameter = 3;
static const uint32_t idMethodBytes = 4;
Expand All @@ -90,20 +89,23 @@ namespace services
: public services::ServiceProxy
{
public:
ServiceStubProxy(services::Echo& echo);
ServiceStubProxy(services::Echo& echo, uint32_t serviceId = defaultServiceId);

public:
void Method(uint32_t value);
void MethodNoParameter();

public:
static constexpr uint32_t serviceId = 1;
static constexpr uint32_t defaultServiceId = 1;
static constexpr uint32_t idMethod = 1;
static const uint32_t idMethodNoParameter = 3;
static constexpr uint32_t maxMessageSize = 18;

public:
using MethodTypeList = infra::List<Message, EmptyMessage>;

private:
const uint32_t serviceId;
};
}

Expand Down
20 changes: 20 additions & 0 deletions protobuf/meta_services/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_library(protobuf.meta_services ${EMIL_EXCLUDE_FROM_ALL} STATIC)

target_include_directories(protobuf.meta_services PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../..>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

protocol_buffer_csharp(protobuf.meta_services ServiceDiscovery.proto)
protocol_buffer_java(protobuf.meta_services ServiceDiscovery.proto)
protocol_buffer_echo_all(protobuf.meta_services ServiceDiscovery.proto)

target_sources(protobuf.meta_services PRIVATE
PeerServiceDiscoverer.cpp
PeerServiceDiscoverer.hpp
ServiceDiscoveryEcho.cpp
ServiceDiscoveryEcho.hpp
)

add_subdirectory(test)

Loading
Loading