Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenjoiner committed Sep 4, 2022
1 parent 79d7af4 commit 558eb06
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
11 changes: 6 additions & 5 deletions default.config
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ GroupFile

# ���������ļ���д����
# # file 1
# ; comment too
# # UDP
# PROTOCOL UDP
# SERVER 1.2.4.8,127.0.0.1
# PARALLEL ON
#
# LIST domainlist.txt
#
# example.com
# example.com # comment
#
# # file 2
# # TCP
Expand All @@ -137,10 +138,10 @@ GroupFile
# ע�⣺
# 1.����û��ָ���������������������ѡ��һ������������в�ѯ��
# 2.���ij����ƥ�����������飬��ѡ���˳�����£�
# (1) ����ѡ�񲻺�ͨ�����ƥ��������Ȼ�ж���ƥ�䣬��ѡ��ƥ�����ߵ��Ǹ���
# ���ƥ�����ͬ���������Ȼ�ж���ƥ�䣬��ѡ�����һ����
# (1) ����ѡ�񲻺�ͨ�����ƥ�������ж���ƥ�䣬��ѡ��ƥ�����ߵ��Ǹ���
# ���ƥ�����ͬ��������ж���ƥ�䣬��ѡ�����һ����
# ������ `ipv6.microsoft.com' �� `microsoft.com' �������� `teredo.ipv6.microsoft.com' ��ƥ��ȸ��ߣ�
# (2) Ȼ��ѡ�����ͨ�����ƥ�������ж���ƥ�䣬��ѡ���һ����
# (2) Ȼ��ѡ�����ͨ�����ƥ�������ж���ƥ�䣬�����ѡ��һ����

# ���ʾ����
# һ���� microsoft.com �� office.com ��β������ͨ�� UDP ������ 1.2.4.8 ��ѯ����������ͨ�� TCP ������ 8.8.4.4 ��ѯ��
Expand All @@ -156,7 +157,7 @@ GroupFile
# BlockIP <IP1>,<IP2>,.....
# �赲�������� IP ��ַ��֧�� IPv4 �� IPv6 ��ַ���� DNS ���ݰ� (since 6.0.0)
# IPv6 ��ַ���üӷ�����
BlockIP 243.185.187.39,46.82.174.68,37.61.54.158,93.46.8.89,59.24.3.173,203.98.7.65,8.7.198.45,78.16.49.15,159.106.121.75
BlockIP

# IPSubstituting <IP1 IP'1>,<IP2 IP'2>,.....
# �滻 DNS ���ݰ��е� IP ��ַ��ֻ֧�� IPv4 ��ַ�� (since 5.0.1)
Expand Down
9 changes: 5 additions & 4 deletions default.en.config
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ GroupFile

# GroupFile syntax:
# # file 1
# ; comment too
# # UDP
# PROTOCOL UDP
# SERVER 1.2.4.8,127.0.0.1
# PARALLEL ON
#
# LIST domainlist.txt
#
# example.com
# example.com # comment
#
# # file 2
# # TCP
Expand All @@ -164,12 +165,12 @@ GroupFile
# 1.For domains that aren't explicitly specified, a random server group will be chosen.
# 2.For domains specified to more than one server groups, the order of seletion is as follows:
# (1) The matched item without any wildcards.
# If there are still more than one, choose the most matchable one
# If there are more than one, choose the most matchable one
# (e.g. `ipv6.microsoft.com' is more matchable than `microsoft.com'
# when matching with `teredo.ipv6.microsoft.com').
# If there are more than one most matchable items, choose the last one.
# (2) The matched item with wildcards.
# If there are more than one, the first is chosen.
# If there are more than one, a random one is chosen.
#
# Other Examples:
# 1. Forward quieries to domains tailed with microsoft.com or office.com to 1.2.4.8 over UDP,
Expand All @@ -186,7 +187,7 @@ GroupFile
# BlockIP <IP1>,<IP2>,.....
# Ignore DNS responses from servers with these IPs (since 6.0.0)
# An IPv6 address should NOT be square-bracket-rounded
BlockIP 243.185.187.39,46.82.174.68,37.61.54.158,93.46.8.89,59.24.3.173,203.98.7.65,8.7.198.45,78.16.49.15,159.106.121.75
BlockIP

# IPSubstituting <IP1 IP'1>,<IP2 IP'2>,.....
# Replace an IP with another in every response from servers(only IPv4 supported) (since 5.0.1)
Expand Down
6 changes: 3 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ static int EnvironmentInit(void)
/* UDPGroup 1.2.4.8,114.114.114.114 * on */
ConfigAddAlias(&ConfigInfo, "ServerGroup", "UDPGroup", "UDP", NULL);

TmpTypeDescriptor.boolean = FALSE;
ConfigAddOption(&ConfigInfo, "EnableUDPtoTCP", STRATEGY_DEFAULT, TYPE_BOOLEAN, TmpTypeDescriptor);

/* TCPGroup 1.2.4.8,114.114.114.114 example.com 192.168.50.5:8080, 192.168.50.6:8080*/
/* TCPGroup 1.2.4.8,114.114.114.114 * no*/
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TCPGroup", "TCP", NULL);

/* TLSGroup getdnsapi.net:853:185.49.141.38|foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9S= example.com */
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TLSGroup", "TLS", NULL);

TmpTypeDescriptor.boolean = FALSE;
ConfigAddOption(&ConfigInfo, "EnableUDPtoTCP", STRATEGY_DEFAULT, TYPE_BOOLEAN, TmpTypeDescriptor);

TmpTypeDescriptor.str = NULL;
ConfigAddOption(&ConfigInfo, "BlockIP", STRATEGY_APPEND, TYPE_STRING, TmpTypeDescriptor);

Expand Down
15 changes: 12 additions & 3 deletions mmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ static ModuleMap *CurModuleMap = NULL;
static RWLock ModulesLock = {NULL};
static ConfigFileInfo *CurrConfigInfo = NULL;

static void DomainList_Tidy(StringList *DomainList)
{
DomainList->TrimAll(DomainList, "\t .");
DomainList->LowercaseAll(DomainList);
}

static int MappingAModule(ModuleMap *ModuleMap,
ModuleInterface *Stored,
StringList *DomainList
Expand All @@ -45,9 +51,6 @@ static int MappingAModule(ModuleMap *ModuleMap,
StringListIterator i;
const char *OneDomain;

DomainList->TrimAll(DomainList, "\t .");
DomainList->LowercaseAll(DomainList);

if( StringListIterator_Init(&i, DomainList) != 0 )
{
return -46;
Expand Down Expand Up @@ -159,6 +162,8 @@ static int Udp_Init(ModuleMap *ModuleMap, StringListIterator *i)
return -148;
}

DomainList_Tidy(&DomainList);

if( Udp_Init_Core(ModuleMap, Services, &DomainList, Parallel) != 0 )
{
return -153;
Expand Down Expand Up @@ -240,6 +245,8 @@ static int Tcp_Init(ModuleMap *ModuleMap, StringListIterator *i)
return -148;
}

DomainList_Tidy(&DomainList);

if( Tcp_Init_Core(ModuleMap, Services, &DomainList, Proxies) != 0 )
{
return -233;
Expand Down Expand Up @@ -420,6 +427,8 @@ static int Modules_InitFromFile(ModuleMap *ModuleMap, StringListIterator *i)
}
}

DomainList_Tidy(&Domains);

if( Domains.Count(&Domains) == 0 )
{
ret = 0;
Expand Down

0 comments on commit 558eb06

Please sign in to comment.