PIDiagnostics

git-svn-id: svn://db.shs.com.ru/pip@132 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-05-20 06:48:29 +00:00
parent bfcdb80186
commit 7d506588e6
4 changed files with 34 additions and 10 deletions

View File

@@ -50,7 +50,7 @@ void PIDiagnostics::reset() {
speedIn = speedOut = PIString::readableSize(0) + "/s"; speedIn = speedOut = PIString::readableSize(0) + "/s";
ifreq = immediate_freq = integral_freq = 0.f; ifreq = immediate_freq = integral_freq = 0.f;
cur_pckt = rec_once = 0; cur_pckt = rec_once = 0;
wrong_count = receive_count = send_count = 0; wrong_count = receive_count = send_count = wrong_bytes = receive_bytes = send_bytes = 0;
packets_in_sec = packets_out_sec = bytes_in_sec = bytes_out_sec = 0; packets_in_sec = packets_out_sec = bytes_in_sec = bytes_out_sec = 0;
unlock(); unlock();
} }
@@ -65,9 +65,11 @@ void PIDiagnostics::received(int size, bool correct) {
if (el > 0.f) immediate_freq = ifreq = 1.f / el; if (el > 0.f) immediate_freq = ifreq = 1.f / el;
else immediate_freq = ifreq = 0.f; else immediate_freq = ifreq = 0.f;
receive_count++; receive_count++;
receive_bytes += size;
} else { } else {
immediate_freq = ifreq = 0.f; immediate_freq = ifreq = 0.f;
wrong_count++; wrong_count++;
wrong_bytes += size;
} }
addToHistory(history_rec, size, correct); addToHistory(history_rec, size, correct);
unlock(); unlock();
@@ -77,6 +79,7 @@ void PIDiagnostics::received(int size, bool correct) {
void PIDiagnostics::sended(int size) { void PIDiagnostics::sended(int size) {
lock(); lock();
send_count++; send_count++;
send_bytes += size;
addToHistory(history_send, size); addToHistory(history_send, size);
unlock(); unlock();
} }

View File

@@ -72,6 +72,15 @@ public:
//! Returns sended bytes per second //! Returns sended bytes per second
ullong sendBytesPerSec() const {return bytes_out_sec;} ullong sendBytesPerSec() const {return bytes_out_sec;}
//! Returns overall correct received bytes
ullong receiveBytes() const {return receive_bytes;}
//! Returns overall wrong received bytes
ullong wrongBytes() const {return wrong_bytes;}
//! Returns overall sended bytes
ullong sendBytes() const {return send_bytes;}
//! Returns overall correct received packets count //! Returns overall correct received packets count
ullong receiveCount() const {return receive_count;} ullong receiveCount() const {return receive_count;}
@@ -109,6 +118,15 @@ public:
//! Returns sended bytes per second pointer. Useful for output to PIConsole //! Returns sended bytes per second pointer. Useful for output to PIConsole
const ullong * sendBytesPerSec_ptr() const {return &bytes_out_sec;} const ullong * sendBytesPerSec_ptr() const {return &bytes_out_sec;}
//! Returns overall correct received bytes pointer. Useful for output to PIConsole
const ullong * receiveBytes_ptr() const {return &receive_bytes;}
//! Returns overall wrong received bytes pointer. Useful for output to PIConsole
const ullong * wrongBytes_ptr() const {return &wrong_bytes;}
//! Returns overall sended bytes pointer. Useful for output to PIConsole
const ullong * sendBytes_ptr() const {return &send_bytes;}
//! Returns overall correct received packets count pointer. Useful for output to PIConsole //! Returns overall correct received packets count pointer. Useful for output to PIConsole
const ullong * receiveCount_ptr() const {return &receive_count;} const ullong * receiveCount_ptr() const {return &receive_count;}
@@ -183,7 +201,7 @@ private:
PISystemTime disconn_st; PISystemTime disconn_st;
PITimeMeasurer tm; PITimeMeasurer tm;
char cur_pckt, rec_once; char cur_pckt, rec_once;
ullong wrong_count, receive_count, send_count; ullong wrong_count, receive_count, send_count, wrong_bytes, receive_bytes, send_bytes;
ullong packets_in_sec, packets_out_sec, bytes_in_sec, bytes_out_sec; ullong packets_in_sec, packets_out_sec, bytes_in_sec, bytes_out_sec;
}; };

View File

@@ -71,10 +71,12 @@ PIByteArray PICrypt::crypt(const PIByteArray & data) {
} }
PIByteArray PICrypt::crypt(const PIByteArray & data, const PIByteArray & key) { PIByteArray PICrypt::crypt(const PIByteArray & data, PIByteArray key) {
PIByteArray ret; PIByteArray ret;
#ifdef PIP_CRYPT #ifdef PIP_CRYPT
if (key.size() != crypto_secretbox_KEYBYTES) return PIByteArray(); if (key.size() != crypto_secretbox_KEYBYTES)
key.resize(crypto_secretbox_KEYBYTES, ' ');
//return PIByteArray();
sodium_init(); sodium_init();
PIByteArray n; PIByteArray n;
ret.resize(data.size() + crypto_secretbox_MACBYTES); ret.resize(data.size() + crypto_secretbox_MACBYTES);
@@ -107,13 +109,14 @@ PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, bool *ok) {
} }
PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, const PIByteArray & key, bool *ok) { PIByteArray PICrypt::decrypt(const PIByteArray & crypt_data, PIByteArray key, bool *ok) {
PIByteArray ret; PIByteArray ret;
#ifdef PIP_CRYPT #ifdef PIP_CRYPT
if (key.size() != crypto_secretbox_KEYBYTES) { if (key.size() != crypto_secretbox_KEYBYTES)
if (ok) *ok = false; key.resize(crypto_secretbox_KEYBYTES, ' ');
/*if (ok) *ok = false;
return PIByteArray(); return PIByteArray();
} }*/
if (crypt_data.size() < crypto_secretbox_NONCEBYTES + crypto_secretbox_MACBYTES) { if (crypt_data.size() < crypto_secretbox_NONCEBYTES + crypto_secretbox_MACBYTES) {
if (ok) *ok = false; if (ok) *ok = false;
return PIByteArray(); return PIByteArray();

View File

@@ -46,10 +46,10 @@ public:
PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0); PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0);
//! Encrypt given data "data" with key "key", result size will be increased by \a sizeCrypt() //! Encrypt given data "data" with key "key", result size will be increased by \a sizeCrypt()
static PIByteArray crypt(const PIByteArray & data, const PIByteArray & key); static PIByteArray crypt(const PIByteArray & data, PIByteArray key);
//! Decrypt given data "crypt_data" with key "key" //! Decrypt given data "crypt_data" with key "key"
static PIByteArray decrypt(const PIByteArray & crypt_data, const PIByteArray & key, bool * ok = 0); static PIByteArray decrypt(const PIByteArray & crypt_data, PIByteArray key, bool * ok = 0);
//! Generate hash from keyphrase "secret", may be used as a key for encryption //! Generate hash from keyphrase "secret", may be used as a key for encryption
static PIByteArray hash(const PIString & secret); static PIByteArray hash(const PIString & secret);