creationix / seaduk

An implementation of nucleus-js using duktape and libuv implemented in C
Other
34 stars 5 forks source link

DNS branch #11

Open FreshXOpenSource opened 8 years ago

FreshXOpenSource commented 8 years ago

i started to work on a basic DNS implementation at https://github.com/FreshXOpenSource/seaduk/tree/dns (for now only _sync name lookups to ip-strings or arrays work).

i realize that im not yet that fit to implement an async version and would like to request help here for one async resolve example. furthermore there are several issues not yet addressed:

any input welcome...

creationix commented 8 years ago

I like how dns was done in luvit. I simply bound the libuv methods directly and then implemented the node dns APIs on top of the libuv udp bindings.

creationix commented 8 years ago

I can work on the C part tonight if you need dns in seaduk. It covers the main case of resolving a domain name to a dns address.

creationix commented 8 years ago

I've added the dns bindings to seaduk.

There are two new functions uv.getnameinfo(options, callback) and uv.getaddrinfo(options, callback)

uv.getnameinfo(options, callback)

address-to-name translation in protocol-independent manner

The callback will have (err, hostname, servicename).

uv.getaddrinfo(options, callback)

network address and service translation


To simply resolve a hostname to an IPv4 address, do something like:

uv.getaddrinfo({
  node: "luvit.io",
  socktype: "stream", // Only show TCP results
  family: "inet",  // Only show IPv4 results
}, function (err, results) {
  assert(!err, err);
  p("Dns results for luvit.io", results);
});
creationix commented 8 years ago

I believe libuv supports sync mode and I can add it with more work (same as the uv.fs_* functions). Currently it runs in async mode and you must pass in a callback.

FreshXOpenSource commented 8 years ago

that looks pretty nice to me! the sync functionality is not really needed.

prust commented 8 years ago

Nice! Thanks for doing this @creationix!