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";
ifreq = immediate_freq = integral_freq = 0.f;
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;
unlock();
}
@@ -65,9 +65,11 @@ void PIDiagnostics::received(int size, bool correct) {
if (el > 0.f) immediate_freq = ifreq = 1.f / el;
else immediate_freq = ifreq = 0.f;
receive_count++;
receive_bytes += size;
} else {
immediate_freq = ifreq = 0.f;
wrong_count++;
wrong_bytes += size;
}
addToHistory(history_rec, size, correct);
unlock();
@@ -77,6 +79,7 @@ void PIDiagnostics::received(int size, bool correct) {
void PIDiagnostics::sended(int size) {
lock();
send_count++;
send_bytes += size;
addToHistory(history_send, size);
unlock();
}

View File

@@ -72,6 +72,15 @@ public:
//! Returns sended bytes per second
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
ullong receiveCount() const {return receive_count;}
@@ -109,6 +118,15 @@ public:
//! Returns sended bytes per second pointer. Useful for output to PIConsole
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
const ullong * receiveCount_ptr() const {return &receive_count;}
@@ -183,7 +201,7 @@ private:
PISystemTime disconn_st;
PITimeMeasurer tm;
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;
};

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;
#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();
PIByteArray n;
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;
#ifdef PIP_CRYPT
if (key.size() != crypto_secretbox_KEYBYTES) {
if (ok) *ok = false;
if (key.size() != crypto_secretbox_KEYBYTES)
key.resize(crypto_secretbox_KEYBYTES, ' ');
/*if (ok) *ok = false;
return PIByteArray();
}
}*/
if (crypt_data.size() < crypto_secretbox_NONCEBYTES + crypto_secretbox_MACBYTES) {
if (ok) *ok = false;
return PIByteArray();

View File

@@ -46,10 +46,10 @@ public:
PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0);
//! 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"
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
static PIByteArray hash(const PIString & secret);