### Configure and Build ndn-cxx with Examples Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Enable the building of examples by passing the --with-examples flag during configuration. This is followed by the standard build and install steps. ```shell ./waf configure --with-examples ./waf sudo ./waf install sudo ldconfig # on Linux only ``` -------------------------------- ### Configure ndn-cxx with Examples Source: https://github.com/named-data/ndn-cxx/blob/master/examples/README.md Enables the building of example applications within the ndn-cxx project. This is a prerequisite for compiling and running any examples. ```bash ./waf configure --with-examples ./waf ``` -------------------------------- ### Install Optional Dependencies for Documentation on FreeBSD Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs tools for building documentation for ndn-cxx on FreeBSD. ```shell sudo pkg install doxygen graphviz py39-sphinx ``` -------------------------------- ### Install Certificate as Default Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-cert-install.md Installs a certificate from a file and sets it as the default for the corresponding identity. ```bash $ ndnsec cert-install cert_file.cert ``` -------------------------------- ### Add Simple Single-File Example Source: https://github.com/named-data/ndn-cxx/blob/master/examples/README.md Adds a basic C++ example directly to the 'examples/' directory. The executable name is derived from the filename. ```bash echo 'int main() { return 0; }' > examples/foo.cpp ./waf # ... Compiling examples/foo.cpp # ... Linking build/examples/foo # To run the example ./build/examples/foo ``` -------------------------------- ### NDN_LOG Examples Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-log.md Examples demonstrating how to set the NDN_LOG environment variable for specific modules or all modules. ```shell export NDN_LOG="ndn.*=DEBUG" ``` ```shell export NDN_LOG="ndn.UnixTransport=INFO" ``` ```shell export NDN_LOG="sync.Logic=ERROR" ``` ```shell export NDN_LOG="*=DEBUG:ndn.UnixTransport=INFO:sync.Logic=ERROR" ``` -------------------------------- ### PIB Configuration Example (Default Location) Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-client.conf.md This example demonstrates setting the PIB to use SQLite3 with the default location, omitting the location parameter. ```none pib=pib-sqlite3 ``` -------------------------------- ### TPM File Configuration Example (Default Location) Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-client.conf.md This example shows how to configure the TPM to use file-based storage with the default location, omitting the location parameter. ```none tpm=tpm-file ``` -------------------------------- ### Add Multi-File Example Source: https://github.com/named-data/ndn-cxx/blob/master/examples/README.md Adds a more complex C++ example using a subdirectory under 'examples/'. All .cpp files in the subdirectory are compiled into a single executable. ```bash mkdir examples/bar echo 'int bar(); int main() { return bar(); }' > examples/bar/a.cpp echo 'int bar() { return 10; }' > examples/bar/b.cpp ./waf # ... Compiling examples/bar/a.cpp # ... Compiling examples/bar/b.cpp # ... Linking build/examples/bar/bar # To run the example ./build/examples/bar/bar ``` -------------------------------- ### Install Optional Dependencies for Documentation on Debian/Ubuntu Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs tools for building documentation and Python packages for ndn-cxx on Debian-based systems. ```shell sudo apt install doxygen graphviz python3-pip python3 -m pip install --user -r docs/requirements.txt ``` -------------------------------- ### Install Build Tools on FreeBSD Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs essential build tools and development libraries required for ndn-cxx on FreeBSD. ```shell sudo pkg install boost-libs openssl sqlite3 pkgconf python3 ``` -------------------------------- ### Add and Build a New Sample Application Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Create a new C++ application file in the examples directory and compile it by re-running the build process. ```shell cp examples/consumer.cpp examples/my-new-app.cpp ... # edit examples/my-new-app.cpp with your preferred editor ./waf sudo ./waf install sudo ldconfig # on Linux only ./build/examples/my-new-app ``` -------------------------------- ### Install Optional Dependencies for Documentation on macOS Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs tools for building documentation and Python packages for ndn-cxx on macOS. ```shell brew install doxygen graphviz python3 -m pip install --user -r docs/requirements.txt ``` -------------------------------- ### Create and Build a Simple Tool Source: https://github.com/named-data/ndn-cxx/blob/master/tools/README.md Demonstrates how to create a simple C++ tool with a single translation unit, build it using waf, and install it. ```bash echo "int main() { return 0; }" > tools/foo.cpp ./waf # ... Compiling tools/foo.cpp # ... Linking build/bin/foo sudo ./waf install # ... install /usr/local/bin/foo (from build/bin/foo) # To run the tool /usr/local/bin/foo ``` -------------------------------- ### Install Build Tools on macOS with Homebrew Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs necessary development libraries for ndn-cxx on macOS using Homebrew. ```shell brew install boost openssl pkgconf ``` -------------------------------- ### Create and Build a Multi-Unit Tool Source: https://github.com/named-data/ndn-cxx/blob/master/tools/README.md Illustrates the process of creating a tool with multiple C++ source files, organizing them in a subdirectory, building with waf, and installing. ```bash mkdir tools/bar echo "int bar(); int main() { return bar(); }" > tools/bar/a.cpp echo "int bar() { return 10; } " > tools/bar/b.cpp ./waf # ... Compiling tools/bar/a.cpp # ... Compiling tools/bar/b.cpp # ... Linking build/bin/bar sudo ./waf install # ... install /usr/local/bin/bar (from build/bin/bar) # To run the tool /usr/local/bin/bar ``` -------------------------------- ### Install Optional Dependencies for Documentation on CentOS/Fedora Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs tools for building documentation and Python packages for ndn-cxx on Red Hat-based systems. ```shell sudo dnf install doxygen graphviz python3-pip python3 -m pip install --user -r docs/requirements.txt ``` -------------------------------- ### Run ndn-cxx Examples Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Execute the pre-built trivial producer and consumer applications. Includes a consumer application with timer functionality. ```shell # trivial producer app ./build/examples/producer # trivial consumer app ./build/examples/consumer # trivial consumer app with timers ./build/examples/consumer-with-timer ``` -------------------------------- ### Install Build Tools on Debian/Ubuntu Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs essential build tools and development libraries required for ndn-cxx on Debian-based systems. ```shell sudo apt install build-essential libboost-all-dev libssl-dev libsqlite3-dev pkgconf python3 ``` -------------------------------- ### Generate Example Trust Anchor Source: https://github.com/named-data/ndn-cxx/blob/master/examples/README.md Generates a new public/private key pair for the '/example' namespace and exports the public certificate. This serves as a trust anchor for example applications. ```bash ndnsec key-gen /example ndnsec cert-dump -i /example > example-trust-anchor.cert ``` -------------------------------- ### Using 'get' and 'set' for Attribute Access Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md The terms 'get' and 'set' should be used when directly accessing attributes. ```c++ employee.getName(); employee.setName(name); matrix.getElement(2, 4); matrix.setElement(2, 4, value); ``` -------------------------------- ### Install Certificate Without Changing Defaults Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-cert-install.md Installs a certificate from a file without modifying any default identity or key settings. ```bash $ ndnsec cert-install -N cert_file.cert ``` -------------------------------- ### Example ndn-client.conf Configuration Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-client.conf.md This snippet shows a typical configuration file for ndn-cxx, illustrating settings for transport, PIB, and TPM. ```ini ; "transport" specifies the default transport connection used by the client-side face to communicate ; with a (local or remote) NDN forwarder. The value must be a Face URI with a Unix or TCP scheme. ; ; For example: ; unix:///tmp/nfd/nfd.sock ; tcp://192.0.2.1 ; tcp4://example.com:6363 ; tcp6://[2001:db8::1]:6363 ; ; The default value of this field is platform-dependent, being "unix:///run/nfd/nfd.sock" on Linux ; and "unix:///var/run/nfd/nfd.sock" on other platforms. ; transport=unix:///var/run/nfd/nfd.sock ; "pib" determines which Public Information Base (PIB) should used by default in applications. ; Currently, the only supported value for "pib" is: ; - "pib-sqlite3" (default if not specified) ; pib=pib-sqlite3 ; "tpm" determines which Trusted Platform Module (TPM) should used by default in applications. ; The supported values for "tpm" are: ; - "tpm-file" (default if not specified) ; - "tpm-osxkeychain" ; tpm=tpm-file ``` -------------------------------- ### Create and Sign Producer Key Source: https://github.com/named-data/ndn-cxx/blob/master/examples/README.md Generates a key for the '/example/testApp' namespace and signs its certificate request using the '/example' trust anchor. The resulting certificate is then installed. ```bash ndnsec key-gen /example/testApp ndnsec sign-req /example/testApp | ndnsec cert-gen -s /example -i example | ndnsec cert-install - ``` -------------------------------- ### Install Build Tools on CentOS/Fedora Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Installs essential build tools and development libraries required for ndn-cxx on Red Hat-based systems. ```shell sudo dnf install gcc-c++ boost-devel openssl-devel sqlite-devel pkgconf python3 ``` -------------------------------- ### Configure and Build ndn-cxx Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Configures, builds, and installs the ndn-cxx library in release mode. ```shell ./waf configure ./waf sudo ./waf install ``` -------------------------------- ### Example Validator Configuration File Source: https://github.com/named-data/ndn-cxx/blob/master/docs/tutorials/security-validator-config.md This configuration file defines two rules for validating data packets and specifies a trust anchor file. The order of rules is crucial for correct validation logic. ```none rule { id "Simple Rule" for data filter { type name name /localhost/example relation is-prefix-of } checker { type customized sig-type rsa-sha256 key-locator { type name name /ndn/edu/ucla/yingdi/KEY/1234 relation equal } } } rule { id "Testbed Validation Rule" for data checker { type hierarchical sig-type rsa-sha256 } } trust-anchor { type file file-name "testbed-trust-anchor.cert" } ``` -------------------------------- ### Signed Interest Example Name Source: https://github.com/named-data/ndn-cxx/blob/master/docs/specs/signed-interest.md Provides an example of a Signed Interest name, showing the addition of timestamp, random value, SignatureInfo, and SignatureValue components after the base name. ```none /signed/interest/name//// \ / ----------------------------- -------------------------- \/ Additional components of Signed Interest ``` -------------------------------- ### Consumer with Scheduler Source: https://github.com/named-data/ndn-cxx/blob/master/docs/examples.md This C++ example demonstrates using ndn-cxx's Scheduler to send an initial Interest and then schedule a second Interest to be sent approximately 3 seconds later. It utilizes boost::asio::io_context for asynchronous operations. ```cpp /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * * ndn-cxx library is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received copies of the GNU General Public License and GNU Lesser * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see * . * * See AUTHORS.md for complete list of ndn-cxx authors and contributors. */ #include #include #include #include // Enclosing code in ndn simplifies coding (can also use `using namespace ndn`) namespace ndn { // Additional nested namespaces should be used to prevent/limit name conflicts namespace examples { class ConsumerWithTimer { public: void run() { Name interestName("/example/testApp/randomData"); interestName.appendVersion(); Interest interest(interestName); interest.setMustBeFresh(true); interest.setInterestLifetime(2_s); std::cout << "Sending Interest " << interest << std::endl; m_face.expressInterest(interest, std::bind(&ConsumerWithTimer::onData, this, _1, _2), std::bind(&ConsumerWithTimer::onNack, this, _1, _2), std::bind(&ConsumerWithTimer::onTimeout, this, _1)); // Schedule a new event m_scheduler.schedule(3_s, [this] { delayedInterest(); }); // m_ioCtx.run() will block until all events finished or m_ioCtx.stop() is called m_ioCtx.run(); // Alternatively, m_face.processEvents() can also be called. // processEvents will block until the requested data received or timeout occurs. // m_face.processEvents(); } private: void onData(const Interest&, const Data& data) const { std::cout << "Received Data " << data << std::endl; } void onNack(const Interest& interest, const lp::Nack& nack) const { std::cout << "Received Nack with reason " << nack.getReason() << " for " << interest << std::endl; } void onTimeout(const Interest& interest) const { std::cout << "Timeout for " << interest << std::endl; } void delayedInterest() { std::cout << "One more Interest, delayed by the scheduler" << std::endl; Name interestName("/example/testApp/randomData"); interestName.appendVersion(); Interest interest(interestName); interest.setMustBeFresh(true); interest.setInterestLifetime(2_s); std::cout << "Sending Interest " << interest << std::endl; m_face.expressInterest(interest, std::bind(&ConsumerWithTimer::onData, this, _1, _2), std::bind(&ConsumerWithTimer::onNack, this, _1, _2), std::bind(&ConsumerWithTimer::onTimeout, this, _1)); } private: // Explicitly create io_context object, which will be shared between Face and Scheduler boost::asio::io_context m_ioCtx; Face m_face{m_ioCtx}; Scheduler m_scheduler{m_ioCtx}; }; } // namespace examples } // namespace ndn int main(int argc, char** argv) { try { ndn::examples::ConsumerWithTimer consumer; consumer.run(); return 0; } catch (const std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } ``` -------------------------------- ### Configure and Build ndn-cxx with Tests Source: https://github.com/named-data/ndn-cxx/blob/master/README-dev.md Build ndn-cxx with unit test support enabled. Ensure the library is installed to the correct location for tests to run. ```shell ./waf configure --with-tests # --debug is also strongly recommended while developing ./waf sudo ./waf install ``` -------------------------------- ### Trivial Consumer Example Source: https://github.com/named-data/ndn-cxx/blob/master/docs/examples.md This C++ code demonstrates a basic consumer that sends an Interest for data and handles the response. Ensure NFD is configured and running before execution. The consumer specifies callbacks for Data, Nack, and timeouts. ```C++ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- * * Copyright (c) 2013-2022 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * * ndn-cxx library is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received copies of the GNU General Public License and GNU Lesser * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see * . * * See AUTHORS.md for complete list of ndn-cxx authors and contributors. */ #include #include #include // Enclosing code in ndn simplifies coding (can also use `using namespace ndn`) namespace ndn { // Additional nested namespaces should be used to prevent/limit name conflicts namespace examples { class Consumer { public: Consumer() { m_validator.load("trust-schema.conf"); } void run() { Name interestName("/example/testApp/randomData"); interestName.appendVersion(); Interest interest(interestName); interest.setMustBeFresh(true); interest.setInterestLifetime(6_s); // The default is 4 seconds std::cout << "Sending Interest " << interest << std::endl; m_face.expressInterest(interest, std::bind(&Consumer::onData, this, _1, _2), std::bind(&Consumer::onNack, this, _1, _2), std::bind(&Consumer::onTimeout, this, _1)); // processEvents will block until the requested data is received or a timeout occurs m_face.processEvents(); } private: void onData(const Interest&, const Data& data) { std::cout << "Received Data " << data << std::endl; m_validator.validate(data, [] (const Data&) { std::cout << "Data conforms to trust schema" << std::endl; }, [] (const Data&, const security::ValidationError& error) { std::cout << "Error authenticating data: " << error << std::endl; }); } void onNack(const Interest&, const lp::Nack& nack) const { std::cout << "Received Nack with reason " << nack.getReason() << std::endl; } void onTimeout(const Interest& interest) const { std::cout << "Timeout for " << interest << std::endl; } private: Face m_face; ValidatorConfig m_validator{m_face}; }; } // namespace examples } // namespace ndn int main(int argc, char** argv) { try { ndn::examples::Consumer consumer; consumer.run(); return 0; } catch (const std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } ``` -------------------------------- ### Variable Initialization Example Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Variables should be initialized where they are declared. If initialization is impossible at declaration, leave them uninitialized rather than using a phony value. ```c++ int x, y, z; getCenter(&x, &y, &z); ``` -------------------------------- ### PIB Deletion Command Example Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-client.conf.md This command shows how to remove the default PIB storage directory when changing PIB schemes. ```bash rm -rf ~/.ndn/ndnsec-* ``` -------------------------------- ### NDN_LOG Order of Operations Example Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-log.md Illustrates the correct order for specifying loglevel assignments in NDN_LOG to avoid overwriting specific settings with general ones. ```shell export NDN_LOG="*=INFO:ndn.*=ERROR:ndn.UnixTransport=TRACE" ``` -------------------------------- ### Enable ndn-cxx Logging with NDN_LOG Source: https://github.com/named-data/ndn-cxx/blob/master/docs/release-notes/release-notes-0.5.0.md Set the NDN_LOG environment variable to enable logging for specific modules at a chosen level. This example enables TRACE level logging for the ndn.mgmt.Dispatcher module. ```shell export NDN_LOG=ndn.mgmt.Dispatcher=TRACE ``` -------------------------------- ### Import Certificate and Private Key from File Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-import.md Import a certificate and private key from the specified file. The command will prompt for a passphrase if not provided via the -P option. ```none $ ndnsec import alice.ndnkey ``` -------------------------------- ### Update Shared Library Cache on Linux Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Updates the dynamic linker cache on Linux after installing shared libraries. ```shell sudo ldconfig ``` -------------------------------- ### Variable Names in C++ Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Variable names must be in English, use mixed case, and start with a lowercase letter. ```c++ MyClass myClass; Line line; SavingsAccount savingsAccount; int theAnswerToLifeTheUniverseAndEverything; ``` -------------------------------- ### Enumeration Constant Naming Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Prefix enumeration constants with a common type name for clarity. For example, 'COLOR_RED', 'COLOR_GREEN', 'COLOR_BLUE'. ```c++ enum Color { COLOR_RED, COLOR_GREEN, COLOR_BLUE }; ``` -------------------------------- ### Type Names in C++ Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Names representing types must be in English, use mixed case, and start with an uppercase letter. ```c++ class MyClass; class Line; class SavingsAccount; ``` -------------------------------- ### Complement Name Pairs Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Use complement names for symmetric operations to reduce complexity. Examples include get/set, add/remove, create/destroy. ```none get/set, add/remove, create/destroy, start/stop, insert/erase, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous (and commonly used next/prev), open/close, show/hide, suspend/resume, etc. The pair `insert/erase` is preferred. `insert/delete` can also be used if it does not conflict with the `delete` keyword of C++. ``` -------------------------------- ### Run NetworkMonitor Integration Test Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Execute the network-monitor integration test binary to observe initial interface and address enumeration. ```shell # sudo not required ./build/tests/integration/network-monitor ``` -------------------------------- ### List Initialization Styles Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Various ways to use list initialization for objects and types. ```c++ T object{arg1, arg2}; ``` ```c++ T{arg1, arg2}; ``` ```c++ new T{arg1, arg2}; ``` ```c++ return {arg1, arg2}; ``` ```c++ function({arg1, arg2}, otherArgument); ``` ```c++ object[{arg1, arg2}]; ``` ```c++ T({arg1, arg2}) ``` ```c++ T object = {arg1, arg2}; ``` ```c++ class Class { private: T m_member{arg1, arg2}; static T s_member = {arg1, arg2}; }; ``` ```c++ T object{}; ``` ```c++ T object = {}; ``` -------------------------------- ### Build ndn-cxx Documentation Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Commands to build different sets of documentation, including tutorials, API docs, or a full set. ```shell # Full set of documentation (tutorials + API) in build/docs ./waf docs # Only tutorials in build/docs ./waf sphinx # Only API docs in build/docs/doxygen ./waf doxygen ``` -------------------------------- ### Development Build Configuration for ndn-cxx Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Perform a development build with debug flags and tests enabled. This includes the standard build and install steps. ```shell ./waf configure --debug --with-tests ./waf sudo ./waf install sudo ldconfig # on Linux only ``` -------------------------------- ### Name Filter: NDN Regular Expression Source: https://github.com/named-data/ndn-cxx/blob/master/docs/tutorials/security-validator-config.md Captures packets whose names match the provided NDN regular expression. This example captures all certificates. ```none filter { type name regex ^<>*<><><> } ``` -------------------------------- ### Constructor Initialization List Style Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Format for initializing class variables in a constructor. ```c++ SomeClass::SomeClass(int value, const std::string& string) : m_value(value) , m_string(string) ... { } ``` -------------------------------- ### Run All Unit Tests Source: https://github.com/named-data/ndn-cxx/blob/master/README-dev.md Execute all compiled unit tests by running the test binary without parameters. ```shell ./build/unit-tests ``` -------------------------------- ### Configure ndn-cxx for Static Library Build Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Configures the build system to enable the static variant of the ndn-cxx library. ```shell ./waf configure --enable-static ``` -------------------------------- ### Method and Function Names in C++ Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Method and function names must be commands starting with a verb and use mixed case, beginning with a lowercase letter. ```c++ std::string getName() { ... } double computeTotalWidth() { ... } ``` -------------------------------- ### Linux: Simulate Cable Plugged In and Monitor State Changes Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Simulate plugging an ethernet cable back in on Linux and observe the 'onStateChanged' events indicating a 'running' state. This tests the recovery from a 'no-carrier' state. ```shell eth0: onStateChanged no-carrier -> running nmtest0: onStateChanged no-carrier -> running ``` -------------------------------- ### Configure ndn-cxx with Disabled Debug Symbols Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Override default compiler flags to disable debug symbols and specify installation paths for the library and configuration files. ```shell CXXFLAGS="-O2" ./waf configure --prefix=/usr --sysconfdir=/etc ./waf sudo ./waf install ``` -------------------------------- ### Running Applications with sudo and NDN_LOG Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndn-log.md Demonstrates the correct methods for setting the NDN_LOG environment variable when running an application with sudo privileges. ```shell # Correct sudo env NDN_LOG=logLevel ./ndn-application ``` ```shell # Also correct sudo -s export NDN_LOG=logLevel ./ndn-application ``` -------------------------------- ### Exception Class Naming Convention Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Exceptions can be suffixed with 'Exception' or 'Error'. Declare exception classes as nested types within the class that throws them. For example, 'Foo::Error'. ```c++ #include class Foo { public: class Error : public std::runtime_error { public: // You can inherit constructors from std::runtime_error like this: using std::runtime_error::runtime_error; // Additional constructors, if desired, can be declared as usual: Error(const std::string& what, const std::exception& inner) : std::runtime_error(what + ": " + inner.what()) { } }; }; ``` -------------------------------- ### Linux: Add VLAN Interface and Monitor Events Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Simulate adding a VLAN interface on Linux and observe the 'onInterfaceAdded' event. This is useful for testing interface detection. ```shell sudo ip link add link eth0 name nmtest0 type vlan id 42 ``` -------------------------------- ### Avoid Type References in Variable Names Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Do not include variable type information in names (avoid Hungarian notation). For example, use 'Line* line;' instead of 'Line* pLine;' or 'Line* linePtr;'. ```c++ Line* line; // NOT: Line* pLine; // NOT: Line* linePtr; size_t nPoints; // NOT lnPoints char* name; // NOT szName ``` -------------------------------- ### Linux: Bring Interface Up and Monitor State Changes Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Bring a VLAN interface up on Linux and observe the 'onStateChanged' event. This tests the detection of interface state transitions. ```shell sudo ip link set dev nmtest0 up ``` -------------------------------- ### Header Guard Example Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md Header files must include a header guard to prevent multiple inclusions. The macro name should reflect the file path relative to the source tree and be prefixed with the application/library name. ```c++ #ifndef APP_MODULE_CLASS_NAME_HPP #define APP_MODULE_CLASS_NAME_HPP ... #endif // APP_MODULE_CLASS_NAME_HPP ``` -------------------------------- ### Configure Logging with NDN_LOG Environment Variable Source: https://github.com/named-data/ndn-cxx/blob/master/docs/release-notes/release-notes-0.6.0.md Set the NDN_LOG environment variable to control logging levels and modules. Examples show setting global logging to ALL, specific modules to ALL, or different levels for different modules. ```sh export NDN_LOG="*=ALL" ``` ```sh export NDN_LOG="ndn.*=ALL" ``` ```sh export NDN_LOG="ndn.security=DEBUG:ndn.TcpTransport=ALL" ``` -------------------------------- ### C++ Header and Source File Naming Source: https://github.com/named-data/ndn-cxx/blob/master/docs/code-style.md C++ header files should use the .hpp extension, and source files should use the .cpp extension. File names should be all lowercase, with words separated by dashes. Class names should match file names. ```none my-class.hpp my-class.cpp ``` -------------------------------- ### Trivial Producer Application Source: https://github.com/named-data/ndn-cxx/blob/master/docs/examples.md This C++ code implements a basic producer that listens for Interests, creates Data packets with content, signs them using the KeyChain, and sends them back. It requires setting up an Interest filter and processing events. Ensure keys and certificates are properly configured for signing. ```C++ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * Copyright (c) 2013-2023 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * * ndn-cxx library is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received copies of the GNU General Public License and GNU Lesser * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see * . * * See AUTHORS.md for complete list of ndn-cxx authors and contributors. */ #include #include #include #include // Enclosing code in ndn simplifies coding (can also use `using namespace ndn`) namespace ndn { // Additional nested namespaces should be used to prevent/limit name conflicts namespace examples { class Producer { public: void run() { m_face.setInterestFilter("/example/testApp/randomData", std::bind(&Producer::onInterest, this, _2), nullptr, // RegisterPrefixSuccessCallback is optional std::bind(&Producer::onRegisterFailed, this, _1, _2)); auto cert = m_keyChain.getPib().getDefaultIdentity().getDefaultKey().getDefaultCertificate(); m_certServeHandle = m_face.setInterestFilter(security::extractIdentityFromCertName(cert.getName()), [this, cert] (auto&&...) { m_face.put(cert); }, std::bind(&Producer::onRegisterFailed, this, _1, _2)); m_face.processEvents(); } private: void onInterest(const Interest& interest) { std::cout << ">> I: " << interest << std::endl; // Create Data packet auto data = std::make_shared(); data->setName(interest.getName()); data->setFreshnessPeriod(10_s); data->setContent("Hello, world!"); // In order for the consumer application to be able to validate the packet, you need to setup // the following keys: // 1. Generate example trust anchor // // ndnsec key-gen /example // ndnsec cert-dump -i /example > example-trust-anchor.cert // // 2. Create a key for the producer and sign it with the example trust anchor // // ndnsec key-gen /example/testApp // ndnsec sign-req /example/testApp | ndnsec cert-gen -s /example -i example | ndnsec cert-install - // Sign Data packet with default identity m_keyChain.sign(*data); // m_keyChain.sign(*data, signingByIdentity()); // m_keyChain.sign(*data, signingByKey()); // m_keyChain.sign(*data, signingByCertificate()); // m_keyChain.sign(*data, signingWithSha256()); // Return Data packet to the requester std::cout << "<< D: " << *data << std::endl; m_face.put(*data); } void onRegisterFailed(const Name& prefix, const std::string& reason) { std::cerr << "ERROR: Failed to register prefix '" << prefix << "' with the local forwarder (" << reason << ")\n"; m_face.shutdown(); } private: Face m_face; KeyChain m_keyChain; ScopedRegisteredPrefixHandle m_certServeHandle; }; } // namespace examples } // namespace ndn int main(int argc, char** argv) { try { ndn::examples::Producer producer; producer.run(); return 0; } catch (const std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; return 1; } } ``` -------------------------------- ### Display Identity, Key, and Certificate Names Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-list.md Displays all identity, key, and certificate names in the PIB. An asterisk denotes the default certificate for each key. ```none $ ndnsec list -c * /ndn/edu/ucla/cs/yingdi +->* /ndn/edu/ucla/cs/yingdi/ksk-1397247318867 +->* /ndn/edu/ucla/cs/yingdi/KEY/ksk-1397247318867/ID-CERT/%00%00%01ERn%1B%BE +-> /ndn/edu/ucla/cs/yingdi/ksk-1393811874052 +->* /ndn/edu/ucla/cs/yingdi/KEY/ksk-1393811874052/ID-CERT/%FD%01D%85%A9a%DD /ndn/test/cathy +->* /ndn/test/cathy/ksk-1394129695418 +->* /ndn/test/KEY/cathy/ksk-1394129695418/ID-CERT/%FD%01D%98%9A%F3J /ndn/test/bob +->* /ndn/test/bob/ksk-1394129695308 +->* /ndn/test/KEY/bob/ksk-1394129695308/ID-CERT/%FD%01D%98%9A%F2%AE /ndn/test/alice +->* /ndn/test/alice/ksk-1394129695025 +->* /ndn/test/KEY/alice/ksk-1394129695025/ID-CERT/%FD%01D%98%9A%F2%3F ``` -------------------------------- ### macOS: Create VLAN Interface and Monitor Events Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Create a VLAN interface on macOS using 'ifconfig' and observe the 'onInterfaceAdded' event. This tests VLAN interface creation detection. ```shell sudo ifconfig vlan1 create ``` -------------------------------- ### macOS: Simulate Cable Plugged In and Monitor State Changes Source: https://github.com/named-data/ndn-cxx/blob/master/tests/integration/network-monitor.README.md Simulate plugging an ethernet cable back in on macOS and observe the 'onStateChanged' event indicating a 'running' state. This tests the recovery from a 'down' state on macOS. ```shell en6: onStateChanged down -> running ``` -------------------------------- ### Configure ndn-cxx for Static-Only Build Source: https://github.com/named-data/ndn-cxx/blob/master/docs/INSTALL.md Configures the build system to build only the static variant of the ndn-cxx library. ```shell ./waf configure --enable-static --disable-shared ``` -------------------------------- ### Set Default Certificate for Key Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-set-default.md Sets a specific certificate as the default for a key. The provided name must refer to an existing certificate. ```bash $ ndnsec set-default -c /ndn/test/KEY/alice/ksk-1394129695025/ID-CERT/%FD%01D%98%9A%F2%3F ``` -------------------------------- ### Run Test Cases Across Suites Source: https://github.com/named-data/ndn-cxx/blob/master/README-dev.md Execute test cases with a common name, such as 'Basic', across all available test suites. ```shell ./build/unit-tests -t */Basic ``` -------------------------------- ### Show Test Progress Bar Source: https://github.com/named-data/ndn-cxx/blob/master/README-dev.md Enable a progress bar to visualize the execution status of tests. ```shell ./build/unit-tests -p ``` -------------------------------- ### Print Root Certificate in Human-Readable Format Source: https://github.com/named-data/ndn-cxx/blob/master/docs/manpages/ndnsec-cert-dump.md Fetches the NDN testbed root certificate using curl and prints it in a human-readable format using ndnsec cert-dump. The certificate is read from standard input. ```none $ curl -A ndnsec -fsLS https://named-data.net/ndnsec/ndn-testbed-root.ndncert.x3.base64 | ndnsec cert-dump -fp - Certificate Name: /ndn/KEY/%EC%F1L%8EQ%23%15%E0/ndn/%FD%00%00%01u%E6%7F2%10 Additional Description: fullname: NDN Testbed Root X3 Public Key: Key Type: 256-bit EC MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGx+3Y4FvYo1eScIvgD74lQhQdzN4 zq021dop8t7kGfEpfGdKf2HGpnn4/qoF9iJ1yUZE/7Na8zzO4xT6RpIM0Q== Validity: Not Before: 2020-11-20T16:31:37 Not After: 2024-12-31T23:59:59 Signature Information: Signature Type: SignatureSha256WithEcdsa Key Locator: Name=/ndn/KEY/%EC%F1L%8EQ%23%15%E0 Self-Signed: yes ```