For some reason I’m getting an EOF error when trying to read from the connection after several successful blocks.
The actual number of blocks I’m able to fetch is consistent and dependent on the actual piece, for example for {Length:2549700 Name:itsworking.gif PieceLength:262144
I manage 12 blocks.
Logs look like this:
[your_program] Fetching block 1 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 2 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 3 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 4 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 5 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 6 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 7 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 8 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 9 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 10 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 11 of 16 of length: 16384
[your_program] Received piece message with length: 16393
[your_program] Fetching block 12 of 16 of length: 16384
[your_program] panic: EOF
[your_program]
[your_program] goroutine 1 [running]:
[your_program] main.check(...)
[your_program] /app/cmd/mybittorrent/common.go:5
[your_program] main.(*Peer).ReadMessage(0x47514a?)
[your_program] /app/cmd/mybittorrent/peers.go:115 +0x274
[your_program] main.(*Peer).fetchBlock(0xc0000ddaa0, 0x86020?, 0xc0?, 0x6c963b?)
[your_program] /app/cmd/mybittorrent/peers.go:148 +0xc5
[your_program] main.(*Peer).fetchBlocks(0xc0000ddaa0, 0x9, 0x40000)
[your_program] /app/cmd/mybittorrent/peers.go:165 +0x26a
[your_program] main.(*Peer).DownloadPiece(0xc0000ddaa0, {0x7386a0, 0xc000044020}, 0x9, 0x40000)
[your_program] /app/cmd/mybittorrent/peers.go:193 +0x2f4
[your_program] main.downloadPiece({0x7ffd6364f831?, 0x1?}, {0x7ffd6364f811, 0x1f}, 0x9)
[your_program] /app/cmd/mybittorrent/download.go:23 +0x205
[your_program] main.main()
[your_program] /app/cmd/mybittorrent/main.go:139 +0x976
[tester::#ND2] Application didn't terminate successfully without errors. Expected 0 as exit code, got: 2
Here’s my code: codecrafters-bittorrent-go/cmd/mybittorrent/peers.go at master · arashout/codecrafters-bittorrent-go · GitHub