IPFS Usage
This section details how IPFS is used within the Embedded Blockchain Surveillance System, including how video data is uploaded from IoT devices, retrieved by the cloud server, and linked to smart contracts via CIDs and timestamps.
Overview
IPFS (InterPlanetary File System) is used in the Embedded Blockchain Surveillance System to provide decentralized storage for:
- Surveillance video streams from IoT devices.
- Mugshots and other images for criminal profiles.
- Metadata and logs related to surveillance sessions.
By using IPFS, the system ensures that this critical data is:
- Permanently available (as long as it is pinned).
- Tamper-proof (immutable once stored).
- Distributed (no single point of failure).
Data Storage Architecture
Content Addressing
All files stored on IPFS are referenced by their Content Identifier (CID), which is a cryptographic hash of the file content. This ensures:
- Immutability: Files cannot be changed without generating a new CID.
- Verifiability: Anyone can verify file integrity by hashing the content.
- Deduplication: Identical files are stored only once across the network.
File Types and Usage
| File Type | Usage | Example CID |
|---|---|---|
| Surveillance Video | Raw or processed video footage from an event | bafybeig... |
| Criminal Mugshot | Profile images for criminal identification | bafkreib... |
| Session Metadata | JSON file containing details about a surveillance session | bafkreih... |
Integration with Smart Contracts
Storing References
Rather than storing large files on the blockchain, smart contracts store only the CIDs:
solidity
struct CriminalProfile {
uint id;
string name;
string[] aliases;
string[] offenses;
string cid; // IPFS CID for mugshot
}
struct SurveillanceEvent {
uint id;
uint sessionId;
uint deviceId;
uint timestamp;
Detection[] detections;
string cid; // IPFS CID for video footage
uint createdAt;
}Retrieving Files
When the web application needs to display a criminal's mugshot or a surveillance video:
- The smart contract is queried for the relevant record (e.g., a
CriminalProfileorSurveillanceEvent). - The
cidis extracted from the struct. - An IPFS gateway is used to retrieve the file:
https://ipfs.io/ipfs/{cid}. - The file (image or video) is displayed to the user.
Upload Process (IoT Device -> Server -> IPFS)
- Capture: An IoT device (like an ESP32-CAM) detects motion and captures a video stream.
- Transmit: The device sends the video data to the central cloud server.
- Process & Upload: The server receives the data. It may perform initial processing (like face detection) and then uploads the video file to IPFS using a library like
helia. - Get CID: IPFS returns a unique CID for the uploaded video.
- Smart Contract Update: The server calls the
recordEventfunction on the appropriateSurveillanceSessioncontract, passing the CID, timestamp, and any detection data. The blockchain transaction creates an immutable link between the on-chain event and the off-chain video data.
Retrieval Process (Web App)
- Smart Contract Query: The frontend queries a
SurveillanceSessioncontract to get a list of events. - Extract CID: For a specific event, the frontend gets the
cidfrom theSurveillanceEventstruct. - IPFS Gateway Access: The frontend constructs the IPFS URL and retrieves the video file from an IPFS gateway.
- File Display: The retrieved video is displayed in the UI, often using an HTML5 video player.
Security Considerations
Content Integrity
- CIDs cryptographically guarantee that the video footage or mugshot has not been tampered with since it was first recorded.
- The link between the on-chain event and the off-chain data is immutable.
Privacy
- All data on the public IPFS network is public.
- For a real-world application, sensitive surveillance footage must be encrypted on the server before being uploaded to IPFS.
- Decryption keys would need to be managed securely and only made available to authorized users (e.g., via the application backend).
Best Practices
File Optimization
- Compress video streams using modern codecs (like H.264 or VP9) to reduce file size without significant quality loss.
- Standardize on efficient image formats like WebP for mugshots.
Pinning Strategy
- Use a reliable pinning service like Pinata to ensure that all critical evidence is permanently available.
- Implement automated pinning for all new surveillance events.
Error Handling
- Implement fallback IPFS gateways in the web application in case one is down.
- Use loading indicators and handle cases where video retrieval might be slow.