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

Expose local_address and remote_address. #63

Closed
wants to merge 1 commit into from

Conversation

miracle2k
Copy link
Contributor

No description provided.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 44

  • 2 of 4 (50.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 79.458%

Changes Missing Coverage Covered Lines Changed/Added Lines %
trio_websocket/init.py 2 4 50.0%
Files with Coverage Reduction New Missed Lines %
trio_websocket/init.py 1 87.42%
Totals Coverage Status
Change from base Build 41: -0.5%
Covered Lines: 352
Relevant Lines: 443

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 44

  • 2 of 4 (50.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 79.458%

Changes Missing Coverage Covered Lines Changed/Added Lines %
trio_websocket/init.py 2 4 50.0%
Files with Coverage Reduction New Missed Lines %
trio_websocket/init.py 1 87.42%
Totals Coverage Status
Change from base Build 41: -0.5%
Covered Lines: 352
Relevant Lines: 443

💛 - Coveralls

Copy link
Member

@belm0 belm0 left a comment

Choose a reason for hiding this comment

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

Thank you. Would you please add a test?

Is there any argument to be made for just exposing the socket object proper?

@njsmith
Copy link
Member

njsmith commented Oct 20, 2018

It would make more sense to expose the stream object than to expose the socket object. There isn't always a socket, but there is always a stream. And the stream is useful in other circumstances too, e.g. SSLStream has methods to get information about the peer's certificate.

There's also python-trio/trio#280, which is about giving Stream a high-level API for accessing local and remote addresses... that + exposing the stream on the websocket could potentially replace this PR.

Note that when we do add this API to Stream, it will probably use await to fetch the addresses, and probably won't return bare tuples.

@miracle2k
Copy link
Contributor Author

Maybe the way forward then is to expose the stream, require the user for now to access websocket.stream.socket.getpeername(), which should remain stable, and later gain the benefit of the new trio APIs that might be available on stream directly.

@mehaase
Copy link
Contributor

mehaase commented Oct 22, 2018

Making stream part of the public API feels dangerous. If the caller starts doing things with the raw stream, it could break the WebSocket protocol. For example, the caller could do perform some send or receive on the stream that would cause our local WebSocket state to miss some frames and yield invalid state.

I'd much prefer the public API to have read-only properties like remote address, local address, or SSL certificate. If somebody really needs to manipulate the stream, they can either access the private attribute _stream or they can create their own stream and wrap it in a WebSocket.

"""
Local address of the connection. This is a ``(host, port)`` tuple.
"""
return self._stream.socket.getsockname()
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this PR but a few requests:

  1. Not all streams have a socket, and we shouldn't leak an AttributeError. Returning None seems reasonable.
  2. There is a ListenPort class in this file that combines an IP address and a port number and exposes them in a nice little object. Maybe we can reuse that here if it is renamed to something like SocketInfo or something like that.
  3. Please add test coverage.

Also,

@mehaase
Copy link
Contributor

mehaase commented May 15, 2019

This is addressed in #109.

@mehaase mehaase closed this May 15, 2019
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.

5 participants