@@ -34,8 +34,8 @@ async def prepare_ciphers(cipher, reader, writer, bind=None, server_side=True):
3434 else :
3535 return None , None
3636
37- def schedule (rserver , salgorithm , host_name ):
38- filter_cond = lambda o : o .alive and (not o .match or o .match (host_name ))
37+ def schedule (rserver , salgorithm , host_name , port ):
38+ filter_cond = lambda o : o .alive and (not o .match or o .match (host_name ) or o . match ( str ( port )) )
3939 if salgorithm == 'fa' :
4040 return next (filter (filter_cond , rserver ), None )
4141 elif salgorithm == 'rr' :
@@ -69,7 +69,7 @@ async def stream_handler(reader, writer, unix, lbind, protos, rserver, cipher, a
6969 elif block and block (host_name ):
7070 raise Exception ('BLOCK ' + host_name )
7171 else :
72- roption = schedule (rserver , salgorithm , host_name ) or ProxyURI .DIRECT
72+ roption = schedule (rserver , salgorithm , host_name , port ) or ProxyURI .DIRECT
7373 verbose (f'{ lproto .name } { remote_text } { roption .logtext (host_name , port )} ' )
7474 try :
7575 reader_remote , writer_remote = await roption .open_connection (host_name , port , local_addr , lbind )
@@ -109,7 +109,7 @@ async def tcp_handler(reader, writer, host_name, port):
109109 try :
110110 if block and block (host_name ):
111111 raise Exception ('BLOCK ' + host_name )
112- roption = schedule (rserver , salgorithm , host_name ) or ProxyURI .DIRECT
112+ roption = schedule (rserver , salgorithm , host_name , port ) or ProxyURI .DIRECT
113113 verbose (f'{ lproto .name } { remote_text } { roption .logtext (host_name , port )} ' )
114114 try :
115115 reader_remote , writer_remote = await roption .open_connection (host_name , port , local_addr , lbind )
@@ -132,7 +132,7 @@ async def udp_handler(sendto, data, host_name, port, sid):
132132 try :
133133 if block and block (host_name ):
134134 raise Exception ('BLOCK ' + host_name )
135- roption = schedule (urserver , salgorithm , host_name ) or ProxyURI .DIRECT
135+ roption = schedule (urserver , salgorithm , host_name , port ) or ProxyURI .DIRECT
136136 verbose (f'UDP { lproto .name } { remote_text } { roption .logtext (host_name , port )} ' )
137137 data = roption .prepare_udp_connection (host_name , port , data )
138138 await roption .open_udp_connection (host_name , port , data , sid , sendto )
@@ -154,7 +154,7 @@ async def datagram_handler(writer, data, addr, protos, urserver, block, cipher,
154154 elif block and block (host_name ):
155155 raise Exception ('BLOCK ' + host_name )
156156 else :
157- roption = schedule (urserver , salgorithm , host_name ) or ProxyURI .DIRECT
157+ roption = schedule (urserver , salgorithm , host_name , port ) or ProxyURI .DIRECT
158158 verbose (f'UDP { lproto .name } { remote_text } { roption .logtext (host_name , port )} ' )
159159 data = roption .prepare_udp_connection (host_name , port , data )
160160 def reply (rdata ):
@@ -408,6 +408,8 @@ async def udp_sendto(self, host, port, data, answer_cb, local_addr=None):
408408 await self .open_udp_connection (host , port , data , local_addr , answer_cb )
409409 @classmethod
410410 def compile_rule (cls , filename ):
411+ if filename .startswith ("{" ) and filename .endswith ("}" ):
412+ return re .compile (filename [1 :- 1 ]).match
411413 with open (filename ) as f :
412414 return re .compile ('(:?' + '' .join ('|' .join (i .strip () for i in f if i .strip () and not i .startswith ('#' )))+ ')$' ).match
413415 @classmethod
0 commit comments