Skip to content

A lightweight decentralized social micro-network built with Flask, IPFS, and a local blockchain. Each node stores encrypted blocks, syncs peers over LAN, and delivers posts via IPFS—no central server required.

Notifications You must be signed in to change notification settings

TheTechTiger/DecentralizedSMN

Repository files navigation

🧱 Decentralized Blockchain Post System

A lightweight decentralized social micro-network powered by Flask, IPFS, and local blockchain.

Python Flask License GitHub


🧩 Overview

DecentralizedSMN is a Flask-based blockchain experiment that allows users in the same local network to create, share, and synchronize posts stored on IPFS, without relying on any central server.

Each device acts as an independent node, maintaining its own local blockchain, verifying integrity via cryptographic hashes, and syncing missing blocks automatically from peers.


🚀 Features

  • 🔒 Encrypted blockchain storage using cryptography.fernet
  • 🌐 Peer-to-peer block synchronization over LAN (fetchDevices.py)
  • 📦 IPFS-based content storage for decentralized posts
  • 🧠 Local identity management (userID file per node)
  • 💾 Persistent, verifiable blockchain in the blocks/ directory
  • ⚙️ Flask REST API for interacting with the blockchain
  • 🧾 Automatic recovery & verification of all blocks on startup

🗂️ Directory Structure


DecentralizedSMN/
│
├── app.py                     # Main Flask blockchain app
├── fetchDevices.py            # Local subnet scanner
├── ipfs_test.py               # IPFS upload/retrieve module
├── DB_Constructor.py          # (Optional) Database helper
├── blocks/                    # Encrypted blockchain storage
├── templates/
│   ├── create_post.html       # Post creation page
│   └── view_posts.html        # Optional UI for viewing posts
└── userID                     # Generated per user on first run


⚙️ Installation

1️⃣ Clone the repository

git clone https://github.com/TheTechTiger/DecentralizedSMN.git
cd DecentralizedSMN

2️⃣ Install dependencies

pip install flask cryptography requests

You may also need to install packages required by fetchDevices.py and your IPFS client.

3️⃣ Configure IPFS

Ensure ipfs_test.py implements these functions:

def ipfs_upload(content):
    # Uploads text content to IPFS and returns its CID
    ...

def ipfs_retrieve(cid):
    # Retrieves content from IPFS using the given CID
    ...

4️⃣ Network Scanning

Ensure fetchDevices.py includes:

def scan_all_subnets(port):
    # Scans local subnets for active devices running this app
    ...

▶️ Running the App

python app.py

On first launch:

  • A new user ID (userID) is generated.
  • You’ll be asked to enter your name.
  • The app will create a genesis block if none exists.

The Flask server will start at:

http://0.0.0.0:1878

🌍 REST API Endpoints

Endpoint Method Description
/block/<index> GET Retrieve a specific block by index
/blockcount GET Get total block count
/sync GET Sync blockchain with other devices in the network
/createPost GET/POST Create a new post (stored on IPFS)
/viewPosts/ GET View posts (paginated, 10 per page)
/updateBlockchain POST Replace local blockchain with provided JSON

🧠 Blockchain Structure

Each block includes metadata and a hash link to the previous chain state:

{
  "action": "create_post" | "create_acc" | "genesis",
  "hash": "<sha256_of_previous_chain>",
  "data": {
    "cid": "<ipfs_cid>",
    "token": "<user_token>"
  },
  "name": "<username>",
  "token": "<unique_user_id>"
}
  • Each block’s hash is derived from the entire previous chain to maintain integrity.

  • Blockchain files are encrypted per block using:

    key = b'65A100d105i116t105i97a107k104h105iTechTiger='

🖥️ Example Usage

✅ Create a Post

curl -X POST -F "content=Hello, decentralized world!" http://localhost:1878/createPost

✅ View Posts

curl http://localhost:1878/viewPosts/

✅ Sync with Other Devices

curl http://localhost:1878/sync

✅ Get Block Count

curl http://localhost:1878/blockcount

💡 How It Works

  1. Each node stores encrypted blocks in blocks/.
  2. Nodes use fetchDevices.py to discover peers on the same subnet.
  3. Missing blocks are fetched automatically from other devices.
  4. Posts are uploaded to IPFS for decentralized content delivery.
  5. All updates are cryptographically verified and appended to the local blockchain.

🔐 Security Notes

  • Blocks are encrypted with a symmetric Fernet key.
  • Each node must use the same key to decrypt and verify incoming blocks.
  • The system ensures data consistency and tamper resistance across nodes.

🧾 License

This project is released under the MIT License. You are free to use, modify, and distribute it with attribution.


🌟 Future Improvements

  • ✅ Digital signatures for user validation
  • ✅ Web dashboard for browsing posts
  • ✅ Peer discovery via UDP broadcast
  • ✅ Multi-gateway IPFS support
  • ✅ Optional encryption for post content

📎 Repository

GitHub: https://github.com/TheTechTiger/DecentralizedSMN


Built with ❤️ by TheTechTiger

"A small step towards decentralized micro-networks."

About

A lightweight decentralized social micro-network built with Flask, IPFS, and a local blockchain. Each node stores encrypted blocks, syncs peers over LAN, and delivers posts via IPFS—no central server required.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •