Face Class¶
A Face provides the top-level interface to the library. It holds a connection to a forwarder and supports interest / data exchange.
[C++]: | #include <ndn-cpp/face.hpp> Namespace:
ndn |
---|---|
[Python]: | Module: pyndn |
[Java]: | Package: net.named_data.jndn |
Face Constructors¶
Face Constructor (explicit Transport)¶
Create a new Face object with the given Transport to manage NDN communication.
[C++]: | Face(
const ptr_lib::shared_ptr<Transport>& transport,
const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo
);
|
---|---|
[Python]: | def __init__(self,
transport, # Transport
connectionInfo # Transport.ConnectionInfo
)
|
[JavaScript]: | var Face = function Face(
transport, // Transport
connectionInfo // Transport.ConnectionInfo
)
|
[Java]: | public Face(
Transport transport,
Transport.ConnectionInfo connectionInfo
)
|
Parameters: |
|
Face Constructor (default Transport)¶
Create a new Face object with optional settings to manage NDN communication.
[C++]: | Face(
[const char* host]
[, unsigned short port]
);
|
---|---|
[Python]: | def __init__(self
[, host # str]
[, port # int]
)
|
[JavaScript]: | var Face = function Face(
[settings // associative array]
)
|
[Java]: | public Face(
[String host]
[, int port]
)
|
Parameters: |
|
Face.expressInterest Methods¶
Face.expressInterest Method (from Interest)¶
Send the interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.
Note
[except JavaScript] Your application must call processEvents. The onData callback is called on the same thread that calls processEvents.
[C++]: | uint64_t expressInterest(
const Interest& interest,
const OnData& onData,
[, const OnTimeout& onTimeout]
[, const OnNetworkNack& onNetworkNack]
);
|
---|---|
[Python]: | # Returns int
def expressInterest(self,
interest, # Interest
onData # function object
[, onTimeout # function object]
[, onNetworkNack # function object]
)
|
[JavaScript]: | // Returns number
Face.prototype.expressInterest = function(
interest // Interest
onData, // function
[, onTimeout // function]
[, onNetworkNack // function]
)
|
[Java]: | public long expressInterest(
Interest interest,
OnData onData,
[, OnTimeout onTimeout]
[, OnNetworkNack onNetworkNack]
)
|
Parameters: |
|
Returns: | The pending interest ID which can be used with removePendingInterest. |
Throw: | Throw an exception if the encoded interest size exceeds getMaxNdnPacketSize(). |
Face.expressInterest Method (from Name)¶
Encode name as an Interest, using the interestTemplate if supplied, send the interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.
Note
[except JavaScript] Your application must call processEvents. The onData callback is called on the same thread that calls processEvents.
[C++]: | uint64_t expressInterest(
const Name& name,
[, const Interest* interestTemplate]
const OnData& onData,
[, const OnTimeout& onTimeout]
[, const OnNetworkNack& onNetworkNack]
);
|
---|---|
[Python]: | # Returns int
def expressInterest(self,
name # Name
[, interestTemplate # Interest]
onData, # function object
[, onTimeout # function object]
[, onNetworkNack # function object]
)
|
[JavaScript]: | // Returns number
Face.prototype.expressInterest = function(
name, // Name
[, interestTemplate // Interest]
onData, // function
[, onTimeout // function]
[, onNetworkNack // function]
)
|
[Java]: | public long expressInterest(
Name name,
[, Interest interestTemplate]
OnData onData,
[, OnTimeout onTimeout]
[, OnNetworkNack onNetworkNack]
)
|
Parameters: |
|
Returns: | The pending interest ID which can be used with removePendingInterest. |
Throw: | Throw an exception if the encoded interest size exceeds getMaxNdnPacketSize(). |
Face.getMaxNdnPacketSize Method¶
This is a static method to get the practical limit of the size of a network-layer packet. If a packet is larger than this, the library or application MAY drop it.
[C++]: | static size_t getMaxNdnPacketSize();
|
---|---|
[Python]: | # Returns int
@staticmethod
def getMaxNdnPacketSize()
|
[JavaScript]: | // Returns number
Face.getMaxNdnPacketSize = function()
|
[Java]: | public static int getMaxNdnPacketSize()
|
Returns: | The maximum NDN packet size. |
Face.isLocal Method¶
Experimental
This method is experimental. The API is not finalized.
Check if the face is local based on the current connection through the Transport. This affects the processing of registerPrefix with NFD: if the NFD is local, registration occurs with the ‘/localhost/nfd/…’ prefix; if non-local, remote prefix registration is attempted using ‘/localhop/nfd/…’ . Some Transport subclasses may cause network I/O (e.g. an IP host name lookup).
[C++]: | bool isLocal();
|
---|---|
[Python]: | # Returns bool
def isLocal()
|
[JavaScript]: | Face.prototype.isLocal = function(
onResult, // function
onError // function
)
|
[Java]: | public boolean isLocal()
|
Parameters: |
|
Returns: | (except JavaScript) True if the face is local, false if not. |
Face.makeCommandInterest Method¶
Experimental
This method is experimental. The API is not finalized.
Append a timestamp component and a random value component to interest’s name. Then use the keyChain and certificateName from setCommandSigningInfo to sign the interest. If the interest lifetime is not set, this sets it.
[C++]: | void makeCommandInterest(
Interest& interest
);
|
---|---|
[Python]: | def makeCommandInterest(self,
interest // Interest
)
|
[JavaScript]: | Face.prototype.makeCommandInterest = function(
interest // Interest
)
|
[Java]: | public void makeCommandInterest(
Interest interest
)
|
Parameters: |
|
Face.processEvents Method¶
[except JavaScript] Process any packets to receive and call callbacks such as onData, onInterest or onTimeout. This returns immediately if there is no data to receive. This blocks while calling the callbacks. You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn’t use 100% of the CPU. Since processEvents modifies the pending interest table, your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).
[C++]: | void processEvents();
|
---|---|
[Python]: | def processEvents(self)
|
[Java]: | public void processEvents()
|
Throw: | This may throw an exception, for example in processing incoming data. If you call this from a main event loop, you should catch and log/dicard exceptions. |
Face.putData Method¶
The onInterest callback calls this to put a Data packet which satisfies an Interest.
[C++]: | void putData(
const Data& data
);
|
---|---|
[Python]: | def putData(self,
data # Data
)
|
[JavaScript]: | Face.prototype.putData = function(
data // Data
)
|
[Java]: | public void putData(
Data data
)
|
Parameters: |
|
Throw: | Throw an exception if the encoded Data packet size exceeds getMaxNdnPacketSize(). |
Face.putNack Method¶
Experimental
This method is an experimental feature, and the API may change.
The OnInterest callback can call this to put a Nack for the received Interest.
[C++]: | void putNack(
const Interest& interest,
const NetworkNack& networkNack
);
|
---|---|
[Python]: | def putNack(self,
interest, # Interest
networkNack # NetworkNack
)
|
[JavaScript]: | Face.prototype.putNack = function(
interest, // Interest
networkNack // NetworkNack
)
|
[Java]: | public void putNack(
Interest interest,
NetworkNack networkNack
)
|
Parameters: |
|
Throw: | Throw an exception if the encoded Data packet size exceeds getMaxNdnPacketSize(). |
Face.registerPrefix Method¶
Register prefix with the connected NDN hub and call onInterest when a matching interest is received. To register a prefix with NFD, you must first call setCommandSigningInfo. This connects to a local or remote forwarder according to isLocal.
Note
[except JavaScript] Your application must call processEvents. The onInterest callback is called on the same thread that calls processEvents.
[C++]: | uint64_t registerPrefix(
const Name &prefix,
const OnInterestCallback &onInterest,
const OnRegisterFailed &onRegisterFailed
[, const OnRegisterSuccess &onRegisterSuccess]
[, const RegistrationOptions& registrationOptions]
)
|
---|---|
[Python]: | # Returns int
def registerPrefix(self,
prefix, # Name
onInterest, # function object
onRegisterFailed # function object
[, onRegisterSuccess # function object]
[, registrationOptions # RegistrationOptions]
)
|
[JavaScript]: | // Returns number
Face.prototype.registerPrefix = function(
prefix, // Name
onInterest, // function
onRegisterFailed // function
[, onRegisterSuccess // function]
[, registrationOptions // RegistrationOptions]
)
|
[Java]: | public long registerPrefix(
Name prefix,
OnInterestCallback onInterest,
OnRegisterFailed onRegisterFailed
[, OnRegisterSuccess onRegisterSuccess]
[, RegistrationOptions registrationOptions]
)
|
Parameters: |
|
Returns: | The registered prefix ID which can be used with removeRegisteredPrefix. |
Face.removePendingInterest Method¶
Remove the pending interest entry with the pendingInterestId from the pending interest table. This does not affect another pending interest with a different pendingInterestId, even if it has the same interest name. If there is no entry with the pendingInterestId, do nothing.
[C++]: | void removePendingInterest(
uint64_t pendingInterestId
);
|
---|---|
[Python]: | def removePendingInterest(self,
pendingInterestId # int
)
|
[JavaScript]: | Face.prototype.removePendingInterest = function(
pendingInterestId // number
)
|
[Java]: | public void removePendingInterest(
long pendingInterestId
)
|
Parameters: |
|
Face.removeRegisteredPrefix Method¶
Remove the registered prefix entry with the registeredPrefixId from the registered prefix table. This does not affect another registered prefix with a different registeredPrefixId, even if it has the same prefix name. If an interest filter was automatically created by registerPrefix, also remove it. If there is no entry with the registeredPrefixId, do nothing.
[C++]: | void removeRegisteredPrefix(
uint64_t registeredPrefixId
);
|
---|---|
[Python]: | def removeRegisteredPrefix(self,
registeredPrefixId # int
)
|
[JavaScript]: | Face.prototype.removeRegisteredPrefix = function(
registeredPrefixId // number
)
|
[Java]: | public void removeRegisteredPrefix(
long registeredPrefixId
)
|
Parameters: |
|
Face.send Method¶
Send the encoded packet out through the face.
[C++]: | void send(
const Blob& encoding
);
void send(
const uint8_t* encoding,
size_t encodingLength
);
|
---|---|
[Python]: | def send(self,
encoding # Blob or an array type with int elements
)
|
[JavaScript]: | Face.prototype.send = function(
encoding // Blob or Buffer
)
|
[Java]: | public void send(
Blob encoding
)
public void send(
ByteBuffer encoding
)
|
Parameters: |
|
Throw: | Throw an exception if the encoded packet size exceeds getMaxNdnPacketSize(). |
Face.setCommandCertificateName Method¶
Set the certificate name used to sign command interest (e.g. for registerPrefix), using the KeyChain that was set with setCommandSigningInfo.
[C++]: | void setCommandCertificateName(
const Name& certificateName
);
|
---|---|
[Python]: | def setCommandCertificateName(self,
certificateName # Name
)
|
[JavaScript]: | Face.prototype.setCommandCertificateName = function(
certificateName // Name
)
|
[Java]: | public void setCommandCertificateName(
Name certificateName
)
|
Parameters: |
|
Face.setCommandSigningInfo Method¶
Set the KeyChain and certificate name used to sign command interests (e.g. for registerPrefix).
[C++]: | void setCommandSigningInfo(
KeyChain& keyChain,
const Name& certificateName
);
|
---|---|
[Python]: | def setCommandSigningInfo(self,
keyChain # KeyChain
certificateName # Name
)
|
[JavaScript]: | Face.prototype.setCommandSigningInfo = function(
keyChain // KeyChain
certificateName // Name
)
|
[Java]: | public void setCommandSigningInfo(
KeyChain keyChain,
Name certificateName
)
|
Parameters: |
|
Face.setInterestFilter Methods¶
Face.setInterestFilter Method (from InterestFilter)¶
Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest. This method only modifies the library’s local callback table and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix.
[C++]: | uint64_t setInterestFilter(
const InterestFilter& filter,
const OnInterestCallback &onInterest
)
|
---|---|
[Python]: | # Returns int
def setInterestFilter(self,
filter, # InterestFilter
onInterest # function object
)
|
[JavaScript]: | // Returns number
Face.prototype.setInterestFilter = function(
filter, // InterestFilter
onInterest // function
)
|
[Java]: | public long setInterestFilter(
InterestFilter filter,
OnInterestCallback onInterest
)
|
Parameters: |
|
Returns: | The interest filter ID which can be used with unsetInterestFilter. |
Face.setInterestFilter Method (from prefix)¶
Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest. This method only modifies the library’s local callback table and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix.
[C++]: | uint64_t setInterestFilter(
const Name &prefix,
const OnInterestCallback &onInterest
)
|
---|---|
[Python]: | # Returns int
def setInterestFilter(self,
prefix, # Name
onInterest # function object
)
|
[JavaScript]: | // Returns number
Face.prototype.setInterestFilter = function(
prefix, // Name
onInterest // function
)
|
[Java]: | public long setInterestFilter(
Name prefix,
OnInterestCallback onInterest
)
|
Parameters: |
|
Returns: | The interest filter ID which can be used with unsetInterestFilter. |
Face.setInterestLoopbackEnabled Method¶
Enable or disable Interest loopback. If Interest loopback is enabled, then an Interest to expressInterest is also sent to each of the matching OnInterest callbacks that the application gave to registerPrefix or setInterestFilter, and a Data that the application gives to putData can satisfy pending Interests. This way one part of an application can do Interest/Data exchange with another part through the same Face. Interest loopback is disabled by default.
[C++]: | void setInterestLoopbackEnabled(
bool interestLoopbackEnabled
);
|
---|---|
[Python]: | def setInterestLoopbackEnabled(self,
interestLoopbackEnabled # bool
)
|
[JavaScript]: | Face.prototype.setInterestLoopbackEnabled = function(
interestLoopbackEnabled // boolean
)
|
[Java]: | public final void setInterestLoopbackEnabled(
boolean interestLoopbackEnabled
)
|
Parameters: |
|
Face.unsetInterestFilter Method¶
Remove the interest filter entry which has the interestFilterId from the interest filter table. This does not affect another interest filter with a different interestFilterId, even if it has the same prefix name. If there is no entry with the interestFilterId, do nothing.
[C++]: | void unsetInterestFilter(
uint64_t interestFilterId
);
|
---|---|
[Python]: | def unsetInterestFilter(self,
interestFilterId # int
)
|
[JavaScript]: | Face.prototype.unsetInterestFilter = function(
interestFilterId // number
)
|
[Java]: | public void unsetInterestFilter(
long interestFilterId
)
|
Parameters: |
|