-
Notifications
You must be signed in to change notification settings - Fork 219
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
Getting service info on unregistration #1235
Comments
You need to watch for Removed callbacks. Check the examples |
Hey @bdraco. Thanks for responding. As I mentioned, as far as I understand it, the I looked at the examples, but perhaps I'm missing something? |
Once a service has been removed it’s info is gone and there is no responder on the network anymore to answer questions to fill ServiceInfo, you’ll have to save it when it’s added if you need it later |
No I get that, but even if you keep a list as each service is added, you don't know which one of them was removed when you get the notification - only that one of them has been. |
The name is in the remove callback so you can keep a dict of the service info by name when it's added |
Yes, but as I mentioned I'm only tracking one type of custom service. So all of the add and remove notifications are for the same type of service, but not necessarily the same server. |
You probably need to install your own RecordUpdateListener and watch records as they come in and are removed. |
Thanks @bdraco, but I'm still struggling. I looked up what I could find on
|
I'm sorry but it doesn't. It's not clear what you're directing me to. This looks like a method of a class derived from |
👋🏽 |
You'll have to cache the data when the service is added or updated, as once it's removed, the device is off-line and will not respond to requests |
Right, but cache which data? |
From your opening text, I expect you need to keep a map of service name to host/port and look it up in the dict when it goes offline |
@bdraco, as I mentioned above the remove notification doesn't tell you which host went offline. So even if you keep a cache of service, host, and port as they come online, you don't know which one of them went offline when they do. You're only given the name of the service. |
You'll need to keep a map of
The name of the service is in the |
That still doesn't address the problem. As I said above I have multiple machines advertising the same service on the network. Each machine has a different host and port. When the service is announced a listener sees the name of the service, its host, and port. When the service goes offline, the listener only knows that an instance of a service name is gone, but not which host and port. |
Its a bit unconventional that you would have multiple different hosts published for the same service name that change frequently, but in that case you'll have to go with the python-zeroconf/src/zeroconf/_core.py Line 569 in 9d8dd27
python-zeroconf/src/zeroconf/_updates.py Line 52 in 9d8dd27
|
Thanks @bdraco. I'll give it a go when I have time and report back. |
I just ran into this problem, I will try to illustrate.
Well, I have a work setup, where I have (let's say) 10 Raspberry Pis, each of which runs an OLA server. And also, let's say I want to keep track of all of them - whether their OLA servers are online - in a table. So, I run my So first I get this printout (formatting mine)
Great - so I have an OLA Server running on device with hostname
Soon afterwards, I get this printout:
Great again - so I also have an OLA Server running on device with hostname
Excellent - exactly what I want: a list of devices with their hostnames and IP addresses, offering the service I'm interested on, on a given port. OK, now just for fun, I log in to
Soon thereafter, I receive the
Great - now I know that an OLA Server went offline - but which one? 192.168.1.15 or 192.168.1.27? Which entry do I remove from the table? Looking at this:
... I still cannot tell whether this RecordUpdate will have some sort of a unique identifier, relating it to a given hostname + IP address + port combination? Because if there isn't such an identifier, it is useless for the kind of "table tracking" I've just described above. But I guess, I'll have to take a look ... In any case - if worse comes to worse, - I guess I could live with the following workaround: |
Excellent illustration of the problem, @sdbbs. Thank you. |
OK, I found one workaround: given that in the context of this problem, we actually start by managing an online servers table, obviously, at first, we will get this table populated with entries advertising the service of interest (SOI) via Then, let's say So then, the solution is: when Here is an example I cooked up from the README example:
So I could only test with one RPi with OLA on the local network; but when I start the script with RPI OLA server online on local network, I get printouts:
Then I log in to the RPi, and shut down OLA server with
... and soon afterwards I get this printout:
For the kind of context I need this for (servers running on Raspberry Pis on local network, unencrypted) this seems to work - though I'm not sure if socket checking for open ports will work for HTTPS servers or similar .... so some more complicated "check open port" or "establish connection" or "ping" methods might be required there for this concept to work ... This has not been extensively tested so YMMV, but at least with one device, - in principle - it seems to work. |
On Fri, 2024-04-19 at 12:37 -0700, sdbbs wrote:
So then, the solution is: when remove_service hits, loop through all
entries of the (previously) online servers table, and check if the
specified port at the specified IP address is open; when we arrive at
a device in the online servers list that does not respond at the port
any more, then it is this device('s server) that went offline, and is
the source of remove_service Zeroconf event; and so, it is this
device entry that should be removed from the online servers list.
It's a clever hack, but me thinks this isn't elegant and probably
something in the library should be improved to just provide what we
need during the remove_service callback.
Imagine the table has potentially hundreds of devices in it. The
algorithm doesn't scale well. It can also potentially get you into
trouble because port scanning somethings gets you blocked.
My guess is the devices probably already are providing the necessary
information down at the protocol level. It just needs to make its way
elegantly through the library to the application.
…--
Kip Warner
OpenPGP signed/encrypted mail preferred
https://www.thevertigo.com
|
Hey everyone,
I note that the listener's
add_service()
callback has available to it the coordinates for the custom service that I am tracking. Whenever it comes online this callback can useget_service_info()
to get the host and port.I note that the listener's
remove_service()
callback cannot try to obtain the host and port of the service that just went offline by queryingget_service_info()
. The latter will returnNone
.My application would like to track a particular service and update a GUI accordingly. When the service comes online it's easy to add the host and port to some kind of GUI list, but I cannot figure out how to determine which server just went down when
remove_service()
callback is invoked.How can I get this information?
Maybe I'm going about this all the wrong way, but presumably this is a common issue others have had in the past.
The text was updated successfully, but these errors were encountered: