eliasson / pieces Goto Github PK
View Code? Open in Web Editor NEWAn experimental BitTorrent client in Python 3.5
License: Apache License 2.0
An experimental BitTorrent client in Python 3.5
License: Apache License 2.0
As documented, the client sometimes freezes upon startup; I tried to debug this and managed to root out the cause.
In a nutshell, we're running into an infinite loop trying to parse the handshake response:
async def _handshake(self):
"""
Send the initial handshake to the remote peer and wait for the peer
to respond with its handshake.
"""
self.writer.write(Handshake(self.info_hash, self.peer_id).encode())
await self.writer.drain()
buf = b''
while len(buf) < Handshake.length:
buf = await self.reader.read(PeerStreamIterator.CHUNK_SIZE)
When debugging, I noticed that the len(buf)
stays at 0 at all times during the occasional freeze, thus creating the infinite loop. I'm not entirely surely if it's a problem with our parsing methods, or if the handshake from that one peer was indeed invalid.
That said, I think we can easily mitigate this issue by hardcoding a retry limit. I've attempted a fix in #2 in conjunction with main feature in that PR, and things seemed to work fine (i.e, we can download a torrent without freezing).
I have recently been learning how to implement a P2P client through your blog and GitHub repo. However, I encountered numerous network issues when testing the downloads. I have browsed through many answers on Stack Overflow and even used ChatGPT, but none of them resolved the issue. So, I cloned your code and attempted to download the 'ubuntu' file in the 'tests' directory. Unfortunately, I faced the same problems. During the file download process, I encountered the following error messages:
1. ConnectionError: Unable to connect to tracker: status code 502
2. ConnectionError: Unable to connect to tracker: d14:failure reason63:Requested download is not authorized for use with this tracker.e
3. OSError: [WinError 121] The timeout for the semaphore has expired.
4. async for message in PeerStreamIterator(self.reader, buffer):
TypeError: 'async for' received an object from __aiter__ that does not implement __anext__: coroutine
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.