Refurbished the ADC hub stress-tester tool; adcrush
This commit is contained in:
parent
cb6236691b
commit
2e8c99b7ec
@ -164,6 +164,9 @@ if(OPENSSL_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
target_link_libraries(mod_welcome ${OPENSSL_LIBRARIES})
|
target_link_libraries(mod_welcome ${OPENSSL_LIBRARIES})
|
||||||
target_link_libraries(mod_logging ${OPENSSL_LIBRARIES})
|
target_link_libraries(mod_logging ${OPENSSL_LIBRARIES})
|
||||||
|
if (ADC_STRESS)
|
||||||
|
target_link_libraries(adcrush ${OPENSSL_LIBRARIES})
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file ("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_SOURCE_DIR}/version.h")
|
configure_file ("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_SOURCE_DIR}/version.h")
|
||||||
@ -173,7 +176,7 @@ if (RELEASE)
|
|||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
else()
|
else()
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
add_definitions(-DDEBUG)
|
# add_definitions(-DDEBUG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* uhub - A tiny ADC p2p connection hub
|
* uhub - A tiny ADC p2p connection hub
|
||||||
* Copyright (C) 2007-2011, Jan Vidar Krey
|
* Copyright (C) 2007-2012, Jan Vidar Krey
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -24,10 +24,12 @@
|
|||||||
#define ADC_CID_SIZE 39
|
#define ADC_CID_SIZE 39
|
||||||
#define BIG_BUFSIZE 32768
|
#define BIG_BUFSIZE 32768
|
||||||
#define TIGERSIZE 24
|
#define TIGERSIZE 24
|
||||||
|
#define STATS_INTERVAL 3
|
||||||
#define ADCRUSH "adcrush/0.3"
|
#define ADCRUSH "adcrush/0.3"
|
||||||
#define ADC_NICK "[BOT]adcrush"
|
#define ADC_NICK "[BOT]adcrush"
|
||||||
#define ADC_DESC "crash\\stest\\sdummy"
|
#define ADC_DESC "crash\\stest\\sdummy"
|
||||||
|
|
||||||
|
|
||||||
#define LVL_INFO 1
|
#define LVL_INFO 1
|
||||||
#define LVL_DEBUG 2
|
#define LVL_DEBUG 2
|
||||||
#define LVL_VERBOSE 3
|
#define LVL_VERBOSE 3
|
||||||
@ -38,6 +40,32 @@ static int cfg_level = 1; /* activity level (0..3) */
|
|||||||
static int cfg_chat = 0; /* chat mode, allow sending chat messages */
|
static int cfg_chat = 0; /* chat mode, allow sending chat messages */
|
||||||
static int cfg_quiet = 0; /* quiet mode (no output) */
|
static int cfg_quiet = 0; /* quiet mode (no output) */
|
||||||
static int cfg_clients = ADC_CLIENTS_DEFAULT; /* number of clients */
|
static int cfg_clients = ADC_CLIENTS_DEFAULT; /* number of clients */
|
||||||
|
static int cfg_netstats_interval = STATS_INTERVAL;
|
||||||
|
static int running = 1;
|
||||||
|
static int logged_in = 0;
|
||||||
|
static int blank = 0;
|
||||||
|
static struct net_statistics* stats_intermediate;
|
||||||
|
static struct net_statistics* stats_total;
|
||||||
|
|
||||||
|
static int handle(struct ADC_client* client, enum ADC_client_callback_type type, struct ADC_client_callback_data* data);
|
||||||
|
static void timer_callback(struct timeout_evt* t);
|
||||||
|
|
||||||
|
static void do_blank(int n)
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
fprintf(stdout, " ");
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AdcFuzzUser
|
||||||
|
{
|
||||||
|
struct ADC_client* client;
|
||||||
|
struct timeout_evt* timer;
|
||||||
|
int logged_in;
|
||||||
|
};
|
||||||
|
|
||||||
#define MAX_CHAT_MSGS 35
|
#define MAX_CHAT_MSGS 35
|
||||||
const char* chat_messages[MAX_CHAT_MSGS] = {
|
const char* chat_messages[MAX_CHAT_MSGS] = {
|
||||||
@ -103,10 +131,31 @@ static void bot_output(struct ADC_client* client, int level, const char* format,
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (cfg_debug >= level)
|
if (cfg_debug >= level)
|
||||||
fprintf(stdout, "* [%p] %s\n", client, logmsg);
|
{
|
||||||
|
int num = fprintf(stdout, "* [%p] %s", client, logmsg);
|
||||||
|
do_blank(blank - num);
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* format_size(size_t bytes)
|
||||||
|
{
|
||||||
|
static char buf[64];
|
||||||
|
static const char* quant[] = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
|
||||||
|
size_t b = bytes;
|
||||||
|
size_t factor = 0;
|
||||||
|
size_t divisor = 1;
|
||||||
|
while (b > 1024)
|
||||||
|
{
|
||||||
|
factor++;
|
||||||
|
b = (b >> 10);
|
||||||
|
divisor = (divisor << 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%.2f %s", (double) bytes / (double) divisor, quant[factor]);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static size_t get_wait_rand(size_t max)
|
static size_t get_wait_rand(size_t max)
|
||||||
{
|
{
|
||||||
static size_t next = 0;
|
static size_t next = 0;
|
||||||
@ -115,120 +164,144 @@ static size_t get_wait_rand(size_t max)
|
|||||||
return ((size_t )(next / 65536) % max);
|
return ((size_t )(next / 65536) % max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t get_next_timeout_evt()
|
||||||
|
{
|
||||||
|
switch (cfg_level)
|
||||||
|
{
|
||||||
|
case 0: return get_wait_rand(120);
|
||||||
|
case 1: return get_wait_rand(60);
|
||||||
|
case 2: return get_wait_rand(15);
|
||||||
|
case 3: return get_wait_rand(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void perf_result(struct ADC_client* client, sid_t target, const char* what, const char* token);
|
static void perf_result(struct ADC_client* client, sid_t target, const char* what, const char* token);
|
||||||
|
|
||||||
static void perf_chat(struct ADC_client* client, int priv)
|
static void perf_chat(struct ADC_client* client, int priv)
|
||||||
{
|
{
|
||||||
char buf[1024] = { 0, };
|
|
||||||
size_t r = get_wait_rand(MAX_CHAT_MSGS-1);
|
size_t r = get_wait_rand(MAX_CHAT_MSGS-1);
|
||||||
char* msg = adc_msg_escape(chat_messages[r]);
|
char* msg = adc_msg_escape(chat_messages[r]);
|
||||||
|
struct adc_message* cmd = NULL;
|
||||||
|
|
||||||
if (priv)
|
if (priv)
|
||||||
{
|
cmd = adc_msg_construct_source_dest(ADC_CMD_DMSG, ADC_client_get_sid(client), ADC_client_get_sid(client), strlen(msg));
|
||||||
strcat(buf, "EMSG ");
|
|
||||||
strcat(buf, sid_to_string(client->sid));
|
|
||||||
strcat(buf, " ");
|
|
||||||
strcat(buf, sid_to_string(client->sid));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
cmd = adc_msg_construct_source(ADC_CMD_BMSG, ADC_client_get_sid(client), strlen(msg));
|
||||||
strcat(buf, "BMSG ");
|
|
||||||
strcat(buf, sid_to_string(client->sid));
|
|
||||||
}
|
|
||||||
strcat(buf, " ");
|
|
||||||
|
|
||||||
strcat(buf, msg);
|
|
||||||
hub_free(msg);
|
hub_free(msg);
|
||||||
|
|
||||||
strcat(buf, "\n");
|
ADC_client_send(client, cmd);
|
||||||
ADC_client_send(client, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_search(struct ADC_client* client)
|
static void perf_search(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
char buf[1024] = { 0, };
|
|
||||||
size_t r = get_wait_rand(MAX_SEARCH_MSGS-1);
|
size_t r = get_wait_rand(MAX_SEARCH_MSGS-1);
|
||||||
size_t pst = get_wait_rand(100);
|
size_t pst = get_wait_rand(100);
|
||||||
|
struct adc_message* cmd = NULL;
|
||||||
|
|
||||||
if (pst > 80)
|
if (pst > 80)
|
||||||
{
|
{
|
||||||
strcat(buf, "FSCH ");
|
cmd = adc_msg_construct_source(ADC_CMD_FSCH, ADC_client_get_sid(client), strlen(search_messages[r]) + 6);
|
||||||
strcat(buf, sid_to_string(client->sid));
|
adc_msg_add_argument(cmd, "+TCP4");
|
||||||
strcat(buf, " +TCP4 ");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcat(buf, "BSCH ");
|
cmd = adc_msg_construct_source(ADC_CMD_BSCH, ADC_client_get_sid(client), strlen(search_messages[r]) + 6);
|
||||||
strcat(buf, sid_to_string(client->sid));
|
adc_msg_add_argument(cmd, "+TCP4");
|
||||||
strcat(buf, " ");
|
|
||||||
}
|
}
|
||||||
strcat(buf, search_messages[r]);
|
ADC_client_send(client, cmd);
|
||||||
strcat(buf, "\n");
|
|
||||||
ADC_client_send(client, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_result(struct ADC_client* client, sid_t target, const char* what, const char* token)
|
static void perf_result(struct ADC_client* client, sid_t target, const char* what, const char* token)
|
||||||
{
|
{
|
||||||
char buf[1024] = { 0, };
|
char tmp[256];
|
||||||
strcat(buf, "DRES ");
|
struct adc_message* cmd = adc_msg_construct_source_dest(ADC_CMD_DRES, ADC_client_get_sid(client), target, strlen(what) + strlen(token) + 64);
|
||||||
strcat(buf, sid_to_string(client->sid));
|
|
||||||
strcat(buf, " ");
|
snprintf(tmp, sizeof(tmp), "FNtest/%s.dat", what);
|
||||||
strcat(buf, sid_to_string(target));
|
adc_msg_add_argument(cmd, tmp);
|
||||||
strcat(buf, " FN" "test/");
|
|
||||||
strcat(buf, what);
|
adc_msg_add_argument(cmd, "SL0");
|
||||||
strcat(buf, ".dat");
|
adc_msg_add_argument(cmd, "SI1209818412");
|
||||||
strcat(buf, " SL" "0");
|
adc_msg_add_argument(cmd, "TR5T6YJYKO3WECS52BKWVSOP5VUG4IKNSZBZ5YHBA");
|
||||||
strcat(buf, " SI" "908987128912");
|
snprintf(tmp, sizeof(tmp), "TO%s", token);
|
||||||
strcat(buf, " TR" "5T6YJYKO3WECS52BKWVSOP5VUG4IKNSZBZ5YHBA");
|
adc_msg_add_argument(cmd, tmp);
|
||||||
strcat(buf, " TO");
|
|
||||||
strcat(buf, token);
|
ADC_client_send(client, cmd);
|
||||||
strcat(buf, "\n");
|
|
||||||
ADC_client_send(client, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_ctm(struct ADC_client* client)
|
static void perf_ctm(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
char buf[1024] = { 0, };
|
char buf[1024] = { 0, };
|
||||||
strcat(buf, "DCTM ");
|
struct adc_message* cmd = adc_msg_construct_source_dest(ADC_CMD_DCTM, ADC_client_get_sid(client), ADC_client_get_sid(client), 32);
|
||||||
strcat(buf, sid_to_string(client->sid));
|
adc_msg_add_argument(cmd, "ADC/1.0");
|
||||||
strcat(buf, " ");
|
adc_msg_add_argument(cmd, "TOKEN123456");
|
||||||
strcat(buf, sid_to_string(client->sid));
|
adc_msg_add_argument(cmd, sid_to_string(ADC_client_get_sid(client)));
|
||||||
strcat(buf, " ");
|
ADC_client_send(client, cmd);
|
||||||
strcat(buf, "ADC/1.0");
|
|
||||||
strcat(buf, " TOKEN111");
|
|
||||||
strcat(buf, sid_to_string(client->sid));
|
|
||||||
strcat(buf, "\n");
|
|
||||||
ADC_client_send(client, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void perf_update(struct ADC_client* client)
|
static void perf_update(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
char buf[1024] = { 0, };
|
char buf[16] = { 0, };
|
||||||
int n = (int) get_wait_rand(10)+1;
|
int n = (int) get_wait_rand(10)+1;
|
||||||
|
struct adc_message* cmd = adc_msg_construct_source(ADC_CMD_BINF, ADC_client_get_sid(client), 32);
|
||||||
|
snprintf(buf, sizeof(buf), "HN%d", n);
|
||||||
|
adc_msg_add_argument(cmd, buf);
|
||||||
|
ADC_client_send(client, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
strcat(buf, "BINF ");
|
static void client_disconnect(struct AdcFuzzUser* c)
|
||||||
strcat(buf, sid_to_string(client->sid));
|
{
|
||||||
strcat(buf, " HN");
|
ADC_client_destroy(c->client);
|
||||||
strcat(buf, uhub_itoa(n));
|
hub_free(c->client);
|
||||||
|
c->client = 0;
|
||||||
|
|
||||||
strcat(buf, "\n");
|
timeout_queue_remove(net_backend_get_timeout_queue(), c->timer);
|
||||||
ADC_client_send(client, buf);
|
hub_free(c->timer);
|
||||||
|
c->timer = 0;
|
||||||
|
|
||||||
|
c->logged_in = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void client_connect(struct AdcFuzzUser* c, const char* nick, const char* description)
|
||||||
|
{
|
||||||
|
size_t timeout = get_next_timeout_evt();
|
||||||
|
struct ADC_client* client = ADC_client_create(nick, description, c);
|
||||||
|
|
||||||
|
c->client = client;
|
||||||
|
c->timer = (struct timeout_evt*) hub_malloc(sizeof(struct timeout_evt));
|
||||||
|
timeout_evt_initialize(c->timer, timer_callback, c);
|
||||||
|
timeout_queue_insert(net_backend_get_timeout_queue(), c->timer, timeout);
|
||||||
|
|
||||||
|
bot_output(client, LVL_VERBOSE, "Initial timeout: %d seconds", timeout);
|
||||||
|
c->logged_in = 0;
|
||||||
|
|
||||||
|
ADC_client_set_callback(client, handle);
|
||||||
|
ADC_client_connect(client, cfg_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_normal_action(struct ADC_client* client)
|
static void perf_normal_action(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
|
struct AdcFuzzUser* user = (struct AdcFuzzUser*) ADC_client_get_ptr(client);
|
||||||
size_t r = get_wait_rand(5);
|
size_t r = get_wait_rand(5);
|
||||||
size_t p = get_wait_rand(100);
|
size_t p = get_wait_rand(100);
|
||||||
|
|
||||||
switch (r)
|
switch (r)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (p > (90 - (10 * cfg_level)))
|
// if (p > (90 - (10 * cfg_level)))
|
||||||
{
|
{
|
||||||
|
struct ADC_client* c;
|
||||||
|
char* nick = hub_strdup(ADC_client_get_nick(client));
|
||||||
|
char* desc = hub_strdup(ADC_client_get_description(client));
|
||||||
|
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> disconnect");
|
bot_output(client, LVL_VERBOSE, "timeout -> disconnect");
|
||||||
ADC_client_disconnect(client);
|
client_disconnect(user);
|
||||||
|
client_connect(user, nick, desc);
|
||||||
|
|
||||||
|
hub_free(nick);
|
||||||
|
hub_free(desc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -236,6 +309,7 @@ static void perf_normal_action(struct ADC_client* client)
|
|||||||
if (cfg_chat)
|
if (cfg_chat)
|
||||||
{
|
{
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> chat");
|
bot_output(client, LVL_VERBOSE, "timeout -> chat");
|
||||||
|
if (user->logged_in)
|
||||||
perf_chat(client, 0);
|
perf_chat(client, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -243,30 +317,35 @@ static void perf_normal_action(struct ADC_client* client)
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> search");
|
bot_output(client, LVL_VERBOSE, "timeout -> search");
|
||||||
|
if (user->logged_in)
|
||||||
perf_search(client);
|
perf_search(client);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> update");
|
bot_output(client, LVL_VERBOSE, "timeout -> update");
|
||||||
|
if (user->logged_in)
|
||||||
perf_update(client);
|
perf_update(client);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> privmsg");
|
bot_output(client, LVL_VERBOSE, "timeout -> privmsg");
|
||||||
|
if (user->logged_in)
|
||||||
perf_chat(client, 1);
|
perf_chat(client, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
bot_output(client, LVL_VERBOSE, "timeout -> ctm/rcm");
|
bot_output(client, LVL_VERBOSE, "timeout -> ctm/rcm");
|
||||||
|
if (user->logged_in)
|
||||||
perf_ctm(client);
|
perf_ctm(client);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static int handle(struct ADC_client* client, enum ADC_client_callback_type type, struct ADC_client_callback_data* data)
|
static int handle(struct ADC_client* client, enum ADC_client_callback_type type, struct ADC_client_callback_data* data)
|
||||||
{
|
{
|
||||||
|
struct AdcFuzzUser* user = (struct AdcFuzzUser*) ADC_client_get_ptr(client);
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ADC_CLIENT_CONNECTING:
|
case ADC_CLIENT_CONNECTING:
|
||||||
@ -274,7 +353,7 @@ static int handle(struct ADC_client* client, enum ADC_client_callback_type type,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_CONNECTED:
|
case ADC_CLIENT_CONNECTED:
|
||||||
bot_output(client, LVL_DEBUG, "*** Connected.");
|
// bot_output(client, LVL_DEBUG, "*** Connected.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_DISCONNECTED:
|
case ADC_CLIENT_DISCONNECTED:
|
||||||
@ -282,38 +361,40 @@ static int handle(struct ADC_client* client, enum ADC_client_callback_type type,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_LOGGING_IN:
|
case ADC_CLIENT_LOGGING_IN:
|
||||||
bot_output(client, LVL_DEBUG, "*** Logging in...");
|
// bot_output(client, LVL_DEBUG, "*** Logging in...");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_PASSWORD_REQ:
|
case ADC_CLIENT_PASSWORD_REQ:
|
||||||
bot_output(client, LVL_DEBUG, "*** Requesting password.");
|
//bot_output(client, LVL_DEBUG, "*** Requesting password.");
|
||||||
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_LOGGED_IN:
|
case ADC_CLIENT_LOGGED_IN:
|
||||||
bot_output(client, LVL_DEBUG, "*** Logged in.");
|
bot_output(client, LVL_DEBUG, "*** Logged in.");
|
||||||
|
user->logged_in = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_LOGIN_ERROR:
|
case ADC_CLIENT_LOGIN_ERROR:
|
||||||
bot_output(client, LVL_DEBUG, "*** Login error");
|
bot_output(client, LVL_DEBUG, "*** Login error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ADC_CLIENT_SSL_HANDSHAKE:
|
||||||
|
case ADC_CLIENT_SSL_OK:
|
||||||
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_MESSAGE:
|
case ADC_CLIENT_MESSAGE:
|
||||||
bot_output(client, LVL_DEBUG, " <%s> %s", sid_to_string(data->chat->from_sid), data->chat->message);
|
// bot_output(client, LVL_DEBUG, " <%s> %s", sid_to_string(data->chat->from_sid), data->chat->message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_USER_JOIN:
|
case ADC_CLIENT_USER_JOIN:
|
||||||
bot_output(client, LVL_VERBOSE, " JOIN: %s", data->user->name);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_USER_QUIT:
|
case ADC_CLIENT_USER_QUIT:
|
||||||
bot_output(client, LVL_VERBOSE, " QUIT");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_SEARCH_REQ:
|
case ADC_CLIENT_SEARCH_REQ:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADC_CLIENT_HUB_INFO:
|
case ADC_CLIENT_HUB_INFO:
|
||||||
bot_output(client, LVL_DEBUG, " Hub: \"%s\" [%s]\n"
|
|
||||||
" \"%s\"\n", data->hubinfo->name, data->hubinfo->version, data->hubinfo->description);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -324,30 +405,71 @@ static int handle(struct ADC_client* client, enum ADC_client_callback_type type,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void timer_callback(struct timeout_evt* t)
|
||||||
|
{
|
||||||
|
size_t timeout = get_next_timeout_evt();
|
||||||
|
struct AdcFuzzUser* client = (struct AdcFuzzUser*) t->ptr;
|
||||||
|
if (client->logged_in)
|
||||||
|
{
|
||||||
|
perf_normal_action(client->client);
|
||||||
|
bot_output(client->client, LVL_VERBOSE, "Next timeout: %d seconds", (int) timeout);
|
||||||
|
}
|
||||||
|
timeout_queue_reschedule(net_backend_get_timeout_queue(), client->timer, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct AdcFuzzUser client[ADC_MAX_CLIENTS];
|
||||||
|
void p_status()
|
||||||
|
{
|
||||||
|
static char rxbuf[64] = { "0 B" };
|
||||||
|
static char txbuf[64] = { "0 B" };
|
||||||
|
int logged_in = 0;
|
||||||
|
size_t n;
|
||||||
|
static size_t rx = 0, tx = 0;
|
||||||
|
|
||||||
|
for (n = 0; n < cfg_clients; n++)
|
||||||
|
{
|
||||||
|
if (client[n].logged_in)
|
||||||
|
logged_in++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (difftime(time(NULL), stats_intermediate->timestamp) >= cfg_netstats_interval)
|
||||||
|
{
|
||||||
|
net_stats_get(&stats_intermediate, &stats_total);
|
||||||
|
rx = stats_intermediate->rx / cfg_netstats_interval;
|
||||||
|
tx = stats_intermediate->tx / cfg_netstats_interval;
|
||||||
|
net_stats_reset();
|
||||||
|
strcpy(rxbuf, format_size(rx));
|
||||||
|
strcpy(txbuf, format_size(tx));
|
||||||
|
}
|
||||||
|
|
||||||
|
n = blank;
|
||||||
|
blank = printf("Connected bots: %d/%d, network: rx=%s/s, tx=%s/s", logged_in, cfg_clients, rxbuf, txbuf);
|
||||||
|
if (n > blank)
|
||||||
|
do_blank(n-blank);
|
||||||
|
printf("\r");
|
||||||
|
}
|
||||||
|
|
||||||
void runloop(size_t clients)
|
void runloop(size_t clients)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
struct ADC_client* client[ADC_MAX_CLIENTS];
|
blank = 0;
|
||||||
|
|
||||||
for (n = 0; n < clients; n++)
|
for (n = 0; n < clients; n++)
|
||||||
{
|
{
|
||||||
char nick[20];
|
char nick[20];
|
||||||
snprintf(nick, 20, "adcrush_%d", (int) n);
|
snprintf(nick, 20, "adcrush_%d", (int) n);
|
||||||
struct ADC_client* c = ADC_client_create(nick, "stresstester");
|
client_connect(&client[n], nick, "stresstester");
|
||||||
client[n] = c;
|
|
||||||
ADC_client_set_callback(c, handle);
|
|
||||||
ADC_client_connect(c, cfg_uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (net_backend_process())
|
while (running && net_backend_process())
|
||||||
{
|
{
|
||||||
|
p_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < clients; n++)
|
for (n = 0; n < clients; n++)
|
||||||
{
|
{
|
||||||
ADC_client_destroy(client[n]);
|
struct AdcFuzzUser* c = &client[n];
|
||||||
free(client[n]);
|
client_disconnect(c);
|
||||||
client[n] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,6 +493,7 @@ static void print_usage(const char* program)
|
|||||||
printf(" -c Allow broadcasting chat messages.\n");
|
printf(" -c Allow broadcasting chat messages.\n");
|
||||||
printf(" -d Enable debug output.\n");
|
printf(" -d Enable debug output.\n");
|
||||||
printf(" -q Quiet mode (no output).\n");
|
printf(" -q Quiet mode (no output).\n");
|
||||||
|
printf(" -i <num> Average network statistics for given interval (default: 3)\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -404,6 +527,10 @@ int parse_arguments(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
cfg_level = MIN(MAX(uhub_atoi(argv[opt]), 0), 3);
|
cfg_level = MIN(MAX(uhub_atoi(argv[opt]), 0), 3);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[opt], "-i") && (++opt) < argc)
|
||||||
|
{
|
||||||
|
cfg_netstats_interval = MAX(uhub_atoi(argv[opt]), 1);
|
||||||
|
}
|
||||||
else if (!strcmp(argv[opt], "-n") && (++opt) < argc)
|
else if (!strcmp(argv[opt], "-n") && (++opt) < argc)
|
||||||
{
|
{
|
||||||
cfg_clients = MIN(MAX(uhub_atoi(argv[opt]), 1), ADC_MAX_CLIENTS);
|
cfg_clients = MIN(MAX(uhub_atoi(argv[opt]), 1), ADC_MAX_CLIENTS);
|
||||||
@ -425,13 +552,15 @@ void parse_command_line(int argc, char** argv)
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
parse_command_line(argc, argv);
|
parse_command_line(argc, argv);
|
||||||
|
|
||||||
net_initialize();
|
net_initialize();
|
||||||
|
net_stats_get(&stats_intermediate, &stats_total);
|
||||||
|
|
||||||
hub_log_initialize(NULL, 0);
|
hub_log_initialize(NULL, 0);
|
||||||
hub_set_log_verbosity(1000);
|
hub_set_log_verbosity(1000);
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
runloop(cfg_clients);
|
runloop(cfg_clients);
|
||||||
|
|
||||||
net_destroy();
|
net_destroy();
|
||||||
|
Loading…
Reference in New Issue
Block a user