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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
*
* Project: IDFetch.
* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
* Mentoring organization: Gentoo Linux.
* Sponsored by GSOC 2010.
*
* This file is part of Segget.
*
* Segget is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Segget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Segget; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __DISTFILE_H__
#define __DISTFILE_H__
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
# include <unistd.h>
#endif
#include <curl/multi.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <json/json.h>
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
#include "segment.h"
#include "mirror.h"
#include "checksum.h"
#include "network.h"
#include "networkbroker.h"
#include "segment.h"
#include "response.h"
class Tsegment;
//#include <sys/types.h>
//#include <sys/socket.h>
//#include <stdio.h>
//#include <netinet/in.h>
//#include <arpa/inet.h>
//#include <sys/ioctl.h>
//#include <unistd.h>
//#include <stdlib.h>
//#include <string>
//#include <string.h>
//#include "client.cpp"
using namespace std;
typedef unsigned int uint;
enum Tdistfile_status{
DNEW,
D_NOT_PROXY_REQUESTED,
DPROXY_REJECTED,
DPROXY_QUEUED,
DPROXY_DOWNLOADING,
DPROXY_DOWNLOADED,
DPROXY_FAILED,
DWAITING,
DDOWNLOADING,
DDOWNLOADED,
DFAILED
};
long is_symlink_restricted(string distfile_name);
class Tdistfile{
private:
bool choose_best_local_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num);
bool choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num);
public:
uint dld_segments_count;
Tnetwork_distfile_broker network_distfile_brokers_array[MAX_NETWORKS];
string json_data;
// bool downloaded;
Tdistfile_status status;
uint active_connections_num;
string *url_list;
uint url_num;
uint segment_num;
uint segments_count;
Tsegment *dn_segments;
string name;
uint num;
ulong size;
string RMD160;
string SHA1;
string SHA256;
string SHA512;
string WHIRLPOOL;
string MD5;
string CRC32;
uint url_count;
uint segment_size;
Tdistfile():
dld_segments_count(0),
json_data(""),
// downloaded(0),
status(DNEW),
active_connections_num(0),
url_list(0),
url_num(0),
segment_num(0),
segments_count(0),
dn_segments(0),
name(""),
num(0),
size(0),
RMD160(""),
SHA1(""),
SHA256(""),
SHA512(""),
WHIRLPOOL(""),
MD5(""),
CRC32(""),
url_count(0),
segment_size(settings.max_segment_size)
{init();};
Tdistfile(const Tdistfile &L); // copy constructor
Tdistfile & operator=(const Tdistfile &L);
~Tdistfile();
int request(ulong network_num, string msg);
void init();
bool allows_new_actions();
bool load_distfile_from_json(json_object* json_obj_distfile);
void load_url_list(json_object* json_array_distfile_urllist);
void split_into_segments();
uint provide_local_network(CURLM* cm, uint connection_num, uint seg_num, uint network_priority);
uint request_proxy_fetcher_network(uint network_priority);
uint provide_remote_or_coral_cdn_network(CURLM* cm, uint connection_num, uint seg_num, uint network_priority);
int provide_segment(CURLM* cm, uint connection_num, uint seg_num);
void inc_dld_segments_count(Tsegment * current_segment);
void symlink_distfile_to_provide_mirror_dir();
int combine_segments();
bool check_if_dld();
};
#endif
|