Skip to content

Commit

Permalink
fix: serve certificate to forwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Dec 19, 2023
1 parent fa57504 commit a40c2b8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/backend/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is the main file gluing all components and maintain a global context.
// Should be changed to something better if refactor.
import { Endpoint } from "@ndn/endpoint"
import { Endpoint, Producer } from "@ndn/endpoint"
import { Data, Name, Signer, digestSigning } from '@ndn/packet'
import { ControlCommand, enableNfdPrefixReg } from "@ndn/nfdmgmt"
import { FwFace } from "@ndn/fw"
Expand Down Expand Up @@ -45,6 +45,7 @@ export let nfdWsFace: FwFace | undefined = undefined
const connState = new BackendSignal<ConnState>('DISCONNECTED')
export let nfdCmdSigner: Signer = digestSigning
export let nfdCertificate: Certificate | undefined
let nfdCertProducer: Producer | undefined
let commandPrefix = ControlCommand.localhopPrefix

// ============= Connectivity =============
Expand Down Expand Up @@ -306,6 +307,7 @@ export async function stopWorkspace() {
async function checkPrefixRegistration(cancel: boolean) {
if (cancel && nfdWsFace !== undefined) {
if (!UseAutoAnnouncement) {
// Unregister prefixes
await ControlCommand.call("rib/unregister", {
name: nodeId!,
origin: 65, // client
Expand All @@ -322,6 +324,9 @@ async function checkPrefixRegistration(cancel: boolean) {
commandPrefix: commandPrefix,
signer: nfdCmdSigner,
})

// Stop serving certificate
nfdCertProducer?.close()
}
} else if (!cancel && nfdWsFace !== undefined && bootstrapped) {
// Note: UseAutoAnnouncement works, the following code is kept for test.
Expand All @@ -330,6 +335,13 @@ async function checkPrefixRegistration(cancel: boolean) {
// an invalid certificate to connect to a testbed node.
// - UseAutoAnnouncement will announce sync prefixes
if (!UseAutoAnnouncement) {
// Serve the certificate back to the forwarder
nfdCertProducer?.close()
if (nfdCertificate) {
nfdCertProducer = endpoint.produce(nfdCertificate.name, async () => nfdCertificate?.data)
}

// Register prefixes
const cr = await ControlCommand.call("rib/register", {
name: appPrefix!,
origin: 65, // client
Expand Down

0 comments on commit a40c2b8

Please sign in to comment.