Ubuntu measure upstream

[GitHub #121]
This commit is contained in:
Aoran Zeng 2024-11-22 09:58:00 +08:00
parent fd762f9d3c
commit e65a16c009
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 40 additions and 26 deletions

View File

@ -597,8 +597,8 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
{ {
Source_t src = sources[i]; Source_t src = sources[i];
const SourceProvider_t *provider = src.provider; SourceProvider_t *provider = src.provider;
const SpeedMeasureInfo_t smi = provider->smi; SpeedMeasureInfo_t smi = provider->smi;
bool skip = smi.skip; bool skip = smi.skip;
@ -621,18 +621,23 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
{ {
if (xy_streql ("upstream", provider->code)) if (xy_streql ("upstream", provider->code))
{ {
// 上游源不测速但不置0因为要避免这种情况: 可能其他镜像站测速都为0最后反而选择了该 upstream /* 上游源不测速但不置0因为要避免这种情况: 可能其他镜像站测速都为0最后反而选择了该 upstream */
speed = -1024*1024*1024; speed = -1024*1024*1024;
if (!src.url)
{
smi.skip_reason_CN = "默认上游源URL未知请帮助补充";
smi.skip_reason_EN = "The default upstream source URL is unknown, please help to add";
}
} }
else if (xy_streql ("user", provider->code)) else if (xy_streql ("user", provider->code))
{ {
// 代码不会执行至此 /* 代码不会执行至此 */
speed = 1024*1024*1024; speed = 1024*1024*1024;
} }
else else
{ {
// 什么情况? /* 不测速的 Provider */
speed = -1; speed = 0;
} }
get_measured[i] = false; get_measured[i] = false;
speed_records[i] = speed; speed_records[i] = speed;
@ -649,7 +654,11 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor
else else
{ {
const char *msg = CliOpt_InEnglish ? provider->abbr : provider->name; const char *msg = CliOpt_InEnglish ? provider->abbr : provider->name;
measure_msgs[i] = xy_strjoin (3, " - ", msg, " ... "); if (xy_streql ("upstream", provider->code))
measure_msgs[i] = xy_strjoin (3, " ^ ", msg, " ... ");
else
measure_msgs[i] = xy_strjoin (3, " - ", msg, " ... ");
printf ("%s", measure_msgs[i]); printf ("%s", measure_msgs[i]);
fflush (stdout); fflush (stdout);

View File

@ -14,10 +14,10 @@
typedef struct SpeedMeasureInfo_t typedef struct SpeedMeasureInfo_t
{ {
bool skip; /* 是否默认跳过 */ bool skip; /* 是否默认跳过 */
const char *skip_reason_CN; /* 跳过的原因(中文)*/ char *skip_reason_CN; /* 跳过的原因(中文)*/
const char *skip_reason_EN; /* 跳过的原因(英文)*/ char *skip_reason_EN; /* 跳过的原因(英文)*/
const char *url; /* 测速链接 */ char *url; /* 测速链接 */
} }
SpeedMeasureInfo_t; SpeedMeasureInfo_t;
@ -54,10 +54,10 @@ UserDefinedProvider = {
typedef struct Source_t typedef struct Source_t
{ {
union { union {
const SourceProvider_t *provider; SourceProvider_t *provider;
const MirrorSite_t *mirror; MirrorSite_t *mirror;
}; };
const char *url; char *url;
} }
Source_t; Source_t;

View File

@ -6,7 +6,7 @@
* Contributors : Zhao <1792582687@qq.com> * Contributors : Zhao <1792582687@qq.com>
* | * |
* Created On : <2023-08-30> * Created On : <2023-08-30>
* Last Modified : <2024-11-21> * Last Modified : <2024-11-22>
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
/** /**
@ -14,18 +14,18 @@
*/ */
static Source_t static Source_t
os_ubuntu_sources[] = { os_ubuntu_sources[] = {
{&UpstreamProvider, "http://archive.ubuntu.com/ubuntu/"}, //不支持https {&UpstreamProvider, "http://archive.ubuntu.com/ubuntu/"}, //不支持https
{&MirrorZ, "https://mirrors.cernet.edu.cn/ubuntu/"}, {&MirrorZ, "https://mirrors.cernet.edu.cn/ubuntu/"},
{&Ali, "https://mirrors.aliyun.com/ubuntu"}, {&Ali, "https://mirrors.aliyun.com/ubuntu"},
{&Volcengine, "https://mirrors.volces.com/ubuntu"}, {&Volcengine, "https://mirrors.volces.com/ubuntu"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu"}, {&Bfsu, "https://mirrors.bfsu.edu.cn/ubuntu"},
{&Ustc, "https://mirrors.ustc.edu.cn/ubuntu"}, {&Ustc, "https://mirrors.ustc.edu.cn/ubuntu"},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu"}, {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/ubuntu"},
{&Tencent, "https://mirrors.tencent.com/ubuntu"}, {&Tencent, "https://mirrors.tencent.com/ubuntu"},
// {&Tencent_Intra, "https://mirrors.tencentyun.com/ubuntu"}, // {&Tencent_Intra, "https://mirrors.tencentyun.com/ubuntu"},
{&Huawei, "https://mirrors.huaweicloud.com/ubuntu"}, {&Huawei, "https://mirrors.huaweicloud.com/ubuntu"},
{&Netease, "https://mirrors.163.com/ubuntu"}, {&Netease, "https://mirrors.163.com/ubuntu"},
{&Sohu, "https://mirrors.sohu.com/ubuntu"} {&Sohu, "https://mirrors.sohu.com/ubuntu"}
}; };
def_sources_n(os_ubuntu); def_sources_n(os_ubuntu);
@ -88,6 +88,11 @@ os_ubuntu_setsrc (char *option)
{ {
chsrc_ensure_root (); chsrc_ensure_root ();
// https://github.com/RubyMetric/chsrc/issues/121
SpeedMeasureInfo_t *upsmi = &UpstreamProvider.smi;
upsmi->skip = NotSkip;
upsmi->url = "http://archive.ubuntu.com/ubuntu/dists/noble/Contents-amd64.gz";
if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822)) if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822))
{ {
char *msg = CliOpt_InEnglish ? "Will change source based on new format" char *msg = CliOpt_InEnglish ? "Will change source based on new format"