Distributed-flagging-system

Distributed Flagging System

A secure social media application which uses Distributed Computing to verify if a image a user wants to post is similar to the images given in the reference database. This is achieved using hashing methods like Perceptual Hashing, Average hashing, Difference hashing and Median hashing where the hash values are precomputed for reference images in a Database.

The uploaded image is then hashed with it's respective hash and later verified with the precomputed hashes with Hamming Distance and a threshold for the System to decide whether to vote or not for the given image.

If a Quorum exists the image isn't uploaded to the social media and the user is flagged and banned from the application after 2 warnings (Since this a proof of concept we used Cat Images as the reference image, so you can't post cat images in this server).

</img>

Image Hashing Algorithms

Image Hashing is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions which rely on the avalanche effect of small changes in input leading to drastic changes in the output here we use Similarity of Images.

Image Image Hash
</img> </img>
Query Image (Cat) 0xa4ad99b3629076ae

The above is an Example of Image Hashing Where We Query Using an Image and It’s Hash is computed on Each Server depending on the algorithm

Image Hashing Algorithms Implemented

Perceptual Hash

Uses Discrete Cosine Transform to capture frequencies in the image and Perform hash based on the 8x8 upper-left part of image and set bit to 1 if > mean

Median Hash

Scale Down grayscale Image to 8x8 and compute Median of the values of pixels and set bit to 1 if > median

Average Hash

Compute the average of the pixel values in the image (8x8) without DCT and compute the hash

Difference Hash

After Image Scaling and Gray scaling compute dhash by computing the difference between adjacent pixels and compute hash

What’s the need for Multiple Algorithms?

Certain Algorithm are not resistant to image augmentation such as Skewing , Cropping , Contrast changes

Each Algorithm will have a threshold beyond which the algorithm identifies the image as illegal so we provide a distributed environment using raft consensus protocol where each hash is computed and voted based on its threshold ensuring:

1.Fault Tolerance (Regular Raft Leader Election at select time-intervals)
2.Reliablity (Multiple Servers' Vote Ensure Reliablity)
3.Safety 

System Voting Architecture

</img>

You can check out the immplementation here: Demo video

Replicated Classes and Types:

The following is the type initilization for the HashServer Class in Backend:

Make it Work for your Use Case:

Setup Instructions

Backend Setup

  1. Navigate to the backend directory.
  2. Create a virtual environment:
     > python3 -m venv venv
    
  3. Activate the virtual environment:
    • On Windows:
        > venv\Scripts\activate
      
    • On macOS and Linux:
        > source venv/bin/activate
      
  4. Install dependencies:
     > pip install -r requirements.txt
    
  5. Set up the database:
    • Modify the config.py file to specify your database configuration.
  6. Start the Flask server:
     > flask run
    

Frontend Setup

  1. Navigate to the d_flag directory.
  2. Install dependencies:
     > npm install
    
  3. Start the React development server:
     > npm start
    

Usage

Folder Structure

Authors