pyndn package

Subpackages

Submodules

pyndn.control_parameters module

This module defines the ControlParameters class which holds a Name and other fields for a ControlParameters which is used, for example, in the command interest to register a prefix with a forwarder.

class pyndn.control_parameters.ControlParameters(value=None)[source]

Bases: object

clear()[source]
cost

Get the cost value.

Returns:The cost value, or None if not specified.
Return type:int
equals(other)[source]
expirationPeriod

Get the expiration period.

Returns:The expiration period in milliseconds, or None if not specified.
Return type:float
faceId

Get the face ID.

Returns:The face ID, or None if not specified.
Return type:int
forwardingFlags

Get the ForwardingFlags object.

Returns:the ForwardingFlags object.
Return type:ForwardingFlags
getCost()[source]

Get the cost value.

Returns:The cost value, or None if not specified.
Return type:int
getExpirationPeriod()[source]

Get the expiration period.

Returns:The expiration period in milliseconds, or None if not specified.
Return type:float
getFaceId()[source]

Get the face ID.

Returns:The face ID, or None if not specified.
Return type:int
getForwardingFlags()[source]

Get the ForwardingFlags object.

Returns:the ForwardingFlags object.
Return type:ForwardingFlags
getLocalControlFeature()[source]

Get the local control feature value.

Returns:The local control feature value, or None if not specified.
Return type:int
getName()[source]

Get the name.

Returns:The name. If not specified, return None.
Return type:Name
getOrigin()[source]

Get the origin value.

Returns:The origin value, or None if not specified.
Return type:int
getStrategy()[source]

Get the strategy.

Returns:The strategy or an empty Name.
Return type:Name
getUri()[source]

Get the URI.

Returns:The face URI, or an empty string if not specified.
Return type:str
localControlFeature

Get the local control feature value.

Returns:The local control feature value, or None if not specified.
Return type:int
name

Get the name.

Returns:The name. If not specified, return None.
Return type:Name
origin

Get the origin value.

Returns:The origin value, or None if not specified.
Return type:int
setCost(cost)[source]

Set the cost value.

Parameters:cost (int) – The new cost value, or None for not specified.
setExpirationPeriod(expirationPeriod)[source]

Set the expiration period.

Parameters:expirationPeriod (float) – The expiration period in milliseconds, or None for not specified.
setFaceId(faceId)[source]

Set the Face ID.

Parameters:faceId (int) – The new face ID, or None for not specified.
setForwardingFlags(forwardingFlags)[source]

Set the ForwardingFlags object to a copy of forwardingFlags. You can use getForwardingFlags() and change the existing ForwardingFlags object.

Parameters:forwardingFlags (ForwardingFlags) – The new ForwardingFlace object.
setLocalControlFeature(localControlFeature)[source]

Set the local control feature value.

Parameters:localControlFeature (int) – The new local control feature value, or None for not specified.
setName(name)[source]

Set the name.

Parameters:name (Name) – The name. If not specified, set to None. If specified, this makes a copy of the name.
setOrigin(origin)[source]

Set the origin value.

Parameters:origin (int) – The new origin value, or None for not specified.
setStrategy(strategy)[source]

Set the strategy to a copy of the given Name.

Parameters:strategy (Name) – The Name to copy, or an empty Name if not specified.
setUri(uri)[source]

Set the URI.

Parameters:uri (str) – The new uri, or an empty string for not specified.
strategy

Get the strategy.

Returns:The strategy or an empty Name.
Return type:Name
uri

Get the URI.

Returns:The face URI, or an empty string if not specified.
Return type:str
wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this ControlParameters.

Parameters:
  • input (An array type with int elements) – The array with the bytes to decode.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this ControlParameters. If omitted, use WireFormat.getDefaultWireFormat().
wireEncode(wireFormat=None)[source]

Encode this ControlParameters for a particular wire format.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this ControlParameters. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer.
Return type:Blob

pyndn.control_response module

This module defines the ControlResponse class which holds a status code, status text and other fields for a ControlResponse which is used, for example, in the response from sending a register prefix control command to a forwarder. See http://redmine.named-data.net/projects/nfd/wiki/ControlCommand

class pyndn.control_response.ControlResponse(value=None)[source]

Bases: object

Create a new ControlResponse object, possibly copying values from another object.

Parameters:value (ControlResponse) – (optional) If value is a ControlResponse, copy its values. If value is omitted, all values are unspecified.
bodyAsControlParameters

Get the control response body as a ControlParameters.

Returns:The ControlParameters, or None if the body is not specified or if it is not a ControlParameters.
Return type:ControlParameters
clear()[source]
getBodyAsControlParameters()[source]

Get the control response body as a ControlParameters.

Returns:The ControlParameters, or None if the body is not specified or if it is not a ControlParameters.
Return type:ControlParameters
getStatusCode()[source]

Get the status code.

Returns:The status code. If not specified, return None.
Return type:int
getStatusText()[source]

Get the status text.

Returns:The status text. If not specified, return “”.
Return type:str
setBodyAsControlParameters(controlParameters)[source]

Set the control response body as a ControlParameters.

Parameters:controlParameters (ControlParameters) – The ControlParameters for the body. This makes a copy of the ControlParameters. If not specified or if the body is not a ControlParameters, set to None.
Returns:This ControlResponse so that you can chain calls to update values.
Return type:ControlResponse
setStatusCode(statusCode)[source]

Set the status code.

Parameters:statusCode (int) – The status code. If not specified, set to None.
Returns:This ControlResponse so that you can chain calls to update values.
Return type:ControlResponse
setStatusText(statusText)[source]

Set the status text.

Parameters:statusText (str) – The status text. If not specified, set to “”.
Returns:This ControlResponse so that you can chain calls to update values.
Return type:ControlResponse
statusCode

Get the status code.

Returns:The status code. If not specified, return None.
Return type:int
statusText

Get the status text.

Returns:The status text. If not specified, return “”.
Return type:str
wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this ControlResponse.

Parameters:
  • input (An array type with int elements) – The array with the bytes to decode.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this ControlParameters. If omitted, use WireFormat.getDefaultWireFormat().
wireEncode(wireFormat=None)[source]

Encode this ControlResponse for a particular wire format.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this ControlParameters. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer.
Return type:Blob

pyndn.data module

This module defines the NDN Data class.

class pyndn.data.Data(value=None)[source]

Bases: object

content

Get the data packet’s content.

Returns:The content as a Blob, which isNull() if unspecified.
Return type:Blob
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getContent()[source]

Get the data packet’s content.

Returns:The content as a Blob, which isNull() if unspecified.
Return type:Blob
getDefaultWireEncoding()[source]

Return the default wire encoding, which was encoded with getDefaultWireEncodingFormat().

Returns:The default wire encoding, whose isNull() may be true if there is no default wire encoding.
Return type:SignedBlob
getDefaultWireEncodingFormat()[source]

Get the WireFormat which is used by getDefaultWireEncoding().

Returns:The WireFormat, which is only meaningful if the getDefaultWireEncoding() is not isNull().
Return type:WireFormat
getIncomingFaceId()[source]

Get the incoming face ID according to the incoming packet header.

Returns:The incoming face ID. If not specified, return None.
Return type:int
getMetaInfo()[source]

Get the data packet’s meta info.

Returns:The meta info.
Return type:MetaInfo
getName()[source]

Get the data packet’s name.

Returns:The name.
Return type:Name
getSignature()[source]

Get the data packet’s signature object.

Returns:The signature object.
Return type:a subclass of Signature such as Sha256WithRsaSignature
metaInfo

Get the data packet’s meta info.

Returns:The meta info.
Return type:MetaInfo
name

Get the data packet’s name.

Returns:The name.
Return type:Name
setContent(content)[source]

Set the content to the given value.

Parameters:content (A Blob or an array type with int elements) – The array with the content bytes. If content is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
setLpPacket(lpPacket)[source]

An internal library method to set the LpPacket for an incoming packet. The application should not call this.

Parameters:lpPacket (LpPacket) – The LpPacket. This does not make a copy.
Returns:This Data so that you can chain calls to update values.
Return type:Data
Note :This is an experimental feature. This API may change in the future.
setMetaInfo(metaInfo)[source]

Set metaInfo to a copy of the given MetaInfo.

Parameters:metaInfo (MetaInfo) – The MetaInfo which is copied.
Returns:This Data so that you can chain calls to update values.
Return type:Data
setName(name)[source]

Set name to a copy of the given Name.

Parameters:name (Name) – The Name which is copied.
Returns:This Data so that you can chain calls to update values.
Return type:Data
setSignature(signature)[source]

Set the signature to a copy of the given signature.

Parameters:signature (a subclass of Signature such as Sha256WithRsaSignature) – The signature object which is cloned.
Returns:This Data so that you can chain calls to update values.
Return type:Data
signature

Get the data packet’s signature object.

Returns:The signature object.
Return type:a subclass of Signature such as Sha256WithRsaSignature
wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this Data. If wireFormat is the default wire format, also set the defaultWireEncoding to another pointer to the input.

Parameters:
  • input (A Blob or an array type with int elements) – The array with the bytes to decode. If input is not a Blob, then copy the bytes to save the defaultWireEncoding (otherwise take another pointer to the same Blob).
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this Data object. If omitted, use WireFormat.getDefaultWireFormat().
wireEncode(wireFormat=None)[source]

Encode this Data for a particular wire format. If wireFormat is the default wire format, also set the defaultWireEncoding field to the encoded result.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this Data object. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer in a SignedBlob object.
Return type:SignedBlob

pyndn.delegation_set module

This module defines the DelegationSet class which holds a list of DelegationSet.Delegation entries which is used as the content of a Link instance. If you add elements with add(), then the list is a set sorted by preference number then by name. But wireDecode will add the elements from the wire encoding, preserving the given order and possible duplicates (in which case a DelegationSet really holds a “list” and not necessarily a “set”).

class pyndn.delegation_set.DelegationSet(value=None)[source]

Bases: object

Create a new DelegationSet object, possibly copying values from another object.

Parameters:value (DelegationSet) – (optional) If value is a DelegationSet, copy its values.
class Delegation(preference, name)[source]

Bases: object

A DelegationSet.Delegation holds a preference number and delegation name. Create a new DelegationSet.Delegation with the given values.

Parameters:
  • preference (int) – The preference number.
  • name (Name) – The delegation name. This makes a copy of the name.
compare(other)[source]

Compare this Delegation with other according to the ordering, based first on the preference number, then on the delegation name.

Parameters:other (DelegationSet.Delegation) – The other Delegation to compare with.
Returns:0 If they compare equal, -1 if this Delegation comes before other in the ordering, or 1 if this Delegation comes after.
Return type:int
getName()[source]

Get the delegation name.

Returns:The delegation name. NOTE: You must not change the name object - if you need to change it then make a copy.
Return type:Name
getPreference()[source]

Get the preference number.

Returns:The preference number.
Return type:int
DelegationSet.add(preference, name)[source]

Add a new DelegationSet.Delegation to the list of delegations, sorted by preference number then by name. If there is already a delegation with the same name, update its preference, and remove any extra delegations with the same name.

Parameters:
  • preference (int) – The preference number.
  • name (Name) – The delegation name. This makes a copy of the name.
DelegationSet.addUnsorted(preference, name)[source]

Add a new DelegationSet.Delegation to the end of the list of delegations, without sorting or updating any existing entries. This is useful for adding preferences from a wire encoding, preserving the supplied ordering and possible duplicates.

Parameters:
  • preference (int) – The preference number.
  • name (Name) – The delegation name. This makes a copy of the name.
DelegationSet.clear()[source]

Clear the list of delegations.

DelegationSet.find(name)[source]

Find the first delegation with the given name and return its index.

Parameters:name (Name) – Then name of the delegation to find.
Returns:The index of the delegation, or -1 if not found.
Return type:int
DelegationSet.get(i)[source]

Get the delegation at the given index, according to the ordering described in add().

Parameters:i (int) – The index of the component, starting from 0.
Returns:The delegation at the index.
Return type:DelegationSet.Delegation
DelegationSet.remove(name)[source]

Remove every DelegationSet.Delegation with the given name.

Parameters:name (Name) – The name to match the name of the delegation(s) to be removed.
Returns:True if a DelegationSet.Delegation was removed, otherwise False.
Return type:bool
DelegationSet.size()[source]

Get the number of delegation entries.

Returns:The number of delegation entries.
Return type:int
DelegationSet.wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this DelegationSet.

Parameters:
  • input (A Blob or an array type with int elements) – The array with the bytes to decode.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
DelegationSet.wireEncode(wireFormat=None)[source]

Encode this DelegationSet for a particular wire format.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer.
Return type:Blob

pyndn.digest_sha256_signature module

This module defines the DigestSha256Signature class which extends Signature and holds the signature bits (which are only the SHA256 digest) and an empty SignatureInfo for a data packet or signed interest.

class pyndn.digest_sha256_signature.DigestSha256Signature(value=None)[source]

Bases: pyndn.signature.Signature

Create a new DigestSha256Signature object, possibly copying values from another object.

Parameters:value (DigestSha256Signature) – (optional) If value is a DigestSha256Signature, copy its values. If value is omitted, the signature is unspecified.
clear()[source]
clone()[source]

Create a new DigestSha256Signature which is a copy of this object.

Returns:A new object which is a copy of this object.
Return type:DigestSha256Signature
getChangeCount()[source]

Get the change count, which is incremented each time this object is changed.

Returns:The change count.
Return type:int
getSignature()[source]

Get the data packet’s signature bytes (which is the digest).

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
setSignature(signature)[source]

Set the signature bytes (which is the digest) to the given value.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
signature

Get the data packet’s signature bytes (which is the digest).

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob

pyndn.exclude module

class pyndn.exclude.Exclude(value=None)[source]

Bases: object

Create a new Interest object, possibly copying values from another object.

Parameters:value (Exclude) – (optional) If value is an Exclude, copy its values. If value is omitted, this creates an object with no entries.
ANY = 0
COMPONENT = 1
class Entry(value=None)[source]

Bases: object

Create a new Exclude.Entry.

Parameters:value (Name.Component or a value for the Name.Component constructor) – (optional) If value is omitted, create an Exclude.Entry of type Exclude.ANY. Otherwise creat an Exclude.Entry of type Exclude.COMPONENT with the value.
getComponent()[source]
Get the component for this Exclude.Entry (if the type of this
is Exclude.COMPONENT).
Returns:The component for this entry, or None if the type of this entry is not Exclude.COMPONENT.
Return type:Name.Component
getType()[source]

Get the type of this Exclude.Entry.

Returns:The type of this entry which is Exclude.ANY or Exclude.COMPONENT.
Return type:int
Exclude.appendAny()[source]

Append a new entry of type Exclude.ANY.

Returns:This Exclude so that you can chain calls to append.
Return type:Exclude
Exclude.appendComponent(component)[source]

Append a new entry of type Exclude.COMPONENT with the give component.

Parameters:component (Exclude.Entry, Name.Component or a value for the Name.Component constructor) – The new exclude component.
Returns:This Exclude so that you can chain calls to append.
Return type:Exclude
Exclude.clear()[source]

Clear all the entries.

static Exclude.compareComponents(component1, component2)[source]

Compare the components using NDN component ordering. A component is less if it is shorter, otherwise if equal length do a byte comparison.

Parameters:
  • component1 (Name.Component) – The first name component.
  • component2 (Name.Component) – The first name component.
Returns:

-1 if component1 is less than component2, 1 if greater or 0 if equal.

Return type:

int

Exclude.get(i)[source]

Get the entry at the given index.

Parameters:i (int) – The index of the entry, starting from 0.
Returns:The entry at the index.
Return type:Exclude.Entry
Exclude.getChangeCount()[source]

Get the change count, which is incremented each time this object is changed.

Returns:The change count.
Return type:int
Exclude.matches(component)[source]

Check if the component matches any of the exclude criteria.

Parameters:component (Name.Component) – The name component to check.
Returns:True if the component matches any of the exclude criteria, otherwise False.
Exclude.size()[source]

Get the number of entries.

Returns:The number of entries.
Return type:int
Exclude.toUri()[source]

Return a string representation of the exclude values.

Returns:The string representation.
Return type:string

pyndn.face module

This module defines the Face class which provides the main methods for NDN communication.

class pyndn.face.Face(arg1=None, arg2=None)[source]

Bases: object

Create a new Face for communication with an NDN hub. This constructor has the forms Face(), Face(transport, connectionInfo) or Face(host, port). If the default Face() constructor is used, if the forwarder’s Unix socket file exists then connect using UnixTransport, otherwise connect to “localhost” on port 6363 using TcpTransport.

Parameters:
  • transport (Transport) – An object of a subclass of Transport used for communication.
  • connectionInfo (Transport.ConnectionInfo) – An object of a subclass of Transport.ConnectionInfo to be used to connect to the transport.
  • host (str) – In the Face(host, port) form of the constructor, host is the host of the NDN hub to connect using TcpTransport.
  • port (int) – (optional) In the Face(host, port) form of the constructor, port is the port of the NDN hub. If omitted. use 6363.
callLater(delayMilliseconds, callback)[source]

Call callback() after the given delay. Even though this is public, it is not part of the public API of Face.This default implementation just calls Node.callLater, but a subclass can override.

Parameters:
  • delayMilliseconds (float) – The delay in milliseconds.
  • callback (function object) – This calls callback() after the delay.
expressInterest(interestOrName, arg2, arg3=None, arg4=None, arg5=None, arg6=None)[source]

Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below. There are two forms of expressInterest. The first form takes the exact interest (including lifetime): expressInterest(interest, onData [, onTimeout] [, onNetworkNack] [, wireFormat]). The second form creates the interest from a name and optional interest template: expressInterest(name [, interestTemplate], onData [, onTimeout] [, onNetworkNack] [, wireFormat]).

Parameters:
  • interest (Interest) – The Interest (if the first form is used). This copies the Interest.
  • name (Name) – A name for the Interest (if the second form is used).
  • interestTemplate (Interest) – (optional) if not None, copy interest selectors from the template (if the second form is used). If omitted, use a default interest lifetime.
  • onData (function object) – When a matching data packet is received, this calls onData(interest, data) where interest is the interest given to expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • onTimeout (function object) – (optional) If the interest times out according to the interest lifetime, this calls onTimeout(interest) where interest is the interest given to expressInterest. However, if onTimeout is None or omitted, this does not use it. NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • onNetworkNack (function object) – (optional) When a network Nack packet for the interest is received and onNetworkNack is not None, this calls onNetworkNack(interest, networkNack) and does not call onTimeout. interest is the sent Interest and networkNack is the received NetworkNack. If onNetworkNack is supplied, then onTimeout must be supplied too. However, if a network Nack is received and onNetworkNack is null, do nothing and wait for the interest to time out. (Therefore, an application which does not yet process a network Nack reason treats a Nack the same as a timeout.) NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode the message. If omitted, use WireFormat.getDefaultWireFormat().
Returns:

The pending interest ID which can be used with removePendingInterest.

Return type:

int

Throws :

RuntimeError If the encoded interest size exceeds Face.getMaxNdnPacketSize().

static getMaxNdnPacketSize()[source]

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.

Returns:The maximum NDN packet size.
Return type:int
isLocal()[source]

Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g. an IP host name lookup).

Returns:True if the face is local, false if not.
Rtype bool:
makeCommandInterest(interest, wireFormat=None)[source]

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. :note: This method is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/face.html#face-makecommandinterest-method .

Parameters:
  • interest (Interest) – The interest whose name is appended with components.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode the SignatureInfo and to encode the interest name for signing. If omitted, use WireFormat.getDefaultWireFormat().
processEvents()[source]

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).

Raises :This may raise an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
putData(data, wireFormat=None)[source]

The OnInterest callback calls this to put a Data packet which satisfies an Interest.

Parameters:
  • data (Data) – The Data packet which satisfies the interest.
  • wireFormat (WireFormat) – (optional) A WireFormat object used to encode the Data packet. If omitted, use WireFormat.getDefaultWireFormat().
Throws :

RuntimeError If the encoded Data packet size exceeds getMaxNdnPacketSize().

registerPrefix(prefix, onInterest, onRegisterFailed, onRegisterSuccess=None, flags=None, wireFormat=None)[source]

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.

Parameters:
  • prefix (Name) – The Name for the prefix to register. This copies the Name.
  • onInterest (function object) – If not None, this creates an interest filter from prefix so that when an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter). NOTE: You must not change the prefix or filter objects - if you need to change them then make a copy. If onInterest is None, it is ignored and you must call setInterestFilter. NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • onRegisterFailed (function object) – If register prefix fails for any reason, this calls onRegisterFailed(prefix). NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • onRegisterSuccess (function object) – (optional) This calls onRegisterSuccess(prefix, registeredPrefixId) when this receives a success message from the forwarder. If onRegisterSuccess is None or omitted, this does not use it. (The onRegisterSuccess parameter comes after onRegisterFailed because it can be None or omitted, unlike onRegisterFailed.) NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
  • flags (ForwardingFlags) – (optional) The flags for finer control of which interests are forwardedto the application.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this ControlParameters. If omitted, use WireFormat.getDefaultWireFormat().
Raises :

This raises an exception if setCommandSigningInfo has not been called to set the KeyChain, etc. for signing the command interest.

removePendingInterest(pendingInterestId)[source]

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.

Parameters:pendingInterestId (int) – The ID returned from expressInterest.
removeRegisteredPrefix(registeredPrefixId)[source]

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 there is no entry with the registeredPrefixId, do nothing.

Parameters:registeredPrefixId (int) – The ID returned from registerPrefix.
send(encoding)[source]

Send the encoded packet out through the face.

Parameters:encoding (Blob or an array type with int elements) – The blob or array with the the encoded packet to send.
Throws :RuntimeError If the packet size exceeds getMaxNdnPacketSize().
setCommandCertificateName(certificateName)[source]

Set the certificate name used to sign command interest (e.g. for registerPrefix), using the KeyChain that was set with setCommandSigningInfo.

Parameters:certificateName (Name) – The certificate name for signing interest. This makes a copy of the Name.
setCommandSigningInfo(keyChain, certificateName)[source]

Set the KeyChain and certificate name used to sign command interests (e.g. for registerPrefix).

Parameters:
  • keyChain (KeyChain) – The KeyChain object for signing interests, which must remain valid for the life of this Face. You must create the KeyChain object and pass it in. You can create a default KeyChain for your system with the default KeyChain constructor.
  • certificateName (Name) – The certificate name for signing interests. This makes a copy of the Name. You can get the default certificate name with keyChain.getDefaultCertificateName() .
setInterestFilter(filterOrPrefix, onInterest)[source]

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. There are two forms of setInterestFilter. The first form uses the exact given InterestFilter: setInterestFilter(filter, onInterest). The second form creates an InterestFilter from the given prefix Name: setInterestFilter(prefix, onInterest).

Parameters:
  • filter (InterestFilter) – The InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
  • prefix (Name) – The Name prefix used to match the name of an incoming Interest. This makes a copy of the Name.
  • onInterest (function object) – When an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter). NOTE: The library will log any exceptions raised by this callback, but for better error handling the callback should catch and properly handle any exceptions.
Returns:

The interest filter ID which can be used with unsetInterestFilter.

Return type:

int

shutdown()[source]

Shut down and disconnect this Face.

unsetInterestFilter(interestFilterId)[source]

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.

Parameters:interestFilterId (int) – The ID returned from setInterestFilter.

pyndn.forwarding_flags module

This module defines the ForwardingFlags class which holds the flags which specify how the forwarding daemon should forward an interest for a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding bits are changed, amended or deprecated.

class pyndn.forwarding_flags.ForwardingFlags(value=None)[source]

Bases: object

Create a new ForwardingFlags object, possibly copying values from another object.

Parameters:value (ForwardingFlags) – (optional) If value is a ForwardingFlags, copy its values. If value is omitted, the type is the default with “childInherit” True and other flags False.
NfdForwardingFlags_CAPTURE = 2
NfdForwardingFlags_CHILD_INHERIT = 1
capture
childInherit
equals(other)[source]
getCapture()[source]
getChildInherit()[source]
getNfdForwardingFlags()[source]

Get an integer with the bits set according to the NFD forwarding flags as used in the ControlParameters of the command interest.

Returns:An integer with the bits set.
Return type:int
setCapture(value)[source]
setChildInherit(value)[source]
setNfdForwardingFlags(nfdForwardingFlags)[source]

Set the flags according to the NFD forwarding flags as used in the ControlParameters of the command interest.

Parameters:nfdForwardingFlags (int) – An integer with the bits set.

pyndn.generic_signature module

This module defines the GenericSignature class which extends Signature and holds the encoding bytes of the SignatureInfo so that the application can process experimental signature types. When decoding a packet, if the type of SignatureInfo is not recognized, the library creates a GenericSignature.

class pyndn.generic_signature.GenericSignature(value=None)[source]

Bases: pyndn.signature.Signature

Create a new GenericSignature object, possibly copying values from another object.

Parameters:value (GenericSignature) – (optional) If value is a GenericSignature, copy its values.
clear()[source]
clone()[source]

Create a new GenericSignature which is a copy of this object.

Returns:A new object which is a copy of this object.
Return type:GenericSignature
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getSignature()[source]

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
getSignatureInfoEncoding()[source]

Get the bytes of the entire signature info encoding (including the type code).

Returns:The encoding bytes. If not specified, the value isNull().
Return type:Blob
getTypeCode()[source]

Get the type code of the signature type. When wire decode calls setSignatureInfoEncoding, it sets the type code. Note that the type code is ignored during wire encode, which simply uses getSignatureInfoEncoding() where the encoding already has the type code.

:return:The type code, or None if not known. :rtype: int

setSignature(signature)[source]

Set the signature bytes to the given value.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
setSignatureInfoEncoding(signatureInfoEncoding, typeCode=None)[source]

Set the bytes of the entire signature info encoding (including the type code).

Parameters:
  • signatureInfoEncoding (A Blob or an array type with int elements) – The array with the encoding bytes. If signatureInfoEncoding is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
  • typeCode (int) – (optional) The type code of the signature type, or None if not known. (When a GenericSignature is created by wire decoding, it sets the typeCode.)
signature

Get the type code of the signature type. When wire decode calls setSignatureInfoEncoding, it sets the type code. Note that the type code is ignored during wire encode, which simply uses getSignatureInfoEncoding() where the encoding already has the type code.

:return:The type code, or None if not known. :rtype: int

signatureInfoEncoding

Get the bytes of the entire signature info encoding (including the type code).

Returns:The encoding bytes. If not specified, the value isNull().
Return type:Blob

pyndn.hmac_with_sha256_signature module

This module defines the HmacWithSha256Signature which extends Signature and holds the signature bits and other info representing an HmacWithSha256 signature in a packet.

class pyndn.hmac_with_sha256_signature.HmacWithSha256Signature(value=None)[source]

Bases: pyndn.signature.Signature

Create a new HmacWithSha256Signature object, possibly copying values from another object.

Parameters:value (HmacWithSha256Signature) – (optional) If value is a HmacWithSha256Signature, copy its values. If value is omitted, the keyLocator is the default with unspecified values and the signature is unspecified.
clear()[source]
clone()[source]

Create a new HmacWithSha256Signature which is a copy of this object.

Returns:A new object which is a copy of this object.
Return type:HmacWithSha256Signature
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getKeyLocator()[source]

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
getSignature()[source]

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
keyLocator

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
setKeyLocator(keyLocator)[source]

Set the key locator to a copy of the given keyLocator.

Parameters:keyLocator (KeyLocator) – The KeyLocator to copy.
setSignature(signature)[source]

Set the signature bytes to the given value.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
signature

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob

pyndn.interest module

This module defines the NDN Interest class.

class pyndn.interest.Interest(value=None)[source]

Bases: object

childSelector

Get the child selector.

Returns:The child selector, or None if not specified.
Return type:int
exclude

Get the exclude object.

Returns:The exclude object. If the exclude size() is zero, then the exclude is not specified.
Return type:Exclude
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getChildSelector()[source]

Get the child selector.

Returns:The child selector, or None if not specified.
Return type:int
getDefaultWireEncoding()[source]

Return the default wire encoding, which was encoded with getDefaultWireEncodingFormat().

Returns:The default wire encoding, whose isNull() may be true if there is no default wire encoding.
Return type:SignedBlob
getDefaultWireEncodingFormat()[source]

Get the WireFormat which is used by getDefaultWireEncoding().

Returns:The WireFormat, which is only meaningful if the getDefaultWireEncoding() is not isNull().
Return type:WireFormat
getExclude()[source]

Get the exclude object.

Returns:The exclude object. If the exclude size() is zero, then the exclude is not specified.
Return type:Exclude
getIncomingFaceId()[source]

Get the incoming face ID according to the incoming packet header.

Returns:The incoming face ID. If not specified, return None.
Return type:int
getInterestLifetimeMilliseconds()[source]

Get the interest lifetime.

Returns:The interest lifetime in milliseconds, or None if not specified.
Return type:float
getKeyLocator()[source]

Get the interest key locator.

Returns:The key locator. If getType() is None, then the key locator is not specified.
Return type:KeyLocator

Get the link object. If necessary, decode it from the link wire encoding.

Returns:The link object, or null if not specified.
Return type:Link
Raises ValueError:
 For error decoding the link wire encoding (if necessary).
getLinkWireEncoding(wireFormat=None)[source]

Get the wire encoding of the link object. If there is already a wire encoding then return it. Otherwise encode from the link object (if available).

Parameters:wireFormat (WireFormat) – (optional) A WireFormat object used to encode the Link. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The wire encoding, or an isNull Blob if the link is not specified.
Return type:Blob
getMaxSuffixComponents()[source]

Get the max suffix components.

Returns:The max suffix components, or None if not specified.
Return type:int
getMinSuffixComponents()[source]

Get the min suffix components.

Returns:The min suffix components, or None if not specified.
Return type:int
getMustBeFresh()[source]

Get the must be fresh flag.

Returns:The must be fresh flag. If not specified, the default is True.
Return type:bool
getName()[source]

Get the interest Name.

Returns:The name. The name size() may be 0 if not specified.
Return type:Name
getNonce()[source]

Return the nonce value from the incoming interest. If you change any of the fields in this Interest object, then the nonce value is cleared.

Returns:The nonce. If isNull() then the nonce is omitted.
Return type:Blob
getSelectedDelegationIndex()[source]

Get the selected delegation index.

Returns:The selected delegation index. If not specified, return None.
Return type:int

Check if this interest has a link object (or a link wire encoding which can be decoded to make the link object).

Returns:True if this interest has a link object, False if not.
Return type:bool
interestLifetimeMilliseconds

Get the interest lifetime.

Returns:The interest lifetime in milliseconds, or None if not specified.
Return type:float
keyLocator

Get the interest key locator.

Returns:The key locator. If getType() is None, then the key locator is not specified.
Return type:KeyLocator
matchesName(name)[source]

Check if this interest’s name matches the given name (using Name.match) and the given name also conforms to the interest selectors.

Parameters:name (Name) – The name to check.
Returns:True if the name and interest selectors match, False otherwise.
Return type:bool
maxSuffixComponents

Get the max suffix components.

Returns:The max suffix components, or None if not specified.
Return type:int
minSuffixComponents

Get the min suffix components.

Returns:The min suffix components, or None if not specified.
Return type:int
mustBeFresh

Get the must be fresh flag.

Returns:The must be fresh flag. If not specified, the default is True.
Return type:bool
name

Get the interest Name.

Returns:The name. The name size() may be 0 if not specified.
Return type:Name
nonce

Return the nonce value from the incoming interest. If you change any of the fields in this Interest object, then the nonce value is cleared.

Returns:The nonce. If isNull() then the nonce is omitted.
Return type:Blob
refreshNonce()[source]

Update the bytes of the nonce with new random values. This ensures that the new nonce value is different than the current one. If the current nonce is not specified, this does nothing.

setChildSelector(childSelector)[source]

Set the child selector.

Parameters:childSelector (int) – The child selector. If not specified, set to None.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setExclude(exclude)[source]

Set this interest to use a copy of the given Exclude object.

Note :You can also call getExclude and change the exclude entries directly.
Parameters:exclude (Exclude) – The Exclude object. This makes a copy of the object. If no exclude is specified, set to a new default Exclude(), or to an Exclude with size() 0.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setInterestLifetimeMilliseconds(interestLifetimeMilliseconds)[source]

Set the interest lifetime.

Parameters:interestLifetimeMilliseconds (float) – The interest lifetime in milliseconds. If not specified, set to -1.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setKeyLocator(keyLocator)[source]

Set this interest to use a copy of the given KeyLocator object.

Note :You can also call getKeyLocator and change the key locator directly.
Parameters:keyLocator (KeyLocator) – The KeyLocator object. This makes a copy of the object. If no key locator is specified, set to a new default KeyLocator(), or to a KeyLocator with an unspecified type.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setLinkWireEncoding(encoding, wireFormat=None)[source]

Set the link wire encoding bytes, without decoding them. If there is a link object, set it to null. If you later call getLink(), it will decode the wireEncoding to create the link object.

Parameters:
  • encoding (Blob) – The Blob with the bytes of the link wire encoding. If no link is specified, set to an empty Blob() or call unsetLink().
  • wireFormat (WireFormat) – The wire format of the encoding, to be used later if necessary to decode. If omitted, use WireFormat.getDefaultWireFormat().
Returns:

This Interest so that you can chain calls to update values.

Return type:

Interest

setLpPacket(lpPacket)[source]

An internal library method to set the LpPacket for an incoming packet. The application should not call this.

Parameters:lpPacket (LpPacket) – The LpPacket. This does not make a copy.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
Note :This is an experimental feature. This API may change in the future.
setMaxSuffixComponents(maxSuffixComponents)[source]

Set the max suffix components count.

Parameters:maxSuffixComponents (int) – The max suffix components count. If not specified, set to None.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setMinSuffixComponents(minSuffixComponents)[source]

Set the min suffix components count.

Parameters:minSuffixComponents (int) – The min suffix components count. If not specified, set to None.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setMustBeFresh(mustBeFresh)[source]

Set the MustBeFresh flag.

Parameters:mustBeFresh (bool) – True if the content must be fresh, otherwise False. If you do not set this flag, the default value is true.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setName(name)[source]

Set the interest name.

Note :You can also call getName and change the name values directly.
Parameters:name (Name) – The interest name. This makes a copy of the name.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
setNonce(nonce)[source]
Deprecated :You should let the wire encoder generate a random nonce

internally before sending the interest.

setSelectedDelegationIndex(selectedDelegationIndex)[source]

Set the selected delegation index.

Parameters:selectedDelegationIndex (int) – The selected delegation index. If not specified, set to None.
Returns:This Interest so that you can chain calls to update values.
Return type:Interest
toUri()[source]

Encode the name according to the “NDN URI Scheme”. If there are interest selectors, append ”?” and add the selectors as a query string. For example “/test/name?ndn.ChildSelector=1”. :note: This is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/interest.html#interest-touri-method .

Returns:The URI string.
Return type:string

Clear the link wire encoding and link object so that getLink() returns None.

Returns:This Interest so that you can chain calls to update values.
Return type:Interest
wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this Interest. If wireFormat is the default wire format, also set the defaultWireEncoding to another pointer to the input.

Parameters:
  • input (A Blob or an array type with int elements) – The array with the bytes to decode. If input is not a Blob, then copy the bytes to save the defaultWireEncoding (otherwise take another pointer to the same Blob).
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this Interest. If omitted, use WireFormat.getDefaultWireFormat().
wireEncode(wireFormat=None)[source]

Encode this Interest for a particular wire format. If wireFormat is the default wire format, also set the defaultWireEncoding field to the encoded result.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this Interest. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer.
Return type:SignedBlob

pyndn.interest_filter module

This module defines the InterestFilter class which holds a Name prefix and optional regex match expression for use in Face.setInterestFilter.

class pyndn.interest_filter.InterestFilter(prefix, regexFilter=None)[source]

Bases: object

Create an InterestFilter to match any Interest whose name starts with the given prefix. If the optional regexFilter is provided then the remaining components match the regexFilter regular expression as described in doesMatch.

Parameters:
  • prefix (Name or str) – The prefix. If a Name then this makes a copy of the Name. Otherwise it create a Name from the URI string.
  • regexFilter (str) – (optional) The regular expression for matching the remaining name components.
doesMatch(name)[source]

Check if the given name matches this filter. Match if name starts with this filter’s prefix. If this filter has the optional regexFilter then the remaining components match the regexFilter regular expression. For example, the following InterestFilter:

InterestFilter(“/hello”, “<world><>+”)

will match all Interests, whose name has the prefix /hello which is followed by a component world and has at least one more component after it. Examples:

/hello/world/! /hello/world/x/y/z

Note that the regular expression will need to match all remaining components (e.g., there are implicit heading ^ and trailing $ symbols in the regular expression).

Parameters:name (Name) – The name to check against this filter.
Returns:True if name matches this filter, otherwise False.
Return type:bool
getPrefix()[source]

Get the prefix given to the constructor.

Returns:The prefix Name which you should not modify.
Return type:Name
getRegexFilter()[source]

Get the regex filter. This is only valid if hasRegexFilter() is True.

Returns:The regular expression for matching the remaining name components.
Return type:str
hasRegexFilter()[source]

Check if a regexFilter was supplied to the constructor.

Returns:True if a regexFilter was supplied to the constructor.
Return type:bool
static makePattern(regexFilter)[source]

If regexFilter doesn’t already have them, add ^ to the beginning and $ to the end since these are required by NdnRegexMatcher.match.

Parameters:regexFilter (str) – The regex filter.
Returns:The regex pattern with ^ and $.
Rtype str:

pyndn.key_locator module

This module defines the KeyLocator class which represents an NDN KeyLocator which is used in a Sha256WithRsaSignature and Interest selectors.

class pyndn.key_locator.KeyLocator(value=None)[source]

Bases: object

Create a new KeyLocator object, possibly copying values from another object.

Parameters:value (KeyLocator) – (optional) If value is a KeyLocator, copy its values. If value is omitted, set the fields to unspecified.
static canGetFromSignature(signature)[source]

If the signature is a type that has a KeyLocator (so that getFromSignature will succeed), return true. Note: This is a static method of KeyLocator instead of a method of Signature so that the Signature base class does not need to be overloaded with all the different kinds of information that various signature algorithms may use.

Parameters:signature (Signature) – An object of a subclass of Signature.
Returns:True if the signature is a type that has a KeyLocator, otherwise False.
Return type:bool
clear()[source]

Clear the fields and set the type to None.

equals(other)[source]
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
static getFromSignature(signature)[source]

If the signature is a type that has a KeyLocator, then return it. Otherwise throw an error.

Parameters:signature (Signature) – An object of a subclass of Signature.
Returns:The signature’s KeyLocator. It is an error if signature doesn’t have a KeyLocator.
Return type:KeyLocator
getKeyData()[source]

Get the key data. This is the digest bytes if getType() is KeyLocatorType.KEY_LOCATOR_DIGEST.

Returns:The key data as a Blob, which isNull() if unspecified.
Return type:Blob
getKeyName()[source]

Get the key name. This is meaningful if getType() is KeyLocatorType.KEYNAME.

Returns:The key name. If not specified, the Name is empty.
Return type:Name
getType()[source]

Get the key locator type. If KeyLocatorType.KEYNAME, you may also getKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you may also getKeyData() to get the digest.

Returns:The key locator type, or None if not specified.
Return type:an int from KeyLocatorType
keyData

Get the key data. This is the digest bytes if getType() is KeyLocatorType.KEY_LOCATOR_DIGEST.

Returns:The key data as a Blob, which isNull() if unspecified.
Return type:Blob
keyName

Get the key name. This is meaningful if getType() is KeyLocatorType.KEYNAME.

Returns:The key name. If not specified, the Name is empty.
Return type:Name
setKeyData(keyData)[source]

Set the key data to the given value. This is the digest bytes if getType() is KeyLocatorType.KEY_LOCATOR_DIGEST.

Parameters:keyData (A Blob or an array type with int elements) – The array with the key data bytes. If keyData is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
setKeyName(keyName)[source]

Set key name to a copy of the given Name. This is the name if getType() is KeyLocatorType.KEYNAME.

Parameters:keyName (Name) – The key name which is copied.
setType(type)[source]

Set the key locator type. If KeyLocatorType.KEYNAME, you must also setKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you must also setKeyData() to set the digest.

Parameters:type (an int from KeyLocatorType) – The key locator type. If None, the type is unspecified.
type

Get the key locator type. If KeyLocatorType.KEYNAME, you may also getKeyName(). If KeyLocatorType.KEY_LOCATOR_DIGEST, you may also getKeyData() to get the digest.

Returns:The key locator type, or None if not specified.
Return type:an int from KeyLocatorType
class pyndn.key_locator.KeyLocatorType[source]

Bases: object

A KeyLocatorType specifies the type of a KeyLocator object.

KEYNAME = 1
KEY_LOCATOR_DIGEST = 2

pyndn.meta_info module

This module defines the MetaInfo class which is used by Data and represents the fields of an NDN MetaInfo.

class pyndn.meta_info.ContentType[source]

Bases: object

A ContentType specifies the content type in a MetaInfo object.

BLOB = 0
KEY = 2
NACK = 3
class pyndn.meta_info.MetaInfo(value=None)[source]

Bases: object

Create a new MetaInfo object, possibly copying values from another object.

Parameters:value (MetaInfo) – (optional) If value is a MetaInfo, copy its values. If value is omitted, the type is the default ContentType.BLOB and the freshness period is not specified.
equals(other)[source]
finalBlockID
Deprecated :Use getFinalBlockId.
finalBlockId

Get the final block ID.

Returns:The final block ID as a Name.Component. If the Name.Component getValue().size() is 0, then the final block ID is not specified.
Return type:Name.Component
freshnessPeriod

Get the freshness period.

Returns:The freshness period in milliseconds, or None if not specified.
Return type:float
getChangeCount()[source]

Get the change count, which is incremented each time this object is changed.

Returns:The change count.
Return type:int
getFinalBlockID()[source]
Deprecated :Use getFinalBlockId.
getFinalBlockId()[source]

Get the final block ID.

Returns:The final block ID as a Name.Component. If the Name.Component getValue().size() is 0, then the final block ID is not specified.
Return type:Name.Component
getFreshnessPeriod()[source]

Get the freshness period.

Returns:The freshness period in milliseconds, or None if not specified.
Return type:float
getType()[source]

Get the content type.

Returns:The content type.
Return type:an int from ContentType
setFinalBlockID(finalBlockId)[source]
Deprecated :Use setFinalBlockId.
setFinalBlockId(finalBlockId)[source]

Set the final block ID.

Parameters:finalBlockId (Name.Component or value for the Name.Component constructor) – The final block ID. If it is another Name.Component, use its value. Otherwise pass value to the Name.Component constructor. If finalBlockId is None, set to a Name.Component of size 0 so that the finalBlockId is not specified and not encoded.
setFreshnessPeriod(freshnessPeriod)[source]

Set the freshness period.

Parameters:freshnessPeriod (float) – The freshness period in milliseconds, or None for not specified.
setType(type)[source]

Set the content type.

Parameters:type (an int from ContentType) – The content type. If None, this uses ContentType.BLOB.
type

Get the content type.

Returns:The content type.
Return type:an int from ContentType

pyndn.name module

This module defines the NDN Name class.

class pyndn.name.Name(value=None)[source]

Bases: object

Create a new Name which holds an array of Name.Component and represents an NDN name.

Parameters:value (Name or str) – (optional) If value is another Name, then copy it. If value is a str then call set(value) to create from the URI. If ommitted, create an empty name.
class Component(value=None)[source]

Bases: object

Create a new Name.Component.

Parameters:value (Blob or Name.Component or value for Blob constructor) – (optional) If value is already a Blob or Name.Component, then take another pointer to the value. Otherwise, create a new Blob with a copy of the value. If omitted, create an empty component.
compare(other)[source]

Compare this to the other Component using NDN canonical ordering.

Parameters:other (Name.Component) – The other Component to compare with.
Returns:0 If they compare equal, -1 if self comes before other in the canonical ordering, or 1 if self comes after other in the canonical ordering.
Return type:int
See :http://named-data.net/doc/0.2/technical/CanonicalOrder.html
equals(other)[source]

Check if this is the same component as other.

Parameters:other (Name.Component) – The other Component to compare with.
Returns:True if the components are equal, otherwise False.
Return type:bool
static fromNumber(number)[source]

Create a component whose value is the nonNegativeInteger encoding of the number.

Parameters:number (int) – The number to be encoded.
Returns:The component value.
Return type:Name.Component
static fromNumberWithMarker(number, marker)[source]

Create a component whose value is the marker appended with the nonNegativeInteger encoding of the number.

Parameters:
  • number (int) – The number to be encoded.
  • marker (int) – The marker to use as the first byte of the component.
Returns:

The component value.

Return type:

Name.Component

static fromSegment(segment)[source]

Create a component with the encoded segment number according to NDN naming conventions for “Segment number” (marker 0x00). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:segment (int) – The segment number.
Returns:The new Component.
Return type:Name.Component
static fromSegmentOffset(segmentOffset)[source]

Create a component with the encoded segment byte offset according to NDN naming conventions for segment “Byte offset” (marker 0xFB). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:segmentOffset (int) – The segment byte offset.
Returns:The new Component.
Return type:Name.Component
static fromSequenceNumber(sequenceNumber)[source]

Create a component with the encoded sequence number according to NDN naming conventions for “Sequencing” (marker 0xFE). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:sequenceNumber (int) – The sequence number.
Returns:The new Component.
Return type:Name.Component
static fromTimestamp(timestamp)[source]

Create a component with the encoded timestamp according to NDN naming conventions for “Timestamp” (marker 0xFC). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:timestamp (int) – The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.
Returns:The new Component.
Return type:Name.Component
static fromVersion(version)[source]

Create a component with the encoded version number according to NDN naming conventions for “Versioning” (marker 0xFD). http://named-data.net/doc/tech-memos/naming-conventions.pdf Note that this encodes the exact value of version without converting from a time representation.

Parameters:version (int) – The version number.
Returns:The new Component.
Return type:Name.Component
getSuccessor()[source]

Get the successor of this component, as described in Name.getSuccessor.

Returns:A new Name.Component which is the successor of this.
Return type:Name.Component
getValue()[source]

Get the value of the component.

Returns:The component value.
Return type:Blob
isSegment()[source]

Check if this component is a segment number according to NDN naming conventions for “Segment number” (marker 0x00). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:True if this is a segment number.
Return type:bool
isSegmentOffset()[source]

Check if this component is a segment byte offset according to NDN naming conventions for segment “Byte offset” (marker 0xFB). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:True if this is a segment byte offset.
Return type:bool
isSequenceNumber()[source]

Check if this component is a sequence number according to NDN naming conventions for “Sequencing” (marker 0xFE). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:True if this is a sequence number.
Return type:bool
isTimestamp()[source]

Check if this component is a timestamp according to NDN naming conventions for “Timestamp” (marker 0xFC). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:True if this is a timestamp.
Return type:bool
isVersion()[source]

Check if this component is a version number according to NDN naming conventions for “Versioning” (marker 0xFD). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:True if this is a version number.
Return type:bool
toEscapedString(result=None)[source]

Convert this component to a string, escaping characters according to the NDN URI Scheme. This also adds ”...” to a value with zero or more ”.”.

Parameters:result (BytesIO) – (optional) The BytesIO stream to write to. If omitted, return a str with the result.
Returns:The result as a string (only if result is omitted).
Return type:str
toNumber()[source]

Interpret this name component as a network-ordered number and return an integer.

Returns:The integer number.
Return type:int
toNumberWithMarker(marker)[source]

Interpret this name component as a network-ordered number with a marker and return an integer.

Parameters:marker (int) – The required first byte of the component.
Returns:The integer number.
Return type:int
Raises RuntimeError:
 If the first byte of the component does not equal the marker.
toSegment()[source]

Interpret this name component as a segment number according to NDN naming conventions for “Segment number” (marker 0x00). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:The integer segment number.
Return type:int
Raises RuntimeError:
 If the first byte of the component is not the expected marker.
toSegmentOffset()[source]

Interpret this name component as a segment byte offset according to NDN naming conventions for segment “Byte offset” (marker 0xFB). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:The integer segment byte offset.
Return type:int
Raises RuntimeError:
 If the first byte of the component is not the expected marker.
toSequenceNumber()[source]

Interpret this name component as a sequence number according to NDN naming conventions for “Sequencing” (marker 0xFE). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:The integer sequence number.
Return type:int
Raises RuntimeError:
 If the first byte of the component is not the expected marker.
toTimestamp()[source]

Interpret this name component as a timestamp according to NDN naming conventions for “Timestamp” (marker 0xFC). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.
Return type:int
Raises RuntimeError:
 If the first byte of the component is not the expected marker.
toVersion()[source]

Interpret this name component as a version number according to NDN naming conventions for “Versioning” (marker 0xFD). Note that this returns the exact number from the component without converting it to a time representation. http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns:The integer version number.
Return type:int
Raises RuntimeError:
 If the first byte of the component is not the expected marker.
Name.append(value)[source]

Append a new component.

Parameters:value (Name, Name.Component or value for Name.Component constructor) – If value is another Name, append all its components. If value is another Name.Component, use its value. Otherwise pass value to the Name.Component constructor.
Name.appendSegment(segment)[source]

Append a component with the encoded segment number according to NDN naming conventions for “Segment number” (marker 0x00). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:segment (int) – The segment number.
Returns:This name so that you can chain calls to append.
Return type:Name
Name.appendSegmentOffset(segmentOffset)[source]

Append a component with the encoded segment byte offset according to NDN naming conventions for segment “Byte offset” (marker 0xFB). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:segmentOffset (int) – The segment byte offset.
Returns:This name so that you can chain calls to append.
Return type:Name
Name.appendSequenceNumber(sequenceNumber)[source]

Append a component with the encoded sequence number according to NDN naming conventions for “Sequencing” (marker 0xFE). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:sequenceNumber (int) – The sequence number.
Returns:This name so that you can chain calls to append.
Return type:Name
Name.appendTimestamp(timestamp)[source]

Append a component with the encoded timestamp according to NDN naming conventions for “Timestamp” (marker 0xFC). http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters:timestamp (int) – The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.
Returns:This name so that you can chain calls to append.
Return type:Name
Name.appendVersion(version)[source]

Append a component with the encoded version number according to NDN naming conventions for “Versioning” (marker 0xFD). http://named-data.net/doc/tech-memos/naming-conventions.pdf Note that this encodes the exact value of version without converting from a time representation.

Parameters:version (int) – The version number.
Returns:This name so that you can chain calls to append.
Return type:Name
Name.clear()[source]

Clear all the components.

Name.compare(iStartComponent, nComponents=None, other=None, iOtherStartComponent=None, nOtherComponents=None)[source]

Compare this to the other Name using NDN canonical ordering. If the first components of each name are not equal, this returns -1 if the first comes before the second using the NDN canonical ordering for name components, or 1 if it comes after. If they are equal, this compares the second components of each name, etc. If both names are the same up to the size of the shorter name, this returns -1 if the first name is shorter than the second or 1 if it is longer. For example, sorted gives: /a/b/d /a/b/cc /c /c/a /bb . This is intuitive because all names with the prefix /a are next to each other. But it may be also be counter-intuitive because /c comes before /bb according to NDN canonical ordering since it is shorter. The first form of compare is simply compare(other). The second form is compare(iStartComponent, nComponents, other [, iOtherStartComponent] [, nOtherComponents]) which is equivalent to self.getSubName(iStartComponent, nComponents).compare (other.getSubName(iOtherStartComponent, nOtherComponents)) .

Parameters:
  • iStartComponent (int) – The index if the first component of this name to get. If iStartComponent is -N then compare components starting from name.size() - N.
  • nComponents (int) – The number of components starting at iStartComponent. If greater than the size of this name, compare until the end of the name.
  • other (Name) – The other Name to compare with.
  • iOtherStartComponent (int) – (optional) The index if the first component of the other name to compare. If iOtherStartComponent is -N then compare components starting from other.size() - N. If omitted, compare starting from index 0.
  • nOtherComponents (int) – (optional) The number of components starting at iOtherStartComponent. If omitted or greater than the size of this name, compare until the end of the name.
Returns:

0 If they compare equal, -1 if self comes before other in the canonical ordering, or 1 if self comes after other in the canonical ordering.

Return type:

int

See :

http://named-data.net/doc/0.2/technical/CanonicalOrder.html

Name.equals(name)[source]

Check if this name has the same component count and components as the given name.

Parameters:name (Name) –
Returns:True if the names are equal, otherwise False.
Return type:bool
static Name.fromEscapedString(escapedString, beginOffset=0, endOffset=None)[source]

Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme. (If offsets are omitted, then decode the whole string.) If the escaped string is “”, ”.” or ”..” then return a Blob with a null pointer, which means the component should be skipped in a URI name.

Parameters:escapedString (str) – The escaped string.
Returns:The unescaped Blob value. If the escapedString is not a valid escaped component, then the Blob isNull().
Name.get(i)[source]

Get the component at the given index.

Parameters:i (int) – The index of the component, starting from 0. However, if i is negative, return the component at size() - (-i).
Name.getChangeCount()[source]

Get the change count, which is incremented each time this object is changed.

Returns:The change count.
Return type:int
Name.getPrefix(nComponents)[source]

Return a new Name with the first nComponents components of this Name.

Parameters:nComponents (int) – The number of prefix components. If nComponents is -N then return the prefix up to name.size() - N. For example getPrefix(-1) returns the name without the final component.
Returns:The name prefix.
Return type:Name
Name.getSubName(iStartComponent, nComponents=None)[source]

Get a new name, constructed as a subset of components.

Parameters:
  • iStartComponent (int) – The index if the first component to get. If iStartComponent is -N then return return components starting from name.size() - N.
  • nComponents (int) – (optional) The number of components starting at iStartComponent. If omitted or greater than the size of this name, get until the end of the name.
Returns:

A new name.

Return type:

Name

Name.getSuccessor()[source]

Get the successor of this name which is defined as follows.

N represents the set of NDN Names, and X,Y in N. Operator < is defined by the NDN canonical order on N. Y is the successor of X, if (a) X < Y, and (b) not exists Z in N s.t. X < Z < Y.

In plain words, the successor of a name is the same name, but with its last component advanced to a next possible value.

Examples:

  • The successor of / is /%00
  • The successor of /%00%01/%01%02 is /%00%01/%01%03
  • The successor of /%00%01/%01%FF is /%00%01/%02%00
  • The successor of /%00%01/%FF%FF is /%00%01/%00%00%00
Returns:A new name which is the successor of this.
Return type:Name
Name.isPrefixOf(name)[source]

Check if the N components of this name are the same as the first N components of the given name.

Parameters:name (Name) – The Name to check.
Returns:True if this matches the given name, otherwise False. This always returns True if this name is empty.
Return type:bool
Name.match(name)[source]

Check if the N components of this name are the same as the first N components of the given name.

Parameters:name (Name) – The Name to check.
Returns:True if this matches the given name, otherwise False. This always returns True if this name is empty.
Return type:bool
Name.set(uri)[source]

Parse the uri according to the NDN URI Scheme and set the name with the components.

Parameters:uri (str) – The URI string.
Name.size()[source]

Get the number of components.

Returns:The number of components.
Return type:int
static Name.toEscapedString(value, result=None)[source]

Convert value to a string, escaping characters according to the NDN URI Scheme. This also adds ”...” to a value with zero or more ”.”.

Parameters:
  • value (An array type with int elements) – The buffer with the value to escape.
  • result (BytesIO) – (optional) The BytesIO stream to write to. If omitted, return a str with the result.
Returns:

The result as a string (only if result is omitted).

Return type:

str

Name.toUri(includeScheme=False)[source]

Encode this name as a URI according to the NDN URI Scheme.

Parameters:includeScheme (bool) – (optional) If True, include the “ndn:” scheme in the URI, e.g. “ndn:/example/name”. If False, just return the path, e.g. “/example/name”. If ommitted, then just return the path which is the default case where toUri() is used for display.
Returns:The encoded URI.
Return type:str
Name.wireDecode(input, wireFormat=None)[source]

Decode the input using a particular wire format and update this Name.

Parameters:
  • input (A Blob or an array type with int elements) – The array with the bytes to decode.
  • wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to decode this Name. If omitted, use WireFormat.getDefaultWireFormat().
Name.wireEncode(wireFormat=None)[source]

Encode this Name for a particular wire format.

Parameters:wireFormat (A subclass of WireFormat) – (optional) A WireFormat object used to encode this Name. If omitted, use WireFormat.getDefaultWireFormat().
Returns:The encoded buffer.
Return type:Blob

pyndn.network_nack module

This module defines the NetworkNack class which represents a network Nack packet and includes a Nack reason.

class pyndn.network_nack.NetworkNack[source]

Bases: object

class Reason[source]

Bases: object

A NetworkNack.Reason specifies the reason in a NetworkNack packet. If the reason code in the packet is not a recognized enum value, then we use Reason.OTHER_CODE and you can call getOtherReasonCode(). We do this to keep the recognized reason values independent of packet encoding formats.

CONGESTION = 50
DUPLICATE = 100
NONE = 0
NO_ROUTE = 150
OTHER_CODE = 1
static NetworkNack.getFirstHeader(lpPacket)[source]

Get the first header field in lpPacket which is a NetworkNack. This is an internal method which the application normally would not use.

Parameters:lpPacket (LpPacket) – The LpPacket with the header fields to search.
Returns:The first NetworkNack header field, or None if not found.
Return type:NetworkNack
NetworkNack.getOtherReasonCode()[source]

Get the reason code from the packet which is other than a recognized Reason enum value. This is only meaningful if getReason() is Reason.OTHER_CODE.

Returns:The reason code.
Return type:int
NetworkNack.getReason()[source]

Get the network Nack reason.

Returns:The reason enum value. If this is Reason.OTHER_CODE, then call getOtherReasonCode() to get the unrecognized reason code.
Return type:an int from NetworkNack.Reason
NetworkNack.setOtherReasonCode(otherReasonCode)[source]

Set the packet’s reason code to use when the reason enum is Reason.OTHER_CODE. If the packet’s reason code is a recognized enum value, just call setReason().

Parameters:otherReasonCode (int) – The packet’s unrecognized reason code.
NetworkNack.setReason(reason)[source]

Set the network Nack reason.

Parameters:reason (an int from NetworkNack.Reason) – The network Nack reason enum value. If the packet’s reason code is not a recognized Reason enum value, use Reason.OTHER_CODE and call setOtherReasonCode().

pyndn.node module

This module defines the Node class which provides functionality for the Face class.

class pyndn.node.Node(transport, connectionInfo)[source]

Bases: object

Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo.

Parameters:
  • transport (Transport) – An object of a subclass of Transport used for communication.
  • connectionInfo (Transport.ConnectionInfo) – An object of a subclass of Transport.ConnectionInfo to be used to connect to the transport.
callLater(delayMilliseconds, callback)[source]

Call callback() after the given delay. This adds to self._delayedCallTable which is used by processEvents().

Parameters:
  • delayMilliseconds (float) – The delay in milliseconds.
  • callback (function object) – This calls callback() after the delay.
expressInterest(pendingInterestId, interestCopy, onData, onTimeout, onNetworkNack, wireFormat, face)[source]

Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.

Parameters:
  • pendingInterestId (int) – The getNextEntryId() for the pending interest ID which Face got so it could return it to the caller.
  • interestCopy (Interest) – The Interest which is NOT copied for this internal Node method. The Face expressInterest is responsible for making a copy for Node to use.
  • onData (function object) – When a matching data packet is received, this calls onData(interest, data) where interest is the Interest given to expressInterest and data is the received Data object.
  • onTimeout (function object) – If the interest times out according to the interest lifetime, this calls onTimeout(interest) where interest is the Interest given to expressInterest. If onTimeout is None, this does not use it.
  • onNetworkNack (function object) – When a network Nack packet for the interest is received and onNetworkNack is not None, this calls onNetworkNack(interest, networkNack) and does not call onTimeout. interest is the sent Interest and networkNack is the received NetworkNack. However, if a network Nack is received and onNetworkNack is None, do nothing and wait for the interest to time out.
  • wireFormat (a subclass of WireFormat) – A WireFormat object used to encode the message.
  • face (Face) – The face which has the callLater method, used for interest timeouts. The callLater method may be overridden in a subclass of Face.
Throws :

RuntimeError If the encoded interest size exceeds getMaxNdnPacketSize().

getConnectionInfo()[source]

Get the connectionInfo object given to the constructor.

Returns:The connectionInfo object.
Return type:Transport.ConnectionInfo
static getMaxNdnPacketSize()[source]

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.

Returns:The maximum NDN packet size.
Return type:int
getNextEntryId()[source]

Get the next unique entry ID for the pending interest table, interest filter table, etc. This uses a threading.Lock() to be thread safe. Most entry IDs are for the pending interest table (there usually are not many interest filter table entries) so we use a common pool to only have to do the thread safe lock in one method which is called by Face.

Returns:The next entry ID.
Return type:int
getTransport()[source]

Get the transport object given to the constructor.

Returns:The transport object.
Return type:Transport
isLocal()[source]

Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g. an IP host name lookup).

Returns:True if the face is local, False if not.
Rtype bool:
makeCommandInterest(interest, keyChain, certificateName, wireFormat)[source]

Append a timestamp component and a random value component to interest’s name. Then use the keyChain and certificateName to sign the interest. If the interest lifetime is not set, this sets it.

Parameters:
  • interest (Interest) – The interest whose name is append with components.
  • keyChain (KeyChain) – The KeyChain for calling sign.
  • certificateName (Name) – The certificate name of the key to use for signing.
  • wireFormat (A subclass of WireFormat) – A WireFormat object used to encode the SignatureInfo and to encode the interest name for signing.
onReceivedElement(element)[source]

This is called by the transport’s ElementReader to process an entire received Data or Interest element.

Parameters:element (An array type with int elements) – The bytes of the incoming element.
processEvents()[source]

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).

Raises :This may raise an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
registerPrefix(registeredPrefixId, prefixCopy, onInterest, onRegisterFailed, onRegisterSuccess, flags, wireFormat, commandKeyChain, commandCertificateName, face)[source]

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.

Parameters:
  • registeredPrefixId (int) – The getNextEntryId() for the registered prefix ID which Face got so it could return it to the caller.
  • prefixCopy (Name) – The Name for the prefix to register which is NOT copied for this internal Node method. The Face registerPrefix is responsible for making a copy for Node to use.
  • onInterest (function object) – (optional) If not None, this creates an interest filter from prefixCopy so that when an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter). NOTE: You must not change the prefix or filter objects - if you need to change them then make a copy. If onInterest is None, it is ignored and you must call setInterestFilter.
  • onRegisterFailed (function object) – A function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix.
  • onRegisterSuccess (function object) – This calls onRegisterSuccess(prefix, registeredPrefixId) when this receives a success message from the forwarder. If onRegisterSuccess is None, this does not use it.
  • flags (ForwardingFlags) – The flags for finer control of which interests are forwardedto the application.
  • wireFormat (a subclass of WireFormat) – A WireFormat object used to encode the message.
  • commandKeyChain (KeyChain) – The KeyChain object for signing interests.
  • commandCertificateName (Name) – The certificate name for signing interests.
  • face (Face) – The face which is passed to the onInterest callback. If onInterest is None, this is ignored.
removePendingInterest(pendingInterestId)[source]

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.

Parameters:pendingInterestId (int) – The ID returned from expressInterest.
removeRegisteredPrefix(registeredPrefixId)[source]

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.

Parameters:registeredPrefixId (int) – The ID returned from registerPrefix.
send(encoding)[source]

Send the encoded packet out through the transport.

Parameters:encoding (An array type with int elements) – The array of bytes for the encoded packet to send.
Throws :RuntimeError If the packet size exceeds getMaxNdnPacketSize().
setInterestFilter(interestFilterId, filterCopy, onInterest, face)[source]

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.

Parameters:
  • interestFilterId (int) – The getNextEntryId() for the interest filter ID which Face got so it could return it to the caller.
  • filterCopy (InterestFilter) – The InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest, which is NOT copied for this internal Node method. The Face setInterestFilter is responsible for making a copy for Node to use.
  • onInterest (function object) – When an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter).
  • face (Face) – The face which is passed to the onInterest callback.
shutdown()[source]

Call getTransport().close().

unsetInterestFilter(interestFilterId)[source]

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.

Parameters:interestFilterId (int) – The ID returned from setInterestFilter.

pyndn.sha256_with_ecdsa_signature module

This module defines the Sha256WithEcdsaSignature class which extends Signature and holds the signature bits and other info representing a SHA256-with-ECDSA signature in a data packet.

class pyndn.sha256_with_ecdsa_signature.Sha256WithEcdsaSignature(value=None)[source]

Bases: pyndn.signature.Signature

Create a new Sha256WithEcdsaSignature object, possibly copying values from another object.

Parameters:value (Sha256WithEcdsaSignature) – (optional) If value is a Sha256WithEcdsaSignature, copy its values. If value is omitted, the keyLocator is the default with unspecified values and the signature is unspecified.
clear()[source]
clone()[source]

Create a new Sha256WithEcdsaSignature which is a copy of this object.

Returns:A new object which is a copy of this object.
Return type:Sha256WithEcdsaSignature
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getKeyLocator()[source]

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
getSignature()[source]

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
keyLocator

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
setKeyLocator(keyLocator)[source]

Set the key locator to a copy of the given keyLocator.

Parameters:keyLocator (KeyLocator) – The KeyLocator to copy.
setSignature(signature)[source]

Set the signature bytes to the given value.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
signature

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob

pyndn.sha256_with_rsa_signature module

This module defines the Sha256WithRsaSignature class which extends Signature and holds the signature bits and other info representing a SHA256-with-RSA signature in a data packet.

class pyndn.sha256_with_rsa_signature.Sha256WithRsaSignature(value=None)[source]

Bases: pyndn.signature.Signature

Create a new Sha256WithRsaSignature object, possibly copying values from another object.

Parameters:value (Sha256WithRsaSignature) – (optional) If value is a Sha256WithRsaSignature, copy its values. If value is omitted, the keyLocator is the default with unspecified values and the signature is unspecified.
clear()[source]
clone()[source]

Create a new Sha256WithRsaSignature which is a copy of this object.

Returns:A new object which is a copy of this object.
Return type:Sha256WithRsaSignature
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:The change count.
Return type:int
getKeyLocator()[source]

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
getSignature()[source]

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
keyLocator

Get the key locator.

Returns:The key locator.
Return type:KeyLocator
setKeyLocator(keyLocator)[source]

Set the key locator to a copy of the given keyLocator.

Parameters:keyLocator (KeyLocator) – The KeyLocator to copy.
setSignature(signature)[source]

Set the signature bytes to the given value.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
signature

Get the data packet’s signature bytes.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob

pyndn.signature module

This module defines the Signature class which is an abstract base class providing methods to work with the signature information in an NDN Data packet. You must use an object of a subclass, for example Sha256WithRsaSignature.

class pyndn.signature.Signature[source]

Bases: object

clone()[source]

Create a new Signature which is a copy of this signature. Your derived class should override.

Returns:A new object which is a copy of this object.
Return type:A subclass of Signature
Raises RuntimeError:
 for unimplemented if the derived class does not override.
getChangeCount()[source]

Get the change count, which is incremented each time this object (or a child object) is changed. Your derived class should override.

Returns:The change count.
Return type:int
Raises RuntimeError:
 for unimplemented if the derived class does not override.
getSignature()[source]

Get the data packet’s signature bytes. Your derived class should override.

Returns:The signature bytes as a Blob, which maybe isNull().
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
setSignature(signature)[source]

Set the signature bytes to the given value. Your derived class should override.

Parameters:signature (A Blob or an array type with int elements) – The array with the signature bytes. If signature is not a Blob, then create a new Blob to copy the bytes (otherwise take another pointer to the same Blob).
Raises RuntimeError:
 for unimplemented if the derived class does not override.

pyndn.threadsafe_face module

This module defines the ThreadsafeFace class which extends Face to provide the main methods for NDN communication in a thread-safe manner.

class pyndn.threadsafe_face.ThreadsafeFace(loop, arg1=None, arg2=None)[source]

Bases: pyndn.face.Face

Create a new ThreadsafeFace to use the asyncio loop to process events and schedule communication calls. You must start the loop on the thread in which you want the library to call communication callbacks such as onData and onInterest. In Python <= 3.2, you must have the prerequisite Trollius library. See the INSTALL file for installation details. For usage, see the example test_get_async_threadsafe.py. This constructor has the forms ThreadsafeFace(loop), ThreadsafeFace(loop, transport, connectionInfo) or ThreadsafeFace(loop, host, port). If the default Face(loop) constructor is used, if the forwarder’s Unix socket file exists then connect using AsyncUnixTransport, otherwise connect to “localhost” on port 6363 using AsyncTcpTransport. You do not need to call processEvents since the asyncio loop does all processing. (Exception: If you pass a transport that is not an async transport like AsyncTcpTransport, then your application needs to call processEvents.)

Parameters:
  • loop – The event loop, for example from asyncio.get_event_loop(). It is the responsibility of the application to start and stop the loop.
  • transport (Transport) – An object of a subclass of Transport used for communication. If you do not want to call processEvents, then the transport should be an async transport like AsyncTcpTransport, in which case the transport should use the same loop.
  • connectionInfo (Transport.ConnectionInfo) – An object of a subclass of Transport.ConnectionInfo to be used to connect to the transport.
  • host (str) – In the Face(host, port) form of the constructor, host is the host of the NDN hub to connect using TcpTransport.
  • port (int) – (optional) In the Face(host, port) form of the constructor, port is the port of the NDN hub. If omitted. use 6363.
callLater(delayMilliseconds, callback)[source]

Override to call callback() after the given delay, using self._loop.call_later. This means that processEvents() is not needed to handle interest timeouts. Even though this is public, it is not part of the public API of Face.

Parameters:
  • delayMilliseconds (float) – The delay in milliseconds.
  • callback (function object) – This calls callback() after the delay.
expressInterest(interestOrName, arg2, arg3=None, arg4=None, arg5=None, arg6=None)[source]

Override to use the event loop given to the constructor to schedule expressInterest to be called in a thread-safe manner. See Face.expressInterest for calling details.

registerPrefix(prefix, onInterest, onRegisterFailed, onRegisterSuccess=None, flags=None, wireFormat=None)[source]

Override to use the event loop given to the constructor to schedule registerPrefix to be called in a thread-safe manner. See Face.registerPrefix for calling details.

removePendingInterest(pendingInterestId)[source]

Override to use the event loop given to the constructor to schedule removePendingInterest to be called in a thread-safe manner. See Face.removePendingInterest for calling details.

removeRegisteredPrefix(registeredPrefixId)[source]

Override to use the event loop given to the constructor to schedule removeRegisteredPrefix to be called in a thread-safe manner. See Face.removeRegisteredPrefix for calling details.

send(encoding)[source]

Override to use the event loop given to the constructor to schedule send to be called in a manner. See Face.send for calling details.

setInterestFilter(filterOrPrefix, onInterest)[source]

Override to use the event loop given to the constructor to schedule setInterestFilter to be called in a thread-safe manner. See Face.setInterestFilter for calling details.

unsetInterestFilter(interestFilterId)[source]

Override to use the event loop given to the constructor to schedule unsetInterestFilter to be called in a thread-safe manner. See Face.unsetInterestFilter for calling details.

Module contents