-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitTorrent.cpp
38 lines (33 loc) · 958 Bytes
/
BitTorrent.cpp
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
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "bt_lib.h"
#include "ParseTorrent.h"
#include "bt_setup.h"
#include "NetworkSocket.h"
using namespace std;
int main(int argc, char* argv[]) {
bt_info_t btStruct;
bt_args_t argStruct;
bt_setup bt;
peer_t * peer;
unsigned char * infoHash;
NetworkSocket netsock;
bt.parse_args(&argStruct, argc, argv);
//to store information in bt_info_t
ParseTorrent parseTorrent;
map<string, string> m = parseTorrent.parseFile(argStruct.torrent_file);
btStruct = parseTorrent.getInfoStructure(m);
// to calculate info hash
peer = argStruct.peers[1];
infoHash = parseTorrent.calInfoHash(argStruct.torrent_file);
cout << "'info hash here" << endl;
char *h = parseTorrent.getHandshakeMessage(infoHash, peer);
if (argStruct.bindCheck == 1) {
netsock.recv_peer_handshake(peer, &argStruct, h);
} else {
netsock.send_peer_handshake(peer, &argStruct, h);
}
return 0;
}