Skip to content

Commit

Permalink
cli-common: change default Unix socket path to /run/nfd/nfd.sock
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jan 8, 2024
1 parent e1420eb commit 0b748bf
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 27 deletions.
18 changes: 10 additions & 8 deletions integ/sync-interop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand All @@ -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

Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions packages/cli-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
26 changes: 19 additions & 7 deletions packages/cli-common/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<NodeJS.Platform, string>> = {
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: {
Expand All @@ -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",
Expand Down
23 changes: 22 additions & 1 deletion packages/cli-common/src/uplinks.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,6 +16,14 @@ if (env.pktTrace) {
FwTracer.enable();
}

async function checkUnixSocket(pathname: string): Promise<boolean> {
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";
Expand Down Expand Up @@ -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:": {
Expand Down
2 changes: 1 addition & 1 deletion packages/nfdmgmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions packages/node-transport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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} <I ${interest.name}`);
yield FwPacket.create(interest);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/repo-external/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (!repoPrefix) {
}
const dataPrefix = new Name(`/NDNts-repo-external/${Math.trunc(Math.random() * 1e8)}`);

const face = await UnixTransport.createFace({}, process.env.DEMO_NFD_UNIX ?? "/run/nfd.sock");
const face = await UnixTransport.createFace({}, process.env.DEMO_NFD_UNIX ?? "/run/nfd/nfd.sock");
enableNfdPrefixReg(face);

const store = new PyRepoStore({
Expand Down

0 comments on commit 0b748bf

Please sign in to comment.