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

some fix and small features #961

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open

some fix and small features #961

wants to merge 15 commits into from

Conversation

M03ED
Copy link
Collaborator

@M03ED M03ED commented Apr 28, 2024

fix:

feat:

refactor:

  • V2rayShareLink class usage
  • remove external if else in share.py

@fodhelper
Copy link

fodhelper commented Apr 29, 2024

gRPC is changes in latest versions of Xray-core, check this : XTLS/Xray-core#1815

There is 3 different type of gRPC server configs :
gRPC Gun (Supported on all clients)
gRPC Multi (Supported only on Xray-core based clients)
gRPC 2 in 1 Inbound: Both types in 1 inbound with Custom Path, for this one Marzban should parse Inbound's serviceName and use Multi for Xray based clients, and Gun for other clients

And network name for gRPC can be 'grpc' or 'gun'
other network names have aliases too. check this :
https://github.com/XTLS/Xray-core/blob/51504c624c4aa9c093cf607cfca16e9548743af0/infra/conf/transport_internet.go#L631

@M03ED
Copy link
Collaborator Author

M03ED commented Apr 29, 2024

gRPC is changes in latest versions of Xray-core, check this : XTLS/Xray-core#1815

ok so we can have this type of grpc with "network": "grpc" or have normal grpc with "network": "gun" right ?

@fodhelper
Copy link

network 'gun' and network 'grpc' are same thing, one transport with multiple aliases

@M03ED
Copy link
Collaborator Author

M03ED commented Apr 30, 2024

gRPC is changes in latest versions of Xray-core, check this : XTLS/Xray-core#1815

There is 3 different type of gRPC server configs : gRPC Gun (Supported on all clients) gRPC Multi (Supported only on Xray-core based clients) gRPC 2 in 1 Inbound: Both types in 1 inbound with Custom Path, for this one Marzban should parse Inbound's serviceName and use Multi for Xray based clients, and Gun for other clients

And network name for gRPC can be 'grpc' or 'gun' other network names have aliases too. check this : https://github.com/XTLS/Xray-core/blob/51504c624c4aa9c093cf607cfca16e9548743af0/infra/conf/transport_internet.go#L631

done.

@fodhelper
Copy link

fodhelper commented Apr 30, 2024

Please revert "feat: support gRPC Custom Path", it's wrong

We must check if path is started with "/" or not
If it's not started with "/" then we must send path like before to all clients

But if it's started with "/" we must split it in serviceName and streamName(Gun) and streamName(Multi)
Example path = "/custom/path/GunCustomPath|MultiCustomPath"
serviceName = custom/path
streamName(Gun) = GunCustomPath
streamName(Multi) = MultiCustomPath

now for Xray based clients we must send the full path ("/custom/path/GunCustomPath|MultiCustomPath")
in sharelink, this path must get urlEncoded
https://github.com/XTLS/Xray-core/releases/tag/v1.8.9
But for v2ray json config i think there is no need to urlEncode the path (must test it)

And when user uses this type of Path for gRPC, it does not mean MultiMode is Enabled, it could be disabled
This type of path only means we use custom streamName

For Clash.Meta and Sing-Box Gun mode will only work if streamName(Gun) is euqal to "Tun"
And we must send path to them like old type of configs (without the first "/" and without /streamName)

@fodhelper
Copy link

You can add randomUserAgent function to the new function file

import random

# Source: https://cdn.jsdelivr.net/gh/microlinkhq/top-user-agents@master/src/index.json
UserAgentList = [
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
]

def genRandUserAgent():
  return random.choice(UserAgentList)

print(genRandUserAgent())

You can add all 100 user agents from the url and update user agent list later too, but making many requests to jsdelivr cdn is not good, they may have or add a rate limit or block our server's ip

gRPC supports custom user-agent too, with user agent and authority of grpc we can use it with no tls and remain undetected

@M03ED
Copy link
Collaborator Author

M03ED commented May 3, 2024

Please revert "feat: support gRPC Custom Path", it's wrong

We must check if path is started with "/" or not If it's not started with "/" then we must send path like before to all clients

But if it's started with "/" we must split it in serviceName and streamName(Gun) and streamName(Multi) Example path = "/custom/path/GunCustomPath|MultiCustomPath" serviceName = custom/path streamName(Gun) = GunCustomPath streamName(Multi) = MultiCustomPath

now for Xray based clients we must send the full path ("/custom/path/GunCustomPath|MultiCustomPath") in sharelink, this path must get urlEncoded https://github.com/XTLS/Xray-core/releases/tag/v1.8.9 But for v2ray json config i think there is no need to urlEncode the path (must test it)

And when user uses this type of Path for gRPC, it does not mean MultiMode is Enabled, it could be disabled This type of path only means we use custom streamName

For Clash.Meta and Sing-Box Gun mode will only work if streamName(Gun) is euqal to "Tun" And we must send path to them like old type of configs (without the first "/" and without /streamName)

this is what they provide as a sample

server side :

"serviceName": "/my/sample/path/customTun|customTunMulti"

client without multi:

"serviceName": "/my/sample/path/customTun",
"multiMode": false

client with multi tun:

"serviceName": "/my/sample/path/customTunMulti",
"multiMode": true

if you don't want to use multi mode without conflict with not xray based client you can just use normal grpc
we already sending path like before , only thing we do its separating grpc path for xray based clients and other ones
but i cant change that custom to be really custom

i'm not sure what you what you mean by urlEncode , we have different type of that

@fodhelper
Copy link

but i cant change that custom to be really custom

check this :

def get_grpc_gun(input: str):
    if not input.startswith("/"):
        return input
    
    servicename = input.rsplit("/", 1)[0]
    streamname = input.rsplit("/", 1)[1].split("|")[0]
    
    if streamname == "Tun":
        return servicename[1:]
    
    return "%s%s%s" % (servicename, "/", streamname)

def get_grpc_multi(input: str):
    if not input.startswith("/"):
        return input
    
    servicename = input.rsplit("/", 1)[0]
    streamname = input.rsplit("/", 1)[1].split("|")[1]

    return "%s%s%s" % (servicename, "/", streamname)

print(get_grpc_gun("oldPath"))
print(get_grpc_gun("/newPath/Tun|MultiCustomPath"))
print(get_grpc_gun("/new/path/GunCustomPath|MultiCustomPath"))

print(get_grpc_multi("oldPath"))
print(get_grpc_multi("/new/path/GunCustomPath|MultiCustomPath"))

i'm not sure what you what you mean by urlEncode , we have different type of that

In xray-core tag 1.8.9 written encodeURIComponent
https://github.com/XTLS/Xray-core/releases/tag/v1.8.9
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
so it must be

from urllib.parse import quote

print(quote("/my/path", safe="-_.!~*'()"))

@M03ED
Copy link
Collaborator Author

M03ED commented May 4, 2024

so for not xray based clients we use get_grpc_gun and for xray based if multimode was enable we use get_grpc_multi?

@M03ED
Copy link
Collaborator Author

M03ED commented May 4, 2024

and i can't find any user agent option for grpc

@fodhelper
Copy link

so for not xray based clients we use get_grpc_gun and for xray based if multimode was enable we use get_grpc_multi?

exactly
If multiMode is disabled >> get_grpc_gun (for all clients)
if multiMode is enabled >> get_grpc_multi (for xray based clients) and get_grpc_gun (for other clients)

and i can't find any user agent option for grpc

They added it in https://github.com/XTLS/Xray-core/pull/1790/files
But they didn't added it in docs because it's useless! as no browser uses gRPC so using a user-agent of browser is useless
no *ray client supports it too, so we must leave it for now

@M03ED
Copy link
Collaborator Author

M03ED commented May 30, 2024

i fix grpc and add encode for service name start with /

@M03ED
Copy link
Collaborator Author

M03ED commented Jun 7, 2024

@SaintShit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants