00001 /*************************************************************************** 00002 ** 00003 ** This file is part of waranrouted. 00004 ** 00005 ** This file may be distributed and/or modified under the terms of the 00006 ** GNU General Public License version 2 or 3 as published by the Free 00007 ** Software Foundation and appearing in the file LICENSE.GPL included 00008 ** in the packaging of this file. 00009 ** 00010 ** This file is distributed in the hope that it will be useful, but WITHOUT 00011 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 ** more details. 00014 ** 00015 ** You should have received a copy of the GNU General Public License 00016 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 ** 00018 ** See http://www.geopsy.org for more information. 00019 ** 00020 ** Created : 2009-08-22 00021 ** Authors: 00022 ** Marc Wathelet 00023 ** Marc Wathelet (LGIT, Grenoble, France) 00024 ** 00025 ***************************************************************************/ 00026 00027 #ifndef PEERTRACKER_H 00028 #define PEERTRACKER_H 00029 00030 #include <GpCoreTools.h> 00031 #include "PeerInfo.h" 00032 #include "KernelRoute.h" 00033 00034 class LinkStream; 00035 00036 class PeerTracker: public Stream 00037 { 00038 public: 00039 PeerTracker(const char * interface, uint16_t tcpPort); 00040 ~PeerTracker(); 00041 00042 bool listen(uint16_t udpPort); 00043 00044 virtual short eventTypes() {return POLLIN;} 00045 virtual void event(short type); 00046 00047 void start(const Address& peer, LinkStream * link); 00048 void stop(const Address& peer); 00049 void checkDeadPeers(double validityDelay); 00050 00051 void setAsMaster(); 00052 void setMasterAddress(const Address& masterAddress); 00053 const Address& masterAddress() const {return _masterAddress;} 00054 00055 void setLink(const Address& peer, const LinkInfo& link, const MasterTime& peerMasterTime); 00056 void resetToMasterGateway(); 00057 void resetFromMasterGateway(); 00058 MasterTime masterTime(const Address& peer) const; 00059 void addFromMasterRoute(const Address& destination, const Address& gateway); 00060 void removeFromMasterRoute(const Address& destination); 00061 00062 static PeerTracker * instance() {return _self;} 00063 private: 00064 void updatePeers(); 00065 void setToMasterGateway(double timeToMaster, const Address& toMasterGateway); 00066 void setFromMasterGateway(double timeFromMaster, const Address& fromMasterGateway); 00067 00068 static PeerTracker * _self; 00069 00070 uint16_t _tcpPort; 00071 00072 PeerInfo ** _peers; 00073 std::list<PeerInfo *> _activePeers; 00074 MasterTime _masterTime; 00075 Address _toMasterGateway, _fromMasterGateway, _masterAddress; 00076 KernelRoute _routes; 00077 }; 00078 00079 #endif // PEERTRACKER_H