diff --git a/integ/sync-interop/README.md b/integ/sync-interop/README.md index bdfde15d..cbeee70c 100644 --- a/integ/sync-interop/README.md +++ b/integ/sync-interop/README.md @@ -5,13 +5,13 @@ Test environment: * Ubuntu 22.04 +* ndn-cxx 0.8.1-26-g502c4c3b +* NFD 22.12-10-g6bf94c02 * Node.js 20.5.0 Reference implementation: -* ndn-cxx 0.8.1-26-g502c4c3b -* NFD 22.12-10-g6bf94c02 -* libpsync 0.4.0-2-g88b7bbd +* PSync 0.4.0-2-g88b7bbd Build reference program: @@ -65,8 +65,10 @@ corepack pnpm literate integ/sync-interop/psync-partial-subscriber.ts Test environment: * Ubuntu 22.04 -* Node.js 20.5.0 -* Docker 24.0.5 +* ndn-cxx 0.8.1-51-g16203ea2 +* NFD 22.12-37-g4c95771b +* Node.js 20.10.0 +* Docker 24.0.7 Reference implementation: @@ -86,7 +88,7 @@ Test `SyncpsPubsub`: ```bash # with NFD running docker run -it --rm \ - --mount type=bind,src=/run/nfd.sock,target=/run/nfd.sock \ + --mount type=bind,src=/run/nfd/nfd.sock,target=/var/run/nfd.sock \ localhost/ndnts-sync-interop-syncps \ /sync-interop/syncps-ind.exe /syncps-interop /syncps-interop-data /syncps-interop-data/ind/$RANDOM @@ -99,12 +101,12 @@ corepack pnpm literate integ/sync-interop/syncps.ts Test environment: * Ubuntu 22.04 +* ndn-cxx 0.8.1-38-g5686c51b +* NFD 22.12-18-g910232fc * Node.js 20.5.1 Reference implementation: -* ndn-cxx 0.8.1-38-g5686c51b -* NFD 22.12-18-g910232fc * [StateVectorSync C++ library](https://github.com/named-data/ndn-svs) commit `81ab1a16765533e3844d9aac11dabc47a737170b` (2023-08-23) Build reference program: diff --git a/packages/cli-common/README.md b/packages/cli-common/README.md index dc0295e6..0c0e6027 100644 --- a/packages/cli-common/README.md +++ b/packages/cli-common/README.md @@ -24,18 +24,22 @@ If the specified prefix does not match any existing key, digest signing will be `NDNTS_UPLINK` environment variable creates an uplink to another forwarder/node. It supports: -* connect to NFD (or similar) via Unix socket, e.g. `unix:///run/nfd.sock` +* connect to NFD (or similar) via Unix socket, e.g. `unix:///run/nfd/nfd.sock` + * This scheme accepts `fallback` parameters for alternative Unix socket paths. + If the primary socket does not exist but a fallback exists, it would be used instead. * connect to NFD via TCP, e.g. `tcp://192.0.2.1:6363` * connect to NFD via UDP unicast, e.g. `udp://192.0.2.1:6363` * connect to NDN-DPDK via UDP: `ndndpdk:` or `ndndpdk-udp:` + * See `NDNTS_NDNDPDK_*` environment variables described below. * connect to NDN-DPDK via memif: `ndndpdk-memif:` + * See `NDNTS_NDNDPDK_*` environment variables described below. * perform NDN-FCH query and connect to global NDN network: `autoconfig:` (prefer UDP) or `autoconfig-tcp:` (prefer TCP) -The default is: +The default is platform-dependent: -* Linux: `unix:///run/nfd.sock` +* Linux: `unix:///run/nfd/nfd.sock` with fallback `/run/nfd.sock` and `/run/ndn/nfd.sock` * Windows: `tcp://127.0.0.1:6363` -* other platforms: `unix:///var/run/nfd.sock` +* other platforms: `unix:///var/run/nfd/nfd.sock` with fallback `/var/run/nfd.sock` `NDNTS_MTU` environment variable sets the MTU for fragmentation of outgoing packets, applicable to UDP and memif. It must be a positive integer, and the default value is 1400. @@ -57,6 +61,7 @@ The default is auto-detected from GraphQL HTTP client. `NDNTS_NDNDPDK_MEMIF_SOCKETPATH` environment variable specifies a directory for memif control socket. The default is `/run/ndn`. +If NDN-DPDK is running in a container, this directory must be mounted into the NDN-DPDK container. ## API diff --git a/packages/cli-common/src/env.ts b/packages/cli-common/src/env.ts index 201451f6..4117560f 100644 --- a/packages/cli-common/src/env.ts +++ b/packages/cli-common/src/env.ts @@ -3,12 +3,24 @@ import "dotenv/config"; import { Name } from "@ndn/packet"; import { makeEnv, parsers } from "@sadams/environment"; -const { - [process.platform]: defaultUplink = "unix:///var/run/nfd.sock", -}: Partial> = { - linux: "unix:///run/nfd.sock", - win32: "tcp://127.0.0.1:6363", -}; +function determineDefaultUplink(): URL { + switch (process.platform) { + case "win32": { + return new URL("tcp://127.0.0.1:6363"); + } + case "linux": { + const u = new URL("unix:///run/nfd/nfd.sock"); // NFD since 2024 + u.searchParams.append("fallback", "/run/nfd.sock"); // NFD until 2023 + u.searchParams.append("fallback", "/run/ndn/nfd.sock"); // ndn6 Docker + return u; + } + default: { + const u = new URL("unix:///var/run/nfd/nfd.sock"); // NFD since 2024 + u.searchParams.append("fallback", "/var/run/nfd.sock"); // NFD until 2023 + return u; + } + } +} export const env = makeEnv({ keychain: { @@ -33,7 +45,7 @@ export const env = makeEnv({ envVarName: "NDNTS_UPLINK", parser: (value) => new URL(value), required: false, - defaultValue: new URL(defaultUplink), + defaultValue: determineDefaultUplink(), }, mtu: { envVarName: "NDNTS_MTU", diff --git a/packages/cli-common/src/uplinks.ts b/packages/cli-common/src/uplinks.ts index ab2d0fd3..13556ab6 100644 --- a/packages/cli-common/src/uplinks.ts +++ b/packages/cli-common/src/uplinks.ts @@ -1,3 +1,6 @@ +import fs from "node:fs/promises"; +import path from "node:path"; + import { connectToNetwork, connectToRouter } from "@ndn/autoconfig"; import { openFace as dpdkOpenFace } from "@ndn/dpdkmgmt"; import { type FwFace, FwTracer } from "@ndn/fw"; @@ -13,6 +16,14 @@ if (env.pktTrace) { FwTracer.enable(); } +async function checkUnixSocket(pathname: string): Promise { + try { + return path.isAbsolute(pathname) && (await fs.stat(pathname)).isSocket(); + } catch { + return false; + } +} + async function makeFace(): Promise<[face: FwFace, nfd: boolean]> { let autoconfigPreferTcp = false; let dpdkScheme: dpdkOpenFace.Options["scheme"] = "udp"; @@ -41,7 +52,17 @@ async function makeFace(): Promise<[face: FwFace, nfd: boolean]> { { preferTcp: false, mtu: env.mtu, testConnection: false })).face, true]; } case "unix:": { - const face = await UnixTransport.createFace({}, env.uplink.pathname); + let { pathname } = env.uplink; + const fallbacks = env.uplink.searchParams.getAll("fallback"); + if (fallbacks.length > 0 && !(await checkUnixSocket(pathname))) { + for (const fallback of fallbacks) { + if (await checkUnixSocket(fallback)) { + pathname = fallback; + break; + } + } + } + const face = await UnixTransport.createFace({}, pathname); return [face, true]; } case "ndndpdk-memif:": { diff --git a/packages/nfdmgmt/README.md b/packages/nfdmgmt/README.md index 380ed103..f315079e 100644 --- a/packages/nfdmgmt/README.md +++ b/packages/nfdmgmt/README.md @@ -40,7 +40,7 @@ const fwC = Forwarder.create(); const fwP = Forwarder.create(); // Connect to NFD using Unix socket transport. -const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock"; +const unixSocket = process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock"; let uplinkC: FwFace; try { uplinkC = await UnixTransport.createFace({ fw: fwC }, unixSocket); diff --git a/packages/node-transport/README.md b/packages/node-transport/README.md index 8fa3cc54..b72ba9d6 100644 --- a/packages/node-transport/README.md +++ b/packages/node-transport/README.md @@ -30,7 +30,7 @@ The `connect()` function of each transport creates a transport. // UnixTransport.connect() establishes a UNIX socket connection. // It accepts a Unix socket path. try { - const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock"); + const unix = await UnixTransport.connect(process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock"); await useInL3Face(unix); } catch (err: unknown) { // NFD is not running console.warn("unix", err); @@ -39,7 +39,7 @@ try { // TcpTransport.connect() establishes a TCP tunnel. // It accepts either host+port or an options object for net.connect(). try { - const tcp4 = await TcpTransport.connect("hobo.cs.arizona.edu", 6363); + const tcp4 = await TcpTransport.connect("suns.cs.ucla.edu", 6363); await useInL3Face(tcp4); } catch (err: unknown) { // router unavailable console.warn("tcp4", err); @@ -55,7 +55,7 @@ try { // UdpTransport.connect() establishes a UDP tunnel. try { - const udp4 = await UdpTransport.connect("hobo.cs.arizona.edu"); + const udp4 = await UdpTransport.connect("suns.cs.ucla.edu"); await useInL3Face(udp4); } catch (err: unknown) { // router unavailable console.warn("udp4", err); @@ -95,7 +95,7 @@ See `@ndn/ws-transport` package documentation for a complete example of `createF // the face to a non-default Forwarder instance. This argument is required. // Subsequent parameters are same as the corresponding connect() function. // It returns a FwFace instance (from @ndn/fw package). -const face = await UdpTransport.createFace({}, "hobo.cs.arizona.edu"); +const face = await UdpTransport.createFace({}, "suns.cs.ucla.edu"); face.close(); // TcpTransport.createFace() and UnixTransport.createFace() behave similarly. @@ -131,7 +131,7 @@ async function useInL3Face(transport: Transport) { let seq = Math.trunc(Math.random() * 1e8); for (let i = 0; i < 5; ++i) { await delay(50); - const interest = new Interest(`/ndn/edu/arizona/ping/NDNts/${seq++}`); + const interest = new Interest(`/ndn/edu/ucla/ping/NDNts/${seq++}`); console.log(`${transport}