-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement chaining support for xray and sing-box config generation
- Loading branch information
1 parent
3045ec0
commit 085f8c5
Showing
9 changed files
with
248 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
import uuid | ||
|
||
from v2share import SingBoxConfig, V2Data | ||
|
||
|
||
def test_sing_box_chaining(): | ||
detour_config = V2Data( | ||
"vmess", | ||
"detour_outbound", | ||
"127.0.0.1", | ||
1234, | ||
uuid=uuid.UUID("bb34fc3a-529d-473a-a3d9-1749b2116f2a"), | ||
) | ||
main_config = V2Data( | ||
"vmess", | ||
"main_outbound", | ||
"127.0.0.1", | ||
1234, | ||
uuid=uuid.UUID("bb34fc3a-529d-473a-a3d9-1749b2116f2a"), | ||
next=detour_config, | ||
) | ||
sb = SingBoxConfig() | ||
sb.add_proxies([main_config]) | ||
|
||
result = json.loads(sb.render()) | ||
|
||
main_outbound, selector_outbounds = None, [] | ||
for outbound in result["outbounds"]: | ||
if outbound["tag"] == "main_outbound": | ||
main_outbound = outbound | ||
|
||
if outbound["type"] == "selector" or outbound["type"] == "urltest": | ||
selector_outbounds.append(outbound) | ||
|
||
assert main_outbound["detour"] == "detour_outbound" | ||
for outbound in selector_outbounds: | ||
assert ( | ||
"detour_outbound" not in outbound["outbounds"] | ||
) # detour outbound should not be in the selectors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
import uuid | ||
|
||
from v2share import XrayConfig, V2Data | ||
|
||
|
||
def test_xray_chaining(): | ||
detour_config = V2Data( | ||
"vmess", | ||
"detour_outbound", | ||
"127.0.0.1", | ||
1234, | ||
uuid=uuid.UUID("bb34fc3a-529d-473a-a3d9-1749b2116f2a"), | ||
) | ||
main_config = V2Data( | ||
"vmess", | ||
"main_outbound", | ||
"127.0.0.1", | ||
1234, | ||
uuid=uuid.UUID("bb34fc3a-529d-473a-a3d9-1749b2116f2a"), | ||
next=detour_config, | ||
) | ||
x = XrayConfig() | ||
x.add_proxies([main_config]) | ||
result = json.loads(x.render()) | ||
|
||
main_outbound = None | ||
for outbound in result[0]["outbounds"]: | ||
if outbound["tag"] == "main_outbound": | ||
main_outbound = outbound | ||
break | ||
assert ( | ||
main_outbound["streamSettings"]["sockopt"]["dialerProxy"] == "detour_outbound" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.