Using Client Libraries with NDNx vs NDNx-TLV vs NFD » History » Version 1
Anonymous, 10/13/2014 11:01 AM
1 | 1 | Anonymous | |
---|---|---|---|
2 | Background |
||
3 | ========== |
||
4 | |||
5 | The NDN project is transitioning both the packet format for NDN and the forwarder codebase. To support comparison, testing, and transition of existing code, the NDN-CPP library supports both wire formats and both forwarders (in certain combinations described below). Support for NDNx and the ndnb wire format is deprecated and may be removed as early as Fall 2014, so we encourage all new applications to be written for the TLV wire format and NFD forwarder. |
||
6 | |||
7 | This document currently covers C++ language support of the Common Client Library (NDN-CPP) only, but will be updated to describe Python, Javascript, and Java libraries as well, which have more limited support for multiple wire formats and forwarders. |
||
8 | |||
9 | Using ndn-cpp with NDNx vs. NDNx-TLV vs. NFD |
||
10 | ============================================ |
||
11 | |||
12 | [ndn-cpp](https://github.com/named-data/ndn-cpp) is an NDN client library for C++. This document explains how it can be used with any of the three NDN forwarders [NDNx](https://github.com/named-data/ndnx), [NDNx-TLV](https://github.com/named-data/ndnd-tlv) and [NFD](https://github.com/named-data/NFD). (This assumes you have installed the latest ndn-cpp which can work with all the forwarders and wire formats.) |
||
13 | |||
14 | Each forwarder has different support for the wire format of [ndnb (Binary XML)](http://named-data.net/doc/0.1/technical/BinaryEncoding.html) vs. [TLV (type-length-value)](http://named-data.net/doc/ndn-tlv/). Also, each forwarder has different requirements for a registerPrefix signed command interest (see "Using registerPrefix with NFD" below). |
||
15 | |||
16 | Forwarder | ndnb (Binary XML) wire format? | TLV wire format? | registerPrefix signed command interest? |
||
17 | ---------- | ------------------------------ | ---------------- | --------------------------------------- |
||
18 | NDNx | ✓ | | no |
||
19 | NDNx-TLV | ✓ | ✓ | no |
||
20 | NFD | | ✓ | YES |
||
21 | |||
22 | # Writing your application based on the forwarder |
||
23 | |||
24 | ## Setting the ndnb wire format (for NDNx) |
||
25 | |||
26 | ndn-cpp will accept an interest or data packet in either ndnb or TLV. By default, ndn-cpp sends an interest or data packet in the TLV wire format. If your application connects to NDNx-TLV or NFD, you do not need to change your code. |
||
27 | |||
28 | However, if your application connects to NDNx, you need to use ndnb (Binary XML). There are two ways to use the ndnb (Binary XML) wire format. At the beginning of your application code, you can set the default wire format: |
||
29 | |||
30 | #include <ndn-cpp/encoding/binary-xml-wire-format.hpp> |
||
31 | ... |
||
32 | WireFormat::setDefaultWireFormat(BinaryXmlWireFormat::get()); |
||
33 | |||
34 | Alternatively, when you use ./configure to build the ndn-cpp library, you can set the default wire format to ndnb (Binary XML): |
||
35 | |||
36 | ./configure --enable-binary-xml=yes |
||
37 | |||
38 | ## Using registerPrefix with NFD |
||
39 | |||
40 | If you only have a consumer application which sends an interest and receives a data packet, and you connect to NDNx, then you only need to follow "Setting the ndnb wire format" above. If you have a publisher application which needs to receive an interest, then it needs to register a prefix with the forwarder. If your application connects to NDNx or NDNx-TLV, you don't need to change your code because the forwarder will accept the self-signed request which is sent by registerPrefix. |
||
41 | |||
42 | However, if your publisher application connects to NFD, it needs to send a signed command interest which is trusted by the forwarder. When you install NFD, it installs a default signing key on your system. For registerPrefix to create a signed command interest using this default signing key, your application needs to use the [default KeyChain constructor](http://named-data.net/doc/ndn-ccl-api/key-chain.html#keychain-constructor) and call [setCommandSigningInfo](http://named-data.net/doc/ndn-ccl-api/face.html#face-setcommandsigninginfo-method) so that the Face can sign the command interest created by [registerPrefix](http://named-data.net/doc/ndn-ccl-api/face.html#face-registerprefix-method): |
||
43 | |||
44 | Face face("localhost"); |
||
45 | KeyChain keyChain; |
||
46 | face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName()); |
||
47 | |||
48 | (See the example application [test-publish-async-nfd](https://github.com/named-data/ndn-cpp/blob/master/tests/test-publish-async-nfd.cpp) .) Note that the default KeyChain constructor will only succeed if NFD has installed the default signing key. If your system only has NDNx or NDNx-TLV, then the default KeyChain constructor will fail. In this case, you should use a KeyChain with a MemoryPrivateKeyStorage as shown in the example application [test-publish-async-ndnx](https://github.com/named-data/ndn-cpp/blob/master/tests/test-publish-async-ndnx.cpp). |
||
49 | |||
50 | # Details |
||
51 | |||
52 | The above should let you make your application work with the different forwarders. Here are the details of how the ndn-cpp library interacts with the different wire formats and protocols. |
||
53 | |||
54 | ## Receiving a packet |
||
55 | |||
56 | When the library receives a data packet, it checks the first byte. If the first byte is 5 (Interest type code), 6 (Data type code) or 0x80, then it decodes the packet as TLV. Otherwise, it decodes it as ndnb (Binary XML). Therefore, you don't have to configure the library for receiving a packet since it automatically handles both TLV and ndnb. |
||
57 | |||
58 | ## Sending a register prefix command |
||
59 | |||
60 | For register prefix, NFD uses a signed commmand interest which has a different format than the register prefix message for NDNx and NDNx-TLV. As explained above, to use registerPrefix with NFD, your application must first call setCommandSigningInfo. Therefore, if your application has not called setCommandSigningInfo then the library assumes that you are connected to NDNx or NDNx-TLV and registerPrefix simply sends a self-signed request in the NDNx format, signing with a hard-wired private key. (NDNx only verifies the signature on the register prefix message using the public key in the message.) In this message, the internal ForwardingEntry and Data packet payload are encoded as ndnb (Binary XML) regardless of the supplied wire format. The outer register prefix interest packet is encoded using the supplied wire format, which is OK because NDNx-TLV will re-encode as ndnb if needed before processing. |
||
61 | |||
62 | However, if your application has called setCommandSigningInfo then registerPrefix uses the info to send a signed command command interest in the NFD format. If your application is connected to NFD then register prefix should succeed. But if your application is connected to NDNx or NDNx-TLV, then the forwarder will reject the request. In this case, the library gets an interest timeout and sends a self-signed request in the NDNx format as described above. Therefore, if your application calls setCommandSigningInfo, registerPrefix will work if connected to any of the forwarders. |
||
63 | |||
64 | ## Interest and Data API for TLV vs. ndnb |
||
65 | |||
66 | There are some differences in the Interest and Data packet wire format for TLV vs. ndnb (Binary XML), but the library uses one Interest class and one Data class to support both wire formats. Here are the details on how the API for ndnb (Binary XML) was changed to support TLV. |
||
67 | |||
68 | * In MetaInfo, added get/setFreshnessPeriod. Deprecated get/setFreshnessSeconds. (This is simple factor of 1000 since FreshnessPeriod is milliseconds.) |
||
69 | * In Interest, added get/setMustBeFresh. Deprecated get/setAnswerOriginKind. Internally, use the inverse of the ANSWER_STALE bit of answerOriginKind. When encoding TLV, give an error if other bits are set. |
||
70 | * In the Interest constructor, set MustBeFresh true by default so that it has the same semantics as the default ANSWER_STALE = 0. |
||
71 | * In Interest, added KeyLocator. Deprecated get/setPublisherPublicKeyDigest. |
||
72 | |||
73 | Here is how the fields of the Interest and Data object are treated when encoding as TLV instead of ndnb (Binary XML): |
||
74 | |||
75 | ### Interest |
||
76 | |||
77 | Field | Treatment if encoding as TLV instead of ndnb (Binary XML) |
||
78 | ---------------------------- | --------------------------------------------------------- |
||
79 | name | same |
||
80 | minSuffixComponents | same |
||
81 | maxSuffixComponents | same |
||
82 | publisherPublicKeyDigest | Deprecated. If the interest needs a publisher public key digest, the keyLocator type is ndn_KeyLocatorType_KEY_LOCATOR_DIGEST. |
||
83 | KeyLocator | if KeyLocator is specified and keyLocatorType is KEYNAME or PUBLISHER_PUBLIC_KEY_DIGEST, use it. Otherwise error. |
||
84 | exclude | same |
||
85 | childSelector | same |
||
86 | answerOriginKind | Set MustBeFresh based on answerOriginKind ANSWER_STALE bit. Error if other anwerOriginKind bits are set. |
||
87 | scope | same |
||
88 | interestLifetimeMilliseconds | same |
||
89 | nonce | If none or < 4 bytes, generate new random nonce bytes before issuing the interest. If > 4 bytes, truncate to 4. Deprecate setNonce in the API. Allow getNonce to show the nonce of an incoming Interest. If any Interest fields are changed, clear the nonce. |
||
90 | |||
91 | ### Data |
||
92 | |||
93 | Field | Treatment if encoding as TLV instead of ndnb (Binary XML) |
||
94 | ------------------------ | --------------------------------------------------------- |
||
95 | name | same |
||
96 | content | same |
||
97 | MetaInfo.type | Require BLOB, LINK or KEY, otherwise error. |
||
98 | MetaInfo.freshnessPeriod | same |
||
99 | MetaInfo.timestamp | ignore |
||
100 | MetaInfo.finalBlockID | same |
||
101 | Signature.keyLocator | if KeyLocator is specified and keyLocatorType is KEYNAME or PUBLISHER_PUBLIC_KEY_DIGEST, use it. Otherwise error. |
||
102 | Signature.signatureBits | same |
||
103 | Signature.witness | ignore. Deprecated get/setWitness. |