60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
|
/***************************************************************************
|
||
|
* By Théophile Bastian, 2017
|
||
|
* M1 Network course project at ENS Cachan, Juliusz Chroboczek.
|
||
|
* License: WTFPL v2 <http://www.wtfpl.net/>
|
||
|
**************************************************************************/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include <list>
|
||
|
#include <ctime>
|
||
|
#include <unordered_map>
|
||
|
#include "data.h"
|
||
|
#include "protocol.h"
|
||
|
|
||
|
class Neighbours {
|
||
|
public:
|
||
|
Neighbours(Protocol* proto);
|
||
|
|
||
|
void fullCheck();
|
||
|
/** Cleans the peers lists by removing the expired entries. */
|
||
|
|
||
|
void fullUpdate();
|
||
|
/** Triggers a full update of the peers lists: sends the appropriate
|
||
|
* packets to the peers (IHU, ...) when approaching expiracy, and
|
||
|
* performs a `fullCheck()`.
|
||
|
*/
|
||
|
|
||
|
void addPotentialNei(const Neighbour& nei);
|
||
|
/** Adds a `Neighbour` to the list of potential neighbours. */
|
||
|
|
||
|
void receivedFrom(u64 id);
|
||
|
/** Signals that a packet was received from `id`, performs the
|
||
|
* appropriate bookkeeping actions.
|
||
|
*/
|
||
|
|
||
|
void hadIHU(u64 id);
|
||
|
/** Signals that a IHU was received from `id`, performs the
|
||
|
* appropriate bookkeeping actions.
|
||
|
*/
|
||
|
|
||
|
private: //meth
|
||
|
class WrongNeiType : public std::exception {};
|
||
|
enum NeiType {
|
||
|
NEI_UNDEF, NEI_POTENTIAL, NEI_UNIDIR, NEI_SYM
|
||
|
};
|
||
|
|
||
|
std::list<Neighbour>& listOfType(NeiType typ);
|
||
|
void changeNeiType(u64 id, NeiType nType);
|
||
|
void updateSendPackets(const Neighbour& nei, Protocol* proto);
|
||
|
|
||
|
private:
|
||
|
Protocol* proto;
|
||
|
std::list<Neighbour> potentialNei, unidirNei, symNei;
|
||
|
std::unordered_map<u64, time_t> lastRecv, lastIHU;
|
||
|
std::unordered_map<u64, time_t> lastPckSent, lastIHUSent;
|
||
|
std::unordered_map<u64, NeiType> neiType;
|
||
|
time_t lastPeerPeek;
|
||
|
};
|
||
|
|