๐Ÿ“œ โฌ†๏ธ โฌ‡๏ธ

Telegram. Unlimited network drive. Free

Hi, Habr.

Surely many people thought about it, maybe someone has this idea in TODO. She lay with me for about a year, but still managed to implement it in the form of a working prototype.

TgCloud:



Implementation details and link to the repository under the cut.


')

Idea


The idea to create a VFS based on Telegram appeared while working on AudioTubeBot and VideoTubeBot - after finding a way to get around the 50Mb limit on downloading files for bots - I studied the source code of Telegram - I discovered a lot of interesting things. For example, the download speed is limited mostly by the client itself, and not by the server.

As a result, I increased the download speed to Telegram cloud up to ~ 240 Mb / s per session (it has been working steadily for over a year), which is 15 times faster than the official client.

The logical step was to use unlimited file storage with a high download speed as a network drive โ€” surely many people do, but the problem is that telegram clients are inconvenient to use for searching and organizing files. In addition - there is a limit of 1.5 GB per file size.

FUSE


To solve these problems, I first decided to make a patch of the Linux kernel and make my virtual file system that would allow us to conveniently group the files uploaded to Telegram, while using only metadata.

In the process of studying the issue, it turned out that the patch kernel is not necessarily because Linux has a special FUSE kernel module that allows developers to create new types of file systems that can be mounted by users without privileges. For the module, there are wrappers for almost all popular languages.



Telethon


To access Telegram, I use the Telethon library version 0.19.1 with a modified multi-threaded file download (TelegramClientX).

Vfs


Not to write a file system from scratch - dedupfs in python is taken as a basis, using fuse and sqlite to store metadata that splits files into blocks, considers sha1 hash and reuses identical blocks - you just need to replace the methods for loading data into the storage with your own.

Tgcloud


By combining all this, a working prototype of tgcloud has turned out, so far without cosmic velocities, but still a worker, I hope to involve the community in the development. The downloaded files are divided into blocks of 10MB, sha1 is calculated and loaded into SavedMessages, the hash is saved in the local database and the file is found when the block is read. The blocks are glued together in the correct order and a stream of bytes is issued โ€” as if you are reading them from the disk.

To run the code



.

P.S. ( )


โ€” , .. โ€” ยซ ยป, โ€” โ€” , , โ€” โ€” . โ€” , , 90% , VFS โ€” .
โ€” , โ€” , Telegram โ€” ยซ โ€” .. ..ยป

Telegram

GitHub



DEDIC.SH Intel Scalable 2019 :

Xeon Silver 4214 โ€” 15210 /
โ€” !

โ€” VDS 150 / โ€” , !

Source: https://habr.com/ru/post/456290/


All Articles