-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.h
45 lines (37 loc) · 1.02 KB
/
peer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* File peer.h
* Group: 14
* Description: Header file for the Peer class which represents the remote peers
* in the network.
*/
#ifndef _PEER_H_
#define _PEER_H_
#include <string>
#include "thread.h"
#include "queue/concurrent_queue.h"
#include "message.h"
#include "socket/socket.h"
class Peer : public Thread {
public:
Peer();
~Peer();
enum State { connected, disconnected, unknown };
State getState() const { return _state; }
ConcurrentQueue<Message>* getReceiveQueue() { return &_receiveQueue; }
void setIpAddress(std::string const ipAddress) { _ipAddress = ipAddress; }
void setPortNumber(int const value) { _portNumber = value; }
void setState(State const value) { _state = value; }
void setSocket(Socket const value) { _socket = value; }
bool connect();
void disconnect();
void sendMessage(Message&);
private:
std::string _ipAddress;
int _portNumber;
State _state;
pthread_t _threadId;
ConcurrentQueue<Message> _receiveQueue;
Socket _socket;
void run();
};
#endif /* _PEER_H_ */