-
Notifications
You must be signed in to change notification settings - Fork 733
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
Zeroconf-based Kolibri P2P discovery system #5660
Conversation
Codecov Report
|
Codecov Report
|
return instances | ||
|
||
|
||
def register_zeroconf_service(port, id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function need the port as a parameter?
Is not possible to get it from the options or reading it from the PID_FILE
as it is done in other parts of the code?
This port
option pushes changes in many parts of this PR code that might not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, PID_FILE could be a good place, yes. I originally wanted to pull it from conf.OPTIONS
, except it can be overridden with --port=XYZ
, which doesn't get stored anywhere (except in the PID file, I guess), just passed in to the start command function as an argument, which was the pattern I followed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand your concerns but, as I understand the code, the value in the PID file is affected both by conf.OPTIONS and env variables, thus it should be the real value for the port. Taking it from there would avoid many modifications you had to do just to drag the port parameter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, agreed! Can't see any issues with that approach. Will update.
The PID is also written into there for kolibri-server, yes? Based on what uwsgi/nginx are exposing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kolibri-server takes the value from conf.OPTIONS because there's no warranty the part of code in Kolibri that saves the PID has been executed before kolibri-server starts. The env variable option does not have sense when running it as a daemon.
After kolibri finishes the starting process, the PID file will have the same value that is in conf.OPTIONS so I think we can consider we are safe on this side too.
(also means that we start with a soft interrupt and only hard-kill later if needed, as we do on Linux)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks so promising!! Am already thinking about what it can contribute to in terms of documentation simplification about static IPs -- that if MDNS is supported widely (IDK) then we could implement the naming of a device in the setup process <unique-device-name>.kolibri.local
.
Scratch that, you already knew 💯 |
assert self.info is None, "Service is already registered!" | ||
|
||
i = 1 | ||
id = self.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assigns to a builtin, or is it just me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems so, yep! Perhaps I'll rename the local var to unique_id
It's sooooooo close to a possibility, EXCEPT that Android doesn't implement any version of mDNS/zeroconf/etc.... and that's one of our most common client devices. 😿 What I'm thinking is that we could make lightweight "launcher" apps for Android/Windows/Linux that do nothing other than quickly scan the local network and find the IP for a Kolibri instance (possibly caching/preferring a specific one after first use), and then pop it open in the web browser. Would be a huge timesaver and headache-avoider in itself. |
Looks like any background tasks are managed inside zeroconf - so, apart from superficial merge conflicts, I don't think it would be affected. |
okay cool. wasn't sure if you were going to want to leverage iceqube machinery for this |
migrating to #6011 and https://github.com/learningequality/kolibri/tree/zeroconf so that @micahscopes can work on it |
Summary
We support local network peer connections for content import, and soon, for data syncing. But right now, it's necessary to manually enter the IP and port, which is at best inconvenient, and at worst an insurmountable barrier for many users.
Enter zeroconf! It's specifically designed for this type of situation -- allowing nearby devices on the same network to discover one another and the services they offer.
This PR is a preliminary, but usable, backend implementation of a zeroconf-based "Kolibri service broadcasting and discovery" system. When Kolibri starts up, it will register itself on the local network, and then monitor and track any other instances of Kolibri on the same local network. The frontend code can then call an API endpoint to enumerate the nearby Kolibri instances, including information about what IP/port they're listening on, and what facilities/channels they have loaded on them.
One of the lovely side-effects of using zeroconf (aka mDNS) for this is that it also ends up creating local
area domain names that can be resolved and used in the browser at least on Linux and OSX:
Note: includes some changes I made to https://github.com/learningequality/python-zeroconf
Reviewer guidance
To test, you'll want to spin up a couple instances of this. To start with, these could be on the same computer, just using different ports and KOLIBRI_HOME directories, e.g.:
Then, login as an admin on each and go to:
http://127.0.0.1:8080/api/discovery/networksearch/
and
http://127.0.0.1:9090/api/discovery/networksearch/
and you should see something like this:
Contributor Checklist
PR process:
Testing:
Reviewer Checklist
yarn
andpip
)TODO:
_http._tcp.local
so it's standardized.