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

epmd: allow alternative to dns resolving for nodename #1694

Merged
merged 1 commit into from
May 17, 2018

Conversation

tverlaan
Copy link
Contributor

This makes it possible to create a custom integration with a
key-value store for example. The key would then point to the
actual address. You would have to write your own epmd module
to make use of that feature.

I have not contributed to erlang/otp before so it's kind of new to me. I have read the contributing guidelines, but I'm not sure if this change requires any of the mentioned steps (except for documentation which I will fix, if this PR is even 'considerable'). Please let me know if I'm missing or not understanding something there.

Having said that I also have "my own" tcp dist and epmd module that implements something alike here (although in Elixir): https://github.com/tverlaan/inet_tcp_dist/

@CLAassistant
Copy link

CLAassistant commented Jan 29, 2018

CLA assistant check
All committers have signed the CLA.

@rickard-green rickard-green added the team:VM Assigned to OTP team VM label Feb 5, 2018
@garazdawi
Copy link
Contributor

Hello, thanks for the PR. Looks good, except lacking tests and docs as your say.

First a question though, what is the reason for epmd using a different resolving strategy than the one that inet uses?

@garazdawi garazdawi self-assigned this Feb 6, 2018
@tverlaan
Copy link
Contributor Author

tverlaan commented Feb 6, 2018

Thanks for taking a look. I'll look into creating tests straight away.

Currently the interface of erl_epmd doesn't seem to be documented nor could I find another good place where to add this piece of information. Do you have a suggestion where to add it? I can also try and create initial documentation for erl_epmd but that is a bit more work.

My first and so far only use case would be to use multicast or broadcast to a known port. A listener will pick up all nodes in the local network and save them in some kind of registry. My epmd module will talk to this registry for resolving name to IP address. I have already implemented a version of this using Multicast DNS.
A second use case would be to have nodes registering to a central k/v store. The empd module would then ask the k/v store to turn a name into an IP. This could be useful for any service discovery and registry framework.

@garazdawi
Copy link
Contributor

I'm wondering a bit, is the erl_epmd the best place to put this? It is really about finding which ip the nodehostname represents, as the IP is also used to do the distributed connect, which has nothing to do with epmd.

An idea, how about extending the inet:getaddr API to be able to do this:
inet:getaddr("test.foo.bar", inet, [{custom, Module}]).

This would allow many more services to use the callback module for resolving the IP. It could even be configured in kernel to be used for all lookups using the stratagies described here: http://erlang.org/doc/apps/erts/inet_cfg.html

We'd also have to add a way to configure inet_tcp_dist to use custom options to the inet:getaddr call.

What do you think?

@legoscia Do you have any thoughts on this?

@tverlaan
Copy link
Contributor Author

tverlaan commented Feb 7, 2018

That is a really interesting thought. I can see that this could prove useful for MDNS in general, but other solutions could be built as well of course.
From another point of view you though, I don't see why, on many occasions, you would call inet:getaddr/3 with your own resolver if you can also just call your own resolver directly with Module:Function. Even in the case of epmd it already allows you to create your own epmd module so you can call your own resolver (and fallback to normal epmd for other operations). I think this would really only be beneficial if inet:getaddr/2 is used on more places inside otp where people might want to add their own resolving method. I'm not familiar enough with otp to see if that is the case or not.

I see Erlang nodenames not as 'hostnames' per se. It is a way of naming and identifying Erlang VMs using some registry. It happens to be that DNS was the chosen registry (and rightfully so). I like to see "epmd module" as an erlang discovery module, not limited to ports. But this just reflects my personal opinion.

@garazdawi
Copy link
Contributor

So, I've been thinking a bit and I see your point. Both approaches have their merits, but I think I/we are leaning towards your approach right now. I still like the idea of adding a callback module to inet:getaddr, but maybe not to solve the problem that you are trying to solve.

However I think that it would be a good idea for the "address_please" call to also allow returns of {ok, Ip, Port}, so that it would be possible to lookup both address and port in one call.

Also the dist_util:start_timer(SetupTime), should most likely be setup around the "address_please" call.

Regarding docs, it is about time that we add some. In the erts User's Guide there is a chapter called "How to Implement an Alternative Carrier for the Erlang Distribution". We should add a chapter called "How to Implement an Alternative Service Discovery for Erlang Distribution" and in there document the erl_epmd API. Linking from the various places where one would expect to find info about how to implement an alternative service discovery mechanism.

What do you think?

@tverlaan
Copy link
Contributor Author

tverlaan commented Feb 13, 2018

Sounds great! I'll see if I can come up with the necessary patches. Do you want documentation as part of this PR or separately, since it would cover more then just this feature?

Initially (in a separate dist module) I implemented address_and_port_please, see https://github.com/tverlaan/inet_tcp_dist/blob/master/lib/inet_tcp_dist.ex#L48. Would you prefer to keep address_please or use the more descriptive, despite long name?

@garazdawi
Copy link
Contributor

Put the doc changes in this pr.

I don't have a strong opinion regarding the naming. Choose what you find to be the best.

@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from 0412212 to 73e24b5 Compare February 14, 2018 09:42
@garazdawi garazdawi added the waiting waiting for changes/input from author label Feb 19, 2018
@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from c6974e0 to ff3ae93 Compare February 23, 2018 16:39
@garazdawi
Copy link
Contributor

How is it going? Need any help with anything?

@tverlaan
Copy link
Contributor Author

tverlaan commented Mar 8, 2018

I've been quite busy past few weeks. I'm slowly making some progress. Thanks!

@garazdawi
Copy link
Contributor

Hello! Any chance of getting this done within the next week? I'd like for it to be part of the OTP-21 rc1 if possible.

@tverlaan
Copy link
Contributor Author

Hey, sorry, have been on holiday as well. I'll finish it this week!

@tverlaan
Copy link
Contributor Author

Hi! I finally got around on finishing the documentation. I also merged master into my branch to resolve a conflict in inet_tls_dist. There was a small change in code I moved to another function, so I moved that change as well so it is still present.

Happy to get any feedback on the documentation :)

@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch 2 times, most recently from 632de5b to f114ca9 Compare May 1, 2018 07:42
@garazdawi
Copy link
Contributor

Great! I'll have a look after the OTP-21 rc1 release is done, which quite soon.

Would you mind doing a rebase ontop of master instead of merging? We never merge master into our development branches, but instead rebase them ontop until they are merged upstream.

@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from f114ca9 to 1baba13 Compare May 2, 2018 08:47
@tverlaan
Copy link
Contributor Author

tverlaan commented May 2, 2018

Ok, rebased my branch on top of master instead of merging it :-)

@garazdawi garazdawi added testing currently being tested, tag is used by OTP internal CI and removed waiting waiting for changes/input from author labels May 2, 2018
@garazdawi
Copy link
Contributor

The xmllint fails in

../xml/alt_disco.xml:113: element p: validity error : Element taglist is not declared in p list of possible children
</p>

If you run: "make xmllint" it should reproduce the error.

@garazdawi garazdawi removed the testing currently being tested, tag is used by OTP internal CI label May 2, 2018
@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from 1baba13 to 9c3d8cc Compare May 2, 2018 21:16
@tverlaan
Copy link
Contributor Author

tverlaan commented May 2, 2018

I couldn't get xmllint work right now (I'll look into it), but I think I resolved the error by looking at other docs.

@garazdawi
Copy link
Contributor

garazdawi commented May 3, 2018

I just pushed xmllint checks into the travis builds on latest master, so if you rebase again you will get the checks in travis instead of having to run them yourself.

@garazdawi garazdawi added the testing currently being tested, tag is used by OTP internal CI label May 3, 2018
@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from 9c3d8cc to 4caa6ac Compare May 3, 2018 08:07
@jhogberg jhogberg removed the testing currently being tested, tag is used by OTP internal CI label May 3, 2018
</header>
<module>erl_epmd</module>
<modulesummary>
Erlang interface towards <seealso marker="erts:epmd"><c>epmd</c></seealso>
Copy link
Contributor

Choose a reason for hiding this comment

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

xmllint fails here since modulesummary may only contain plain text. The rest looks great though!

@jhogberg jhogberg added the testing currently being tested, tag is used by OTP internal CI label May 3, 2018
@garazdawi
Copy link
Contributor

Looks great! I did some small changes and restructured the alt_disco chapter a bit. If you are happy with my changes, please squash all of your and my changes into a single commit and push them to the PR and I'll merge this change.

@tverlaan tverlaan force-pushed the add_dns_alternative_to_tcp_dist branch from 17dc2cb to bc8fde1 Compare May 14, 2018 14:52
<item><p>Return the address of the given node.
If not implemented, <seealso marker="kernel:inet#gethostbyname/1">
inet:gethostbyname/1</seealso> will be used instead</p>
<p>This callback may also return the port of the given node. In that case
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added one sentence here to clarify when port_please/3 may be omitted.

@tverlaan
Copy link
Contributor Author

Thanks. It looks good! I added one sentence and squashed it all in one commit. I hope that's okay!

@garazdawi garazdawi added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels May 14, 2018
This makes it possible to create a custom integration with a
key-value store for example. The key would then point to the
actual address. You would have to write your own epmd module
to make use of that feature.
@garazdawi garazdawi force-pushed the add_dns_alternative_to_tcp_dist branch from bc8fde1 to 662f3c7 Compare May 16, 2018 15:50
@garazdawi
Copy link
Contributor

I did a force push with some link changes.

@garazdawi garazdawi added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels May 16, 2018
@garazdawi garazdawi merged commit db19117 into erlang:master May 17, 2018
@garazdawi
Copy link
Contributor

Merged! Thanks for you contribution!

@tverlaan tverlaan deleted the add_dns_alternative_to_tcp_dist branch May 17, 2018 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants