-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests for announce extension support stage #25
Conversation
60d140c
to
7d89271
Compare
fdb2ef5
to
a4469c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added notes on backward compatibility for older stages
internal/stage_handshake.go
Outdated
@@ -63,9 +60,29 @@ func testHandshake(stageHarness *test_case_harness.TestCaseHarness) error { | |||
return err | |||
} | |||
|
|||
expectedReservedBytes := []byte{0, 0, 0, 0, 0, 0, 0, 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarp when users work on the later stages, their code will be expected to work against older stages too. Based on this diff, it seems like we're going to fail if the user's handshake indicates support for extensions, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, yes, I was thinking people would have to build-in the capability to enable / disable extension support for older stages. would be a good thing to call out in the course description if we're going down this path
is there a better way? if we were to become more lenient for the handshake stage tests, say also accept extensions in handshake tests for the base challenge, I think download piece and download file stages would also fail because the sequence of messages is different (you'd need to do the extension handshake once you signal support for extensions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, we try to keep tests flexible enough to handle later implementations and don't burden the user with having to maintain backward compatibility.
I do see how this could interact with the download_piece/download_file though. Let me think about this a bit... will respond today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarp a peer would only initiate the extension handshake if the base handshake received included the extensions bit, yes? In that case I think we're good - users won't have to disable/enable extension support based on the stage they're on (i.e. the command they're handling), they'd just need to do so based on what bits they receive from a peer in the initial handshake.
We'd still want to be tolerant of the user sending their extension bit set in the initial handshake (for any stage), but we don't need to send it in our client's handshake for earlier stages - and thus won't have to expect the extension handshake to take place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a peer would only initiate the extension handshake if the base handshake received included the extensions bit, yes?
correct
In that case I think we're good - users won't have to disable/enable extension support based on the stage they're on (i.e. the command they're handling), they'd just need to do so based on what bits they receive from a peer in the initial handshake.
problem is that the tracker you've set up on bittorrent-test-tracker.codecrafters.io
always indicates during base handshake that it supports extensions, regardless of the other client supporting it or not. and once both parties support it, extension handshake messages will be sent, also for base stages ...
I see two options:
- one way could be to have two sets of trackers, one for base stages that is configured without extensions support and one tracker with extension support for magnet links and future challenges that need extensions (like DHT)
- other way is that users build the capability to disable extensions for base stages and enable it for magnet links and future extensions (have a flag and enable it for magnet commands)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem is that the tracker you've setup on bittorrent-test-tracker.codecrafters.io always indicates during base handshake that it supports extensions, regardless of your client supporting it or not. and once both parties support it, extension handshake messages will be sent, also for base stages ...
Ah, yeah true. This too might be fine though - the tracker won't initiate an extension handshake unless it receives the extension bit set in the handshake from the user's peer.
If the user does set the extension bit in earlier stages seems fair to expect that they must handle the extension handshake if the tracker advertises it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm trying to avoid here is anything "CodeCrafters-specific" - i.e. code a user would have to write only to pass CodeCrafters tests, but wouldn't have to write when building a real-world implementation. I think the flow described above doesn't count as CodeCrafters-specific - it's just something an implementation would have to handle anyway.
(Maybe this is what you meant by "people would have to build-in the capability to enable / disable extension support for older stages", apologies if so)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it seems reasonable to me to have the ability to enable / disable extension support in a BitTorrent client, wouldn't call it "CodeCrafters-specific"
How do you want to proceed on this PR? If we make handshake more lenient (allow both extensions enabled and disabled), download-piece and download-file stages will fail until they send the extension handshake (next stage), so they will have to disable it for base stages anyway. So I don't see the value of making it more lenient. So I'm in favor of my initial approach, where base stages require extensions to be disabled and magnet links require extensions to be enabled. |
Is it okay to assume that when working on the base stages, it's unlikely that a user will intentionally set the extensions bit to true? If that assumption is safe, then leniency should be okay for the base stages - the user won't have to handle the extension handshake in download_file and download_pieces while working on the base stages. I still think that conditionally disabling/enabling extension protocol support is a CodeCrafters-specific thing, it seems unlikely that you'd want to do this in a real-world client. To clarify what I mean:
|
Yes, this is what our stage instructions say:
I don't follow this part ^
What is your proposal in that case?
I've explained that this wouldn't work in our scenario as the peers on our tracker always advertise extensions, and if you don't perform the extension handshake after saying you support extensions, they will drop your connection
This wouldn't help in our scenario either |
My concrete proposal is that in the early handshake stage, our tester should accept both "no extensions supported" or "extensions supported" for the reserved bits part. As long as it does that, I think the last 2 stages should "just work"? Explanation below:
|
Apologies if I'm missing something here btw! Been a long day and I think I'm making sense but maybe I'm not 😛 Can take a look at this fresh tomorrow if that helps. |
But they haven't implemented it yet, they will implement it in the next 2 stages. This stage is modifying base handshake, next two stages implement extension handshake (they should have given a different name!) |
Ahh okay gotcha, true. That’s the part I was missing. Will think fresh tomorrow and reply! |
Okay! Had some time to think about this today, this suggestion looks good to me:
@sarp just to confirm, it'd be okay to keep the tracker the same and just have different sets of peers, yes? If so, please feel free to proceed assuming this is what we'll do, and I'll try to set this up on Mon/Tue |
yes, that should be fine. |
Sounds good - will set this up tomo! |
friendly ping, are we good to proceed here? |
Ah, sorry this disappeared my list since I submitted a "request changes" review earlier. Looks good! |
This PR adds a test for announce extension support stage
Added checks for reserved bytes to handshake
It also contains refactoring to support easier passing of parameters to peers goroutine:
listenAndServePeersResponse
tolistenAndServeTrackerResponse
TrackerParams
andPeerConnectionParams
types for easier parameter plumbingMagnetTestParams
to make it easier to create magnet tests with all parameters