-
Notifications
You must be signed in to change notification settings - Fork 39
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
mdns: add mdns for local network routing #511
Conversation
ada3336
to
47ac3d7
Compare
pkg/vere/vere.h
Outdated
/* mdns_init(): initialize mdns. | ||
*/ | ||
void | ||
mdns_init(uint16_t port, char* our, mdns_cb* cb, void* context); |
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.
Where should I put this signature? vere.h
seems wrong but don't really know where it should go.
I wonder what we should do in the following scenario: Someone boots a fresh ship on your local network. You receive the mDNS notification and send a |
*/ | ||
static void | ||
_ames_put_dear(char* ship, unsigned long s_addr, uint16_t port, void* context) | ||
{ |
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 should use c3 types: _ames_put_dear(c3_c*, c3_w, c3_s, void*)
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.
Done
if (our == u3t(shp_u)) { | ||
u3z(our); | ||
return; | ||
} |
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 early return leaks shp_u
u3_auto_peer( | ||
u3_auto_plan(&sam_u->car_u, | ||
u3_ovum_init(0, c3__a, wir, cad)), | ||
0, 0, _mdns_dear_bail); |
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.
We don't need to track or handle failures with these events.
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.
I get real ugly crashes on arvo versions that don't support %dear
unless I handle the bail myself.
pkg/vere/mdns.c
Outdated
uv_poll_stop(payload->poll); | ||
c3_free(payload->poll); | ||
c3_free(payload->our); | ||
c3_free(payload); |
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.
leave a comment explaining why we leak sref
.
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.
Done
pkg/vere/mdns.c
Outdated
register_payload->cb = cb; | ||
register_payload->context = context; | ||
register_payload->our = our; | ||
|
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.
It looks like you don't need to save our
in payload
. I would try removing that, and also just passing our + 1
to DNSServiceRegister()
(maybe after checking that '~' = *our
).
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.
Done
pkg/vere/mdns.c
Outdated
char* who; | ||
char* our; | ||
uint16_t port; | ||
uv_poll_t* poll; |
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.
It looks like poll
always has the same lifetime as payload
, so it can just be uv_poll_t
(no *
).
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.
Done
pkg/vere/mdns.c
Outdated
poll->data = (void *)sref; | ||
payload->poll = poll; | ||
uv_poll_init(loop, poll, fd); | ||
uv_poll_start(poll, UV_READABLE, poll_cb); |
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.
If poll
has the same lifetime as payload
(see above), you can remove the malloc here and just
uv_poll_init(loop, &(payload->poll), fd);`
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.
And done.
1a48dfa
to
de78b05
Compare
This PR implements mDNS for vere, significantly improving Urbit routing inside local networks. On startup vere will now broadcast a service with the format
dinleb-rambep._ames._udp.local
. Vere will also listen for any services on the local network with the signature of_ames._udp
. Whenever new services are found vere will send the lane to arvo.On macOS we can use Bonjour and don't need to pull down any dependencies at all. On Linux we can use Avahi, specifically the bonjour compatibility layer. The header we're using is dns_sd.h, documented here.
Tested on macos aarch64 and linux x86_64 so far. To try it out, build vere from this PR, start a fakezod and observe:
You can also start another fake ship on the same network and do
|ames-verb %rcv %odd
to see your fakeships find eachother. For this second part you need the companion arvo PR, here's a pill that has it already: