Skip to content

Commit 1c0e2a7

Browse files
authored
Merge pull request #5 from KrishnanSG/networking
Add documentation
2 parents 653dad2 + ae2be9e commit 1c0e2a7

File tree

8 files changed

+200
-102
lines changed

8 files changed

+200
-102
lines changed

P2P/README.md renamed to P2P/MessageFormat.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ Each message will have this format
99
1010
```
1111

12-
Maybe pad all the messages with some delimiter bytes to seperate the different requests
13-
1412
Once the BF is exchanged
1513
1. Call getMissingContent for both users
1614
2. Send the missing contents of user 1 to user 2
1715
3. Call merge function on user2 side
18-
4. Send entire file sha256 and check on both ends
16+
4. Send entire file hash value and check on both ends
1917
if equal
2018
done
2119
else
22-
send the entire file
20+
send the entire compressed file

P2P/Server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ def create_client(self,ip,port):
5959
host = socket.gethostname()
6060
client.connect((ip,port))
6161
client.setblocking(False)
62-
print("\nHi ",host," you are succesfully connected to")
62+
print("\nHi ",host," you are succesfully connected")

P2P/received_file

Whitespace-only changes.

P2P/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def parse_received_data(data):
4848
# Occurs sometimes when the contents received are not in utf-8
4949
# This can happen for example, when transmitting the hash value.
5050
str_message = bloom_filter
51-
print(bytes.hex(type_specifying_byte))
5251
type_int = int(bytes.hex(type_specifying_byte), 16)
5352
req = Request(type_int, str_message)
5453
return req

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
11
# Interact
2-
Real time file synchronization using Bloom Filter and Splay Tree
2+
3+
An easy to use real time file synchronization application built using Python.
4+
<img src="https://user-images.githubusercontent.com/43802499/68604424-71f7df00-04d0-11ea-9773-1d51344c8318.png" align="right"
5+
title="File-Sync" width="220" height="250">
6+
7+
## Getting Started
8+
9+
These instructions will get you a copy of the project and ready for on your local machine.
10+
11+
### Prerequisites
12+
- Python 3.7
13+
14+
- Clone this repository using the command:
15+
16+
```
17+
git clone https://github.com/KrishnanSG/Interact.git
18+
cd Interact
19+
```
20+
21+
- Then install a few required dependencies by using your favorite terminal
22+
23+
```
24+
pip install -r requirements.txt
25+
```
26+
27+
### How to Use
28+
29+
You're almost there.
30+
The following steps will guide you on how to use this tool.
31+
32+
1. Creating host server
33+
```
34+
python main.py <filename> --host
35+
```
36+
37+
2. Ask your friend to connect to the server
38+
```
39+
python main.py <filename>
40+
41+
Provide inputs for the prompt messages.
42+
```
43+
44+
3. Enjoy the sync. We automatically detect for modification made in the file, so just save the file.
45+
46+
## How does this work?
47+
48+
Most the of the file synchronziers send the complete file across the network for every sync cycle.
49+
50+
### How we do it?
51+
**BloomFilters**
52+
53+
A Bloom filter is a space-efficient probabilistic data structure that is used to test whether an element is a member of a set. Check out this [link](https://www.geeksforgeeks.org/bloom-filters-introduction-and-python-implementation/) to know more.
54+
55+
### The protocol
56+
We will be using a few terms in the due course of the explanation.
57+
- **Host** - the user who has intiated the P2P server.
58+
- **Client** - the user who connects to the host.
59+
- **User1** - the user who initates the sync cycle (would have made some modification to the file).
60+
- **User2** - the user whose file will get updated.
61+
- **getMissingContent()** - a function to find the missing contents.
62+
- **syncFile()** - a function to merge (reproduce the changes on the destination).
63+
64+
![Sync-Protocol](https://user-images.githubusercontent.com/43802499/68604316-31986100-04d0-11ea-9f65-fce7b3cd8357.png)
65+
66+
### Conclusion
67+
The algorithm developed does synchronization effieciently since the size of the BloomFiter transmitted is in **bits** while the file would be in **MBs**.
68+
69+
The total average transmition cost was found out to be size_of_BloomFilter (Few btyes) + number of lines modified (a few 100 bytes).
70+
71+
## Authors
72+
73+
* **Krishnan S G** - [@KrishnanSG](https://github.com/KrishnanSG)
74+
* **Sivagiri Visakan** - [@SivagiriVisakan](https://github.com/SivagiriVisakan)

Synchronizer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@ def computeHash(filename):
4747
# returns 4 byte hash value of the file
4848
file_reader = open(filename,"rb")
4949
file_contents = file_reader.read()
50-
n=abs(mmh3.hash(file_contents)) % 2**32
51-
return (n.to_bytes((n.bit_length()+7)//8,'big'))
52-
50+
n=abs(mmh3.hash(file_contents))
51+
return (n.to_bytes((n.bit_length()+7)//8,'big'))

0 commit comments

Comments
 (0)