Skip to content

Commit

Permalink
Add More Features
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks committed Jul 7, 2024
1 parent 1705e3e commit d517152
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions src/quicreach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ struct ReachConfig {
bool RequireAll {false};
std::vector<const char*> HostNames;
QuicAddr Address;
QuicAddr SourceAddress;
uint32_t Parallel {1};
uint32_t Repeat {0};
uint32_t Timeout {0};
uint16_t Port {443};
MsQuicAlpn Alpn {"h3"};
MsQuicSettings Settings;
Expand Down Expand Up @@ -130,7 +133,10 @@ bool ParseConfig(int argc, char **argv) {
" -m, --mtu <mtu> The initial (IPv6) MTU to use (def=1288)\n"
" -p, --port <port> The UDP port to use (def=443)\n"
" -r, --req-all Require all hostnames to succeed\n"
" -R, --repeat <time> Repeat the requests event N milliseconds\n"
" -s, --stats Print connection statistics\n"
" -S, --source <address> Specify a source IP address\n"
" -t, --timeout <time> Timeout in milliseconds to wait for each handshake\n"
" -u, --unsecure Allows unsecure connections\n"
" -v, --version Prints out the version\n"
);
Expand Down Expand Up @@ -159,7 +165,7 @@ bool ParseConfig(int argc, char **argv) {
} else if (!strcmp(argv[i], "--ip") || !strcmp(argv[i], "-i")) {
if (++i >= argc) { printf("Missing IP address\n"); return false; }
if (!QuicAddrFromString(argv[i], 0, &Config.Address.SockAddr)) {
printf("Invalid address arg passed in\n"); return false;
printf("Invalid address arg\n"); return false;
}

} else if (!strcmp(argv[i], "--parallel") || !strcmp(argv[i], "-l")) {
Expand All @@ -173,9 +179,23 @@ bool ParseConfig(int argc, char **argv) {
} else if (!strcmp(argv[i], "--stats") || !strcmp(argv[i], "-s")) {
Config.PrintStatistics = true;

} else if (!strcmp(argv[i], "--source") || !strcmp(argv[i], "-S")) {
if (++i >= argc) { printf("Missing source address\n"); return false; }
if (!QuicAddrFromString(argv[i], 0, &Config.SourceAddress.SockAddr)) {
printf("Invalid source address arg\n"); return false;
}

} else if (!strcmp(argv[i], "--req-all") || !strcmp(argv[i], "-r")) {
Config.RequireAll = true;

} else if (!strcmp(argv[i], "--repeat") || !strcmp(argv[i], "-R")) {
if (++i >= argc) { printf("Missing repeat arg\n"); return false; }
Config.Repeat = (uint32_t)atoi(argv[i]);

} else if (!strcmp(argv[i], "--timeout") || !strcmp(argv[i], "-t")) {
if (++i >= argc) { printf("Missing timeout arg\n"); return false; }
Config.Timeout = (uint32_t)atoi(argv[i]);

} else if (!strcmp(argv[i], "--unsecure") || !strcmp(argv[i], "-u")) {
Config.CredFlags |= QUIC_CREDENTIAL_FLAG_NO_CERTIFICATE_VALIDATION;

Expand All @@ -201,6 +221,15 @@ struct ReachConnection : public MsQuicConnection {
if (IsValid() && Config.Address.GetFamily() != QUIC_ADDRESS_FAMILY_UNSPEC) {
InitStatus = SetRemoteAddr(Config.Address);
}
if (IsValid() && Config.SourceAddress.GetFamily() != QUIC_ADDRESS_FAMILY_UNSPEC) {
InitStatus = SetLocalAddr(Config.SourceAddress);
}
if (IsValid() && Config.Timeout != 0) {
InitStatus = SetHandshakeIdleTimeoutMs(Config.Timeout);
}
if (IsValid() && Config.Timeout != 0) {
InitStatus = SetDisconnectTimeoutMs(Config.Timeout);
}
if (IsValid()) {
InitStatus = Start(Configuration, HostName, Config.Port);
}
Expand Down Expand Up @@ -363,10 +392,18 @@ int QUIC_CALL main(int argc, char **argv) {
return 1;
}

bool Result = TestReachability();
if (!Config.PrintStatistics) {
printf("%s\n", Result ? "Success" : "Failure");
}
do {
bool Result = TestReachability();
if (!Config.PrintStatistics) {
printf("%s\n", Result ? "Success" : "Failure");
}

if (Config.Repeat) {
CxPlatSleep(Config.Repeat);
}

} while (Config.Repeat);

delete MsQuic;
return Result ? 0 : 1;
}

0 comments on commit d517152

Please sign in to comment.