Skip to content

Comments

refactor readmessage duplicate#7

Open
pseudozach wants to merge 15 commits intoleishman:masterfrom
pseudozach:copilot/refactor-read-message-duplicate
Open

refactor readmessage duplicate#7
pseudozach wants to merge 15 commits intoleishman:masterfrom
pseudozach:copilot/refactor-read-message-duplicate

Conversation

@pseudozach
Copy link

not sure if it was intentional but I figured I would flex my copilot muscles by removing the duplicate readMessage.
I hope PR is helpful.

Extracted duplicate readMessage implementations into shared utility
Added configurable options for validation settings
Created helper method to eliminate code duplication
Removed 84+ lines of duplicate code

Copy link
Contributor

@kwsantiago kwsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rebase onto master

Copilot AI and others added 8 commits January 19, 2026 13:54
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
Co-authored-by: pseudozach <3731591+pseudozach@users.noreply.github.com>
@pseudozach pseudozach force-pushed the copilot/refactor-read-message-duplicate branch from ad1b08d to eb6a9d5 Compare January 19, 2026 22:05
@pseudozach pseudozach requested a review from kwsantiago January 19, 2026 22:17
Comment on lines 195 to 199
// Use same strict validation as courier (4MB limit + checksum verification)
const message = try message_utils.readMessage(stream, allocator, .{
.max_payload_size = 4_000_000,
.verify_checksum = true,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing timeout in handshake loop. A malicious peer can hang indefinitely by sending continuous non-version/verack messages. The courier.zig performHandshake has a 30-second timeout, but scout.zig's performHandshake has none.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be covered now. added the same check to scout.

}

return .{ .header = header, .payload = payload };
}
Copy link
Contributor

@kwsantiago kwsantiago Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have tests? I think you had in a previous commit that were useful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few basic ones. I hope that's ok? let me know anything else I should add.

@pseudozach pseudozach requested a review from kwsantiago January 20, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants