git-svn-id: svn://db.shs.com.ru/pip@267 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "pipeer.h"
|
||||
#include "piconfig.h"
|
||||
|
||||
#define _PIPEER_MSG_SIZE 4000
|
||||
#define _PIPEER_MSG_TTL 100
|
||||
@@ -26,6 +27,7 @@
|
||||
#define _PIPEER_LOOPBACK_PORT_S 13313
|
||||
#define _PIPEER_LOOPBACK_PORT_E (13313+32)
|
||||
#define _PIPEER_MULTICAST_PORT 13360
|
||||
#define _PIPEER_TCP_PORT _PIPEER_MULTICAST_PORT
|
||||
#define _PIPEER_BROADCAST_PORT 13361
|
||||
#define _PIPEER_TRAFFIC_PORT_S 13400
|
||||
#define _PIPEER_TRAFFIC_PORT_E 14000
|
||||
@@ -132,7 +134,7 @@ PIString PIPeer::PeerInfo::fastestAddress() const {
|
||||
|
||||
REGISTER_DEVICE(PIPeer)
|
||||
|
||||
PIPeer::PIPeer(const PIString & n): PIIODevice() {
|
||||
PIPeer::PIPeer(const PIString & n): PIIODevice(), diag_d(false), diag_s(false), eth_tcp_srv(PIEthernet::TCP_Server), eth_tcp_cli(PIEthernet::TCP_Client) {
|
||||
destroyed = false;
|
||||
PIMutexLocker mbl(mc_mutex);
|
||||
PIMutexLocker ethl(eth_mutex);
|
||||
@@ -171,6 +173,8 @@ PIPeer::~PIPeer() {
|
||||
piForeach (PIEthernet * i, eths_bcast)
|
||||
i->stopThreadedRead();
|
||||
eth_lo.stopThreadedRead();
|
||||
eth_tcp_srv.stopThreadedRead();
|
||||
eth_tcp_cli.stopThreadedRead();
|
||||
sendSelfRemove();
|
||||
destroyMBcasts();
|
||||
eth_send.close();
|
||||
@@ -293,6 +297,18 @@ void PIPeer::initMBcasts(PIStringList al) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
eth_tcp_srv.setName("__S__PIPeer_eth_TCP_Server");
|
||||
eth_tcp_srv.init();
|
||||
eth_tcp_srv.listen("0.0.0.0", _PIPEER_TCP_PORT, true);
|
||||
CONNECTU(ð_tcp_srv, newConnection, this, newTcpClient);
|
||||
eth_tcp_srv.startThreadedRead();
|
||||
eth_tcp_cli.setName("__S__PIPeer_eth_TCP_Client");
|
||||
eth_tcp_cli.init();
|
||||
eth_tcp_cli.setDebug(false);
|
||||
tcpClientReconnect();
|
||||
CONNECTU(ð_tcp_cli, threadedReadEvent, this, mbcastRead);
|
||||
CONNECTU(ð_tcp_cli, disconnected, this, tcpClientReconnect);
|
||||
eth_tcp_cli.startThreadedRead();
|
||||
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";
|
||||
}
|
||||
@@ -332,6 +348,7 @@ void PIPeer::destroyMBcasts() {
|
||||
eth_lo.close();
|
||||
eths_mcast.clear();
|
||||
eths_bcast.clear();
|
||||
eth_tcp_srv.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -690,6 +707,16 @@ void PIPeer::sendMBcast(const PIByteArray & ba) {
|
||||
if (eth_lo.send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
PIVector<PIEthernet * > cl = eth_tcp_srv.clients();
|
||||
piForeach (PIEthernet * e, cl) {
|
||||
if (e->isOpened() && e->isConnected())
|
||||
if (e->send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
if (eth_tcp_cli.isOpened() && eth_tcp_cli.isConnected()) {
|
||||
if (eth_tcp_cli.send(ba))
|
||||
diag_s.sended(ba.size_s());
|
||||
}
|
||||
// piCout << "send muticast ok";
|
||||
send_mc_mutex.unlock();
|
||||
}
|
||||
@@ -766,7 +793,17 @@ void PIPeer::pingNeighbours() {
|
||||
|
||||
|
||||
bool PIPeer::openDevice() {
|
||||
PIConfig conf(
|
||||
#ifndef WINDOWS
|
||||
"/etc/pip.conf"
|
||||
#else
|
||||
"pip.conf"
|
||||
#endif
|
||||
, PIIODevice::ReadOnly);
|
||||
server_ip = conf.getValue("peer_server_ip", "");
|
||||
reinit();
|
||||
diag_d.reset();
|
||||
diag_s.reset();
|
||||
PIMutexLocker ml(peers_mutex);
|
||||
if (trust_peer.isEmpty())
|
||||
return !peers.isEmpty();
|
||||
@@ -900,6 +937,14 @@ int PIPeer::write(const void *data, int size) {
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::newTcpClient(PIEthernet *client) {
|
||||
client->setName("__S__PIPeer_eth_TCP_ServerClient" + client->path());
|
||||
piCoutObj << "client" << client->path();
|
||||
CONNECTU(client, threadedReadEvent, this, mbcastRead);
|
||||
client->startThreadedRead();
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::configureFromFullPath(const PIString & full_path) {
|
||||
PIStringList pl = full_path.split(":");
|
||||
for (int i = 0; i < pl.size_s(); ++i) {
|
||||
@@ -925,6 +970,8 @@ void PIPeer::initNetwork() {
|
||||
// piCoutObj << sl << self_info.addresses.size();
|
||||
sl.removeAll("127.0.0.1");
|
||||
initMBcasts(sl);
|
||||
diag_d.start();
|
||||
diag_s.start();
|
||||
// piCoutObj << "initNetwork done";
|
||||
}
|
||||
|
||||
@@ -977,3 +1024,8 @@ void PIPeer::buildMap() {
|
||||
//piCout << "map" << c.name << "=" << cpath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PIPeer::tcpClientReconnect() {
|
||||
eth_tcp_cli.connect(server_ip, _PIPEER_TCP_PORT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user