summaryrefslogtreecommitdiff
path: root/segget
diff options
context:
space:
mode:
Diffstat (limited to 'segget')
-rw-r--r--segget/connection.cpp34
-rw-r--r--segget/distfile.cpp21
-rw-r--r--segget/distfile.h2
-rw-r--r--segget/mirror.cpp49
-rw-r--r--segget/mirror.h1
-rw-r--r--segget/network.cpp2
-rw-r--r--segget/network.h1
-rw-r--r--segget/network0.conf1
-rw-r--r--segget/network1.conf1
-rw-r--r--segget/network2.conf1
-rw-r--r--segget/segment.cpp3
-rw-r--r--segget/str.cpp13
-rw-r--r--segget/str.h2
13 files changed, 101 insertions, 30 deletions
diff --git a/segget/connection.cpp b/segget/connection.cpp
index a9d438e..ec05269 100644
--- a/segget/connection.cpp
+++ b/segget/connection.cpp
@@ -56,12 +56,21 @@ void Tconnection::start(CURLM *cm, uint network_number, uint distfile_num, Tsegm
Tmirror *Pcurr_mirror;
string url;
- if (network_array[network_num].network_mode==MODE_REMOTE){
- url=segment->parent_distfile->url_list[mirror_num];
- Pcurr_mirror=find_mirror(strip_mirror_name(url));
- }else{
- Pcurr_mirror=&network_array[network_num].benchmarked_mirror_list[mirror_num];
- url=Pcurr_mirror->url+segment->parent_distfile->name;
+ switch (network_array[network_num].network_mode){
+ case MODE_REMOTE:{
+ url=segment->parent_distfile->url_list[mirror_num];
+ Pcurr_mirror=find_mirror(strip_mirror_name(url));
+ break;
+ }
+ case MODE_CORAL_CDN:{
+ url=convert_to_coral_cdn_url(segment->parent_distfile->url_list[mirror_num]);
+ Pcurr_mirror=find_mirror(strip_mirror_name(url));
+ break;
+ }
+ default:{
+ Pcurr_mirror=&network_array[network_num].benchmarked_mirror_list[mirror_num];
+ url=Pcurr_mirror->url+segment->parent_distfile->name;
+ }
}
debug(" URL:"+url);
@@ -123,10 +132,15 @@ void Tconnection::stop(CURLcode connection_result){
*/
Tmirror *Pcurr_mirror;
- if (network_array[network_num].network_mode==MODE_REMOTE){
- Pcurr_mirror=find_mirror(strip_mirror_name(segment->url));
- }else{
- Pcurr_mirror=&network_array[network_num].benchmarked_mirror_list[mirror_num];
+ switch (network_array[network_num].network_mode){
+ case MODE_REMOTE:
+ case MODE_CORAL_CDN:{
+ Pcurr_mirror=find_mirror(strip_mirror_name(segment->url));
+ break;
+ }
+ default:{
+ Pcurr_mirror=&network_array[network_num].benchmarked_mirror_list[mirror_num];
+ }
}
timeval now_time;
diff --git a/segget/distfile.cpp b/segget/distfile.cpp
index 04777f3..11b7be7 100644
--- a/segget/distfile.cpp
+++ b/segget/distfile.cpp
@@ -302,6 +302,7 @@ Tdistfile::~Tdistfile(){
error_log("Error: distfile.cpp: ~Tdistfile()");
}
}
+
bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_num, uint seg_num){
try{
Tmirror *Pcurr_mirror;
@@ -310,10 +311,16 @@ bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_
ulong best_mirror_self_rating=-1;
ulong curr_mirror_self_rating;
-
+ string url_str;
for (url_num=0; url_num<url_count; url_num++){
- Pcurr_mirror=find_mirror(strip_mirror_name(url_list[url_num]));
- debug("Evaluating url:"+url_list[url_num]
+ if (network_array[network_num].network_mode==MODE_CORAL_CDN){
+ url_str=convert_to_coral_cdn_url(url_list[url_num]);
+ if (url_str=="") continue;
+ }else{ // MODE_REMOTE
+ url_str=url_list[url_num];
+ }
+ Pcurr_mirror=find_mirror(strip_mirror_name(url_str));
+ debug("Evaluating url:"+url_str
+" active_connections:"+toString(Pcurr_mirror->get_active_num())
+" connection limit:"+toString(settings.max_connections_num_per_mirror));
if (Pcurr_mirror->get_active_num()<settings.max_connections_num_per_mirror){
@@ -330,7 +337,7 @@ bool Tdistfile::choose_best_mirror(CURLM* cm, uint connection_num, uint network_
}
}
if (Pbest_mirror){
- debug("Downloading from BEST_MIRROR:"+url_list[best_mirror_num]);
+ debug("Downloading from BEST_MIRROR:"+url_str);
// Pbest_mirror->start();
// active_connections_num++;
connection_array[connection_num].start(cm, network_num, num, &dn_segments[seg_num], best_mirror_num);
@@ -560,7 +567,7 @@ uint Tdistfile::request_proxy_fetcher_network(uint network_priority){
}
}
-uint Tdistfile::provide_remote_network(CURLM* cm, uint connection_num, uint seg_num, uint network_priority){
+uint Tdistfile::provide_remote_or_coral_cdn_network(CURLM* cm, uint connection_num, uint seg_num, uint network_priority){
try{
debug("network_priority="+toString(network_priority));
//choose network
@@ -574,7 +581,7 @@ uint Tdistfile::provide_remote_network(CURLM* cm, uint connection_num, uint seg_
int best_remote_network_num=-1;
for (uint network_num=0; network_num<MAX_NETWORKS; network_num++){
if (network_array[network_num].priority==network_priority){
- if (network_array[network_num].network_mode==MODE_REMOTE){
+ if ((network_array[network_num].network_mode==MODE_REMOTE) or (network_array[network_num].network_mode==MODE_CORAL_CDN)){
if (network_array[network_num].has_free_connections()){
if
((best_remote_network_num==-1)
@@ -614,7 +621,7 @@ int Tdistfile::provide_segment(CURLM* cm, uint connection_num, uint seg_num){
switch (result){
case ALLOW_REMOTE_NETWORKS:{
debug("Switching to remote networks with priority:"+toString(network_priority));
- result=provide_remote_network(cm, connection_num, seg_num, network_priority);
+ result=provide_remote_or_coral_cdn_network(cm, connection_num, seg_num, network_priority);
// if not lower_priority_networks => result found => return it
if (result!=ALLOW_LOWER_PRIORITY_NETWORKS){
return result;
diff --git a/segget/distfile.h b/segget/distfile.h
index 973bf67..a14e137 100644
--- a/segget/distfile.h
+++ b/segget/distfile.h
@@ -152,7 +152,7 @@ class Tdistfile{
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_network(CURLM* cm, uint connection_num, uint seg_num, 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();
diff --git a/segget/mirror.cpp b/segget/mirror.cpp
index b23bd5f..993cb90 100644
--- a/segget/mirror.cpp
+++ b/segget/mirror.cpp
@@ -28,6 +28,45 @@
map<string,Tmirror *> mirror_list;
+string strip_mirror_name(string path){
+ try{
+ string mirror_name;
+ mirror_name=path.substr(0,path.find("/",(path.find("://",0)+3)));
+ return mirror_name;
+ }catch(...){
+ error_log("Error in mirror.cpp: strip_mirror_name()");
+ return "";
+ }
+}
+
+string convert_to_coral_cdn_url(string url_address){
+ try{
+ string protocol, after_protocol;
+ if (split("://",url_address, protocol, after_protocol)){
+ error_log("Can't convert url:"+url_address+"to CoralCDN url");
+ return "";
+ }
+ if (protocol!="http") return "";
+ string site_name_and_port, path;
+ if (split("/",after_protocol,site_name_and_port,path)){
+ error_log("Can't convert url:"+url_address+"to CoralCDN url");
+ return "";
+ }
+ string site_name,site_port;
+ string new_coral_cdn_url;
+ if (split(":",site_name_and_port,site_name,site_port)){
+ string site_name=site_name_and_port;
+ new_coral_cdn_url=protocol+"://"+site_name+".nyud.net/"+path;
+ }else{;
+ new_coral_cdn_url=protocol+"://"+site_name+"."+site_port+".nyud.net/"+path;
+ }
+ return new_coral_cdn_url;
+ }catch(...){
+ error_log("Error in mirror.cpp: convert_to_coral_cdn_url()");
+ }
+ return "";
+}
+
double Tmirror::mirror_on_the_wall(){
try{
double criterion=honesty*1000000000*dld_time/dld_size;
@@ -85,13 +124,3 @@ Tmirror* find_mirror(string mirror_url){
}
}
-string strip_mirror_name(string path){
- try{
- string mirror_name;
- mirror_name=path.substr(0,path.find("/",(path.find("://",0)+3)));
- return mirror_name;
- }catch(...){
- error_log("Error in mirror.cpp: strip_mirror_name()");
- return "";
- }
-} \ No newline at end of file
diff --git a/segget/mirror.h b/segget/mirror.h
index e747d6b..37d8653 100644
--- a/segget/mirror.h
+++ b/segget/mirror.h
@@ -58,4 +58,5 @@ class Tmirror{
extern map<string,Tmirror *> mirror_list;
string strip_mirror_name(string path);
Tmirror* find_mirror(string mirror_url);
+string convert_to_coral_cdn_url(string url_address);
#endif \ No newline at end of file
diff --git a/segget/network.cpp b/segget/network.cpp
index f67d2fb..782c009 100644
--- a/segget/network.cpp
+++ b/segget/network.cpp
@@ -66,7 +66,7 @@ void Tnetwork::init(uint priority_value){
try{
priority=priority_value;
Tconfig conf("network"+toString(network_num)+".conf");
- conf.set("mode","network_mode",network_mode,0,2);
+ conf.set("mode","network_mode",network_mode,0,3);
conf.set("network_bind","bind_interface",bind_interface);
conf.set("network_connections","max_connections",max_connections,1,MAX_CONNECTS);
conf.set("network_connections","connection_timeout",connection_timeout,1,1000);
diff --git a/segget/network.h b/segget/network.h
index e1180fa..96950f9 100644
--- a/segget/network.h
+++ b/segget/network.h
@@ -42,6 +42,7 @@ using namespace std;
#define MODE_REMOTE 0
#define MODE_PROXY_FETCHER 1
#define MODE_LOCAL 2
+#define MODE_CORAL_CDN 3
class Tnetwork{
static uint network_count;
diff --git a/segget/network0.conf b/segget/network0.conf
index d338d65..6a750e0 100644
--- a/segget/network0.conf
+++ b/segget/network0.conf
@@ -3,6 +3,7 @@
# 0 - remote mirrors (default)
# 1 - proxy fetcher
# 2 - local mirrors
+# 3 - CoralCDN
# - If set to 1 or 2, segget will replace mirror list provided by portage
# system with the list from network#_mirrors.conf file
# - If set to 0, segget will use ONLY mirror list provided by portage
diff --git a/segget/network1.conf b/segget/network1.conf
index da1c680..56bc8e5 100644
--- a/segget/network1.conf
+++ b/segget/network1.conf
@@ -3,6 +3,7 @@
# 0 - remote mirrors (default)
# 1 - proxy fetcher
# 2 - local mirrors
+# 3 - CoralCDN
# - If set to 1 or 2, segget will replace mirror list provided by portage
# system with the list from network#_mirrors.conf file
# - If set to 0, segget will use ONLY mirror list provided by portage
diff --git a/segget/network2.conf b/segget/network2.conf
index 61cc37c..e163e1b 100644
--- a/segget/network2.conf
+++ b/segget/network2.conf
@@ -3,6 +3,7 @@
# 0 - remote mirrors (default)
# 1 - proxy fetcher
# 2 - local mirrors
+# 3 - CoralCDN
# - If set to 1 or 2, segget will replace mirror list provided by portage
# system with the list from network#_mirrors.conf file
# - If set to 0, segget will use ONLY mirror list provided by portage
diff --git a/segget/segment.cpp b/segget/segment.cpp
index d5c2ea3..3dcfa7d 100644
--- a/segget/segment.cpp
+++ b/segget/segment.cpp
@@ -136,6 +136,9 @@ int Tsegment::add_easy_handle_to_multi(CURLM *cm, uint network_num){
}
curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, network_array[network_num].user_agent.c_str());
+ curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt(easyhandle, CURLOPT_MAXREDIRS, 5);
+
if (network_array[network_num].proxy_off)
curl_easy_setopt(easyhandle, CURLOPT_NOPROXY, "*");
else{
diff --git a/segget/str.cpp b/segget/str.cpp
index 4ffbe2f..592e0cd 100644
--- a/segget/str.cpp
+++ b/segget/str.cpp
@@ -106,6 +106,19 @@ string noupper(string s){
}
}
+bool split(string splitter, string str, string &before, string &after){
+ try{
+ uint splitter_pos=str.find(splitter);
+ if (splitter_pos==str.npos) return 1;
+ before=str.substr(0,splitter_pos);
+ after=str.substr(splitter_pos+splitter.length());
+ return 0;
+ }catch(...){
+ error_log("Error in str.cpp: split()");
+ return 1;
+ }
+}
+
string trim(std::string const& source, char const* delims) {
try{
string result(source);
diff --git a/segget/str.h b/segget/str.h
index cd34b9d..6580fad 100644
--- a/segget/str.h
+++ b/segget/str.h
@@ -38,7 +38,7 @@ using namespace std;
string trim(std::string const& source, char const* delims = " \t\r\n");
int lower_char(int c);
string noupper(string s);
-
+bool split(string splitter, string str, string &before, string &after);
string toString(uint t);
string toString(int t);
string toString(ulong t);