Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CODE_REVIEW_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# gwproxy Code Review Summary

## Overview
This document provides a comprehensive code review and analysis of the gwproxy project, including identified issues, improvements implemented, and recommendations for future development.
This document provides a comprehensive code review and analysis of the
gwproxy project, including identified issues, improvements implemented,
and recommendations for future development.

## Project Architecture

Expand Down Expand Up @@ -149,9 +151,15 @@ This document provides a comprehensive code review and analysis of the gwproxy p

## Conclusion

The gwproxy codebase demonstrates solid engineering principles with a focus on performance and reliability. The implemented improvements address key security and robustness concerns while maintaining the high-performance characteristics of the original design.
The gwproxy codebase demonstrates solid engineering principles with a
focus on performance and reliability. The implemented improvements
address key security and robustness concerns while maintaining the
high-performance characteristics of the original design.

The architecture is well-suited for high-throughput proxy scenarios, and the modular design facilitates future enhancements. With the applied fixes and suggested improvements, gwproxy provides a robust foundation for production proxy deployments.
The architecture is well-suited for high-throughput proxy scenarios,
and the modular design facilitates future enhancements. With the
applied fixes and suggested improvements, gwproxy provides a robust
foundation for production proxy deployments.

### Key Metrics After Improvements
- **Test Success Rate**: 100% (from ~60% due to DNS test failures)
Expand Down
27 changes: 19 additions & 8 deletions src/gwproxy/gwproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,34 @@ static int parse_options(int argc, char *argv[], struct gwp_cfg *cfg)
return -EINVAL;
}

if (cfg->target_buf_size <= 1 || cfg->target_buf_size > (1024 * 1024)) {
fprintf(stderr, "Error: --target-buf-size must be between 2 and 1MB.\n");
if (cfg->target_buf_size <= 1 || cfg->target_buf_size > INT_MAX) {
fprintf(stderr, "Error: --target-buf-size must be between 2 and %d bytes (~2GB).\n", INT_MAX);
return -EINVAL;
}

if (cfg->client_buf_size <= 1 || cfg->client_buf_size > (1024 * 1024)) {
fprintf(stderr, "Error: --client-buf-size must be between 2 and 1MB.\n");
if (cfg->client_buf_size <= 1 || cfg->client_buf_size > INT_MAX) {
fprintf(stderr, "Error: --client-buf-size must be between 2 and %d bytes (~2GB).\n", INT_MAX);
return -EINVAL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah, good. 2G should be enough.


if (cfg->connect_timeout < 0 || cfg->connect_timeout > 300) {
fprintf(stderr, "Error: --connect-timeout must be between 0 and 300 seconds.\n");
if (cfg->as_socks5) {
if (cfg->target_buf_size < 1024) {
fprintf(stderr, "Error: --target-buf-size must be at least 1024 bytes when using SOCKS5.\n");
return -EINVAL;
}
if (cfg->client_buf_size < 1024) {
fprintf(stderr, "Error: --client-buf-size must be at least 1024 bytes when using SOCKS5.\n");
return -EINVAL;
}
}

if (cfg->connect_timeout > 300) {
fprintf(stderr, "Error: --connect-timeout must be 300 seconds or less (negative means no timeout).\n");
return -EINVAL;
}

if (cfg->socks5_timeout < 0 || cfg->socks5_timeout > 300) {
fprintf(stderr, "Error: --socks5-timeout must be between 0 and 300 seconds.\n");
if (cfg->socks5_timeout > 300) {
fprintf(stderr, "Error: --socks5-timeout must be 300 seconds or less (negative means no timeout).\n");
return -EINVAL;
}

Expand Down
14 changes: 13 additions & 1 deletion src/gwproxy/tests/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ static const struct req_template req_template[] = {
{ "localhost", "80" },
{ "127.0.0.1", "80" },
{ "::1", "80" },
{ "example.com", "80" },
{ "facebook.com", "80" },
{ "google.com", "443" },
{ "github.com", "443" },
{ "example.com", "80" },
{ "twitter.com", "443" },
{ "reddit.com", "80" },
{ "youtube.com", "443" },
{ "wikipedia.org", "80" },
{ "stackoverflow.com", "443" },
{ "amazon.com", "80" },
{ "microsoft.com", "443" },
{ "apple.com", "80" },
{ "linkedin.com", "443" },
{ "bing.com", "80" },
};

static int poll_all_in(struct pollfd *pfd, int n, int timeout)
Expand Down
Loading