git-svn-id: svn://db.shs.com.ru/pip@226 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -231,4 +231,4 @@ add_subdirectory("utils/remote_console")
|
||||
add_subdirectory("utils/code_model_generator")
|
||||
add_subdirectory("utils/system_daemon")
|
||||
add_subdirectory("utils/udp_file_transfer")
|
||||
add_subdirectory("utils/picrypt")
|
||||
add_subdirectory("utils/crypt_tool")
|
||||
|
||||
@@ -185,6 +185,7 @@ bool PIEthernet::init() {
|
||||
//if (type() == PIEthernet::TCP_Client) ethSetsockoptBool(sock, SOL_SOCKET, SO_KEEPALIVE);
|
||||
applyTimeouts();
|
||||
applyOptInt(IPPROTO_IP, IP_TTL, TTL());
|
||||
// piCoutObj << "inited" << path();
|
||||
//cout << "inited " << sock << ": bc = " << params << endl;
|
||||
//fcntl(sock, F_SETFL, 0/*O_NONBLOCK*/);
|
||||
//piCoutObj << "init" << sock;
|
||||
@@ -356,8 +357,8 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
|
||||
}
|
||||
PIFlags<Parameters> params = parameters();
|
||||
//#ifndef QNX
|
||||
if (!params[Broadcast])
|
||||
;//piCoutObj << "Warning: \"Broadcast\" parameter not set, \"joinMulticastGroup(\"" << group << "\")\" may be useless!";
|
||||
//if (!params[Broadcast])
|
||||
//;piCoutObj << "Warning: \"Broadcast\" parameter not set, \"joinMulticastGroup(\"" << group << "\")\" may be useless!";
|
||||
parseAddress(path(), &ip_, &port_);
|
||||
struct ip_mreqn mreq;
|
||||
memset(&mreq, 0, sizeof(mreq));
|
||||
@@ -499,7 +500,7 @@ int PIEthernet::read(void * read_to, int max_size) {
|
||||
int rs = 0, s = 0, lerr = 0;
|
||||
sockaddr_in client_addr;
|
||||
socklen_t slen = sizeof(client_addr);
|
||||
//piCoutObj << "read from " << ip_ << ":" << port_ << endl;
|
||||
// piCoutObj << "read from " << ip_ << ":" << port_;
|
||||
switch (type()) {
|
||||
case TCP_SingleTCP:
|
||||
::listen(sock, 64);
|
||||
|
||||
@@ -133,6 +133,8 @@ PIPeer::PIPeer(const PIString & name_): PIObject() {
|
||||
destroyed = false;
|
||||
setName(name_);
|
||||
self_info.name = name_;
|
||||
diag_d.setName(name_+"_data");
|
||||
diag_s.setName(name_+"_service");
|
||||
self_info.dist = 0;
|
||||
self_info.time = PISystemTime::current();
|
||||
//joinMulticastGroup("239.240.241.242");
|
||||
@@ -140,6 +142,7 @@ PIPeer::PIPeer(const PIString & name_): PIObject() {
|
||||
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent);
|
||||
prev_ifaces = PIEthernet::interfaces();
|
||||
no_timer = false;
|
||||
initNetwork();
|
||||
sendSelfInfo();
|
||||
timer.addDelimiter(5);
|
||||
@@ -174,6 +177,8 @@ PIPeer::~PIPeer() {
|
||||
|
||||
|
||||
void PIPeer::timerEvent(void * data, int delim) {
|
||||
// piCoutObj << "timerEvent" << delim;
|
||||
if (no_timer) return;
|
||||
switch (delim) {
|
||||
case 1: // every 1 s
|
||||
syncPeers();
|
||||
@@ -187,7 +192,7 @@ void PIPeer::timerEvent(void * data, int delim) {
|
||||
|
||||
|
||||
void PIPeer::initEths(PIStringList al) {
|
||||
piCoutObj << "initEths start";
|
||||
// piCoutObj << "initEths start";
|
||||
PIEthernet * ce;
|
||||
const PIEthernet::Interface * cint = 0;
|
||||
piForeachC (PIString & a, al) {
|
||||
@@ -204,8 +209,8 @@ void PIPeer::initEths(PIStringList al) {
|
||||
self_info.addresses << PeerInfo::Address(ce->path(), cint == 0 ? "255.255.255.0" : cint->netmask);
|
||||
CONNECTU(ce, threadedReadEvent, this, dataRead);
|
||||
ce->startThreadedRead();
|
||||
//piCout << "dc binded to" << ce->path();
|
||||
//piCout << "add eth" << ta;
|
||||
// piCoutObj << "dc binded to" << ce->path();
|
||||
// piCoutObj << "add eth" << a;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
@@ -215,49 +220,61 @@ void PIPeer::initEths(PIStringList al) {
|
||||
eth_send.setDebug(false);
|
||||
eth_send.setName("__S__PIPeer_traffic_eth_send");
|
||||
eth_send.setParameters(0);
|
||||
piCoutObj << "initEths ok";
|
||||
// piCoutObj << "initEths ok";
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::initMBcasts(PIStringList al) {
|
||||
piCoutObj << "initMBcasts start";
|
||||
destroyMBcasts();
|
||||
// destroyMBcasts();
|
||||
PIEthernet * ce;
|
||||
const PIEthernet::Interface * cint;
|
||||
PIString nm;
|
||||
al << _PIPEER_MULTICAST_IP;
|
||||
// piCoutObj << "initMBcasts start" << al;
|
||||
piForeachC (PIString & a, al) {
|
||||
//piCout << "mcast try" << a;
|
||||
ce = new PIEthernet();
|
||||
ce->setDebug(false);
|
||||
// ce->setDebug(false);
|
||||
ce->setName("__S__PIPeer_mcast_eth_" + a);
|
||||
ce->setParameters(0);
|
||||
ce->setSendAddress(_PIPEER_MULTICAST_IP, _PIPEER_MULTICAST_PORT);
|
||||
ce->setReadAddress(a, _PIPEER_MULTICAST_PORT);
|
||||
ce->setMulticastTTL(_PIPEER_MULTICAST_TTL);
|
||||
ce->joinMulticastGroup(_PIPEER_MULTICAST_IP);
|
||||
if (ce->open()) {
|
||||
eths_mcast << ce;
|
||||
CONNECTU(ce, threadedReadEvent, this, mbcastRead);
|
||||
ce->startThreadedRead();
|
||||
// piCout << "mcast bind to" << a << ce->sendIP();
|
||||
} else {
|
||||
delete ce;
|
||||
piCoutObj << "invalid address for mcast" << a;
|
||||
}
|
||||
}
|
||||
al.removeAll(_PIPEER_MULTICAST_IP);
|
||||
piForeachC (PIString & a, al) {
|
||||
ce = new PIEthernet();
|
||||
ce->setDebug(false);
|
||||
// ce->setDebug(false);
|
||||
ce->setName("__S__PIPeer_bcast_eth_" + a);
|
||||
ce->setParameters(PIEthernet::Broadcast);
|
||||
cint = prev_ifaces.getByAddress(a);
|
||||
nm = (cint == 0) ? "255.255.255.0" : cint->netmask;
|
||||
ce->setSendAddress(PIEthernet::getBroadcast(a, nm), _PIPEER_BROADCAST_PORT);
|
||||
ce->setReadAddress(a, _PIPEER_BROADCAST_PORT);
|
||||
//piCout << "mc BC try" << a << nm << ce->sendIP();
|
||||
//piCout << "bcast try" << a << nm;
|
||||
if (ce->open()) {
|
||||
eths_bcast << ce;
|
||||
CONNECTU(ce, threadedReadEvent, this, mbcastRead);
|
||||
ce->startThreadedRead();
|
||||
// piCout << "mc BC try" << a << nm << ce->sendIP();
|
||||
// piCout << "bcast bind to" << a << nm;
|
||||
} else {
|
||||
delete ce;
|
||||
piCoutObj << "invalid address for bcast" << a;
|
||||
}
|
||||
eth_lo.setDebug(false);
|
||||
}
|
||||
// eth_lo.setDebug(false);
|
||||
eth_lo.setName("__S__PIPeer_eth_loopback");
|
||||
eth_lo.setParameters(0);
|
||||
eth_lo.setParameters(PIEthernet::SeparateSockets);
|
||||
eth_lo.init();
|
||||
cint = prev_ifaces.getByAddress("127.0.0.1");
|
||||
for (int p = _PIPEER_LOOPBACK_PORT_S; p <= _PIPEER_LOOPBACK_PORT_E; ++p) {
|
||||
@@ -266,19 +283,20 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
eth_lo.setSendIP("127.0.0.1");
|
||||
CONNECTU(ð_lo, threadedReadEvent, this, mbcastRead);
|
||||
eth_lo.startThreadedRead();
|
||||
//piCout << "lo binded to" << eth_lo.readAddress();
|
||||
// piCout << "lo binded to" << eth_lo.readAddress() << eth_lo.sendAddress();
|
||||
//piCout << "add eth" << ta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (eths_mcast.isEmpty()) piCoutObj << "Warning! Can`t find suitable network interface for multicast receive, check for exists at least one interface with multicasting enabled!";
|
||||
if (eths_bcast.isEmpty()) piCoutObj << "Warning! Can`t find suitable network interface for broadcast receive, check for exists at least one interface with broadcasting enabled!";
|
||||
piCoutObj << "initMBcasts ok";
|
||||
if (eths_mcast.isEmpty() && eths_bcast.isEmpty() && !eth_lo.isOpened()) piCoutObj << "Warning! Can`t find suitable network interface for multicast receive, check for exists at least one interface with multicasting enabled!";
|
||||
// piCoutObj << "initMBcasts ok";
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::destroyEths() {
|
||||
piForeach (PIEthernet * i, eths_traffic) {
|
||||
((PIThread*)i)->stop();
|
||||
((PIThread*)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->close();
|
||||
delete i;
|
||||
@@ -289,16 +307,22 @@ void PIPeer::destroyEths() {
|
||||
|
||||
void PIPeer::destroyMBcasts() {
|
||||
piForeach (PIEthernet * i, eths_mcast) {
|
||||
((PIThread*)i)->stop();
|
||||
((PIThread*)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->leaveMulticastGroup(_PIPEER_MULTICAST_IP);
|
||||
i->close();
|
||||
delete i;
|
||||
}
|
||||
piForeach (PIEthernet * i, eths_bcast) {
|
||||
((PIThread*)i)->stop();
|
||||
((PIThread*)i)->waitForFinish(100);
|
||||
i->stopThreadedRead();
|
||||
i->close();
|
||||
delete i;
|
||||
}
|
||||
((PIThread*)ð_lo)->stop();
|
||||
((PIThread*)ð_lo)->waitForFinish(100);
|
||||
eth_lo.stopThreadedRead();
|
||||
eth_lo.close();
|
||||
eths_mcast.clear();
|
||||
@@ -365,7 +389,10 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
|
||||
|
||||
|
||||
bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
if (destroyed) return true;
|
||||
if (destroyed) {
|
||||
piCout << "[PIPeer] SegFault";
|
||||
return true;
|
||||
}
|
||||
if (size < 16) return true;
|
||||
PIByteArray ba(readed, size), sba, pba;
|
||||
int type, cnt;
|
||||
@@ -467,7 +494,10 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
||||
|
||||
|
||||
bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||
if (destroyed) return true;
|
||||
if (destroyed) {
|
||||
piCout << "[PIPeer] SegFault";
|
||||
return true;
|
||||
}
|
||||
if (size < 8) return true;
|
||||
int type, dist;
|
||||
PIByteArray ba(data, size);
|
||||
@@ -625,6 +655,7 @@ bool PIPeer::sendToNeighbour(PIPeer::PeerInfo * peer, const PIByteArray & ba) {
|
||||
|
||||
|
||||
void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
send_mc_mutex.lock();
|
||||
// piCout << "sendMBcast" << ba.size() << "bytes ...";
|
||||
piForeach (PIEthernet * e, eths_mcast) {
|
||||
//errorClear();
|
||||
@@ -648,6 +679,7 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
// piCout << "send muticast ok";
|
||||
send_mc_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -774,17 +806,23 @@ void PIPeer::checkNetwork() {
|
||||
|
||||
|
||||
void PIPeer::reinit() {
|
||||
no_timer = true;
|
||||
// timer.stop();
|
||||
// timer.clearDelimiters();
|
||||
PIMutexLocker mbl(mc_mutex);
|
||||
PIMutexLocker ethl(eth_mutex);
|
||||
PIMutexLocker pl(peers_mutex);
|
||||
PIMutexLocker sl(send_mutex);
|
||||
initNetwork();
|
||||
eth_send.close();
|
||||
eth_lo.stopThreadedRead();
|
||||
eth_lo.close();
|
||||
eth_send.init();
|
||||
eth_send.open();
|
||||
eth_lo.startThreadedRead();
|
||||
// eth_send.close();
|
||||
// eth_lo.stopThreadedRead();
|
||||
// eth_lo.close();
|
||||
// eth_send.init();
|
||||
// eth_send.open();
|
||||
// eth_lo.startThreadedRead();
|
||||
// timer.addDelimiter(5);
|
||||
// timer.start(1000);
|
||||
no_timer = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -793,6 +831,7 @@ void PIPeer::initNetwork() {
|
||||
eth_send.init();
|
||||
destroyEths();
|
||||
destroyMBcasts();
|
||||
piMSleep(100);
|
||||
// piCoutObj << self_info.addresses.size();
|
||||
self_info.addresses.clear();
|
||||
PIStringList sl = PIEthernet::allAddresses();
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
PIPeer(const PIString & name);
|
||||
explicit PIPeer(const PIString & name);
|
||||
virtual ~PIPeer();
|
||||
|
||||
class PeerInfo {
|
||||
@@ -180,23 +180,22 @@ private:
|
||||
// Data packet: 4, from, to, ticks, data_size, data
|
||||
|
||||
protected:
|
||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex;
|
||||
PIMutex send_mc_mutex;
|
||||
|
||||
typedef PIPair<PIString, PIVector<PeerInfo * > > napair;
|
||||
|
||||
private:
|
||||
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
||||
PIEthernet::InterfaceList prev_ifaces;
|
||||
PIEthernet eth_send, eth_lo;
|
||||
PITimer timer;
|
||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex;
|
||||
|
||||
PeerInfo self_info;
|
||||
PIVector<PeerInfo> peers;
|
||||
PIMap<PIString, PeerInfo * > peers_map;
|
||||
PIMap<PIString, PIVector<PeerInfo * > > addresses_map; // map {"to" = list of nearest peers}
|
||||
PIMap<PIString, PIPair<int, PISystemTime> > removed;
|
||||
PIDiagnostics diag_s, diag_d;
|
||||
bool destroyed;
|
||||
//PIString id_;
|
||||
bool destroyed, no_timer;
|
||||
PIString id_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define PIP_VERSION_MAJOR 0
|
||||
#define PIP_VERSION_MINOR 5
|
||||
#define PIP_VERSION_REVISION 6
|
||||
#define PIP_VERSION_REVISION 7
|
||||
#define PIP_VERSION_SUFFIX ""
|
||||
|
||||
#endif // PIVERSION_H
|
||||
|
||||
@@ -97,8 +97,8 @@ void PIIntrospectionContainers::containerUnused(ullong cnt) {
|
||||
|
||||
|
||||
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent)
|
||||
timer.start(100);
|
||||
CONNECTU(&itimer, tickEvent, this, timerEvent)
|
||||
itimer.start(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
private:
|
||||
EVENT_HANDLER(void, timerEvent);
|
||||
PIString genName();
|
||||
PITimer timer;
|
||||
PITimer itimer;
|
||||
};
|
||||
|
||||
|
||||
|
||||
5
utils/crypt_tool/CMakeLists.txt
Normal file
5
utils/crypt_tool/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
add_executable(picrypt "main.cpp")
|
||||
target_link_libraries(picrypt pip)
|
||||
if (DEFINED LIB)
|
||||
install(TARGETS picrypt DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
endif ()
|
||||
100
utils/crypt_tool/main.cpp
Normal file
100
utils/crypt_tool/main.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "pip.h"
|
||||
#include "picrypt.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Crypt Utility";
|
||||
piCout << Cyan << "Version" << Bold << PIPVersion() << NewLine;
|
||||
piCout << Green << Bold << "Usage:" << Default << "\"picrypt [-thr] [-g <pass>] [-o <out_file>] [{[-c <file>] [-u <file>]} {[-p <pass>] [-s <hash>] [-k <key_file>] [-x <hex_key>]}]\"" << NewLine;
|
||||
piCout << Green << Bold << "Details:";
|
||||
piCout << "-h --help " << Green << "- display this message and exit";
|
||||
piCout << "-g --genhash " << Green << "- generate hash from <pass> string";
|
||||
piCout << "-t --text " << Green << "- output in text base64";
|
||||
piCout << "-o --out <out_file> " << Green << "- write out to file <out_file>";
|
||||
piCout << "-c --crypt <file> " << Green << "- crypt file <file> using secret <pass> or <hash> or <key_file>";
|
||||
piCout << "-u --uncrypt <file> " << Green << "- uncrypt file <file> using secret <pass> or <hash> or <key_file>";
|
||||
piCout << "-p --pass <pass> " << Green << "- use secret from passphrase <pass>";
|
||||
piCout << "-s --secret <hash> " << Green << "- use secret from hash <hash>";
|
||||
piCout << "-k --key <key_file> " << Green << "- use secret from binary key_file <key_file>";
|
||||
piCout << "-x --hex [<hex_key>] " << Green << "- use secret from hex hash <hex_key> or output in text hex";
|
||||
piCout << "-r --random " << Green << "- generate random secret key";
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
PICrypt crypt;
|
||||
PIByteArray bout;
|
||||
PICLI cli(argc, argv);
|
||||
cli.addArgument("genhash", true);
|
||||
cli.addArgument("out", true);
|
||||
cli.addArgument("crypt", true);
|
||||
cli.addArgument("uncrypt", true);
|
||||
cli.addArgument("pass", true);
|
||||
cli.addArgument("secret", true);
|
||||
cli.addArgument("key", true);
|
||||
cli.addArgument("hex", 'x', "hex", true);
|
||||
cli.addArgument("help");
|
||||
cli.addArgument("text");
|
||||
cli.addArgument("random");
|
||||
|
||||
if (!(cli.hasArgument("genhash") ||
|
||||
cli.hasArgument("crypt") ||
|
||||
cli.hasArgument("uncrypt") ||
|
||||
cli.hasArgument("random")) ||
|
||||
cli.hasArgument("help")) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
PIString out_file = cli.argumentValue("out");
|
||||
PIFile outf;
|
||||
if (!out_file.isEmpty()) {
|
||||
if (outf.open(out_file, PIIODevice::ReadWrite)) {
|
||||
outf.resize(0);
|
||||
} else piCout << "error: while open out file";
|
||||
}
|
||||
|
||||
if (cli.hasArgument("genhash")) {
|
||||
PIString s = cli.argumentValue("genhash");
|
||||
bout = crypt.hash(s);
|
||||
} else if (cli.hasArgument("random")) bout = crypt.generateKey();
|
||||
|
||||
if (cli.hasArgument("crypt") || cli.hasArgument("uncrypt")) {
|
||||
PIByteArray secret;
|
||||
if (cli.hasArgument("key")) {
|
||||
PIFile keyf(cli.argumentValue("key"), PIIODevice::ReadOnly);
|
||||
if (keyf.open()) secret = keyf.readAll();
|
||||
else piCout << "error: while open key file";
|
||||
}
|
||||
if (cli.hasArgument("pass")) secret = crypt.hash(cli.argumentValue("pass"));
|
||||
if (cli.hasArgument("secret")) secret = PIByteArray::fromBase64(cli.argumentValue("secret").toByteArray());
|
||||
if (cli.hasArgument("hex")) secret = PIByteArray::fromHex(cli.argumentValue("hex").toByteArray());
|
||||
if (secret.size() == crypt.sizeKey()) {
|
||||
PIFile inf;
|
||||
PIString in_file;
|
||||
PIByteArray bin;
|
||||
crypt.setKey(secret);
|
||||
if (cli.hasArgument("crypt")) in_file = cli.argumentValue("crypt");
|
||||
if (cli.hasArgument("uncrypt")) in_file = cli.argumentValue("uncrypt");
|
||||
if (inf.open(in_file, PIIODevice::ReadOnly)) {
|
||||
bin = inf.readAll();
|
||||
if (cli.hasArgument("crypt")) bout = crypt.crypt(bin);
|
||||
if (cli.hasArgument("uncrypt")) bout = crypt.decrypt(bin);
|
||||
} else piCout << "error: while open input file";
|
||||
} else piCout << "error: invalid secret";
|
||||
}
|
||||
|
||||
if (!bout.isEmpty()) {
|
||||
if (cli.hasArgument("text")) bout.convertToBase64();
|
||||
else if (cli.hasArgument("hex") && cli.argumentValue("hex").isEmpty()) bout = bout.toHex().toByteArray();
|
||||
if (outf.isOpened()) {
|
||||
outf.write(bout);
|
||||
outf.close();
|
||||
}
|
||||
else fwrite(bout.data(), 1, bout.size(), stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ void Daemon::TileFileProgress::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
|
||||
Daemon::Daemon(): PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)), fm(this) {
|
||||
setName("Daemon");
|
||||
timer.setName("__S__Daemon_timer");
|
||||
dtimer.setName("__S__Daemon_timer");
|
||||
mode = offset = cur = height = 0;
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent)
|
||||
CONNECTU(&dtimer, tickEvent, this, timerEvent)
|
||||
CONNECTU(&fm, tileKey, this, fmKeyEvent)
|
||||
CONNECTU(&fm, actionRequest, this, fmActionRequest)
|
||||
timer.addDelimiter(5);
|
||||
timer.start(200);
|
||||
dtimer.addDelimiter(5);
|
||||
dtimer.start(200);
|
||||
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
|
||||
@@ -54,6 +54,9 @@ public:
|
||||
|
||||
bool lockedEth() const {return eth_mutex.isLocked();}
|
||||
bool lockedPeers() const {return peers_mutex.isLocked();}
|
||||
bool lockedMBcasts() const {return mc_mutex.isLocked();}
|
||||
bool lockedSends() const {return send_mutex.isLocked();}
|
||||
bool lockedMCSends() const {return send_mc_mutex.isLocked();}
|
||||
|
||||
private:
|
||||
enum PacketType {
|
||||
@@ -138,7 +141,7 @@ private:
|
||||
void sendDirToRemote(Remote * r);
|
||||
|
||||
mutable PIStringList available_daemons;
|
||||
PITimer timer;
|
||||
PITimer dtimer;
|
||||
PIString conn_name;
|
||||
PIMutex remote_mutex;
|
||||
PIMap<int, PIString> dnames;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Remote console viewer
|
||||
PIp System Daemon
|
||||
Copyright (C) 2016 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -74,6 +74,10 @@ public:
|
||||
mt->hide(); mt->name() = "peer info";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tpeerdiag = peerDiagTile();
|
||||
mt->hide(); mt->name() = "peer diag";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
TilePICout * outt = new TilePICout();
|
||||
outt->size_policy = PIScreenTypes::Expanding;
|
||||
screen.rootTile()->addTile(outt);
|
||||
@@ -91,6 +95,7 @@ public:
|
||||
ret->content << TileList::Row("Connect to another daemon", CellFormat());
|
||||
ret->content << TileList::Row("Peer info", CellFormat());
|
||||
ret->content << TileList::Row("Peer reinit", CellFormat());
|
||||
ret->content << TileList::Row("Peer diagnostics", CellFormat());
|
||||
ret->content << TileList::Row("Exit", CellFormat());
|
||||
ret->selection_mode = TileList::NoSelection;
|
||||
return ret;
|
||||
@@ -107,6 +112,23 @@ public:
|
||||
ret->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount), CellFormat());
|
||||
return ret;
|
||||
}
|
||||
PIScreenTile * peerDiagTile() {
|
||||
PIScreenTile * ret = new PIScreenTile();
|
||||
TileSimple * htl = new TileSimple();
|
||||
htl->size_policy = PIScreenTypes::Fixed;
|
||||
ret->direction = PIScreenTypes::Vertical;
|
||||
htl->content << TileSimple::Row("Peer: " + daemon_.name() + " | " + daemon_.selfInfo().name, CellFormat(PIScreenTypes::Default, PIScreenTypes::Default, PIScreenTypes::Bold));
|
||||
PIScreenTile * diag = new PIScreenTile();
|
||||
diag->direction = PIScreenTypes::Horizontal;
|
||||
peerdiagdata_tl = new TileSimple();
|
||||
peerdiagservice_tl = new TileSimple();
|
||||
ret->addTile(htl);
|
||||
ret->addTile(diag);
|
||||
diag->addTile(peerdiagdata_tl);
|
||||
diag->addTile(peerdiagservice_tl);
|
||||
// updatePeerInfo();
|
||||
return ret;
|
||||
}
|
||||
PIScreenTile * peerTile() {
|
||||
PIScreenTile* ret = new PIScreenTile();
|
||||
TileSimple * htl = new TileSimple();
|
||||
@@ -123,9 +145,21 @@ public:
|
||||
ret->addTile(peerinfo_tl);
|
||||
ret->addTile(addrs_tl);
|
||||
ret->addTile(peermap_tl);
|
||||
updatePeerInfo();
|
||||
// updatePeerInfo();
|
||||
return ret;
|
||||
}
|
||||
void updatePeerDiag(TileSimple * tl, const PIDiagnostics & diag) {
|
||||
tl->content.clear();
|
||||
tl->content << TileSimple::Row(diag.name() + " diagnostics", CellFormat(PIScreenTypes::Default, PIScreenTypes::Default, PIScreenTypes::Bold));
|
||||
tl->content << TileSimple::Row("Received count: " + PIString::fromNumber(diag.receiveCount()), CellFormat());
|
||||
tl->content << TileSimple::Row("Invalid count: " + PIString::fromNumber(diag.wrongCount()), CellFormat());
|
||||
tl->content << TileSimple::Row("Sended count: " + PIString::fromNumber(diag.sendCount()), CellFormat());
|
||||
tl->content << TileSimple::Row("Immediate Frequency, Hz: " + PIString::fromNumber(diag.immediateFrequency()), CellFormat());
|
||||
tl->content << TileSimple::Row("Integral Frequency, Hz: " + PIString::fromNumber(diag.integralFrequency()), CellFormat());
|
||||
tl->content << TileSimple::Row("Receive speed: " + diag.receiveSpeed(), CellFormat());
|
||||
tl->content << TileSimple::Row("Send speed: " + diag.sendSpeed(), CellFormat());
|
||||
tl->content << TileSimple::Row("Quality: " + PIString::fromNumber((int)diag.quality()), CellFormat());
|
||||
}
|
||||
void updatePeerInfo() {
|
||||
bool pm = daemon_.lockedPeers();
|
||||
screen.lock();
|
||||
@@ -136,6 +170,9 @@ public:
|
||||
peermap_tl->content.clear();
|
||||
peers_tl->content << TileList::Row("this | 0 | 0 | " + PIString::fromNumber(daemon_.allPeers().size_s()) +
|
||||
" [em = " + PIString::fromBool(daemon_.lockedEth()) + ", "
|
||||
"mm = " + PIString::fromBool(daemon_.lockedMBcasts()) + ", "
|
||||
"sm = " + PIString::fromBool(daemon_.lockedSends()) + ", "
|
||||
"ms = " + PIString::fromBool(daemon_.lockedMCSends()) + ", "
|
||||
"pm = " + PIString::fromBool(pm) + "]", CellFormat());
|
||||
piForeachC(PIPeer::PeerInfo &p , daemon_.allPeers())
|
||||
peers_tl->content << TileList::Row(p.name + " | d = " + PIString::fromNumber(p.dist) +
|
||||
@@ -160,6 +197,8 @@ public:
|
||||
}
|
||||
piForeachC(PIString &s , peermap)
|
||||
peermap_tl->content << TileList::Row(s, CellFormat());
|
||||
updatePeerDiag(peerdiagdata_tl, daemon_.diagnosticData());
|
||||
updatePeerDiag(peerdiagservice_tl, daemon_.diagnosticService());
|
||||
daemon_.unlock();
|
||||
screen.unlock();
|
||||
}
|
||||
@@ -183,7 +222,8 @@ public:
|
||||
case 2: daemon_.showMainList(); tdaemon->show(); break;
|
||||
case 3: tpeer->show(); peers_tl->setFocus(); break;
|
||||
case 4: daemon_.reinit(); tmenu->show(); break;
|
||||
case 5: PIKbdListener::exiting = true; break;
|
||||
case 5: tpeerdiag->show(); break;
|
||||
case 6: PIKbdListener::exiting = true; break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -198,13 +238,14 @@ public:
|
||||
}
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
|
||||
if (screen.dialogTile()) return;
|
||||
if (tpeer->visible || tinfo->visible)
|
||||
if (tpeer->visible || tinfo->visible || tpeerdiag->visible)
|
||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||
//piCout << "key" << e.key;
|
||||
}
|
||||
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon, * tpeer;
|
||||
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon, * tpeer, * tpeerdiag;
|
||||
TileList * peers_tl, * addrs_tl, * peermap_tl;
|
||||
TileSimple * peerinfo_tl;
|
||||
TileSimple * peerdiagdata_tl, * peerdiagservice_tl;
|
||||
PIVector<PIScreenTile * > mtiles;
|
||||
int cur_peer;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user