APIs Provided by SuperNode

This topic explains how to use the APIs provided by the SuperNode (the cluster manager).

Registration

  1. POST /peer/registry

Parameters

Parameters are encodeds as application/x-www-form-urlencoded.

ParameterTypeDescription
cidStringThe client ID.
ipString (IPv4)The client IP address.
hostNameStringThe hostname of the client.
superNodeIpString (IPv4)The IP address of the registered SuperNode.
portIntegerThe port which the client opens for P2P downloading.
callSystemStringThe caller identifier.
versionStringThe client version.
dfdaemonBooleanTells whether it is a call from dfdaemon.
pathStringThe service path which the client offers.
rawUrlStringThe resource URL provided by command line parameter.
taskUrlStringThe resource URL.
md5StringThe MD5 checksum for the resource. Optional.
identifierStringThe resource identifer.
headersMapExtra HTTP headers to be sent to the raw URL.

Upon receiving a request of registration from the client, the SuperNode constructs a new instance of based on the information provided by parameters. Specifically, it generates a task with taskId based on rawUrl, md5, and identifier.

Then the task is stored in the memory cache. Meanwhile, the SuperNode retrieves extra information such as the content-length which normally would be set. The pieceSize is calculated as per the following strategy:

  1. If the total size is less than 200MB, then the piece size is 4MB by default.
  2. Otherwise, it equals to the smaller value between (${totalSize} / 100MB) + 2 MB and 15MB.

Next, the peer information along with the task will be recorded:

  1. The peer will be saved.
  2. The task will be saved.

The last step is to trigger a progress.

Response

An example response:

  1. {
  2. "code": 200,
  3. "data": {
  4. "fileLength": 687481,
  5. "pieceSize": 4194304,
  6. "taskId": "ba270626349198840d0255de8358b6c93fe6d57d922d036fbf40bcf3499f44a8"
  7. }
  8. }

Other possible values of code in the response include:

  • 606: The task ID already exists.
  • 607: The URL is invalid.
  • 608 or 609: Authentication required.

Get Task

  1. GET /peer/task

Parameters

ParameterTypeDescription
superNodeString (IPv4)The IP address of the super node.
dstCIDStringThe destination client ID.
rangeStringByte range.
statusInteger
resultInteger
taskIdStringThe task ID.
srcCIDStringThe source client ID.

First, the SuperNode will analyze the status and result.

  • Running: if status == 701.
  • Success: if status == 702 and result == 501.
  • Fail: if status == 702 and result == 500.
  • Wait: if status == 700.

In Wait status, the SuperNode will save the status to be Running.

In Running status, the SuperNode will extract the piece status:

  • Success: if result == 501.
  • Fail: if result == 500.
  • SemiSuc: if result == 503.

Tip: result == 502 suggests invalid code.

Then the SuperNode updates the progress for this specific task, and checks the status of the task and the peers. After this, the SuperNode tells the client which peer has enough details to download another piece. Otherwise, it fails.

Response

An example resonse:

  1. {
  2. "code": 602,
  3. "msg": "client sucCount:0,cdn status:Running,cdn sucCount: 0"
  4. }

This example response means that the client has to wait, since no peer can serve this piece now. If there is a peer which can serve this request, the response will be something like:

  1. {
  2. "code": 601,
  3. "data": [
  4. {
  5. "cid": "cdnnode:10.148.177.242~ba270626349198840d0255de8358b6c93fe6d57d922d036fbf40bcf3499f44a8",
  6. "downLink": "20480",
  7. "path": "/qtdown/ba2/ba270626349198840d0255de8358b6c93fe6d57d922d036fbf40bcf3499f44a8",
  8. "peerIp": "10.148.177.242",
  9. "peerPort": 8001,
  10. "pieceMd5": "d78ef0af9e95e880fa583b41cf5ad791:687486",
  11. "pieceNum": 0,
  12. "pieceSize": 4194304,
  13. "range": "0-4194303"
  14. }
  15. ]
  16. }

Peer Progress

  1. GET /peer/piece/suc

Parameters

ParameterTypeDescription
dstCIDStringThe destination client ID.
pieceRangeStringByte range.
taskIdStringThe task ID.
cIDStringThe client ID.

Response

An example response:

  1. {
  2. "code": 200,
  3. "msg": "success"
  4. }