NFD的环境配置是个“有趣的探索”!这么多篇install.md,我TM要看哪一个?不论哪一个都缺失依赖库好嘛T^T被折腾了将近一个月,貌似找到一篇还比较靠谱的安装说明,再加上万能的谷歌和stackoverflow,目前配环境的速度越来越快了~~对于一个天天写bug,随时需要重装系统的人来说,配置环境可是一个很重要的一项基本技能好嘛!!!
Step-By-Step - Common Client Libraries
This document shows step-by-step how to get a minimal NFD running so you can start writing applications to use the NDN Common Client Libraries (NDN-CPP, NDN-JS, PyNDN, jNDN).
Prerequisites
Ubuntu 12.04
In a terminal, enter:
Ubuntu 13.10, Ubuntu 14.04 and Ubuntu 15.04
In a terminal, enter:
If you are 64-bit, you must also install libstdc++6:i386 use the command: sudo apt-get install libstdc++6:i386, or you will get the following errors: when you successfully install nfd, and use the commond "nfd-start", you will see "/usr/local/bin/ndnsec: error while loading shared libraries: libndn-cxx.so.0.4.1: cannot open shared object file : no such file or directory". If you have installed this library, you still can't solve this problem, you may still have to install lib32z1 : sudo apt-get install lib32z1.
假如还是没有办法解决的话,那就是“no such file or directory”的原因了:建立软连接sudo ln -s /usr/local/lib/libndn-cxx.so.0.4.1 /usr/lib/
肘子在这里可是卡了很久很久啊~说出来都是泪啊~
Attention: This step is very import to solve the dependent libraries for ndn-cxx and nfd.
Build/Install NFD
These are steps from build/install NFD which work with the CCL. In a terminal, enter:
If waf says "program doxygen not found", "program sphinx-build not found" or "library rt not found", it is OK.
If waf says "libndn-cxx not found", then set PKG_CONFIG_PATH
as shown in the Prerequisites above.
The NFD programs are installed in /usr/local/bin
. The NFD configuration file is in /usr/local/etc/ndn
. Copy the sample configuration file to make it the default:
Ubuntu and Raspbian (Raspberry Pi)
[Ubuntu and Raspbian only] Update the path to the shared libraries:
Configure NFD
NFD provides mechanisms to enable strict authorization for all management commands. In particular, one can authorize only a specific public key to create new Faces or to change the strategy choice for specific namespaces. For more information about how to generate a private/public key pair, generate a self-signed certificate, and use this self-signed certificate to authorize NFD management commands, refer to NFD Configuration Tips.
In the sample configuration file, all authorization is disabled, effectively allowing anybody on the local machine to issue NFD management commands. The sample file is intended only for demo purposes and MUST NOT be used in a production environment.
Start NFD
Open a new terminal window (so you can watch the NFD messages) and enter:
On OS X it may ask for your keychain password or ask "nfd wants to sign using key in your keychain." Enter your keychain password and click Always Allow.
Later, you can stop NFD with nfd-stop
.
Add a route to another NFD host (optional)
The previous instructions are good for testing on the local host. If you want to route an interest to another NFD host, in a terminal enter:
where <other host>
is the name or IP address of the other host (e.g., spurs.cs.ucla.edu
). The "/ndn" means that NFD will forward all interests that start with /ndn
through the face to the other host. If you only want to forward interests with a certain prefix then use it instead of "/ndn".
This only forwards interests to the other host, but there is no "back route" for the other host to forward interests to you. For that, you must go to the other host and use nfdc
to add the route. (The "back route" can also be automatically configured with nfd-autoreg
. For more information refer to nfd-autoreg manpage.)
Install the Common Client Library
If you haven't done so, get the library from GitHub and follow the INSTALL instructions for your language:
- C++: NDN-CPP (INSTALL instructions)
- Python: PyNDN2 (INSTALL instructions)
- JavaScript: NDN-JS (INSTALL instructions)
- JavaScript: jNDN (INSTALL instructions)
Send an Interest to receive a Data packet
The example program "test get async" is a simple program to send some interests and get a data packet. Here they are on the various languages:
- C++:
test-get-async.cpp
- Python:
test_get_async.py
- JavaScript (browser):
test-get-async.html
- JavaScript (node):
fetch.js
- Java:
TestGetAsync.java
The main calls to the API are (using Python for example):
Call the Face constructor and specify the host.
Create a Name for the Interest, using a Name URI.
Call expressInterest, passing in the callbacks for onData and onTimeout.
Start an event loop to keep calling processEvents until the application is finished. Your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).