Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 1 | # ndn-cxx examples |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 2 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 3 | By default, the examples in `examples/` folder are not built. To enable them, use |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 4 | `--with-examples` configure option. For example: |
| 5 | |
| 6 | ./waf configure --with-examples |
| 7 | ./waf |
| 8 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 9 | There are two ways to add new examples, depending on their complexity. |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 10 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 11 | 1. **Examples with a single translation unit** |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 12 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 13 | For simple examples that have a single translation unit, the `.cpp` file can be directly put |
| 14 | in the `examples/` folder and it will be automatically compiled on the next run of `./waf`. |
| 15 | The name of the compiled executable will be determined by the base name of the `.cpp` file. |
| 16 | For instance, `examples/foo.cpp` will be compiled into an executable named `foo` inside the |
| 17 | `build/examples` folder: |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 19 | echo 'int main() { return 0; }' > examples/foo.cpp |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 20 | ./waf |
| 21 | # ... Compiling examples/foo.cpp |
| 22 | # ... Linking build/examples/foo |
| 23 | |
| 24 | # To run the example |
| 25 | ./build/examples/foo |
| 26 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 27 | 2. **Examples with multiple translation units** |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 29 | For more complex examples that contain multiple translation units, one can use |
| 30 | the following directory structure: |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 32 | - Create a directory under the `examples/` folder (e.g., `examples/bar`). The name of this |
| 33 | directory will determine the name of the compiled executable (`build/examples/bar/bar`). |
| 34 | - Place any number of translation units (e.g., `examples/bar/a.cpp`, `examples/bar/b.cpp`, |
| 35 | ...) in this directory. All `.cpp` files in this directory will be compiled and linked |
| 36 | together to produce the binary executable of the example. One of the .cpp files must |
| 37 | contain the `main()` function. |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 39 | For example: |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 40 | |
| 41 | mkdir examples/bar |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 42 | echo 'int bar(); int main() { return bar(); }' > examples/bar/a.cpp |
| 43 | echo 'int bar() { return 10; }' > examples/bar/b.cpp |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 44 | ./waf |
| 45 | # ... Compiling examples/bar/a.cpp |
| 46 | # ... Compiling examples/bar/b.cpp |
| 47 | # ... Linking build/examples/bar/bar |
| 48 | |
| 49 | # To run the example |
| 50 | ./build/examples/bar/bar |
Alexander Afanasyev | d1b6f95 | 2021-07-13 15:05:43 -0400 | [diff] [blame] | 51 | |
| 52 | ## Security configuration for example apps |
| 53 | |
| 54 | In order for the ``consumer`` example app to be able to properly authenticate data packets |
| 55 | created by the ``producer`` app, you must configure the following parameters. |
| 56 | |
| 57 | 1. Generate example trust anchor: |
| 58 | |
| 59 | ndnsec key-gen /example |
| 60 | ndnsec cert-dump -i /example > example-trust-anchor.cert |
| 61 | |
| 62 | 2. Create a key for the producer and sign it with the example trust anchor: |
| 63 | |
| 64 | ndnsec key-gen /example/testApp |
| 65 | ndnsec sign-req /example/testApp | ndnsec cert-gen -s /example -i example | ndnsec cert-install - |