Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions include/envoy/network/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class EnvoyInternalAddress {

enum class Type { Ip, Pipe, EnvoyInternal };

constexpr absl::string_view IpName = "Ip";
constexpr absl::string_view PipeName = "Pipe";
constexpr absl::string_view EnvoyInternalName = "EnvoyInternal";

/**
* Interface for all network addresses.
*/
Expand Down
27 changes: 27 additions & 0 deletions source/extensions/io_socket/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_extension_package",
)

licenses(["notice"]) # Apache 2

envoy_extension_package()

envoy_cc_extension(
name = "address_map",
hdrs = [
"address_map.h",
],
security_posture = "unknown",
status = "alpha",
deps = [
"//include/envoy/network:address_interface",
],
)

envoy_cc_library(
name = "client_connection_factory",
hdrs = ["config.h"],
deps = [
":address_map",
"//include/envoy/config:typed_config_interface",
"//include/envoy/network:connection_interface",
"//include/envoy/registry",
"//source/common/common:assert_lib",
"//source/common/singleton:const_singleton",
],
)
27 changes: 27 additions & 0 deletions source/extensions/io_socket/address_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "envoy/network/address.h"

namespace Envoy {
namespace Network {
namespace Address {

class AddressMap {
public:
constexpr absl::string_view operator[](Type address_type) const {
switch (address_type) {
case Type::Ip:
return IpName;
case Type::Pipe:
return PipeName;
case Type::EnvoyInternal:
return EnvoyInternalName;
}
}
};

constexpr AddressMap addressMap;

} // namespace Address
} // namespace Network
} // namespace Envoy
14 changes: 14 additions & 0 deletions source/extensions/io_socket/buffered_io_socket/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_extension_package",
)

Expand Down Expand Up @@ -38,3 +39,16 @@ envoy_cc_extension(
"//source/common/network:default_socket_interface_lib",
],
)

envoy_cc_library(
name = "b_factory",
srcs = [
"b_factory.cc",
],
hdrs = [
"b_factory.h",
],
deps = [
"//source/extensions/io_socket:client_connection_factory",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "extensions/io_socket/buffered_io_socket/b_factory.h"
24 changes: 24 additions & 0 deletions source/extensions/io_socket/buffered_io_socket/b_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "envoy/network/address.h"
#include "extensions/io_socket/config.h"

namespace Envoy {
namespace Extensions {
namespace IoSocket {

class BioClientConnectionFactory : public ClientConnectionFactory {
public:
~BioClientConnectionFactory() override = default;

/**
* Create a particular client connection.
* @return ClientConnectionPtr the client connection.
*/
Network::ClientConnectionPtr createClientConnection() override { return nullptr; }

std::string name() const override { return std::string(Network::Address::EnvoyInternalName); }
};
} // namespace IoSocket
} // namespace Extensions
} // namespace Envoy
49 changes: 49 additions & 0 deletions source/extensions/io_socket/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <memory>
#include <string>

#include "envoy/buffer/buffer.h"
#include "envoy/config/typed_config.h"
#include "envoy/registry/registry.h"
#include "envoy/network/connection.h"

#include "extensions/io_socket/address_map.h"

#include "common/common/assert.h"
#include "common/singleton/const_singleton.h"

namespace Envoy {
namespace Extensions {
namespace IoSocket {

class ClientConnectionFactory : public Envoy::Config::UntypedFactory {
public:
~ClientConnectionFactory() override = default;

/**
* Create a particular client connection.
* @return ClientConnectionPtr the client connection.
*/
virtual Network::ClientConnectionPtr createClientConnection() PURE;

std::string category() const override { return "envoy.connection"; }

/**
* Convenience method to lookup a factory by destination address type.
* @return ClientConnectionFactory& for the destiantion address.
*/
static ClientConnectionFactory*
getFactoryByAddress(Network::Address::InstanceConstSharedPtr& destination_address) {
if (destination_address == nullptr) {
return nullptr;
}

return Registry::FactoryRegistry<ClientConnectionFactory>::getFactory(
Network::Address::addressMap[destination_address->type()]);
}
};

} // namespace IoSocket
} // namespace Extensions
} // namespace Envoy
9 changes: 9 additions & 0 deletions test/extensions/io_socket/buffered_io_socket/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ envoy_cc_test(
"//test/test_common:utility_lib",
],
)

envoy_cc_test(
name = "b_factory_test",
srcs = ["b_factory_test.cc"],
deps = [
"//source/extensions/io_socket/buffered_io_socket:b_factory",
"//test/test_common:registry_lib",
],
)
38 changes: 38 additions & 0 deletions test/extensions/io_socket/buffered_io_socket/b_factory_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include "common/network/address_impl.h"

#include "extensions/io_socket/buffered_io_socket/b_factory.h"
#include "test/test_common/registry.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"

using testing::_;
using testing::NiceMock;

namespace Envoy {
namespace Extensions {
namespace IoSocket {
namespace BufferedIoSocket {
namespace {

class FactoryTest : public testing::Test {};

TEST_F(FactoryTest, TestCreate) {
BioClientConnectionFactory factory;
Registry::InjectFactory<ClientConnectionFactory> registration(factory);
// TODO(lambdai): share_ptr<const Type> covariance
auto address = std::dynamic_pointer_cast<const Envoy::Network::Address::Instance>(
std::make_shared<const Network::Address::EnvoyInternalInstance>("abc"));
auto* f = ClientConnectionFactory::getFactoryByAddress(address);
// Registered.
ASSERT_NE(nullptr, f);
auto connection = f->createClientConnection();
// Naive implemention.
ASSERT_EQ(nullptr, connection);
}
} // namespace
} // namespace BufferedIoSocket
} // namespace IoSocket
} // namespace Extensions
} // namespace Envoy