git-svn-id: svn://db.shs.com.ru/pip@24 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -260,10 +260,31 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
PIMutexLocker locker(eth_mutex);
|
PIMutexLocker locker(eth_mutex);
|
||||||
PIMutexLocker plocker(peers_mutex);
|
PIMutexLocker plocker(peers_mutex);
|
||||||
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type;
|
//piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type;
|
||||||
if (type == 5) { // ping
|
if (type == 5) { // ping request
|
||||||
|
PIString addr;
|
||||||
|
PISystemTime time;
|
||||||
|
ba >> to >> from >> addr >> time;
|
||||||
|
piCout << "ping request" << to << from << addr;
|
||||||
|
if (from == self_info.name) { // send ping back
|
||||||
|
const PeerInfo * pi = getPeerByName(to);
|
||||||
|
if (pi) {
|
||||||
|
if (pi->isNeighbour()) {
|
||||||
|
sba << int(6) << to << from << addr << time;
|
||||||
|
//piCout << "ping from" << from << addr << ", send back to" << pi->name;
|
||||||
|
piForeachC (PeerInfo::Address & a, pi->addresses) {
|
||||||
|
if (eth_send.send(a.address, sba))
|
||||||
|
diag_s.received(sba.size_s());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (type == 6) { // ping request
|
||||||
PIString addr;
|
PIString addr;
|
||||||
PISystemTime time, ptime, ctime = PISystemTime::current(true);
|
PISystemTime time, ptime, ctime = PISystemTime::current(true);
|
||||||
ba >> to >> from >> addr >> time;
|
ba >> to >> from >> addr >> time;
|
||||||
|
piCout << "ping reply" << to << from << addr;
|
||||||
if (to == self_info.name) { // ping echo
|
if (to == self_info.name) { // ping echo
|
||||||
piForeach (PeerInfo & p, peers) {
|
piForeach (PeerInfo & p, peers) {
|
||||||
if (!p.isNeighbour()) continue;
|
if (!p.isNeighbour()) continue;
|
||||||
@@ -282,22 +303,6 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (from == self_info.name) { // send ping back
|
|
||||||
const PeerInfo * pi = getPeerByName(to);
|
|
||||||
if (pi) {
|
|
||||||
if (pi->isNeighbour()) {
|
|
||||||
sba = PIByteArray(readed, size);
|
|
||||||
piCout << "ping from" << to << addr << ", send back to" << pi->name;
|
|
||||||
piForeachC (PeerInfo::Address & a, pi->addresses) {
|
|
||||||
if (eth_send.send(a.address, sba))
|
|
||||||
diag_s.received(sba.size_s());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//PIEthernet * eth = (PIEthernet*)emitter();
|
|
||||||
//()->send();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (type != 4) return true;
|
if (type != 4) return true;
|
||||||
@@ -538,7 +543,7 @@ void PIPeer::pingNeighbours() {
|
|||||||
a.wait_ping = true;
|
a.wait_ping = true;
|
||||||
sba = ba;
|
sba = ba;
|
||||||
sba << p.name << a.address << PISystemTime::current(true);
|
sba << p.name << a.address << PISystemTime::current(true);
|
||||||
//piCout << "ping" << p.name << a.address << a.last_ping;
|
piCout << "ping" << p.name << a.address << a.last_ping;
|
||||||
if (eth_send.send(a.address, sba))
|
if (eth_send.send(a.address, sba))
|
||||||
diag_s.sended(sba.size_s());
|
diag_s.sended(sba.size_s());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ private:
|
|||||||
bool sendToNeighbour(PeerInfo * peer, const PIByteArray & ba);
|
bool sendToNeighbour(PeerInfo * peer, const PIByteArray & ba);
|
||||||
inline static bool isPeerRecent(const PeerInfo & my, const PeerInfo & income) {return (my.cnt < income.cnt) || (my.time < income.time);}
|
inline static bool isPeerRecent(const PeerInfo & my, const PeerInfo & income) {return (my.cnt < income.cnt) || (my.time < income.time);}
|
||||||
|
|
||||||
// 1 - new peer, 2 - remove peer, 3 - sync peers, 4 - data, 5 - ping
|
// 1 - new peer, 2 - remove peer, 3 - sync peers, 4 - data, 5 - ping request, 6 - ping reply
|
||||||
// Data packet: 4, from, to, ticks, data_size, data
|
// Data packet: 4, from, to, ticks, data_size, data
|
||||||
|
|
||||||
typedef PIPair<PIString, PIVector<PeerInfo * > > napair;
|
typedef PIPair<PIString, PIVector<PeerInfo * > > napair;
|
||||||
|
|||||||
Reference in New Issue
Block a user