mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
improved network logging
This commit is contained in:
parent
d951d368a6
commit
164d9c637d
|
@ -23,6 +23,11 @@ static void con_dbg_dumpmem(void *result, void *user_data)
|
|||
mem_debug_dump();
|
||||
}
|
||||
|
||||
static void con_dbg_lognetwork(void *result, void *user_data)
|
||||
{
|
||||
netcommon_openlog("network_sent.dat", "network_recv.dat");
|
||||
}
|
||||
|
||||
|
||||
static char application_save_path[512] = {0};
|
||||
static char *datadir_override = 0;
|
||||
|
@ -76,6 +81,7 @@ void engine_init(const char *appname)
|
|||
jobs_initpool(&hostlookuppool, 1);
|
||||
|
||||
MACRO_REGISTER_COMMAND("dbg_dumpmem", "", con_dbg_dumpmem, 0x0);
|
||||
MACRO_REGISTER_COMMAND("dbg_lognetwork", "", con_dbg_lognetwork, 0x0);
|
||||
|
||||
/* reset the config */
|
||||
config_reset();
|
||||
|
|
|
@ -77,7 +77,8 @@ int recvinfo_fetch_chunk(NETRECVINFO *info, NETCHUNK *chunk)
|
|||
}
|
||||
|
||||
|
||||
static IOHANDLE datalog = 0;
|
||||
static IOHANDLE datalog_sent = 0;
|
||||
static IOHANDLE datalog_recv = 0;
|
||||
static HUFFMAN_STATE huffmanstate;
|
||||
|
||||
#define COMPRESSION 1
|
||||
|
@ -113,10 +114,13 @@ void send_packet(NETSOCKET socket, NETADDR *addr, NETPACKETCONSTRUCT *packet)
|
|||
int final_size = -1;
|
||||
|
||||
/* log the data */
|
||||
if(datalog)
|
||||
if(datalog_sent)
|
||||
{
|
||||
io_write(datalog, &packet->data_size, sizeof(packet->data_size));
|
||||
io_write(datalog, &packet->chunk_data, packet->data_size);
|
||||
int type = 1;
|
||||
io_write(datalog_sent, &type, sizeof(type));
|
||||
io_write(datalog_sent, &packet->data_size, sizeof(packet->data_size));
|
||||
io_write(datalog_sent, &packet->chunk_data, packet->data_size);
|
||||
io_flush(datalog_sent);
|
||||
}
|
||||
|
||||
/* compress if its enabled */
|
||||
|
@ -140,10 +144,21 @@ void send_packet(NETSOCKET socket, NETADDR *addr, NETPACKETCONSTRUCT *packet)
|
|||
/* set header and send the packet if all things are good */
|
||||
if(final_size >= 0)
|
||||
{
|
||||
final_size += NET_PACKETHEADERSIZE;
|
||||
buffer[0] = ((packet->flags<<4)&0xf0)|((packet->ack>>8)&0xf);
|
||||
buffer[1] = packet->ack&0xff;
|
||||
buffer[2] = packet->num_chunks;
|
||||
net_udp_send(socket, addr, buffer, NET_PACKETHEADERSIZE+final_size);
|
||||
net_udp_send(socket, addr, buffer, final_size);
|
||||
|
||||
/* log raw socket data */
|
||||
if(datalog_sent)
|
||||
{
|
||||
int type = 0;
|
||||
io_write(datalog_sent, &type, sizeof(type));
|
||||
io_write(datalog_sent, &final_size, sizeof(final_size));
|
||||
io_write(datalog_sent, buffer, final_size);
|
||||
io_flush(datalog_sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +172,16 @@ int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *packet)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* log the data */
|
||||
if(datalog_recv)
|
||||
{
|
||||
int type = 0;
|
||||
io_write(datalog_recv, &type, sizeof(type));
|
||||
io_write(datalog_recv, &size, sizeof(size));
|
||||
io_write(datalog_recv, buffer, size);
|
||||
io_flush(datalog_recv);
|
||||
}
|
||||
|
||||
/* read the packet */
|
||||
packet->flags = buffer[0]>>4;
|
||||
packet->ack = ((buffer[0]&0xf)<<8) | buffer[1];
|
||||
|
@ -174,11 +199,29 @@ int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *packet)
|
|||
else
|
||||
{
|
||||
if(packet->flags&NET_PACKETFLAG_COMPRESSION)
|
||||
huffman_decompress(&huffmanstate, &buffer[3], packet->data_size, packet->chunk_data, sizeof(packet->chunk_data));
|
||||
packet->data_size = huffman_decompress(&huffmanstate, &buffer[3], packet->data_size, packet->chunk_data, sizeof(packet->chunk_data));
|
||||
else
|
||||
mem_copy(packet->chunk_data, &buffer[3], packet->data_size);
|
||||
}
|
||||
|
||||
/* check for errors */
|
||||
if(packet->data_size < 0)
|
||||
{
|
||||
if(config.debug)
|
||||
dbg_msg("network", "error during packet decoding");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* log the data */
|
||||
if(datalog_recv)
|
||||
{
|
||||
int type = 1;
|
||||
io_write(datalog_recv, &type, sizeof(type));
|
||||
io_write(datalog_recv, &packet->data_size, sizeof(packet->data_size));
|
||||
io_write(datalog_recv, packet->chunk_data, packet->data_size);
|
||||
io_flush(datalog_recv);
|
||||
}
|
||||
|
||||
/* return success */
|
||||
return 0;
|
||||
}
|
||||
|
@ -212,9 +255,25 @@ unsigned char *unpack_chunk_header(unsigned char *data, NETCHUNKHEADER *header)
|
|||
}
|
||||
|
||||
|
||||
void netcommon_openlog(const char *filename)
|
||||
void netcommon_openlog(const char *sentlog, const char *recvlog)
|
||||
{
|
||||
datalog = io_open(filename, IOFLAG_WRITE);
|
||||
if(sentlog)
|
||||
{
|
||||
datalog_sent = io_open(sentlog, IOFLAG_WRITE);
|
||||
if(datalog_sent)
|
||||
dbg_msg("network", "logging sent packages to '%s'", sentlog);
|
||||
else
|
||||
dbg_msg("network", "failed to open for logging '%s'", sentlog);
|
||||
}
|
||||
|
||||
if(recvlog)
|
||||
{
|
||||
datalog_recv = io_open(recvlog, IOFLAG_WRITE);
|
||||
if(recvlog)
|
||||
dbg_msg("network", "logging recv packages to '%s'", recvlog);
|
||||
else
|
||||
dbg_msg("network", "failed to open for logging '%s'", recvlog);
|
||||
}
|
||||
}
|
||||
|
||||
static const unsigned freq_table[256+1] = {
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef int (*NETFUNC_DELCLIENT)(int cid, void *user);
|
|||
typedef int (*NETFUNC_NEWCLIENT)(int cid, void *user);
|
||||
|
||||
/* both */
|
||||
void netcommon_openlog(const char *filename);
|
||||
void netcommon_openlog(const char *sentlog, const char *recvlog);
|
||||
void netcommon_init();
|
||||
int netcommon_compress(const void *data, int data_size, void *output, int output_size);
|
||||
int netcommon_decompress(const void *data, int data_size, void *output, int output_size);
|
||||
|
|
|
@ -1248,8 +1248,6 @@ int main(int argc, char **argv)
|
|||
dbg_msg("server", "starting...");
|
||||
engine_init("Teeworlds");
|
||||
|
||||
netcommon_openlog("output.dat");
|
||||
|
||||
/* register all console commands */
|
||||
server_register_commands();
|
||||
mods_console_init();
|
||||
|
|
Loading…
Reference in a new issue