Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main branch changes #3

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,7 @@

[![Build Xray-core binding](https://github.com/LorenEteval/Xray-core-python/actions/workflows/wheels.yml/badge.svg?branch=main)](https://github.com/LorenEteval/Xray-core-python/actions/workflows/wheels.yml)

Python bindings for [Xray-core](https://github.com/XTLS/Xray-core), the best v2ray-core with XTLS support. This package
provides a bridge to start Xray-core client directly from Python on any platform.

Looking for [hysteria](https://github.com/apernet/hysteria) bindings?
Check [hysteria-python](https://github.com/LorenEteval/hysteria-python).

See the real-world production GUI client that takes advantage of the Python binding:
[Furious](https://github.com/LorenEteval/Furious).

## Start

To use this binding, please first make sure that:

* You are a Python developer, or your application is associated with this package.
* You are building a client application. There is no point to use binding on the server side.
* You want to provide additional abstraction for your client. The core(i.e. Xray-core) will be shipped with your
application as dynamic link library, not an executable.
* This bridge provides functionality to start Xray-core directly from Python string(see the API below). What that means
is that the client config stays in memory all the time, and cannot(or very hard to) be inspected. So you can, for
example, get a configuration template from a remote server and edit it for a group of specific client and start the
service.
Python bindings for [Xray-core](https://github.com/XTLS/Xray-core).

## Install

Expand Down
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@


def getXrayCoreVersion():
with open(ROOT_DIR / 'xray-go' / 'core' / 'core.go') as file:
content = file.read()

matches = re.search(
r'Version_x byte = (\d+)\s*Version_y byte = (\d+)\s*Version_z byte = (\d+)\s*',
content,
)

return '.'.join(matches.group(i) for i in range(1, 4))
return '1.8.5'


def runCommand(command):
Expand Down
10 changes: 8 additions & 2 deletions src/xray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ namespace {
{
GoString jsonString{json.data(), static_cast<ptrdiff_t>(json.size())};

startFromJSON(jsonString);
{
py::gil_scoped_release release;

startFromJSON(jsonString);

py::gil_scoped_acquire acquire;
}
}

PYBIND11_MODULE(xray, m) {
Expand All @@ -42,6 +48,6 @@ namespace {
"Start Xray client with JSON string",
py::arg("json"));

m.attr("__version__") = "1.8.4";
m.attr("__version__") = "1.8.5";
}
}
12 changes: 6 additions & 6 deletions xray-go/.github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
permissions:
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/xray-core
flavor: latest=true
Expand All @@ -23,19 +23,19 @@ jobs:
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
Expand Down
8 changes: 3 additions & 5 deletions xray-go/.github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ jobs:
strategy:
matrix:
# Include amd64 on all platforms.
goos: [windows, freebsd, openbsd, linux, dragonfly, darwin]
goos: [windows, freebsd, openbsd, linux, darwin]
goarch: [amd64, 386]
exclude:
# Exclude i386 on darwin and dragonfly.
- goarch: 386
goos: dragonfly
# Exclude i386 on darwin
- goarch: 386
goos: darwin
include:
Expand Down Expand Up @@ -158,7 +156,7 @@ jobs:
CGO_ENABLED: 0
steps:
- name: Checkout codebase
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Show workflow information
run: |
Expand Down
2 changes: 1 addition & 1 deletion xray-go/.github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
go-version: '1.21'
check-latest: true
- name: Checkout codebase
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Restore Cache
uses: actions/cache/restore@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions xray-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- iOS & macOS arm64
- [Mango](https://github.com/arror/Mango)
- [FoXray](https://apps.apple.com/app/foxray/id6448898396)
- [Streisand](https://apps.apple.com/app/streisand/id6450534064)
- macOS arm64 & x64
- [V2rayU](https://github.com/yanue/V2rayU)
- [V2RayXS](https://github.com/tzmax/V2RayXS)
Expand All @@ -90,6 +91,8 @@

- iOS & macOS arm64
- [Shadowrocket](https://apps.apple.com/app/shadowrocket/id932747118)
- Xray Tools
- [xray-knife](https://github.com/lilendian0x00/xray-knife)
- Xray Wrapper
- [XTLS/libXray](https://github.com/XTLS/libXray)
- [xtlsapi](https://github.com/hiddify/xtlsapi)
Expand Down
2 changes: 1 addition & 1 deletion xray-go/app/commander/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xray-go/app/dispatcher/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions xray-go/app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (d *DefaultDispatcher) shouldOverride(ctx context.Context, result SniffResu
protocolString = resComp.ProtocolForDomainResult()
}
for _, p := range request.OverrideDestinationForProtocol {
if strings.HasPrefix(protocolString, p) || strings.HasPrefix(protocolString, p) {
if strings.HasPrefix(protocolString, p) || strings.HasPrefix(p, protocolString) {
return true
}
if fkr0, ok := d.fdns.(dns.FakeDNSEngineRev0); ok && protocolString != "bittorrent" && p == "fakedns" &&
Expand All @@ -218,11 +218,13 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
if !destination.IsValid() {
panic("Dispatcher: Invalid destination.")
}
ob := &session.Outbound{
OriginalTarget: destination,
Target: destination,
ob := session.OutboundFromContext(ctx)
if ob == nil {
ob = &session.Outbound{}
ctx = session.ContextWithOutbound(ctx, ob)
}
ctx = session.ContextWithOutbound(ctx, ob)
ob.OriginalTarget = destination
ob.Target = destination
content := session.ContentFromContext(ctx)
if content == nil {
content = new(session.Content)
Expand Down Expand Up @@ -271,11 +273,13 @@ func (d *DefaultDispatcher) DispatchLink(ctx context.Context, destination net.De
if !destination.IsValid() {
return newError("Dispatcher: Invalid destination.")
}
ob := &session.Outbound{
OriginalTarget: destination,
Target: destination,
ob := session.OutboundFromContext(ctx)
if ob == nil {
ob = &session.Outbound{}
ctx = session.ContextWithOutbound(ctx, ob)
}
ctx = session.ContextWithOutbound(ctx, ob)
ob.OriginalTarget = destination
ob.Target = destination
content := session.ContentFromContext(ctx)
if content == nil {
content = new(session.Content)
Expand Down
Loading
Loading