31 lines
945 B
C++
31 lines
945 B
C++
#pragma once
|
|
|
|
#include <list>
|
|
#include <memory>
|
|
#include <netdb.h>
|
|
|
|
#include "RemotePeer.hpp"
|
|
|
|
|
|
/**
|
|
* Information about the current state of our machine.
|
|
* Used everywhere to determinate how to behave.
|
|
*/
|
|
class Context {
|
|
public:
|
|
explicit Context() {
|
|
this->socket = -1;
|
|
this->broadcastAddressInfo = nullptr;
|
|
this->server = nullptr;
|
|
|
|
this->latestPeerDiscovery = std::chrono::high_resolution_clock::now();
|
|
}
|
|
|
|
int socket; /// current socket file descriptor, used to communicate
|
|
addrinfo* broadcastAddressInfo; /// address used to broadcast messages
|
|
std::shared_ptr<RemotePeer> server; /// peer currently used as the server
|
|
|
|
Peer me; /// information about our own machine
|
|
std::list<std::shared_ptr<RemotePeer>> remotePeers {}; /// information about other machines
|
|
std::chrono::high_resolution_clock::time_point latestPeerDiscovery; /// time of the latest discovered machine
|
|
};
|