• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yoursunny / NDNts / 16229614996

11 Jul 2025 08:57PM UTC coverage: 95.514% (+0.06%) from 95.456%
16229614996

push

github

yoursunny
mk: upgrade to xo-config 0.1001.0

4085 of 4333 branches covered (94.28%)

295 of 307 new or added lines in 77 files covered. (96.09%)

1 existing line in 1 file now uncovered.

15073 of 15781 relevant lines covered (95.51%)

6813.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.65
/pkg/cli-common/src/uplinks.ts
1
import fs from "node:fs/promises";
1✔
2
import path from "node:path";
1✔
3

4
import { connectToNetwork, connectToRouter } from "@ndn/autoconfig";
1✔
5
import { openFace as dpdkOpenFace } from "@ndn/dpdkmgmt";
1✔
6
import { type FwFace, FwTracer } from "@ndn/fw";
1✔
7
import { enableNfdPrefixReg, PrefixAnn } from "@ndn/nfdmgmt";
1✔
8
import { UnixTransport } from "@ndn/node-transport";
1✔
9
import { Closers } from "@ndn/util";
1✔
10

11
import * as env from "./env";
1✔
12
import { exitClosers } from "./exit";
1✔
13
import { getSignerImpl, openKeyChain } from "./keychain";
1✔
14

15
if (env.pktTrace) {
1!
16
  FwTracer.enable();
×
17
}
×
18

19
async function checkUnixSocket(pathname: string): Promise<boolean> {
×
20
  try {
×
21
    return path.isAbsolute(pathname) && (await fs.stat(pathname)).isSocket();
×
22
  } catch {
×
23
    return false;
×
24
  }
×
25
}
×
26

27
async function makeFace(): Promise<[face: FwFace, nfd: boolean]> {
1✔
28
  let autoconfigPreferTcp = false;
1✔
29
  let dpdkScheme: dpdkOpenFace.Options["scheme"] = "udp";
1✔
30
  switch (env.uplink.protocol) {
1✔
31
    case "autoconfig-tcp:": {
1!
32
      autoconfigPreferTcp = true;
×
33
    }
×
34
    // fallthrough
35
    case "autoconfig:": {
1!
36
      try {
×
37
        const faces = await connectToNetwork({
×
38
          mtu: env.mtu,
×
39
          preferTcp: autoconfigPreferTcp,
×
40
        });
×
41
        return [faces[0]!, true];
×
42
      } catch (err: unknown) {
×
43
        throw new Error(`autoconfig failed: ${err}\nset uplink in NDNTS_UPLINK`, { cause: err });
×
44
      }
×
45
    }
×
46
    case "tcp:": {
1✔
47
      return [(await connectToRouter(
1✔
48
        env.uplink.host,
1✔
49
        { preferTcp: true, testConnection: false },
1✔
50
      )).face, true];
1✔
51
    }
1✔
52
    case "udp:": {
1!
NEW
53
      return [(await connectToRouter(
×
NEW
54
        env.uplink.host,
×
NEW
55
        { preferTcp: false, mtu: env.mtu, testConnection: false },
×
NEW
56
      )).face, true];
×
UNCOV
57
    }
×
58
    case "unix:": {
1!
59
      let { pathname } = env.uplink;
×
60
      const fallbacks = env.uplink.searchParams.getAll("fallback");
×
61
      if (fallbacks.length > 0 && !(await checkUnixSocket(pathname))) {
×
62
        for (const fallback of fallbacks) {
×
63
          if (await checkUnixSocket(fallback)) {
×
64
            pathname = fallback;
×
65
            break;
×
66
          }
×
67
        }
×
68
      }
×
69
      const face = await UnixTransport.createFace({}, pathname);
×
70
      return [face, true];
×
71
    }
×
72
    case "ndndpdk-memif:": {
1!
73
      dpdkScheme = "memif";
×
74
    }
×
75
    // fallthrough
76
    case "ndndpdk-udp:":
1!
77
    case "ndndpdk:": {
1!
78
      const face = await dpdkOpenFace({
×
79
        gqlServer: env.dpdkGql,
×
80
        localHost: env.dpdkLocal,
×
81
        scheme: dpdkScheme,
×
82
        mtu: env.mtu,
×
83
        memif: {
×
84
          socketPath: env.dpdkMemifSocketPath,
×
85
        },
×
86
      });
×
87
      return [face, false];
×
88
    }
×
89
    default: {
1!
90
      throw new Error(`unknown protocol ${env.uplink.protocol} in NDNTS_UPLINK`);
×
91
    }
×
92
  }
1✔
93
}
1✔
94

95
let theUplinks: (Closers & FwFace[]) | undefined;
1✔
96

97
/** Open the uplinks specified by `NDNTS_UPLINK` environ. */
98
export async function openUplinks({ autoClose = true }: openUplinks.Options = {}): Promise<FwFace[]> {
1✔
99
  if (!theUplinks) {
1✔
100
    const [face, nfd] = await makeFace();
1✔
101
    if (nfd && env.nfdReg) {
1✔
102
      const [signer, klName] = await getSignerImpl(env.nfdRegKey);
1✔
103
      enableNfdPrefixReg(face, {
1✔
104
        PrefixAnn: env.nfdRegAnn ? PrefixAnn : undefined,
1!
105
        signer,
1✔
106
        preloadCertName: klName ?? env.nfdRegKey,
1!
107
        preloadFromKeyChain: openKeyChain(),
1✔
108
      });
1✔
109
    }
1✔
110
    theUplinks = new Closers() as (Closers & FwFace[]);
1✔
111
    theUplinks.push(face);
1✔
112
    if (autoClose) {
1✔
113
      exitClosers.push(theUplinks);
1✔
114
    }
1✔
115
  }
1✔
116
  return theUplinks;
1✔
117
}
1✔
118
export namespace openUplinks {
119
  export interface Options {
120
    /**
121
     * Whether to automatically close uplinks at exit.
122
     * @defaultValue true
123
     */
124
    autoClose?: boolean;
125
  }
126
}
127

128
/** Close the uplinks. */
129
export function closeUplinks() {
1✔
130
  theUplinks?.close();
×
131
  theUplinks = undefined;
×
132
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc