Class: Producer

Producer

new Producer(prefix, dataType, face, keyChain, database, repeatAttempts)

A Producer manages content keys used to encrypt a data packet in the group-based encryption protocol. Create a Producer to use the given ProducerDb, Face and other values. A producer can produce data with a naming convention: //SAMPLE//[timestamp] The produced data packet is encrypted with a content key, which is stored in the ProducerDb database. A producer also needs to produce data containing a content key encrypted with E-KEYs. A producer can retrieve E-KEYs through the face, and will re-try for at most repeatAttemps times when E-KEY retrieval fails.
Parameters:
Name Type Description
prefix Name The producer name prefix. This makes a copy of the Name.
dataType Name The dataType portion of the producer name. This makes a copy of the Name.
face Face The face used to retrieve keys.
keyChain KeyChain The keyChain used to sign data packets.
database ProducerDb The ProducerDb database for storing keys.
repeatAttempts number (optional) The maximum retry for retrieving keys. If omitted, use a default value of 3.
Source:

Methods

(static) defaultOnError()

The default onError callback which does nothing.
Source:

(static) excludeAfter(exclude, from)

Exclude all components in the range beginning at "from".
Parameters:
Name Type Description
exclude Exclude The Exclude object to update.
from Name.Component The first component in the exclude range.
Source:

(static) excludeBefore(exclude, to)

Exclude all components in the range ending at "to".
Parameters:
Name Type Description
exclude Exclude The Exclude object to update.
to Name.Component The last component in the exclude range.
Source:

(static) ExcludeEntry(component, anyFollowsComponent)

Create a new ExcludeEntry.
Parameters:
Name Type Description
component Name.Component
anyFollowsComponent boolean
Source:

(static) excludeRange(exclude, from, to)

Exclude all components in the range beginning at "from" and ending at "to".
Parameters:
Name Type Description
exclude Exclude The Exclude object to update.
from Name.Component The first component in the exclude range.
to Name.Component The last component in the exclude range.
Source:

(static) findEntryBeforeOrAt(entries, component) → {number}

Get the latest entry in the array whose component_ is less than or equal to component.
Parameters:
Name Type Description
entries Array.<ExcludeEntry> The array of ExcludeEntry.
component Name.Component The component to compare.
Source:
Returns:
The index of the found entry, or -1 if not found.
Type
number

(static) getExcludeEntries(exclude) → {Array.<ExcludeEntry>}

Create a list of ExcludeEntry from the Exclude object.
Parameters:
Name Type Description
exclude Exclude The Exclude object to read.
Source:
Returns:
A new array of ExcludeEntry.
Type
Array.<ExcludeEntry>

(static) getRoundedTimeSlot_(timeSlot) → {number}

Round timeSlot to the nearest whole hour, so that we can store content keys uniformly (by start of the hour).
Parameters:
Name Type Description
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
Source:
Returns:
The start of the hour as milliseconds since Jan 1, 1970 UTC.
Type
number

(static) setExcludeEntries(exclude, entries)

Set the Exclude object from the array of ExcludeEntry.
Parameters:
Name Type Description
exclude Exclude The Exclude object to update.
entries Array.<ExcludeEntry> The array of ExcludeEntry.
Source:

createContentKey(timeSlot, onEncryptedKeys, onContentKeyName, onError)

Create the content key corresponding to the timeSlot. This first checks if the content key exists. For an existing content key, this returns the content key name directly. If the key does not exist, this creates one and encrypts it using the corresponding E-KEYs. The encrypted content keys are passed to the onEncryptedKeys callback.
Parameters:
Name Type Description
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
onEncryptedKeys function If this creates a content key, then this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onContentKeyName function This calls onContentKeyName(contentKeyName) with the content key name for the time slot. If onContentKeyName is null, this does not use it. (A callback is needed because of async database operations.) NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onError function (optional) This calls onError(errorCode, message) for an error, where errorCode is from EncryptError.ErrorCode and message is a string. If omitted, use a default callback which does nothing. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
Source:

encryptContentKeyPromise_(encryptionKey, eKeyName, timeSlot, onEncryptedKeys, onError) → {Promise}

Get the content key from the database_ and encrypt it for the timeSlot using encryptionKey.
Parameters:
Name Type Description
encryptionKey Blob The encryption key value.
eKeyName Name The key name for the EncryptedContent.
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
onEncryptedKeys function When there are no more interests to process, this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.
onError function This calls onError(errorCode, message) for an error.
Source:
Returns:
A promise that returns true if encryption succeeds, otherwise false.
Type
Promise

handleCoveringKey_(interest, data, timeSlot, onEncryptedKeys, onError)

This is called from an expressInterest OnData to check that the encryption key contained in data fits the timeSlot. This sends a refined interest if required.
Parameters:
Name Type Description
interest Interest The interest given to expressInterest.
data Data The fetched Data packet.
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
onEncryptedKeys function When there are no more interests to process, this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.
onError function This calls onError(errorCode, message) for an error.
Source:

handleTimeout_(interest, timeSlot, onEncryptedKeys, onError)

This is called from an expressInterest timeout to update the state of keyRequest. Re-express the interest if the number of retrials is less than the max limit.
Parameters:
Name Type Description
interest Interest The timed-out interest.
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
onEncryptedKeys function When there are no more interests to process, this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.
onError function This calls onError(errorCode, message) for an error.
Source:

produce(data, timeSlot, content, onComplete, onError)

Encrypt the given content with the content key that covers timeSlot, and update the data packet with the encrypted content and an appropriate data name.
Parameters:
Name Type Description
data Data An empty Data object which is updated.
timeSlot number The time slot as milliseconds since Jan 1, 1970 UTC.
content Blob The content to encrypt.
onComplete function This calls onComplete() when the data packet has been updated. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onError function (optional) This calls onError(errorCode, message) for an error, where errorCode is from EncryptError.ErrorCode and message is a string. If omitted, use a default callback which does nothing. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
Source:

sendKeyInterest_(interest, timeSlot, onEncryptedKeys, onError)

Send an interest with the given name through the face with callbacks to handleCoveringKey_ and handleTimeout_.
Parameters:
Name Type Description
interest Interest The interest to send.
timeSlot number The time slot, passed to handleCoveringKey_ and handleTimeout_.
onEncryptedKeys function The OnEncryptedKeys callback, passed to handleCoveringKey_ and handleTimeout_.
onError function This calls onError(errorCode, message) for an error.
Source:

updateKeyRequest_(keyRequest, timeCount, onEncryptedKeys)

Decrease the count of outstanding E-KEY interests for the C-KEY for timeCount. If the count decreases to 0, invoke onEncryptedKeys.
Parameters:
Name Type Description
keyRequest Producer.KeyRequest_ The KeyRequest with the interestCount to update.
timeCount number The time count for indexing keyRequests_.
onEncryptedKeys function When there are no more interests to process, this calls onEncryptedKeys(keys) where keys is a list of encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.
Source: