Coder Social home page Coder Social logo

nonprojects / tgbox Goto Github PK

View Code? Open in Web Editor NEW
31.0 2.0 4.0 2.8 MB

Encrypted cloud storage Protocol based on Telegram

Home Page: https://tgbox.readthedocs.io/

License: GNU Lesser General Public License v2.1

Python 100.00%
telegram cloud-storage async api encrypted-files python3

tgbox's People

Contributors

notstatilko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tgbox's Issues

Try to multiprocess fastelethon.py (upload/download)

Because of GIL Python always runs on one core, so event loop too. We can create CPU_COUNT processes and upload files in parallel, but there is two big problems: the first, most obvious, is possible FloodWaitError on Telegram side, the second is pickle, it just doesn't work with coroutines and big classes.

aiomultiprocess.Pool doesn't work, as it rely on pickle. dill instead of pickle.... doesn't work. We need to fully rewrite fastelethon, so it's coros will return parts from which we can reconstruct objects in other Process.

It looks good in theory, but FloodWaitError and GIL... meh, i don't want to do it now. If anyone has ideas - feel free to publish them here.

Independence from Telegram

We need to implement a bunch of things:

  • Join requests
  • Set username
  • Make RemoteBox public
  • Change "sign messages"
  • Send messages
  • Rename RemoteBox
  • Change privileges
  • Disable forwarding

LimitInvalidError on big Filedata

The Telethon library throws LimitInvalidError when we try to download a RemoteBoxFile with big filedata (e.g where folder len equals to FOLDERNAME_MAX)

tgbox/api.py

Lines 929 to 931 in 17025f3

filedata_len = bytes_to_int(dec_navbytes[:3],signed=False)
preview_len = bytes_to_int(dec_navbytes[3:],signed=False)
#TODO: BIG FILEDATA LEN IS BROKEN

This error already was reported to Telethon devs.
LonamiWebs/Telethon#3199 (comment)

Anyway, we should investigate this.

Custom attributes on RemoteBoxFile

We have a 255-byte field called comment. I suggest to use it for determining file types.

My thoughts about this:

  1. ;msg; determines that this file is Text-message;
  2. ;rep;5; determines that this file is Reply to another file with ID=5;
  3. ;1;alb;{alb_id}; determines that this file is part of Album. 1 here is order. alb_id is unique Album ID. Maybe 4 random bytes?
  4. ;pubkey;sgn;signature; determines that this file was signed by pubkey.
  5. ...

Bug on iterating files over RemoteBox

When RemoteBox has imported (forwarded) file, and DecryptedLocalBox hasn't FileKey for this file, iterating over RemoteBox.files(), manifests a lag for ~5 seconds or more.

Server closed the connection: 0 bytes read on a total of 8 expected bytes

:2023-05-04 ^ 21:45:56: WARNING:telethon.network.connection.connection~_recv_loop{334} ::: Server closed the connection: 0 bytes read on a total of 8 expected bytes
:2023-05-04 ^ 21:45:58: ERROR:telethon.network.mtprotosender~_recv_loop{519} ::: Unhandled error while receiving data
Traceback (most recent call last):
  File "/home/pronet/.local/lib/python3.9/site-packages/telethon/network/mtprotosender.py", line 505, in _recv_loop
    body = await self._connection.recv()
  File "/home/pronet/.local/lib/python3.9/site-packages/telethon/network/connection/connection.py", line 301, in recv
    raise err
  File "/home/pronet/.local/lib/python3.9/site-packages/telethon/network/connection/connection.py", line 332, in _recv_loop
    data = await self._recv()
  File "/home/pronet/.local/lib/python3.9/site-packages/telethon/network/connection/connection.py", line 369, in _recv
    return await self._codec.read_packet(self._reader)
  File "/home/pronet/.local/lib/python3.9/site-packages/telethon/network/connection/tcpfull.py", line 25, in read_packet
    packet_len_seq = await reader.readexactly(8)  # 4 and 4
  File "/usr/lib/python3.9/asyncio/streams.py", line 721, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 8 expected bytes

Doesn't update LocalBox with asyncio.gather

result = await gather(
    rb.push_file(await dlb.make_file(open('test.jpg','rb'))),
    rb.push_file(await dlb.make_file(open('test.jpg','rb'))),
    rb.push_file(await dlb.make_file(open('test.jpg','rb')))
)
print(result)
Traceback (most recent call last):
  File "/home/non/Scripts/py_projects/tgbox-env/test.py", line 202, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/non/Scripts/py_projects/tgbox-env/test.py", line 77, in main
    result = await gather(
  File "/home/non/Scripts/py_projects/tgbox-env/tgbox/api.py", line 415, in push_file
    await ff.make_local(file_message.id, 
  File "/home/non/Scripts/py_projects/tgbox-env/tgbox/api.py", line 1992, in make_local
    maybe_file = await self.dlb._tgbox_db.Files.select_once(
  File "/home/non/Scripts/py_projects/tgbox-env/tgbox/db.py", line 44, in select_once
    return await (self.select(sql_tuple=sql_tuple)).__anext__()
StopAsyncIteration

English language

I'm not a very big expert of writing in English, so if you found any errors i would be thankful for pull-requests with fixes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.