The problem is that when I try to download a piece from a peer above index 2 (meaning the peers list has more than 3 peers), I get an error indicating that the addresses are wrong.
I investigated this issue further and found that I can’t get more than 3 peers from the tracker. This issue lies within the tracker’s response itself—the peers string length is always 18 bytes (indicating only 3 peers).
To demonstrate this, I printed the raw string response from the tracker and the addresses themselves. Then, I ran the test, which attempts to download a piece from the 9th peer (which isn’t available).
[tester::#ND2] Running tests for Stage #ND2 (Download a piece)
[tester::#ND2] Running ./your_bittorrent.sh download_piece -o /tmp/torrents3518647417/piece-9 /tmp/torrents3518647417/itsworking.gif.torrent 9
[your_program] d8:completei3e10:incompletei0e8:intervali60e12:min intervali60e5:peers18:�>U�%�>RY�ץ�!M��e
[your_program] Invalid address or address not supported: No error information
[your_program] Failed to connect to peer: :0
[your_program] Failed to perform handshake with peer :0
[your_program] 178.62.85.20:51493
[your_program] 178.62.82.89:51415
[your_program] 165.232.33.77:51429
[tester::#ND2] Application didn't terminate successfully without errors. Expected 0 as exit code, got: 1
[tester::#ND2] Test failed