Cannot finish the last stage (handshake fails for each peer)

@sarp that makes sense, thanks!

changing peer_id helps, however I am not able to handshake with 167.172.57.188:51413 locally, the other two (161.35.46.221:51414 and 159.65.84.183:51444) seem to work fine

Hey everyone! We’ve pushed an update that should remove the IP-based rate-limiting. Thanks to @sarp for making this change!

I’ve also changed our E2E tests to specifically test for this - earlier they weren’t trying to download the same file in parallel, so we weren’t hitting this failure case.

If you were running into issues previously, could you try this out again, and please let us know if things are any better? If you’re still running into issues, please do share a link to your code and the error you’re seeing so that we can help debug this better. Here’s how you can publish your code to github: Publish to GitHub - CodeCrafters.

3 Likes

After the update I can handshake with all of the public peers, but my original problem remains in that I still fail #CA4 even though I pass #ND2.

[tester::#ND2] Running tests for Stage #ND2 (Download a piece)
[tester::#ND2] Running ./your_bittorrent.sh download_piece -o /tmp/torrents2692201913/piece-2 /tmp/torrents2692201913/congratulations.gif.torrent 2
[your_program] metainfo: MetaInfo { announce: "http://bittorrent-test-tracker.codecrafters.io/announce", info: Info { length: 820892, name: congratulations.gif, piece_length: 262144, pieces: ["3d42a20edb1cf840cd3528d3a9e921db6338a463", "69f885b3988a52ffb03591985402b6d5285940ab", "76869e6c9c1f101f94f39de153e468be6a638f4f", "bded68d02de011a2b687f75b5833f46cce8e3e9c"] } }
[your_program] Connecting to 165.232.41.73:51579..
[your_program] ..connection successful: Conn { conn: TcpStream { addr: 172.19.3.10:51728, peer: 165.232.41.73:51579, fd: 3 }, peerid: [45, 82, 78, 48, 46, 48, 46, 48, 45, 249, 131, 130, 107, 54, 115, 5, 36, 253, 42, 222], have: [240] }
[your_program] downloaded piece 76869e6c9c1f101f94f39de153e468be6a638f4f index: 2, length: 262144
[tester::#ND2] Running ./your_bittorrent.sh download_piece -o /tmp/torrents2692201913/piece-3 /tmp/torrents2692201913/congratulations.gif.torrent 3
[your_program] metainfo: MetaInfo { announce: "http://bittorrent-test-tracker.codecrafters.io/announce", info: Info { length: 820892, name: congratulations.gif, piece_length: 262144, pieces: ["3d42a20edb1cf840cd3528d3a9e921db6338a463", "69f885b3988a52ffb03591985402b6d5285940ab", "76869e6c9c1f101f94f39de153e468be6a638f4f", "bded68d02de011a2b687f75b5833f46cce8e3e9c"] } }
[your_program] Connecting to 165.232.41.73:51579..
[your_program] ..connection successful: Conn { conn: TcpStream { addr: 172.19.3.10:35544, peer: 165.232.41.73:51579, fd: 3 }, peerid: [45, 82, 78, 48, 46, 48, 46, 48, 45, 249, 131, 130, 107, 54, 115, 5, 36, 253, 42, 222], have: [240] }
[your_program] downloaded piece bded68d02de011a2b687f75b5833f46cce8e3e9c index: 3, length: 34460
[tester::#ND2] Test passed.

[tester::#CA4] Running tests for Stage #CA4 (Peer handshake)
[tester::#CA4] Running ./your_bittorrent.sh handshake /tmp/torrents1157234904/test.torrent 127.0.0.1:38919
[tester::#CA4] Tracker started on address 127.0.0.1:43749...
[tester::#CA4] 
[tester::#CA4] Peer listening on address: 127.0.0.1:38919
[your_program] Connecting to 127.0.0.1:38919..
[tester::#CA4] Waiting to receive handshake message
[tester::#CA4] Received handshake: [infohash: c7e51462e85d8631c25f8c9b8c5479345a1de26b, peer_id: e71dba803bae389b59c25f71a55fc864fcec60d5]
[tester::#CA4] 
[tester::#CA4] Sending back handshake with peer_id: 843ca32022c2323545da8106326c586554d9ca5b
[your_program] thread 'main' panicked at src/main.rs:319:44:
[your_program] called `Result::unwrap()` on an `Err` value: failed to fill whole buffer
[your_program] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[tester::#CA4] Application didn't terminate successfully without errors. Expected 0 as exit code, got: 101
[tester::#CA4] Test failed

@ferret-402 I took a look at your code. The issue arises because:

  • Our tester does not send anything after the handshake in #CA4 (Peer Handshake).

  • The handshake function is doing more than just handling the handshake; it’s also expecting to receive the bitfield message.

Suggestion: Refactor the handshake function to strictly handle the handshake and avoid waiting for additional messages like bitfield.

1 Like

Oh dear :person_facepalming: Thank you for taking a look!

1 Like

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!