Skip to content

Commit 3443a0f

Browse files
refactor(subscription): remove flow_enabled field and simplify flow handling
1 parent aa1cde6 commit 3443a0f

6 files changed

Lines changed: 39 additions & 64 deletions

File tree

app/core/hosts.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,6 @@ async def _prepare_subscription_inbound_data(
342342
random_user_agent=host.random_user_agent,
343343
)
344344

345-
# Compute flow_enabled: VLESS flow is serialized for TLS/REALITY or for
346-
# security=none when the inbound has VLESS encryption.
347-
header_type = getattr(transport_config, "header_type", "none")
348-
flow_security_enabled = tls_value in ("tls", "reality") or (
349-
tls_value in ("", "none", None) and encryption not in ("", "none", None)
350-
)
351-
flow_enabled = (
352-
protocol == "vless"
353-
and flow_security_enabled
354-
and network in ("tcp", "raw", "kcp")
355-
and header_type != "http"
356-
)
357-
358345
return SubscriptionInboundData(
359346
remark=host.remark,
360347
inbound_tag=host.inbound_tag,
@@ -371,7 +358,6 @@ async def _prepare_subscription_inbound_data(
371358
encryption=encryption,
372359
vless_route=host.vless_route,
373360
inbound_flow=inbound_flow,
374-
flow_enabled=flow_enabled,
375361
random_user_agent=host.random_user_agent,
376362
use_sni_as_host=host.use_sni_as_host,
377363
fragment_settings=host.fragment_settings.model_dump() if host.fragment_settings else None,

app/models/subscription.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ class SubscriptionInboundData(BaseModel):
256256

257257
# Flow (from inbound, user can override)
258258
inbound_flow: str = Field("")
259-
flow_enabled: bool = Field(False) # Computed once: if this inbound supports flow
260259

261260
# Additional settings
262261
random_user_agent: bool = Field(False)

app/subscription/clash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def _build_vless(self, remark: str, address: str, inbound: SubscriptionInboundDa
432432
if inbound.encryption != "none":
433433
node["encryption"] = inbound.encryption
434434

435-
if inbound.flow_enabled and (flow := inbound.inbound_flow):
435+
if flow := inbound.inbound_flow:
436436
node["flow"] = flow
437437

438438
self._apply_tls(node, inbound.tls_config, "vless")

app/subscription/links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _build_vless(self, remark: str, address: str, inbound: SubscriptionInboundDa
268268
"headerType": getattr(inbound.transport_config, "header_type", "none"),
269269
}
270270

271-
if inbound.flow_enabled and (flow := inbound.inbound_flow):
271+
if flow := inbound.inbound_flow:
272272
payload["flow"] = flow
273273

274274
self._apply_transport_settings(payload, "vless", inbound, path)

app/subscription/singbox.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,13 @@ def _transport_ws(self, config: WebSocketTransportConfig, path: str) -> dict:
166166

167167
def _transport_grpc(self, config: GRPCTransportConfig, path: str) -> dict:
168168
"""Handle GRPC transport - only gets GRPC config"""
169-
return self._normalize_and_remove_none_values(
170-
{
171-
"type": "grpc",
172-
"service_name": path,
173-
"idle_timeout": f"{config.idle_timeout}s" if config.idle_timeout else "15s",
174-
"ping_timeout": f"{config.health_check_timeout}s" if config.health_check_timeout else "15s",
175-
"permit_without_stream": config.permit_without_stream,
176-
}
177-
)
169+
return self._normalize_and_remove_none_values({
170+
"type": "grpc",
171+
"service_name": path,
172+
"idle_timeout": f"{config.idle_timeout}s" if config.idle_timeout else "15s",
173+
"ping_timeout": f"{config.health_check_timeout}s" if config.health_check_timeout else "15s",
174+
"permit_without_stream": config.permit_without_stream,
175+
})
178176

179177
def _transport_httpupgrade(self, config: WebSocketTransportConfig, path: str) -> dict:
180178
"""Handle HTTPUpgrade transport - only gets WS config (similar to WS)"""
@@ -274,7 +272,7 @@ def _build_vless(self, remark: str, address: str, inbound: SubscriptionInboundDa
274272
id = self.vless_route(id, inbound.vless_route)
275273
user_settings = {"uuid": id}
276274

277-
if inbound.flow_enabled and (flow := inbound.inbound_flow):
275+
if flow := inbound.inbound_flow:
278276
user_settings["flow"] = flow
279277

280278
return self._build_outbound(

app/subscription/xray.py

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -274,27 +274,23 @@ def _transport_quic(self, config: QUICTransportConfig, path: str) -> dict:
274274
"""Handle QUIC transport - only gets QUIC config"""
275275
host = config.host if isinstance(config.host, str) else (config.host[0] if config.host else "")
276276

277-
return self._normalize_and_remove_none_values(
278-
{
279-
"security": host,
280-
"header": {"type": config.header_type},
281-
"key": path,
282-
}
283-
)
277+
return self._normalize_and_remove_none_values({
278+
"security": host,
279+
"header": {"type": config.header_type},
280+
"key": path,
281+
})
284282

285283
def _transport_kcp(self, config: KCPTransportConfig, path: str) -> dict:
286284
"""Handle KCP transport - only gets KCP config"""
287-
return self._normalize_and_remove_none_values(
288-
{
289-
"mtu": config.mtu if config.mtu is not None else 1350,
290-
"tti": config.tti if config.tti is not None else 50,
291-
"uplinkCapacity": config.uplink_capacity if config.uplink_capacity is not None else 5,
292-
"downlinkCapacity": config.downlink_capacity if config.downlink_capacity is not None else 20,
293-
"congestion": config.congestion,
294-
"readBufferSize": config.read_buffer_size if config.read_buffer_size is not None else 2,
295-
"writeBufferSize": config.write_buffer_size if config.write_buffer_size is not None else 2,
296-
}
297-
)
285+
return self._normalize_and_remove_none_values({
286+
"mtu": config.mtu if config.mtu is not None else 1350,
287+
"tti": config.tti if config.tti is not None else 50,
288+
"uplinkCapacity": config.uplink_capacity if config.uplink_capacity is not None else 5,
289+
"downlinkCapacity": config.downlink_capacity if config.downlink_capacity is not None else 20,
290+
"congestion": config.congestion,
291+
"readBufferSize": config.read_buffer_size if config.read_buffer_size is not None else 2,
292+
"writeBufferSize": config.write_buffer_size if config.write_buffer_size is not None else 2,
293+
})
298294

299295
def _apply_transport(self, network: str, inbound: SubscriptionInboundData, path: str) -> dict | None:
300296
"""Apply transport settings using registry pattern"""
@@ -310,17 +306,15 @@ def _apply_tls(self, tls_config: TLSConfig, security: str) -> dict:
310306
sni = tls_config.sni if isinstance(tls_config.sni, str) else (tls_config.sni[0] if tls_config.sni else None)
311307

312308
if security == "reality":
313-
return self._normalize_and_remove_none_values(
314-
{
315-
"serverName": sni,
316-
"fingerprint": tls_config.fingerprint,
317-
"show": False,
318-
"publicKey": tls_config.reality_public_key,
319-
"shortId": tls_config.reality_short_id,
320-
"spiderX": tls_config.reality_spx,
321-
"mldsa65Verify": tls_config.mldsa65_verify,
322-
}
323-
)
309+
return self._normalize_and_remove_none_values({
310+
"serverName": sni,
311+
"fingerprint": tls_config.fingerprint,
312+
"show": False,
313+
"publicKey": tls_config.reality_public_key,
314+
"shortId": tls_config.reality_short_id,
315+
"spiderX": tls_config.reality_spx,
316+
"mldsa65Verify": tls_config.mldsa65_verify,
317+
})
324318
else: # tls
325319
config = {
326320
"serverName": sni,
@@ -389,13 +383,11 @@ def _download_config(self, download_settings: SubscriptionInboundData, link_form
389383
sockopt=sockopt,
390384
)
391385

392-
return self._normalize_and_remove_none_values(
393-
{
394-
"address": download_settings.address,
395-
"port": self._select_port(download_settings.port),
396-
**stream_settings,
397-
}
398-
)
386+
return self._normalize_and_remove_none_values({
387+
"address": download_settings.address,
388+
"port": self._select_port(download_settings.port),
389+
**stream_settings,
390+
})
399391

400392
# ========== Protocol Builders (Registry Methods) ==========
401393

@@ -417,7 +409,7 @@ def _build_vless(self, address: str, inbound: SubscriptionInboundData, settings:
417409

418410
user_settings = {"id": id, "encryption": inbound.encryption}
419411

420-
if inbound.flow_enabled and (flow := inbound.inbound_flow):
412+
if flow := inbound.inbound_flow:
421413
user_settings["flow"] = flow
422414

423415
return self._build_outbound(

0 commit comments

Comments
 (0)