yoursunny / NDNts

NDN libraries for the Modern Web
https://ndnts-docs.ndn.today
ISC License
31 stars 9 forks source link

How to register into nfd? #12

Closed killerdbob closed 2 years ago

killerdbob commented 2 years ago

Hi, I follow your instruction in lib nfdmgmt, it does not work if I don't run produce(). My code is as follow, this will not register a "/hi" into NFD.

    const { face } = await connectToRouter(uri, {
        H3Transport,
        testConnection: false,
    });
    enableNfdPrefixReg(face);
    const prefix = new Name("/hi");
    face.addRoute(prefix);

After I run a produce, the "/hi" will be registered. Is this a bug?

    const { face } = await connectToRouter(uri, {
        H3Transport,
        testConnection: false,
    });
    enableNfdPrefixReg(face);
    const prefix = new Name("/hi");
    face.addRoute(prefix);
    const endpoint = new Endpoint({fw: face.fw});
    endpoint.produce(prefix, null);
yoursunny commented 2 years ago

This behavior is by design.

face1.addRoute(prefix1)

This causes Interests matching prefix1 to be forwarded to face1.

enableNfdPrefixReg(face1)

This creates a ReadvertiseDestination associated with face1. Every time a prefix is announced by a source face other than face1, and the source face is not marked advertiseFrom: false attribute, this ReadvertiseDestination would send a prefix registration command. The prefix registration command would cause Interests matching the announced prefix to come from face1.

endpoint.produce(prefix2, ...)

This creates a new logical face in NDNts internal Forwarder and announces prefix2 on this logical face. The announcement would trigger the ReadvertisementDestination created above to send the prefix registration command, so that Interests matching prefix2 would come from face1, which is further forwarded to the producer handler function.

killerdbob commented 2 years ago

ok, thank you.