Skip to content
Merged
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
6 changes: 6 additions & 0 deletions source/extensions/transport_sockets/alts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ envoy_cc_library(
"//source/common/buffer:buffer_lib",
],
)

envoy_cc_library(
name = "noop_transport_socket_callbacks_lib",
hdrs = ["noop_transport_socket_callbacks.h"],
deps = ["//include/envoy/network:transport_socket_interface"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "envoy/network/transport_socket.h"

namespace Envoy {
namespace Extensions {
namespace TransportSockets {
namespace Alts {

/**
* A TransportSocketCallbacks for wrapped TransportSocket object. Some
* TransportSocket implementation wraps another socket which does actual I/O.
* This class is used by the wrapped socket as its callbacks instead of the real
* connection to hold back callbacks from the underlying socket to connection.
*/
class NoOpTransportSocketCallbacks : public Network::TransportSocketCallbacks {
public:
explicit NoOpTransportSocketCallbacks(Network::TransportSocketCallbacks& parent)
: parent_(parent) {}

int fd() const override { return parent_.fd(); }
Network::Connection& connection() override { return parent_.connection(); }
bool shouldDrainReadBuffer() override { return false; }
/*
* No-op for these two methods to hold back the callbacks.
*/
void setReadBufferReady() override {}
void raiseEvent(Network::ConnectionEvent) override {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this landing as is, but can you please loop me in when it is used? I have some concerns about these particular events being swallowed. Maybe we can add ASSERTs that they're not used so we'll at least catch it in debug builds if a mistake is made? Hopefully seeing where the code is used will allay my concerns :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK'ed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alyssawilk I will merge master and use this in my PR #4153, ASSERT cannot be added here. In #4153, it have to swallow Connected event from RawBufferSocket, and raise it when handshake is done.


private:
Network::TransportSocketCallbacks& parent_;
};

} // namespace Alts
} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy
10 changes: 10 additions & 0 deletions test/extensions/transport_sockets/alts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ envoy_extension_cc_test(
"//test/mocks/event:event_mocks",
],
)

envoy_extension_cc_test(
name = "noop_transport_socket_callbacks_test",
srcs = ["noop_transport_socket_callbacks_test.cc"],
extension_name = "envoy.transport_sockets.alts",
deps = [
"//source/extensions/transport_sockets/alts:noop_transport_socket_callbacks_lib",
"//test/mocks/network:network_mocks",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "extensions/transport_sockets/alts/noop_transport_socket_callbacks.h"

#include "test/mocks/network/mocks.h"

#include "gtest/gtest.h"

namespace Envoy {
namespace Extensions {
namespace TransportSockets {
namespace Alts {
namespace {

class TestTransportSocketCallbacks : public Network::TransportSocketCallbacks {
public:
explicit TestTransportSocketCallbacks(Network::Connection& connection)
: connection_(connection) {}

int fd() const override { return 1; }
Network::Connection& connection() override { return connection_; }
bool shouldDrainReadBuffer() override { return false; }
void setReadBufferReady() override { set_read_buffer_ready_ = true; }
void raiseEvent(Network::ConnectionEvent) override { event_raised_ = true; }

bool event_raised() const { return event_raised_; }
bool set_read_buffer_ready() const { return set_read_buffer_ready_; }

private:
bool event_raised_{false};
bool set_read_buffer_ready_{false};
Network::Connection& connection_;
};

class NoOpTransportSocketCallbacksTest : public testing::Test {
protected:
NoOpTransportSocketCallbacksTest()
: wrapper_callbacks_(connection_), wrapped_callbacks_(wrapper_callbacks_) {}

Network::MockConnection connection_;
TestTransportSocketCallbacks wrapper_callbacks_;
NoOpTransportSocketCallbacks wrapped_callbacks_;
};

TEST_F(NoOpTransportSocketCallbacksTest, TestAllCallbacks) {
EXPECT_EQ(wrapper_callbacks_.fd(), wrapped_callbacks_.fd());
EXPECT_EQ(&connection_, &wrapped_callbacks_.connection());
EXPECT_FALSE(wrapped_callbacks_.shouldDrainReadBuffer());

wrapped_callbacks_.setReadBufferReady();
EXPECT_FALSE(wrapper_callbacks_.set_read_buffer_ready());
wrapped_callbacks_.raiseEvent(Network::ConnectionEvent::Connected);
EXPECT_FALSE(wrapper_callbacks_.event_raised());
}

} // namespace
} // namespace Alts
} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy