Hi,
it seems that most of the times it works locally when downloading the “sample.torrent” file. There were a few times when it worked with some of your other torrent files. Quite often I cannot re-handshake on the second piece (this also happens when running locally). Last run’s outcome was this:
in case you could have a look at the actual code it can be found here.
Submitting changes (commit: 69c3953)...
⚡ This is a turbo test run. https://codecrafters.io/turbo
Running tests. Logs should appear shortly...
[compile] Determining projects to restore...
[compile] Restored /app/codecrafters-bittorrent.csproj (in 83 ms).
[compile] codecrafters-bittorrent -> /app/bin/Release/net8.0/codecrafters-bittorrent.dll
[compile]
[compile] Build succeeded.
[compile] 0 Warning(s)
[compile] 0 Error(s)
[compile]
[compile] Time Elapsed 00:00:04.60
[compile] Compilation successful.
Debug = true
[tester::#JV8] Running tests for Stage #JV8 (Download the whole file)
[tester::#JV8] Running ./your_bittorrent.sh download -o /tmp/torrents3904703960/itsworking.gif /tmp/torrents3904703960/itsworking.gif.torrent
[your_program] Total pieces: 10
[your_program] Handshake completed
[your_program] Peer ID: 2d524e302e302e302d78c2b5f03bcfff7178dc6c
[your_program] Downloading piece index: 0.
[your_program] Piece Length: 262144
[your_program] [0] Block Offset: 0, Block Size: 16384
[your_program] [1] Block Offset: 16384, Block Size: 16384
[your_program] [2] Block Offset: 32768, Block Size: 16384
[your_program] [3] Block Offset: 49152, Block Size: 16384
[your_program] [4] Block Offset: 65536, Block Size: 16384
[your_program] [5] Block Offset: 81920, Block Size: 16384
[your_program] [6] Block Offset: 98304, Block Size: 16384
[your_program] [7] Block Offset: 114688, Block Size: 16384
[your_program] [8] Block Offset: 131072, Block Size: 16384
[your_program] [9] Block Offset: 147456, Block Size: 16384
[your_program] [10] Block Offset: 163840, Block Size: 16384
[your_program] [11] Block Offset: 180224, Block Size: 16384
[your_program] [12] Block Offset: 196608, Block Size: 16384
[your_program] [13] Block Offset: 212992, Block Size: 16384
[your_program] [14] Block Offset: 229376, Block Size: 16384
[your_program] [15] Block Offset: 245760, Block Size: 16384
[your_program] Downloaded piece index: 0.
[your_program] Handshake completed
[your_program] Peer ID: 2d524e302e302e302d78c2b5f03bcfff7178dc6c
[your_program] Downloading piece index: 1.
[your_program] Piece Length: 262144
[your_program] [0] Block Offset: 0, Block Size: 16384
[your_program] [1] Block Offset: 16384, Block Size: 16384
[your_program] [2] Block Offset: 32768, Block Size: 16384
[your_program] [3] Block Offset: 49152, Block Size: 16384
[your_program] [4] Block Offset: 65536, Block Size: 16384
[your_program] [5] Block Offset: 81920, Block Size: 16384
[your_program] [6] Block Offset: 98304, Block Size: 16384
[your_program] [7] Block Offset: 114688, Block Size: 16384
[your_program] [8] Block Offset: 131072, Block Size: 16384
[your_program] [9] Block Offset: 147456, Block Size: 16384
[your_program] [10] Block Offset: 163840, Block Size: 16384
[your_program] [11] Block Offset: 180224, Block Size: 16384
[your_program] [12] Block Offset: 196608, Block Size: 16384
[your_program] [13] Block Offset: 212992, Block Size: 16384
[your_program] [14] Block Offset: 229376, Block Size: 16384
[your_program] [15] Block Offset: 245760, Block Size: 16384
[your_program] Downloaded piece index: 1.
[your_program] Handshake completed
[your_program] Peer ID: 2d524e302e302e302d3441e2dbe70ed747a7c51c
[your_program] Downloading piece index: 2.
[your_program] Piece Length: 262144
[your_program] [0] Block Offset: 0, Block Size: 16384
[your_program] [1] Block Offset: 16384, Block Size: 16384
[your_program] [2] Block Offset: 32768, Block Size: 16384
[your_program] [3] Block Offset: 49152, Block Size: 16384
[your_program] [4] Block Offset: 65536, Block Size: 16384
[your_program] [5] Block Offset: 81920, Block Size: 16384
[your_program] [6] Block Offset: 98304, Block Size: 16384
[your_program] [7] Block Offset: 114688, Block Size: 16384
[your_program] [8] Block Offset: 131072, Block Size: 16384
[your_program] [9] Block Offset: 147456, Block Size: 16384
[your_program] [10] Block Offset: 163840, Block Size: 16384
[your_program] [11] Block Offset: 180224, Block Size: 16384
[your_program] [12] Block Offset: 196608, Block Size: 16384
[your_program] [13] Block Offset: 212992, Block Size: 16384
[your_program] [14] Block Offset: 229376, Block Size: 16384
[your_program] [15] Block Offset: 245760, Block Size: 16384
[your_program] Downloaded piece index: 2.
[your_program] Handshake completed
[your_program] Peer ID: 2d524e302e302e302d3441e2dbe70ed747a7c51c
[your_program] Downloading piece index: 3.
[your_program] Piece Length: 262144
[your_program] [0] Block Offset: 0, Block Size: 16384
[your_program] [1] Block Offset: 16384, Block Size: 16384
[your_program] [2] Block Offset: 32768, Block Size: 16384
[your_program] [3] Block Offset: 49152, Block Size: 16384
[your_program] [4] Block Offset: 65536, Block Size: 16384
[your_program] [5] Block Offset: 81920, Block Size: 16384
[your_program] [6] Block Offset: 98304, Block Size: 16384
[your_program] [7] Block Offset: 114688, Block Size: 16384
[your_program] [8] Block Offset: 131072, Block Size: 16384
[your_program] [9] Block Offset: 147456, Block Size: 16384
[your_program] [10] Block Offset: 163840, Block Size: 16384
[your_program] [11] Block Offset: 180224, Block Size: 16384
[your_program] [12] Block Offset: 196608, Block Size: 16384
[your_program] [13] Block Offset: 212992, Block Size: 16384
[your_program] [14] Block Offset: 229376, Block Size: 16384
[your_program] [15] Block Offset: 245760, Block Size: 16384
[your_program] Downloaded piece index: 3.
[your_program] System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
[your_program] ---> System.Net.Sockets.SocketException (104): Connection reset by peer
[your_program] --- End of inner exception stack trace ---
[your_program] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
[your_program] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
[your_program] at codecrafters_bittorrent.Connection.PeerConnection.Handshake() in /app/src/Connection/PeerConnection.cs:line 75
[your_program] at codecrafters_bittorrent.Connection.PeerConnection.DownloadPiece(Int32 pieceIndex) in /app/src/Connection/PeerConnection.cs:line 16
[your_program] Unhandled exception. System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
[your_program] ---> System.Net.Sockets.SocketException (104): Connection reset by peer
[your_program] --- End of inner exception stack trace ---
[your_program] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
[your_program] at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
[your_program] at codecrafters_bittorrent.Connection.PeerConnection.Handshake() in /app/src/Connection/PeerConnection.cs:line 75
[your_program] at codecrafters_bittorrent.Connection.PeerConnection.DownloadPiece(Int32 pieceIndex) in /app/src/Connection/PeerConnection.cs:line 16
[your_program] at codecrafters_bittorrent.Commands.Download.Execute(String[] args) in /app/src/Commands/Download.cs:line 25
[your_program] at Program.<Main>$(String[] args) in /app/src/Program.cs:line 31
[your_program] at Program.<Main>(String[] args)
[tester::#JV8] execution timed out
[tester::#JV8] Test failed
and here’s the outcome when it works successfully with “sample.torrent” file:
/home/inner/projects/codecrafters-bittorrent-csharp/bin/Debug/net8.0/codecrafters-bittorrent download -o /tmp/test.txt sample.torrent
Total pieces: 3
Handshake completed
Peer ID: 2d524e302e302e302d8fbb7dcf1a18fee7307c14
Downloading piece index: 0.
Piece Length: 32768
[0] Block Offset: 0, Block Size: 16384
[1] Block Offset: 16384, Block Size: 16384
Downloaded piece index: 0.
Handshake completed
Peer ID: 2d524e302e302e302dc3381e92ac5122cdeb08db
Downloading piece index: 1.
Piece Length: 32768
[0] Block Offset: 0, Block Size: 16384
[1] Block Offset: 16384, Block Size: 16384
Downloaded piece index: 1.
Handshake completed
Peer ID: 2d524e302e302e302d4141fc487f6f62fec50b19
Downloading piece index: 2.
Piece Length: 26527
[0] Block Offset: 0, Block Size: 16384
[1] Block Offset: 16384, Block Size: 10143
Downloaded piece index: 2.
Download completed
The contents of the file is a nice read:
What Is a Hacker?
There is a community, a shared culture, of expert programmers and networking wizards that traces its history back through decades to the first time-sharing minicomputers and the earliest ARPAnet experiments. The members of this culture originated the term ‘hacker’. Hackers built the Internet. Hackers made the Unix operating system what it is today. Hackers make the World Wide Web work. If you are part of this culture, if you have contributed to it and other people in it know who you are and call you a hacker, you’re a hacker.
The hacker mind-set is not confined to this software-hacker culture. There are people who apply the hacker attitude to other things, like electronics or music — actually, you can find it at the highest levels of any science or art. Software hackers recognize these kindred spirits elsewhere and may call them ‘hackers’ too — and some claim that the hacker nature is really independent of the particular medium the hacker works in. But in the rest of this document we will focus on the skills and attitudes of software hackers, and the traditions of the shared culture that originated the term ‘hacker’.