Skip to content

network: add transport socket interface#2116

Merged
mattklein123 merged 18 commits intoenvoyproxy:masterfrom
lizan:transport_socket
Dec 5, 2017
Merged

network: add transport socket interface#2116
mattklein123 merged 18 commits intoenvoyproxy:masterfrom
lizan:transport_socket

Conversation

@lizan
Copy link
Copy Markdown
Member

@lizan lizan commented Nov 28, 2017

network: add transport socket interface

Description:
Add transport socket interface and refactors out RawBufferSocket from Network::ConnectionImpl and SslSocket from Ssl::ConnectionImpl.

A step towards #1840, factory for register and instantiate transport sockets will be in next PRs.

API Changes:
envoyproxy/data-plane-api#218

Risk Level: Medium

Testing:
unit test and integration test.

Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
Signed-off-by: Lizan Zhou <zlizan@google.com>
@lizan
Copy link
Copy Markdown
Member Author

lizan commented Nov 29, 2017

This is ready to review, PTAL @mattklein123 @htuch. cc @PiotrSikora

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

This looks great overall - the SSL logic came out really cleanly and I think the read/write semantics work better with a "socket" interface than a "crypto" interface.

I have a bunch of style nits but no major structural changes. Let's get this cleaned up and in! :-)

virtual ~TransportSocketCallbacks() {}

/**
* @return the file descriptor associated with the connection.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We're not terribly consistent about it, but new Envoy style has the return type specified after @return
This should be applied to all @returns in this file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also mild preference for Connection or Network::Connection where we're actually talking about a Network::Connection

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

virtual Connection& connection() PURE;

/**
* @return return whether the read buffer should be drained
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bit more context on this would be nice now that it has moved away from where the code is using it.
You could maybe mention the example that this can be used to enforce yielding for configured read limits or some such

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

* Raise a connection event to the connection.
* @param event supplies the connection event
*/
virtual void raiseEvent(ConnectionEvent event) PURE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is done on the connection, I'd lean towards exposing it there rather than having a wrapper function here. I guess since this is not accessible to all entities that have a connection it could be useful to scope it? Your call.

Either way you could doc up a bit more what this does. It basically fakes the connection getting the specific event from the kernel, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

virtual ~TransportSocket() {}

/**
* Called by connection once to intiialize the transport socket callbacks that the transport
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

initialize

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done


/**
* Closes the transport socket.
* @param event suuplies the connection event that closing the socket.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that -> that is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Address::InstanceConstSharedPtr remote_address,
Address::InstanceConstSharedPtr local_address,
Address::InstanceConstSharedPtr bind_to_address,
TransportSocketPtr transport_socket, bool using_original_dst, bool connected);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TransportSocketPtr&& transport_socket for ownership clarity?

void setTransportSocketCallbacks(TransportSocketCallbacks& callbacks) override;
std::string protocol() const override;
bool canFlushClose() override { return true; }
void closeSocket(Network::ConnectionEvent) override {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't this need to close the socket?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, the raw buffer socket doesn't have to do anything other than the one does in ConnectionImpl.

ENVOY_CONN_LOG(debug, "connected", *this);
state_ &= ~InternalState::Connecting;
onConnected();
transport_socket_->onConnected();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems a little weird - the Network::Connection tells the socket it's connected, and then the socket calls raiseEvents back on the connection.

I suspect there's a good reason to pass through the socket but I'm missing it :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The main purpose of this is for SSL handshake

  • Connection calls TransportSocket::onConnected then transport socket starts the handshake.
  • transport socket call raiseEvents when handshake is complete.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, that's a level of detail which might be worth documenting somewhere (the API file?) that onConnected is called on the transport when the underlying transport is connected, and raiseEvent(connected) is called when any transport-level handshakes are completed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

~ConnectionImpl();

// Network::Connection
Ssl::Connection* ssl() override { return dynamic_cast<SslSocket*>(transport_socket_.get()); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm. If ssl() is a weird function on the base connection class (which returns nullptr) what do you think of making it an additional weird function on the transport socket? It'd let us avoid the dynamic cast, and I think do away with the ConnectionImpl entirely (as we could create the base connection class with a new SslSocket explicitly, and the regular connection class would call the null-returning ssl() for the raw socket.

Copy link
Copy Markdown
Member Author

@lizan lizan Nov 30, 2017

Choose a reason for hiding this comment

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

Yes, I'm planning to remove the whole Ssl::ConnectionImpl at the end. The ssl() is kept here for compatibility with others, as it is used widely in filters, etc. That refactor will involve many classes, can be done in a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, let's TODO that cleanup just so it's clear what the plan is. I'm fine with a follow-up to keep this clean and simple

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

virtual void raiseEvent(ConnectionEvent event) PURE;
};

class TransportSocket {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Class comments?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we could have a bit more detail. What is a transport socket vs a socket? We expect it's doing transformations on the data (TLS/LOAS) which might be worth calling out as part of the "transport" nature?

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Sorry, just got out of a meeting so I don't have time for another full pass tonight. Looking better, here's what I had left so far!


/**
* @return return whether the read buffer should be drained
* @return whether the read buffer should be drained. This is used to enforce yielding for
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@return bool

still missing types on a few others as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

virtual void raiseEvent(ConnectionEvent event) PURE;
};

class TransportSocket {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we could have a bit more detail. What is a transport socket vs a socket? We expect it's doing transformations on the data (TLS/LOAS) which might be worth calling out as part of the "transport" nature?

/**
* Closes the transport socket.
* @param event suuplies the connection event that closing the socket.
* @param event suuplies the connection event that is closing the socket.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

supplies

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@lizan
Copy link
Copy Markdown
Member Author

lizan commented Dec 1, 2017

@alyssawilk ping.

@mattklein123
Copy link
Copy Markdown
Member

@lizan @alyssawilk is out on Fridays. I will take a look at this also this weekend.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

At a high level this LGTM, other than my thinking out loud about FD, which I don't think we can do anything about easily right now.

@lizan I would prefer to hold this PR until we tag 1.5.0. So if possible can you just start working on your next PR on top of this one and we can get this merged later next week?

};

/**
* Callbacks used by transport socket instances to communicate with connection
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: period end of sentence.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

/**
* @return int the file descriptor associated with the connection.
*/
virtual int fd() PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not all transport sockets are going to have a fd. Can this be removed from the interface somehow? (I haven't yet looked in detail at how the rest of the code is factored).

In now reading more of the PR, I guess this is due to the fact that fundamentally we are passing FDs around from listeners. I suppose at some point we may need to turn this into some type of generic handle but this is probably ok for now. Just thinking out loud.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I thought we need some type of generic handle but it is not easy and out of scope of this PR. We can refactor when we have something other than FDs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had the same concern but the SSL stack at least needs this.

We never found a good workaround in the GFE - just made -1 a permissible value which allows all sorts of bad feature creep :-(

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

@mattklein123 if we are waiting for 1.5 should this include release notes?

It's not a functional change, but it allows a feature we and others might care about so I assume it's worth doccing up.

Lizan, I'd suggest adding a few lines about the new API and what it allows to RAW_RELEASE_NOTES.md

/**
* @return int the file descriptor associated with the connection.
*/
virtual int fd() PURE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had the same concern but the SSL stack at least needs this.

We never found a good workaround in the GFE - just made -1 a permissible value which allows all sorts of bad feature creep :-(

virtual std::string protocol() const PURE;

/**
* @return bool whether the socket can be flush closed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"can be flushed and closed" since I'm not sure flush closed is a thing :-)

I'm kind of bummed we can't infer this from Connected. It'd work for TLS since we always raiseEvent Connected() right after the handshake is complete, but it might cause problems for TCP, as the socket isn't flagged connected until it processes the initial event. Matt, think this is worth fixing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lizan the question is for @mattklein123 but can you still update the comment in the interim?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@mattklein123
Copy link
Copy Markdown
Member

if we are waiting for 1.5 should this include release notes?

sorry I meant I would like to wait until after 1.5 is tagged. Either today or tomorrow. We can merge this later in the week? (For 1.6 cycle).

@mattklein123
Copy link
Copy Markdown
Member

Oops nevermind re: my release notes comment, we were saying the same thing. @alyssawilk yeah if we are waiting for 1.6.0 we should add a comment to raw release notes. Thank you!

@lizan
Copy link
Copy Markdown
Member Author

lizan commented Dec 4, 2017

Sure, let's merge this in 1.6 cycle, and I'll start the rest of work. Hopefully there will be no merge conflicts by then :)

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Thanks for adding release notes :-)
LGTM pending that one last comment nit.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM. Nice job @lizan!

@mattklein123 mattklein123 merged commit 8d25070 into envoyproxy:master Dec 5, 2017
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
…to envoy logs. (envoyproxy#2116)

* Added simple logging abstraction so mixer client logs can be relayed to envoy logs when running inside envoy, stderr when running standalone.

* Log threshold guards that prevent needless serialization of logging arguments are now embedded in the log macros.

* Format

* Added do/while guards around logging statements.
jpsim added a commit that referenced this pull request Nov 28, 2022
Description: `TARGET_OS_MAC` is defined on iOS, but is not truth-y, so the previous checks were not sufficient.
Risk Level: Low, re-enabling something that used to be enabled on iOS.
Testing: Verified in our sample apps that WLAN/WWAN interfaces are properly logged when reachability changes.
Docs Changes:
Release Notes:
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
Description: `TARGET_OS_MAC` is defined on iOS, but is not truth-y, so the previous checks were not sufficient.
Risk Level: Low, re-enabling something that used to be enabled on iOS.
Testing: Verified in our sample apps that WLAN/WWAN interfaces are properly logged when reachability changes.
Docs Changes:
Release Notes:
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants