How chandanneralgi/decentralized-file-sharing-system works
Main Components
• Two Node Instances: From the file tree you see “client_server_1” and “main_server”, each representing an independent node running a similar server with a blockchain module. Label them (e.g., “Node A” and “Node B”).
• Blockchain Module: Each node contains a blockchain.py file; this module is responsible for handling block creation, including block index, timestamp, proof, previous hash, and file sharing data (sender, receiver, file hash).
• Server Component: Both directories include a server.py file, which likely manages HTTP endpoints (for file upload/download) and peer-to-peer connections via socket programming.
• Encryption & Constants: The my_constants.py file in each node defines key settings, and the code uses AES for encryption and SHA-256 for hashing.
• User Interface (UI): The static and templates folders in each node show the existence of front-end assets (HTML, CSS, JS) for connecting to the blockchain, uploading files, and downloading files.
• External IPFS Service: Though not a local directory item, the README explains integration with IPFS for storing the actual files so that the blockchain only holds the file’s hash.
• P2P Networking: The peer-to-peer communication (via socket programming) is critical to maintaining synchronized blockchain state across nodes, as explained in the “Creating the Peer to Peer Network” section of the README.
Relationships and Interactions
• Each node’s server handles incoming HTTP requests from a user interface that serves upload/download pages.
• When a file is uploaded, the following happens:
• The file is encrypted with AES using a file key.
• It is sent to IPFS for decentralized storage.
• The blockchain module creates a new block that includes the file’s IPFS hash along with sender/receiver data.
• Nodes communicate via sockets to update and share the current state of the blockchain across the network (the P2P network).
• For file download, a valid file key decrypts the file retrieved from IPFS using its hash stored on the blockchain.
Important Architectural Patterns and Design Principles
• Decentralization: The system uses peer-to-peer networking to maintain a decentralized and replicated blockchain among nodes.
• Layered Architecture: Separate layers for presentation (UI templates & static assets), application logic (server.py and blockchain.py), and external services (IPFS).
• Security by Design: Incorporation of SHA-256 and AES encryption demonstrates a commitment to security (e.g., linking a block’s integrity and ensuring file privacy).
• Loose Coupling: The blockchain module and IPFS integration are decoupled from each node’s server logic, providing modular segments that can work or be scaled independently.