-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeer_manager.h
More file actions
51 lines (46 loc) · 1.25 KB
/
peer_manager.h
File metadata and controls
51 lines (46 loc) · 1.25 KB
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
46
47
48
49
50
51
#ifndef PEER_MANAGER_H
#define PEER_MANAGER_H
#include"socket_util.h"
// Struct representing a peer
#define PROTOCOL_ID 0x41727101980
#define ACTION_CONNECT 0
#define ACTION_RESPONSE_CONNECT 0
#define ACTION_ANNOUNCE 1
struct Peer
{
std::string ip; // Peer IP address
int port; // Peer port number
std::string peer_id; // Peer ID
};
// Struct to represent the announce request
struct AnnounceRequest
{
uint64_t connection_id;
uint32_t action;
uint32_t transaction_id;
uint8_t info_hash[20];
uint8_t peer_id[20];
uint64_t downloaded;
uint64_t left;
uint64_t uploaded;
uint32_t event;
uint32_t ip_address;
uint32_t key;
uint32_t num_want;
uint16_t port;
};
struct ConnectRequest {
uint64_t protocol_id;
uint32_t action;
uint32_t transaction_id;
};
struct ConnectResponse {
uint32_t action;
uint32_t transaction_id;
uint64_t connection_id;
};
uint64_t generateConnectionID();
void handleConnectRequest(char* buffer, int bytesRcvd, int listenSocket, sockaddr_in& clientAddr, socklen_t addrLen);
// Function to process the announce request from a client
void processAnnounceRequest(char *buffer, int length, int sockfd, sockaddr_in &clientAddr);
#endif // PEER_MANAGER_H