PeernetOfficial / core

Core library. Use this to create a new Peernet application.
MIT License
36 stars 5 forks source link

[Draft] Peernet Chat system #111

Open Akilan1999 opened 1 year ago

Akilan1999 commented 1 year ago

Proposal: Chat system for file Shared in Peernet

Motivation

To crate a community interaction with a file posted on Peernet (i.e a Chat System for a p2p network). The proposal proposed new changes to be added to the Peernet protocol to accompany this change.

Expected contribution

High Overview

Database Structure

The database for the storing the Chat is not decided yet. Currently only the structured is discussed.

- <Hash name>
    - <File Name> 
    - <Current Hash> -> Hash of all the messages 
    (Hash (Previous messages) + Hash(New messages added))
    - <Last Message TimeStamp> - <ID>
    - <Messages>: 
        - <TimeStamp> - <NodeID> - <Message> ... N 
    .
    .
    .
    N

The hash mechanism ensures that the state of the previous messages is maintained. To conform to Timestamp standard all messages are stored in UTC+0 timezone. The later iterations will include a round robin database that will delete file chat history of files which are deleted or the last file visited in heap if space is constraint.

Tracker System

The tracker system is a in-memory Data-structure that tracks which file is the user currently viewing to notifying Chat system to send recent chats for that file only. It also includes a history of previous files viewed. This metadata would be useful when implementing a round robin database.

  - <TimeStamp> - <Hash> - <FileName>
  .
  .
  . 
  N

Syncing Mechanism

The Syncing mechanism is to ensure the Chats are the same on all the client viewing the file. The ensure that all Chats are sent to the owner who is hosting the file and Owner merges all incoming Chats and then broadcasts the merged Chats to other clients viewing the current file.

Nodes:
- A
- B 
- C
(<Sample File.txt> -> Node B: Hosting file)

Node A -> Sends a message

Node A (Latest Chat history)             Node B (Latest Chat History)       Node C (Latest Chat History)
     "Hello World"            ------>        (Merges with Chat      
                                                Database) 

     (Receives latest hash)    <-------       (New Hash)         ------>    Sends New Messages and new hash(Merges Latest Message                                            
     and Checks hash with Node
     B)

In the diagram above Node B handles the race condition of incoming Chats.