Hi, I already completed the Peer Handshake stage however I noticed I have to wait around 2 minutes for the peer to response.
Is this some normal behaviour or am I doing something wrong?
pd: im doing it in zig and these are the logs from my program
> timeit { zbr -- handshake sample.torrent 165.232.38.164:51433 }
info: Parsed file sample.torrent
info: Created handshake struct
info: Peer ip: 165.232.38.164:51433
info: Trying to connect to peer...
info: Connected to peer
info: Sending handshake to peer...
info: Waiting for response...
info: Got a response from peer
info: Peer ID: 2d524e302e302e302d9d5e0226875575c6233a13
2min 108ms 115µs 598ns
and here is a link to the source code from github.
UPDATE: Okai so I looked for some other people solution and converted the handshake struct into a extern struct and just used try writer.writeStruct(handshake); and try reader.readStruct(HandShake) and the times went to 75ms which good but i have no idea why does this happen??
@DirewolfespreadAllAlloc internally calls readAllArrayList, which reads until the end of the stream. This behavior makes it unsuitable for use with TCP streams.
Since TCP streams remain open until explicitly closed by the peer, this approach can block indefinitely or lead to unexpected hangs.