Policies
Policy Types
- class ndn.schema.policy.Cache
Cache policy determines how Data packets are stored.
- class ndn.schema.policy.DataEncryption
DataEncryption policy is a type used to indicate the Data encryption policy. Used as the type argument of set_policy.
- class ndn.schema.policy.DataSigning
DataSigning policy is a type used to indicate the Data signer. Used as the type argument of set_policy.
- class ndn.schema.policy.DataValidator
DataValidator policy describes how to verify a Data packet.
- class ndn.schema.policy.Encryption
Encryption policy encrypts and decrypts content. When a user uses encryption policy, he needs to specify whether its
InterestEncryption
orDataEncryption
.
- class ndn.schema.policy.InterestEncryption
InterestSigning policy is a type used to indicate the Interest encryption policy. Used as the type argument of set_policy.
- class ndn.schema.policy.InterestSigning
InterestSigning policy is a type used to indicate the Interest signer. Used as the type argument of set_policy.
- class ndn.schema.policy.InterestValidator
InterestValidator policy describes how to verify an Interest packet.
- class ndn.schema.policy.LocalOnly
LocalOnly means the Data should be stored in the local storage. It prevents the node from sending Interest packets.
- class ndn.schema.policy.Policy
Policy is an annotation attached to a node.
- class ndn.schema.policy.Register
Register policy indicates the node should be registered as a prefix in the forwarder.
- class ndn.schema.policy.Signing
Signing policy gives a signer used to sign a packet. When a user uses signing policy, he needs to specify whether its
InterestSigning
orDataSigning
.
Trust Policies
- class ndn.schema.simple_trust.SignedBy(key, subject_to=None)
SignedBy policy represents the trust schema, specifying the key used to signed the Interest or Data packet. It does the follows:
Match the key used to sign the packet in the static tree. The real key must match the node specified by
key
. Otherwise, the validation fails.Call the checker
subject_to
with two matching variable dict. Fail if the checker returnsFalse
.Call the
need
function of the matched key node to get the public key. Fail if the key cannot be fetched.Verify the signature.
Note
Theoretically, SignedBy should also give the signer used to sign outgoing packets. However, this function is missing in current implementation.
For example,
# This checker checks the Author of Data is the same as the Author of the key. def check_author(data_env, key_env): return data_env['Author'] == key_env['Author'] root = Node() root['/author/<Author>/KEY/<KeyID>/self/<CertID>'] = Node() root['/blog/<Author>/<Category>/<Date>'] = Node() # The Data "/blog/<Author>/<Category>/<Date>" should be signed by # the key "/author/<Author>/KEY/<KeyID>" with the same author. root['/blog/<Author>/<Category>/<Date>'].set_policy( policy.DataValidator, SignedBy(root['/author/<Author>/KEY/<KeyID>'], subject_to=check_author))
Cache Policies
- class ndn.schema.simple_cache.MemoryCache
MemoryCache is a simple cache class that supports searching and storing Data packets in the memory.
- async save(name, packet)
Save a Data packet with name into the memory storage.
- Parameters:
name (
List
[Union
[bytes
,bytearray
,memoryview
]]) – the Data name.packet (
Union
[bytes
,bytearray
,memoryview
]) – the raw Data packet.
- async search(name, param)
Search for the data packet that satisfying an Interest packet with name specified.
- Parameters:
name (
List
[Union
[bytes
,bytearray
,memoryview
]]) – the Interest name.param (
InterestParam
) – the parameters of the Interest. Not used in current implementation.
- Returns:
a raw Data packet or None.
- class ndn.schema.simple_cache.MemoryCachePolicy(cache)
MemoryCachePolicy stores Data packets in memory.