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

Save IP of autopower client in DB #26

Open
UsualSpec opened this issue Sep 21, 2024 · 4 comments
Open

Save IP of autopower client in DB #26

UsualSpec opened this issue Sep 21, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@UsualSpec
Copy link
Collaborator

UsualSpec commented Sep 21, 2024

Somewhat related: why do we send a request to the client in order to get the IP? Why not simply save the IP in the database when the client registers to the server? Sounds like it would be a lot simpler, no?

And if the IP changes, the client would anyway register again to the server I suppose, since changing IP address (almost always) implies we lost network connectivity. Or am I missing something?

Originally posted by @romain-jacob in #24 (comment)

@UsualSpec UsualSpec added the enhancement New feature or request label Sep 21, 2024
@UsualSpec
Copy link
Collaborator Author

The main reason was that saving the IP in the DB is redundant and could become outdated.
Therefore the IP address attributes (along with others) was removed from the schema in a7f7e48

We decided that getting the IP directly from the device in the UI would be a better choice as it's always up to date.

@UsualSpec
Copy link
Collaborator Author

It would be possible to retrieve the IP like in

autopower/server/server.py

Lines 359 to 363 in 1911af7

# if we get back a ping message, overwrite content with ip/peer of client
if resp.msgType == pbdef.api__pb2.clientResponseType.INTRODUCE_CLIENT:
# get ip address only (see https://stackoverflow.com/a/21908815)
ipPort = ulunquote(context.peer())[5:] # remove ipv4/ipv6 prefix
ip, sep, _ = ipPort.rpartition(":")

Then save the IP e.g. in

def registerClient(self, request, context):

@romain-jacob
Copy link
Contributor

I'm not entirely sure what would happen to the gRPC connection if the client IP changes. Would it survive the change? Because if not, then I don't see why would need to collect the IP in a server request; we can just get it when the client registers, as it would need to re-register if the IP changes.

... unless, in some magical way I don't understand, the gRPC connection survives the client getting a new IP?

@UsualSpec
Copy link
Collaborator Author

I believe that currently a client side change would mean that a new connection gets established.
However, if gRPC uses QUIC/HTTP3 in future I could imagine that the connection stays active (QUIC connection migration; https://www.rfc-editor.org/rfc/rfc9000.html#section-5-4). See also https://kmcd.dev/posts/grpc-over-http3/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants