DIG-Network / dig-propagation-server

MIT License
1 stars 1 forks source link
chia-blockchain chia-network dig-network

Upload Protocol - README

Overview

This upload protocol manages file uploads securely and efficiently in a distributed storage network. Each upload session is tied to a unique session ID and is managed via a temporary folder with a customizable Time-to-Live (TTL). The protocol validates key ownership using signatures and supports flexible session handling, including file uploads, session commits, and aborts.

Key Features

API Endpoints

1. HEAD /stores/{storeId}

Description: Check if a store exists and optionally verify if a specific root hash exists in that store.

2. POST /upload/{storeId}

Description: Starts an upload session for a store. If the store does not exist, the user will be required to authenticate.

3. PUT /upload/{storeId}/{sessionId}/{filename}

Description: Uploads a file to the store within an active session. Each file must be validated with a nonce, key ownership signature, and the uploader's public key.

4. POST /commit/{storeId}/{sessionId}

Description: Finalizes the upload by moving files from the session's temporary folder to the store's permanent directory.

Example:

   POST /commit/myStoreId/12345-abcdef-67890

Response:

   {
     "message": "Upload for DataStore myStoreId under session 12345-abcdef-67890 committed successfully."
   }

5. POST /abort/{storeId}/{sessionId}

Description: Aborts the upload session, deletes the temporary session folder, and removes the session from the cache.

Example:

   POST /abort/myStoreId/12345-abcdef-67890

Response:

   {
     "message": "Upload session 12345-abcdef-67890 for DataStore myStoreId aborted and cleaned up."
   }

Example Workflow

  1. Start an Upload Session:

    • Call the POST /upload/{storeId} endpoint to start an upload session.
    • The server responds with a sessionId to track the session.
  2. Upload a File:

    • For each file, send a PUT /upload/{storeId}/{sessionId}/{filename} request.
    • Include the required headers (x-key-ownership-sig, x-public-key, and x-nonce).
  3. Commit the Session:

    • After all files are uploaded, call the POST /commit/{storeId}/{sessionId} endpoint to commit the session.
  4. Abort the Session (Optional):

    • If you need to abort the session and discard the uploaded files, use the POST /abort/{storeId}/{sessionId} endpoint.