Skip to content

Commit

Permalink
Merge pull request #1 from igorskh/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
igorskh authored Nov 10, 2020
2 parents 3f997b5 + 345744c commit 2fcae60
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 87 deletions.
File renamed without changes.
3 changes: 1 addition & 2 deletions Sources/IperfCLib/include/flowlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
#ifndef __FLOW_LABEL_H
#define __FLOW_LABEL_H


#ifdef __linux__
# include "linux/types.h"
#include <linux/types.h>
#else
# include <stdint.h>
# include <netinet/in.h>
Expand Down
4 changes: 2 additions & 2 deletions Sources/IperfCLib/include/iperf.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#include "iperf_config.h"

#include <stdio.h>

#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_STDINT_H
Expand Down Expand Up @@ -70,6 +68,8 @@
#include <openssl/evp.h>
#endif // HAVE_SSL

#include <File.h>

#if !defined(__IPERF_API_H)
typedef uint64_t iperf_size_t;
#endif // __IPERF_API_H
Expand Down
Empty file modified Sources/IperfCLib/include/iperf_api.h
100755 → 100644
Empty file.
17 changes: 10 additions & 7 deletions Sources/IperfCLib/include/iperf_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@
* for complete information.
*/


#if defined(HAVE_SSL)
#include <time.h>
#include <sys/types.h>
//#include <openssl/bio.h>
#include <openssl/bio.h>

int test_load_pubkey_from_file(const char *public_keyfile);
int test_load_private_key_from_file(const char *private_keyfile);
//EVP_PKEY *load_pubkey_from_file(const char *file);
//EVP_PKEY *load_pubkey_from_base64(const char *buffer);
//EVP_PKEY *load_privkey_from_file(const char *file);
//EVP_PKEY *load_privkey_from_base64(const char *buffer);
//int encode_auth_setting(const char *username, const char *password, EVP_PKEY *public_key, char **authtoken);
//int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *private_key, char **username, char **password, time_t *ts);
EVP_PKEY *load_pubkey_from_file(const char *file);
EVP_PKEY *load_pubkey_from_base64(const char *buffer);
EVP_PKEY *load_privkey_from_file(const char *file);
EVP_PKEY *load_privkey_from_base64(const char *buffer);
int encode_auth_setting(const char *username, const char *password, EVP_PKEY *public_key, char **authtoken);
int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *private_key, char **username, char **password, time_t *ts);
int check_authentication(const char *username, const char *password, const time_t ts, const char *filename);
ssize_t iperf_getpass (char **lineptr, size_t *n, FILE *stream);
#endif
2 changes: 2 additions & 0 deletions Sources/IperfCLib/include/iperf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <sys/select.h>
#include <stddef.h>

#include <File.h>

int readentropy(void *out, size_t outsize);

void fill_with_repeating_pattern(void *out, size_t outsize);
Expand Down
File renamed without changes.
11 changes: 8 additions & 3 deletions Sources/IperfCLib/iperf_api.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4214,13 +4214,18 @@ iperf_json_finish(struct iperf_test *test)
if (test->server_output_text) {
cJSON_AddStringToObject(test->json_top, "server_output_text", test->server_output_text);
}
test->json_output_string = cJSON_Print(test->json_top);
// Get ASCII rendering of JSON structure. Then make our
// own copy of it and return the storage that cJSON allocated
// on our behalf. We keep our own copy around.
char *str = cJSON_Print(test->json_top);
if (str == NULL)
return -1;
test->json_output_string = strdup(str);
cJSON_free(str);
if (test->json_output_string == NULL)
return -1;
fprintf(test->outfile, "%s\n", test->json_output_string);
iflush(test);
cJSON_free(test->json_output_string);
test->json_output_string = NULL;
cJSON_Delete(test->json_top);
test->json_top = test->json_start = test->json_connected = test->json_intervals = test->json_server_output = test->json_end = NULL;
return 0;
Expand Down
12 changes: 8 additions & 4 deletions Sources/IperfCLib/iperf_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define _WITH_GETLINE
#include <stdio.h>
#include <termios.h>
#include <inttypes.h>
#include <stdint.h>

#if defined(HAVE_SSL)

Expand All @@ -45,7 +47,7 @@
#include <openssl/buffer.h>
#include <openssl/err.h>

const char *auth_text_format = "user: %s\npwd: %s\nts: %ld";
const char *auth_text_format = "user: %s\npwd: %s\nts: %"PRId64;

void sha256(const char *string, char outputBuffer[65])
{
Expand Down Expand Up @@ -291,7 +293,7 @@ int encode_auth_setting(const char *username, const char *password, EVP_PKEY *pu
if (text == NULL) {
return -1;
}
snprintf(text, text_len, auth_text_format, username, password, utc_seconds);
snprintf(text, text_len, auth_text_format, username, password, (int64_t)utc_seconds);

unsigned char *encrypted = NULL;
int encrypted_len;
Expand All @@ -309,7 +311,8 @@ int encode_auth_setting(const char *username, const char *password, EVP_PKEY *pu
int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *private_key, char **username, char **password, time_t *ts){
unsigned char *encrypted_b64 = NULL;
size_t encrypted_len_b64;
Base64Decode(authtoken, &encrypted_b64, &encrypted_len_b64);
int64_t utc_seconds;
Base64Decode(authtoken, &encrypted_b64, &encrypted_len_b64);

unsigned char *plaintext = NULL;
int plaintext_len;
Expand All @@ -331,7 +334,7 @@ int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *priva
return -1;
}

int rc = sscanf((char *) plaintext, auth_text_format, s_username, s_password, ts);
int rc = sscanf((char *) plaintext, auth_text_format, s_username, s_password, &utc_seconds);
if (rc != 3) {
free(s_password);
free(s_username);
Expand All @@ -344,6 +347,7 @@ int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *priva
}
*username = s_username;
*password = s_password;
*ts = (time_t)utc_seconds;
OPENSSL_free(plaintext);
return (0);
}
Expand Down
22 changes: 19 additions & 3 deletions Sources/IperfCLib/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ iperf_connect(struct iperf_test *test)
return -1;
}

// set TCP_NODELAY for lower latency on control messages
int flag = 1;
if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int))) {
i_errno = IESETNODELAY;
return -1;
}

if (Nwrite(test->ctrl_sck, test->cookie, COOKIE_SIZE, Ptcp) < 0) {
i_errno = IESENDCOOKIE;
return -1;
Expand Down Expand Up @@ -539,11 +546,20 @@ iperf_run_client(struct iperf_test * test)
iperf_time_now(&now);
tmr_run(&now);

/* Is the test done yet? */
/*
* Is the test done yet? We have to be out of omitting
* mode, and then we have to have fulfilled one of the
* ending criteria, either by times, bytes, or blocks.
* The bytes and blocks tests needs to handle both the
* cases of the client being the sender and the client
* being the receiver.
*/
if ((!test->omitting) &&
((test->duration != 0 && test->done) ||
(test->settings->bytes != 0 && test->bytes_sent >= test->settings->bytes) ||
(test->settings->blocks != 0 && test->blocks_sent >= test->settings->blocks))) {
(test->settings->bytes != 0 && (test->bytes_sent >= test->settings->bytes ||
test->bytes_received >= test->settings->bytes)) ||
(test->settings->blocks != 0 && (test->blocks_sent >= test->settings->blocks ||
test->blocks_received >= test->settings->blocks)))) {

// Unset non-blocking for non-UDP tests
if (test->protocol->id != Pudp) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/IperfCLib/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
" -J, --json output in JSON format\n"
" --logfile f send output to a log file\n"
" --forceflush force flushing output at every interval\n"
" --timestamps <format> emit a timestamp at the start of each output line\n"
" (using optional format string as per strftime(3))\n"
" --timestamps<=format> emit a timestamp at the start of each output line\n"
" (optional \"=\" and format string as per strftime(3))\n"

" -d, --debug emit debugging output\n"
" -v, --version show version information and quit\n"
Expand Down
7 changes: 7 additions & 0 deletions Sources/IperfCLib/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ iperf_accept(struct iperf_test *test)
if (test->ctrl_sck == -1) {
/* Server free, accept new client */
test->ctrl_sck = s;
// set TCP_NODELAY for lower latency on control messages
int flag = 1;
if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int))) {
i_errno = IESETNODELAY;
return -1;
}

if (Nread(test->ctrl_sck, test->cookie, COOKIE_SIZE, Ptcp) < 0) {
i_errno = IERECVCOOKIE;
return -1;
Expand Down
7 changes: 7 additions & 0 deletions Sources/IperfSwift/IperfError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public enum IperfError: Int32 {
case IENEWTIMER = 300 // Unable to create new timer (check perror)
case IEUPDATETIMER = 301 // Unable to update timer (check perror)

case INIT_ERROR = 400
case INIT_ERROR_DEFAULTS = 401

public var debugDescription: String {
switch self {
case .UNKNOWN:
Expand Down Expand Up @@ -271,6 +274,10 @@ public enum IperfError: Int32 {
return "Unable to create new timer (check perror)"
case .IEUPDATETIMER:
return "Unable to update timer (check perror)"
case .INIT_ERROR:
return "iperf_new_test failed"
case .INIT_ERROR_DEFAULTS:
return "iperf_defaults failed"
}
}
}
26 changes: 18 additions & 8 deletions Sources/IperfSwift/IperfIntervalResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,50 @@ public struct IperfIntervalResult: Identifiable {
public var totalBytes: UInt64 = 0
public var totalPackets: Int32 = 0
public var totalLostPackets: Int32 = 0
public var totalOutoforderPackets: Int32 = 0
public var averageJitter: Double = 0.0
public var averageRtt: Double = 0.0
public var duration: TimeInterval = 0.0
public var state: IperfState = .UNKNOWN
public var debugDescription: String = ""

public var throughput = IperfThroughput.init(bytesPerSecond: 0.0)
public var hasError: Bool {
state.rawValue < 0 || error != .IENONE
error != .IENONE
}
public var error: IperfError = .IENONE
public var error: IperfError = .UNKNOWN
public var prot: IperfProtocol = .tcp

public init(
runnerState: IperfRunnerState = .unknown,
debugDescription: String = "",
state: IperfState = .UNKNOWN,
error: IperfError = .IENONE
error: IperfError = .UNKNOWN,
prot: IperfProtocol = .tcp
) {
self.runnerState = runnerState
self.debugDescription = debugDescription
self.state = state
self.error = error
self.prot = prot
}

mutating public func evaulate() {
// var sum_jitter: Double = 0.0
var sumJitter: Double = 0.0
for s in streams {
totalBytes += s.bytesTransferred
// totalPackets += s.intervalPacketCount
// totalLostPackets += s.intervalCntError
// sum_jitter += s.jitter
if self.prot == .udp {
totalPackets += s.intervalPacketCount
totalLostPackets += s.intervalCntError
totalOutoforderPackets += s.intervalOutoforderPackets
sumJitter += s.jitter
}
}
if let first = streams.first {
duration = first.intervalDuration
// averageJitter = sum_jitter / Double(streams.count)
if self.prot == .udp {
averageJitter = sumJitter / Double(streams.count)
}
throughput = IperfThroughput(bytes: totalBytes, seconds: first.intervalDuration)
}
}
Expand Down
Loading

0 comments on commit 2fcae60

Please sign in to comment.