Skip to content

Commit

Permalink
mdns: add mdns for local network routing (#511)
Browse files Browse the repository at this point in the history
This PR implements [mDNS](https://en.wikipedia.org/wiki/Multicast_DNS)
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](https://developer.apple.com/bonjour/) and
don't need to pull down any dependencies at all. On Linux we can use
[Avahi](https://www.avahi.org/), specifically the bonjour compatibility
layer. The header we're using is
[dns_sd.h](https://github.com/lathiat/avahi/blob/master/avahi-compat-libdns_sd/dns_sd.h),
[documented
here](https://developer.apple.com/library/archive/documentation/Networking/Conceptual/dns_discovery_api/Introduction.html#//apple_ref/doc/uid/TP40002475-SW1).

Tested on macos aarch64 and linux x86_64 so far. To try it out, build
vere from this PR, start a fakezod and observe:

```
# macos
dns-sd -B _ames._udp

# linux
avahi-browse -r _ames._udp
```

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:

```
./urbit -F zod -u https://urbit-foundation.s3.us-east-2.amazonaws.com/dear.pill
```
  • Loading branch information
pkova authored Dec 5, 2023
2 parents 26927c4 + ae110cb commit e7e06d0
Show file tree
Hide file tree
Showing 13 changed files with 2,102 additions and 2 deletions.
28 changes: 28 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ versioned_http_archive(
version = "9681279cfaa6e6399bb7ca3afbbc27fc2e19df4b",
)

versioned_http_archive(
name = "avahi",
build_file = "//bazel/third_party/avahi:avahi.BUILD",
sha256 = "060309d7a333d38d951bc27598c677af1796934dbd98e1024e7ad8de798fedda",
strip_prefix = "avahi-{version}",
url = "https://github.com/lathiat/avahi/releases/download/v{version}/avahi-{version}.tar.gz",
version = "0.8",
)

versioned_http_archive(
name = "bazel_gazelle",
sha256 = "efbbba6ac1a4fd342d5122cbdfdb82aeb2cf2862e35022c752eaddffada7c3f3",
Expand All @@ -145,6 +154,25 @@ versioned_http_archive(
version = "7.85.0",
)

versioned_http_archive(
name = "dbus",
build_file = "//bazel/third_party/dbus:dbus.BUILD",
sha256 = "a6bd5bac5cf19f0c3c594bdae2565a095696980a683a0ef37cb6212e093bde35",
strip_prefix = "dbus-{version}",
url = "https://dbus.freedesktop.org/releases/dbus/dbus-{version}.tar.xz",
version = "1.14.8",
)

versioned_http_archive(
name = "expat",
build_file = "//bazel/third_party/expat:expat.BUILD",
strip_prefix = "expat-{version}",
sha256 = "ef2420f0232c087801abf705e89ae65f6257df6b7931d37846a193ef2e8cdcbe",
# TODO: fix the R_2_5_0 nonsense
url = "https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-{version}.tar.xz",
version = "2.5.0",
)

versioned_http_archive(
name = "gmp",
build_file = "//bazel/third_party/gmp:gmp.BUILD",
Expand Down
Empty file.
30 changes: 30 additions & 0 deletions bazel/third_party/avahi/avahi.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all",
srcs = glob(["**"]),
)

cc_library(
name = "dns-sd",
hdrs = ["dns_sd.h"],
visibility = ["//visibility:public"],
)

configure_make(
name = "avahi",
args = select({
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
configure_options = ["--with-dbus-system-address='unix:path=/var/run/dbus/system_bus_socket' --with-xml=none --disable-libevent --disable-glib --disable-gobject --disable-gdbm --disable-qt3 --disable-qt4 --disable-qt5 --disable-gtk --disable-gtk3 --disable-mono --disable-monodoc --disable-python --disable-libdaemon --enable-compat-libdns_sd --disable-rpath"],
lib_source = ":all",
# out_include_dir = "avahi-compat-libdns_sd",
deps = ["@dbus"],
configure_in_place = True,
autogen = True,
autoconf = True,
autogen_command = "bootstrap.sh",
out_static_libs = ["libdns_sd.a", "libavahi-client.a", "libavahi-common.a"],
visibility = ["//visibility:public"],
)
Empty file.
21 changes: 21 additions & 0 deletions bazel/third_party/dbus/dbus.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all",
srcs = glob(["**"]),
)

configure_make(
name = "dbus",
lib_name = "libdbus-1",
args = select({
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
copts = ["-O3"],
configure_options = ["--disable-selinux --without-x --disable-tests"],
lib_source = ":all",
configure_in_place = True,
deps = ["@expat"],
visibility = ["//visibility:public"],
)
Empty file.
18 changes: 18 additions & 0 deletions bazel/third_party/expat/expat.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all",
srcs = glob(["**"]),
)

configure_make(
name = "expat",
args = select({
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
copts = ["-O3"],
lib_source = ":all",
out_static_libs = ["libexpat.a"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions pkg/c3/motes.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
# define c3__deep c3_s4('d','e','e','p')
# define c3__defn c3_s4('d','e','f','n')
# define c3__del c3_s3('d','e','l')
# define c3__dear c3_s4('d','e','a','r')
# define c3__delc c3_s4('d','e','l','c')
# define c3__delt c3_s4('d','e','l','t')
# define c3__dept c3_s4('d','e','p','t')
Expand Down
15 changes: 13 additions & 2 deletions pkg/vere/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ vere_library(
hdrs = [
"db/lmdb.h",
"vere.h",
],
"mdns.h",
] + select({
"@platforms//os:macos": [],
"@platforms//os:linux": [
"dns_sd.h",
],
}),
includes = ["."],
linkstatic = True,
visibility = ["//pkg:__subpackages__"],
Expand All @@ -133,7 +139,12 @@ vere_library(
"@lmdb",
"@openssl",
"@uv",
],
] + select({
"@platforms//os:macos": [],
"@platforms//os:linux": [
"@avahi",
],
})
)

#
Expand Down
Loading

0 comments on commit e7e06d0

Please sign in to comment.