Client-side packages

Introduction

Application built with python-ndn can make use of the client packages provided.

There are four parts:

  1. PutfileClient: insert files into the repo.

  2. GetfileClient: get files from the repo.

  3. DeleteClient: detele data packets from the repo.

  4. CommandChecker: check process status from the repo.

The example programs in examples/ illustrate how to use these packages.

Note that the type Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview] in the documentation is equivalent to the ndn.name.NonStrictName type.

Reference

class ndn_python_repo.clients.putfile.PutfileClient(app, prefix, repo_name)

A client to insert files into the repo.

Parameters:
  • app (NDNApp) – NDNApp.

  • prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. The name of this client

  • repo_name (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. Routable name to remote repo.

async insert_file(file_path, name_at_repo, segment_size, freshness_period, cpu_count, forwarding_hint=None, register_prefix=None, check_prefix=None)

Insert a file to remote repo.

Parameters:
  • file_path (str) – Local FS path to file to insert.

  • name_at_repo (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. Name used to store file at repo.

  • segment_size (int) – Max size of data packets.

  • freshness_period (int) – Freshness of data packets.

  • cpu_count (int) – Cores used for converting file to TLV format.

  • forwarding_hint (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview, None]) – NonStrictName. The forwarding hint the repo uses when fetching data.

  • register_prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview, None]) – NonStrictName. If repo is configured with register_root=False, it registers register_prefix after receiving the insertion command.

  • check_prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview, None]) – NonStrictName. The repo will publish process check messages under <check_prefix>/check. It is necessary to specify this value in the param, instead of using a predefined prefix, to make sure the subscriber can register this prefix under the NDN prefix registration security model. If not specified, default value is the client prefix.

Return type:

int

Returns:

Number of packets inserted.

class ndn_python_repo.clients.getfile.GetfileClient(app, repo_name)

This client fetches a file from the repo, and save it to working directory.

A client to retrieve files from the remote repo.

Parameters:
  • app (NDNApp) – NDNApp.

  • repo_name – NonStrictName. Routable name to remote repo.

async fetch_file(name_at_repo, local_filename=None, overwrite=False)

Fetch a file from remote repo, and write to the current working directory.

Parameters:
  • name_at_repo (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. The name with which this file is stored in the repo.

  • local_filename (str) – str. The filename of the retrieved file on the local file system.

  • overwrite – If true, existing files are replaced.

class ndn_python_repo.clients.delete.DeleteClient(app, prefix, repo_name)

This client deletes data packets from the remote repo.

Parameters:
  • app (NDNApp) – NDNApp.

  • repo_name (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. Routable name to remote repo.

async delete_file(prefix, start_block_id=0, end_block_id=None, register_prefix=None, check_prefix=None)

Delete from repo packets between “<name_at_repo>/<start_block_id>” and “<name_at_repo>/<end_block_id>” inclusively.

Parameters:
  • prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. The name of the file stored in the remote repo.

  • start_block_id (int) – int. Default value is 0.

  • end_block_id (int) – int. If not specified, repo will attempt to delete all data packets with segment number starting from start_block_id continously.

  • register_prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview, None]) – If repo is configured with register_root=False, it unregisters register_prefix after receiving the deletion command.

  • check_prefix (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview, None]) – NonStrictName. The repo will publish process check messages under <check_prefix>/check. It is necessary to specify this value in the param, instead of using a predefined prefix, to make sure the subscriber can register this prefix under the NDN prefix registration security model. If not specified, default value is the client prefix.

Return type:

int

Returns:

Number of deleted packets.

class ndn_python_repo.clients.command_checker.CommandChecker(app)

This client sends check interests to the repo.

Parameters:

app (NDNApp) – NDNApp.

async check_delete(repo_name, request_no)

Check the status of a delete process.

Parameters:
  • repo_name – NonStrictName. The name of the remote repo.

  • request_no (bytes) – bytes. The request id of the process to check.

Return type:

RepoCommandRes

Returns:

The response from the repo.

async check_insert(repo_name, request_no)

Check the status of an insert process.

Parameters:
  • repo_name (Union[Iterable[Union[bytes, bytearray, memoryview, str]], str, bytes, bytearray, memoryview]) – NonStrictName. The name of the remote repo.

  • request_no (bytes) – bytes. The request id of the process to check.

Return type:

RepoCommandRes

Returns:

The response from the repo.