@@ -746,6 +746,7 @@ function gen_config(var)
746746 local fakedns = nil
747747 local routing = nil
748748 local observatory = nil
749+ local burstObservatory = nil
749750 local strategy = nil
750751 local inbounds = {}
751752 local outbounds = {}
@@ -1003,19 +1004,31 @@ function gen_config(var)
10031004 fallbackTag = fallback_node_tag ,
10041005 strategy = strategy
10051006 })
1006- if not observatory and ( _node .balancingStrategy == " leastPing" or _node .balancingStrategy == " leastLoad" or fallback_node_tag ) then
1007+ if _node .balancingStrategy == " leastPing" or _node .balancingStrategy == " leastLoad" or fallback_node_tag then
10071008 local t = api .format_go_time (_node .probeInterval )
10081009 if t == " 0s" then
10091010 t = " 60s"
10101011 elseif not t :find (" [hm]" ) and tonumber (t :match (" %d+" )) < 10 then
10111012 t = " 10s"
10121013 end
1013- observatory = {
1014- subjectSelector = { " blc-" },
1015- probeUrl = _node .useCustomProbeUrl and _node .probeUrl or " https://www.google.com/generate_204" ,
1016- probeInterval = t ,
1017- enableConcurrency = true
1018- }
1014+ if _node .balancingStrategy == " leastLoad" then
1015+ burstObservatory = burstObservatory or {
1016+ subjectSelector = { " blc-" },
1017+ pingConfig = {
1018+ destination = _node .useCustomProbeUrl and _node .probeUrl or nil ,
1019+ interval = t ,
1020+ sampling = 3 ,
1021+ timeout = " 5s"
1022+ }
1023+ }
1024+ else
1025+ observatory = observatory or {
1026+ subjectSelector = { " blc-" },
1027+ probeUrl = _node .useCustomProbeUrl and _node .probeUrl or nil ,
1028+ probeInterval = t ,
1029+ enableConcurrency = true
1030+ }
1031+ end
10191032 end
10201033 local loopback_outbound = gen_loopback (loopback_tag , loopback_dst )
10211034 local inbound_tag = loopback_outbound .settings .inboundTag
@@ -1034,14 +1047,25 @@ function gen_config(var)
10341047 else
10351048 local preproxy_node = get_node_by_id (node .preproxy_node )
10361049 if preproxy_node then
1037- local preproxy_outbound = gen_outbound (node [" .name" ], preproxy_node )
1050+ local preproxy_outbound , exist
1051+ if preproxy_node .protocol == " _balancing" then
1052+ local balancer_tag , loopback_outbound = gen_balancer (preproxy_node )
1053+ if loopback_outbound then
1054+ preproxy_outbound = loopback_outbound
1055+ exist = true
1056+ end
1057+ else
1058+ preproxy_outbound = gen_outbound (node [" .name" ], preproxy_node )
1059+ end
10381060 if preproxy_outbound then
10391061 outbound .tag = preproxy_outbound .tag .. " -> " .. outbound .tag
10401062 outbound .proxySettings = {
10411063 tag = preproxy_outbound .tag ,
10421064 transportLayer = true
10431065 }
1044- last_insert_outbound = preproxy_outbound
1066+ if not exist then
1067+ last_insert_outbound = preproxy_outbound
1068+ end
10451069 default_outTag = outbound .tag
10461070 end
10471071 end
@@ -1051,17 +1075,17 @@ function gen_config(var)
10511075 local to_node = get_node_by_id (node .to_node )
10521076 if to_node then
10531077 -- Landing Node not support use special node.
1054- if to_node .protocol :find (" ^_" ) then
1078+ if to_node .protocol and to_node . protocol :find (" ^_" ) then
10551079 to_node = nil
10561080 end
10571081 end
10581082 if to_node then
10591083 local to_outbound
10601084 if to_node .type ~= " Xray" then
1061- local tag = to_node [" .name" ]
1085+ local in_tag = " inbound_ " .. to_node [" .name" ] .. " _ " .. tostring ( outbound . tag )
10621086 local new_port = api .get_new_port ()
10631087 table.insert (inbounds , {
1064- tag = tag ,
1088+ tag = in_tag ,
10651089 listen = " 127.0.0.1" ,
10661090 port = new_port ,
10671091 protocol = " dokodemo-door" ,
@@ -1073,11 +1097,11 @@ function gen_config(var)
10731097 to_node .address = " 127.0.0.1"
10741098 to_node .port = new_port
10751099 table.insert (rules , 1 , {
1076- inboundTag = {tag },
1100+ inboundTag = {in_tag },
10771101 outboundTag = outbound .tag
10781102 })
1079- to_outbound = gen_outbound (node [" .name" ], to_node , tag , {
1080- tag = tag ,
1103+ to_outbound = gen_outbound (node [" .name" ], to_node , to_node [ " .name " ] , {
1104+ tag = to_node [ " .name " ] ,
10811105 run_socks_instance = not no_run
10821106 })
10831107 else
@@ -1670,7 +1694,8 @@ function gen_config(var)
16701694 -- 传出连接
16711695 outbounds = outbounds ,
16721696 -- 连接观测
1673- observatory = observatory ,
1697+ observatory = (not burstObservatory ) and observatory or nil ,
1698+ burstObservatory = burstObservatory ,
16741699 -- 路由
16751700 routing = routing ,
16761701 -- 本地策略
@@ -1720,14 +1745,10 @@ function gen_config(var)
17201745 else
17211746 table.insert (outbounds , blackhole_outbound )
17221747 end
1723-
17241748 for index , value in ipairs (config .outbounds ) do
1725- local s = value .settings
1726- if not value [" _flag_proxy_tag" ] and value [" _id" ] and s and not no_run and
1727- ((s .vnext and s .vnext [1 ] and s .vnext [1 ].address and s .vnext [1 ].port ) or
1728- (s .servers and s .servers [1 ] and s .servers [1 ].address and s .servers [1 ].port ) or
1729- (s .peers and s .peers [1 ] and s .peers [1 ].endpoint ) or
1730- (s .address and s .port )) then
1749+ local pt = value .protocol
1750+ local exclude = { blackhole = 1 , dns = 1 , freedom = 1 , loopback = 1 }
1751+ if not value [" _flag_proxy_tag" ] and value [" _id" ] and pt and not exclude [pt ] and not no_run then
17311752 sys .call (string.format (" echo '%s' >> %s" , value [" _id" ], api .TMP_PATH .. " /direct_node_list" ))
17321753 end
17331754 for k , v in pairs (config .outbounds [index ]) do
0 commit comments