@@ -459,67 +459,6 @@ def _parse_trojan_link(self, link: str) -> dict:
459459 logging .error (f"Failed to parse Trojan link: { str (e )} " )
460460 raise ValueError (f"Invalid Trojan format: { str (e )} " )
461461
462- def _parse_hysteria2_link (self , link : str ):
463- """Parse a Hysteria 2 link into a V2Ray configuration.
464-
465- Supported forms:
466- - hy2://<uuid>@host:port/?insecure=1&sni=example.com#fragment
467- - hy2://<method>:<password>@host:port/?type=tcp&...
468- """
469- if not link .startswith ("hy2://" ):
470- raise ValueError ("Not a valid Hysteria 2 link" )
471-
472- try :
473- parsed = urllib .parse .urlparse (link )
474-
475- # username is typically the token/uuid in hy2 links
476- token = parsed .username
477- host = parsed .hostname
478- port = parsed .port
479-
480- if not host or not port :
481- raise ValueError ("Hysteria link missing host or port" )
482-
483- params = dict (urllib .parse .parse_qsl (parsed .query or "" ))
484-
485- # Build tag from fragment (decode percent-encoding). Append " § 0" to match example tag format.
486- fragment = urllib .parse .unquote (parsed .fragment or "" )
487- tag = (fragment + " § 0" ) if fragment else None
488-
489- # TLS handling: insecure=1/true -> TLS enabled + insecure true.
490- insecure_val = params .get ("insecure" , "" ).lower ()
491- insecure_flag = insecure_val in ("1" , "true" , "yes" )
492-
493- # If explicit security provided and equals 'none', disable TLS; otherwise enable by default when not insecure?
494- security_param = params .get ("security" )
495- if security_param == "none" :
496- tls_enabled = False
497- else :
498- # Enable TLS by default for hysteria links (unless security=none)
499- tls_enabled = True
500-
501- # server_name for TLS comes from sni param or host param
502- server_name = params .get ("sni" ) or params .get ("host" ) or host
503-
504- # Build outbound in the requested shape
505- outbound = {
506- "type" : "hysteria2" ,
507- "tag" : tag or "" ,
508- "server" : host ,
509- "server_port" : int (port ),
510- "password" : token or "" ,
511- "tls" : {
512- "enabled" : bool (tls_enabled ),
513- "server_name" : server_name ,
514- "insecure" : bool (insecure_flag ),
515- },
516- }
517-
518- return outbound
519- except Exception as e :
520- logging .error (f"Failed to parse Hysteria 2 link: { str (e )} " )
521- raise ValueError (f"Invalid Hysteria 2 format: { str (e )} " )
522-
523462 def generate_config (self ):
524463 """Generate V2Ray configuration from link."""
525464 try :
0 commit comments