git-svn-id: svn://db.shs.com.ru/pip@232 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -27,9 +27,9 @@
|
||||
#include "pidiagnostics.h"
|
||||
#include "pidatatransfer.h"
|
||||
|
||||
class PIP_EXPORT PIPeer: public PIObject
|
||||
class PIP_EXPORT PIPeer: public PIIODevice
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIPeer, PIObject)
|
||||
PIIODEVICE(PIPeer)
|
||||
private:
|
||||
|
||||
class PeerData: public PIObject {
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
explicit PIPeer(const PIString & name);
|
||||
explicit PIPeer(const PIString & name = PIString());
|
||||
virtual ~PIPeer();
|
||||
|
||||
class PeerInfo {
|
||||
@@ -132,6 +132,13 @@ public:
|
||||
void reinit();
|
||||
void lock() {peers_mutex.lock();}
|
||||
void unlock() {peers_mutex.unlock();}
|
||||
void changeName(const PIString & new_name);
|
||||
const PIString & trustPeerName() const {return trust_peer;}
|
||||
void setTrustPeerName(const PIString & peer_name) {trust_peer = peer_name;}
|
||||
PIString constructFullPath() const;
|
||||
int read(void *read_to, int max_size);
|
||||
int write(const void * data, int size);
|
||||
|
||||
|
||||
EVENT2(dataReceivedEvent, const PIString &, from, const PIByteArray &, data)
|
||||
EVENT1(peerConnectedEvent, const PIString &, name)
|
||||
@@ -171,7 +178,13 @@ private:
|
||||
void pingNeighbours();
|
||||
void addToRemoved(const PeerInfo & pi) {removed[pi.name] = PIPair<int, PISystemTime>(pi.cnt, pi.time);}
|
||||
bool isRemoved(const PeerInfo & pi) const {return (removed.value(pi.name) == PIPair<int, PISystemTime>(pi.cnt, pi.time));}
|
||||
|
||||
|
||||
bool openDevice();
|
||||
bool closeDevice() {return false;}
|
||||
PIString fullPathPrefix() const {return "peer";}
|
||||
void configureFromFullPath(const PIString &full_path);
|
||||
|
||||
|
||||
PeerInfo * quickestPeer(const PIString & to);
|
||||
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);}
|
||||
@@ -196,8 +209,11 @@ private:
|
||||
PIDiagnostics diag_s, diag_d;
|
||||
bool destroyed, no_timer;
|
||||
PIString id_;
|
||||
|
||||
};
|
||||
PIString trust_peer;
|
||||
PIMutex read_buffer_mutex;
|
||||
PIQueue<PIByteArray> read_buffer;
|
||||
int read_buffer_size;
|
||||
};
|
||||
|
||||
inline PICout operator <<(PICout c, const PIPeer::PeerInfo::Address & v) {c.space(); c << "PeerAddress(" << v.address << ", " << v.netmask << ", " << v.ping << ")"; return c;}
|
||||
inline PICout operator <<(PICout c, const PIPeer::PeerInfo & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;}
|
||||
|
||||
Reference in New Issue
Block a user