pyndn.sync.detail package

Submodules

pyndn.sync.detail.invertible_bloom_lookup_table module

This module defines the InvertibleBloomLookupTable class which implements an Invertible Bloom Lookup Table (IBLT) (Invertible Bloom Filter). This is used by FullPSync2017.

class pyndn.sync.detail.invertible_bloom_lookup_table.InvertibleBloomLookupTable(value)[source]

Bases: object

There are two forms of the constructor: InvertibleBloomLookupTable(expectedNEntries) - Create an InvertibleBloomLookupTable with the expected number of entries. InvertibleBloomLookupTable(iblt) - Create an InvertibleBloomLookupTable as a copy of the given iblt.

Parameters:
  • expectedNEntries (int) – the expected number of entries in the IBLT.
  • iblt (InvertibleBloomLookupTable) – The other InvertibleBloomLookupTable to copy.
ERASE = -1
INSERT = 1
N_HASH = 3
N_HASHCHECK = 11
difference(other)[source]

Get a new IBLT which is the difference of the other IBLT from this IBLT.

Parameters:other (InvertibleBloomLookupTable) – The other IBLT.
Returns:A new IBLT of this - other.
Return type:InvertibleBloomLookupTable
encode()[source]

Encode this IBLT to a Blob. This encodes this hash table from a uint32_t array to a uint8_t array. We create a uin8_t array 12 times the size of the uint32_t array. We put the first count in the first 4 cells, keySum in the next 4, and keyCheck in the next 4. We repeat for all the other cells of the hash table. Then we append this uint8_t array to the name.

Returns:The encoded Blob.
Return type:Blob
equals(other)[source]

Check if this IBLT has the same number of entries as the other IBLT and that they are equal.

Parameters:other (InvertibleBloomLookupTable) – The other OBLT to check.
erase(key)[source]

Erase an entry for the key.

Parameters:key (int) –
initialize(encoding)[source]

Populate the hash table using the encoded array representation of the IBLT.

Parameters:encoding (Blob) – The encoded representation of the IBLT.
Raises:RuntimeError – if the size of the decoded values is not compatible with this IBLT.
insert(key)[source]

Insert an entry for the key.

Parameters:key (int) –
listEntries(positive, negative)[source]

List all the entries in the IBLT. This is called on a difference of two IBLTs: ownIBLT - receivedIBLT. Entries listed in positive are in ownIBLT but not in receivedIBLT. Entries listed in negative are in receivedIBLT but not in ownIBLT.

Parameters:
  • positive (set) – Add positive entries to this set. This first clears the set.
  • negative (set) – Add negative entries to this set. This first clears the set.
Returns:

True if decoding is completed successfully.

Return type:

bool

pyndn.sync.detail.psync_segment_publisher module

This module defines the PSyncSegmentPublisher class which has methods to publish segmented data used by PSync.

class pyndn.sync.detail.psync_segment_publisher.PSyncSegmentPublisher(face, keyChain, inMemoryStorageLimit=100)[source]

Bases: object

MAX_SEGMENTS_STORED = 100

Create a PSyncSegmentPublisher. :param Face face: The application’s Face. :param KeyChain keyChain: The KeyChain for signing Data packets. :param int inMemoryStorageLimit: (optional) The limit for the in-memory

storage. If omitted, use MAX_SEGMENTS_STORED.
publish(interestName, dataName, content, freshnessPeriod, signingInfo=<pyndn.security.signing_info.SigningInfo object>)[source]

Put all the segments in the memory store.

Parameters:
  • interestName (Name) – If the Interest name ends in a segment, immediately send the Data packet for the segment to the Face.
  • dataName (Name) – The Data name, which has components after the Interest name.
  • content (Blob) – The content of the data to be segmented.
:param float freshnessPeriod The freshness period of the segments,
in milliseconds.
:param SigningInfo signingInfo (optional) The SigningInfo for signing
segment Data packets. If omitted, use the default SigningInfo().
replyFromStore(interestName)[source]

Try to reply to the Interest name from the memory store.

Parameters:interestName (Name) – The Interest name for looking up in the memory store.
Returns:True if sent the segment Data packet to the Face, or false if we cannot find the segment, in which case the caller is expected to publish the segment.
Return type:bool

pyndn.sync.detail.psync_state module

This module defines the PSyncState class which represents a sequence of Names as the state of PSync. It has methods to encode and decode for the wire.

class pyndn.sync.detail.psync_state.PSyncState(input=None)[source]

Bases: object

Create a PSyncState and optionally decode the input as an NDN-TLV PSyncContent.

Parameters:input (Blob or an array type with int elements) – (optional) If supplied, input is the array with the bytes to decode. If omitted, create a PSyncState with empty content.
Tlv_PSyncContent = 128
addContent(name)[source]

Append the name to the content.

Parameters:name (Name) – The Name to add, which is copied.
clear()[source]

Remove the content.

getContent()[source]

Get the sequence of Names in the content.

Returns:The array of Names, which you should not modify.
Return type:Array<Name>
toString()[source]

Get the string representation of this PSyncState.

Returns:The string representation.
Return type:str
wireDecode(input)[source]

Decode the input as an NDN-TLV PSyncContent and update this object.

Parameters:input (Blob or an array type with int elements) – The array with the bytes to decode.
wireEncode()[source]

Encode this as an NDN-TLV PSyncContent.

Returns:The encoding as a Blob.
Return type:Blob

pyndn.sync.detail.psync_user_prefixes module

This module defines the PSyncUserPrefixes class which holds the _prefixes map from prefix to sequence number, used by PSyncPartialProducer and FullPSync2017WithUsers.

class pyndn.sync.detail.psync_user_prefixes.PSyncUserPrefixes[source]

Bases: object

addUserNode(prefix)[source]

Add a user node for synchronization based on the prefix Name, and initialize the sequence number to zero. However, if the prefix Name already exists, then do nothing and return False. This does not add sequence number zero to the IBLT because, if a large number of user nodes are added, then decoding the difference between our own IBLT and the other IBLT will not be possible.

Parameters:prefix (Name) – The prefix Name of the user node to be added.
Returns:True if the user node with the prefix Name was added, False if the prefix Name already exists.
Return type:bool
getSequenceNo(prefix)[source]

Return the current sequence number of the given prefix.

Parameters:prefix (Name) – The prefix for the sequence number.
Returns:The sequence number for the prefix, or -1 if not found.
Return type:int
isUserNode(prefix)[source]

Check if the prefix is in _prefixes.

Parameters:prefix (Name) – The prefix to check.
Returns:True if the prefix is in _prefixes.
Return type:bool
removeUserNode(prefix)[source]

Remove the user node from synchronization. If the prefix is not in _prefixes, then do nothing. The caller should first check isUserNode(prefix) and erase the prefix from the IBLT and other maps if needed.

Parameters:prefix (Name) – The prefix Name of the user node to be removed.
updateSequenceNo(prefix, sequenceNo, oldSequenceNo)[source]

Update prefixes_ with the given prefix and sequence number. This does not update the IBLT. This logs a message for the update. Whoever calls this needs to make sure that isUserNode(prefix) is true.

Parameters:
  • prefix (Name) – The prefix of the update.
  • sequenceNo (int) – The sequence number of the update.
  • oldSequenceNo (Array<int>) – This sets oldSequenceNo[0] to the old sequence number for the prefix. If this method returns True and oldSequenceNo[0] is not zero, the caller can remove the old prefix from the IBLT.
:return True if the sequence number was updated, False if the prefix was
not in _prefixes, or if the sequenceNo is less than or equal to the old sequence number. If this returns False, the caller should not update the IBLT.
Return type:bool

Module contents