Skip to content

Commit

Permalink
grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiwuchang committed Dec 7, 2023
1 parent f33aa4d commit 0b92c57
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 25 deletions.
1 change: 0 additions & 1 deletion bin/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ ${s}
* 返回 xray 設定
*/
configure(opts) {
core.println(JSON.stringify(opts.fileds, undefined, " "));
let ips;
let ip;
const address = opts.fileds.address;
Expand Down
3 changes: 3 additions & 0 deletions bin/js/metadata/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ exports.i18n = {
'zh-Hans': '指纹',
'default': 'Fingerprint',
},
grpcMode: {
'default': 'grpc mode',
},
encryption: {
'zh-Hant': '加密方式',
'zh-Hans': '加密方式',
Expand Down
48 changes: 42 additions & 6 deletions bin/js/metadata/trojan.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,33 @@ exports.trojan = {
key: 'host',
label: i18n_1.i18n.host,
ui: 'text',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'host',
},
},
{
// url path
key: 'path',
label: i18n_1.i18n.path,
ui: 'text',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'path',
},
alias: [
{
key: 'protocol',
value: 'grpc',
from: {
from: 'query',
key: 'serviceName',
}
}
],
},
{
// 傳輸層加密
key: 'security',
Expand All @@ -72,7 +93,7 @@ exports.trojan = {
value: [
'xtls', 'tls', 'reality',
],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'security',
Expand All @@ -84,7 +105,7 @@ exports.trojan = {
key: 'userID',
label: i18n_1.i18n.userID,
ui: 'text',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'username',
},
Expand All @@ -94,7 +115,7 @@ exports.trojan = {
key: 'flow',
label: i18n_1.i18n.flow,
ui: 'select-editable',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
value: [
'none', 'xtls-rprx-vision', 'xtls-rprx-vision-udp443'
],
Expand All @@ -103,13 +124,17 @@ exports.trojan = {
key: 'flow',
},
},
{
ui: 'placeholder',
class: 'p-0 col-fixed md:col-4',
},
// row
{
key: 'alpn',
label: i18n_1.i18n.alpn,
ui: 'select-editable',
value: ['', 'h2', 'http/1.1', 'h2,http/1.1'],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'alpn',
Expand All @@ -120,11 +145,22 @@ exports.trojan = {
label: i18n_1.i18n.fingerprint,
ui: 'select-editable',
value: ['', 'chrome', 'firefox', 'safari', 'ios', 'android', 'edge', '360', 'qq', 'random', 'randomized'],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'fp',
},
},
{
key: 'mode',
label: i18n_1.i18n.grpcMode,
ui: 'select',
value: ['', 'gun', 'multi'],
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'mode',
},
},
],
};
13 changes: 11 additions & 2 deletions bin/js/metadata/vless.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,17 @@ exports.vless = {
},
},
{
ui: 'placeholder',
class: 'p-0 col-fixed md:col-4',
key: 'mode',
label: i18n_1.i18n.grpcMode,
ui: 'select',
value: ['', 'gun', 'multi'],
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'mode',
},
// ui: 'placeholder',
// class: 'p-0 col-fixed md:col-4',
},
// row
{
Expand Down
2 changes: 1 addition & 1 deletion bin/js/metadata/vmess.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.vmess = {
label: i18n_1.i18n.protocol,
ui: 'select-editable',
value: [
'tcp', 'ws', 'quic', 'kcp', 'http', 'grpc',
'tcp', 'ws', 'quic', 'kcp', 'http',
],
class: 'col-12 md:col-4',
from: {
Expand Down
18 changes: 17 additions & 1 deletion bin/js/xray/outbounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ class OutboundStream {
case 'grpc':
result.network = 'grpc';
result.grpcSettings = {
serviceName: this._serverName(),
serviceName: this._serviceName(),
multiMode: this._multiMode(),
idle_timeout: 40,
};
break;
Expand All @@ -281,6 +282,21 @@ class OutboundStream {
}
return result;
}
_multiMode() {
var _a;
const fileds = this.opts.fileds;
const val = (_a = fileds.mode) !== null && _a !== void 0 ? _a : '';
return val == 'multi';
}
_serviceName() {
var _a;
const fileds = this.opts.fileds;
const val = (_a = fileds.path) !== null && _a !== void 0 ? _a : '';
if (val != '') {
return val;
}
return '';
}
_path() {
var _a;
const fileds = this.opts.fileds;
Expand Down
1 change: 0 additions & 1 deletion bin/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ ${s}
* 返回 xray 設定
*/
configure(opts: ConfigureOptions<Userdata>): ConfigureResult {
core.println(JSON.stringify(opts.fileds, undefined, " "))
let ips: undefined | Array<string>
let ip: undefined | string
const address = opts.fileds.address!
Expand Down
3 changes: 3 additions & 0 deletions bin/ts/metadata/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export const i18n = {
'zh-Hans': '指纹',
'default': 'Fingerprint',
},
grpcMode: {
'default': 'grpc mode',
},
encryption: {
'zh-Hant': '加密方式',
'zh-Hans': '加密方式',
Expand Down
57 changes: 50 additions & 7 deletions bin/ts/metadata/trojan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,33 @@ export const trojan: Metadata = {
key: 'host',
label: i18n.host,
ui: 'text',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'host',
},
},
{
// url path
key: 'path',
label: i18n.path,
ui: 'text',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'path',
},
alias: [
{
key: 'protocol',
value: 'grpc',
from: {
from: 'query',
key: 'serviceName',
}
}
],
},
{
// 傳輸層加密
key: 'security',
Expand All @@ -71,7 +92,7 @@ export const trojan: Metadata = {
value: [
'xtls', 'tls', 'reality',
],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'security',
Expand All @@ -84,7 +105,7 @@ export const trojan: Metadata = {
key: 'userID',
label: i18n.userID,
ui: 'text',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'username',
},
Expand All @@ -94,7 +115,7 @@ export const trojan: Metadata = {
key: 'flow',
label: i18n.flow,
ui: 'select-editable',
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
value: [
'none', 'xtls-rprx-vision', 'xtls-rprx-vision-udp443'
],
Expand All @@ -103,14 +124,17 @@ export const trojan: Metadata = {
key: 'flow',
},
},

{
ui: 'placeholder',
class: 'p-0 col-fixed md:col-4',
},
// row
{
key: 'alpn',
label: i18n.alpn,
ui: 'select-editable',
value: ['', 'h2', 'http/1.1', 'h2,http/1.1'],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'alpn',
Expand All @@ -121,12 +145,23 @@ export const trojan: Metadata = {
label: i18n.fingerprint,
ui: 'select-editable',
value: ['', 'chrome', 'firefox', 'safari', 'ios', 'android', 'edge', '360', 'qq', 'random', 'randomized'],
class: 'col-12 md:col-6',
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'fp',
},
},
{
key: 'mode',
label: i18n.grpcMode,
ui: 'select',
value: ['', 'gun', 'multi'],
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'mode',
},
},
],
}

Expand All @@ -147,6 +182,10 @@ export interface TrojanFileds {
* 主機名稱
*/
host?: string
/**
* url path,只在 grpc 時有效
*/
path?: string
/**
* 傳輸層加密
*/
Expand All @@ -162,4 +201,8 @@ export interface TrojanFileds {

alpn?: string
fingerprint?: string
/**
* grpc 模式
*/
mode?: string
}
17 changes: 15 additions & 2 deletions bin/ts/metadata/vless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,17 @@ export const vless: Metadata = {
},
},
{
ui: 'placeholder',
class: 'p-0 col-fixed md:col-4',
key: 'mode',
label: i18n.grpcMode,
ui: 'select',
value: ['', 'gun', 'multi'],
class: 'col-12 md:col-4',
from: {
from: 'query',
key: 'mode',
},
// ui: 'placeholder',
// class: 'p-0 col-fixed md:col-4',
},
// row
{
Expand Down Expand Up @@ -240,6 +249,10 @@ export interface VLessFileds {

alpn?: string
fingerprint?: string
/**
* grpc 模式
*/
mode?: string

publicKey?: string
shortID?: string
Expand Down
2 changes: 1 addition & 1 deletion bin/ts/metadata/vmess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const vmess: Metadata = {
label: i18n.protocol,
ui: 'select-editable',
value: [
'tcp', 'ws', 'quic', 'kcp', 'http', 'grpc',
'tcp', 'ws', 'quic', 'kcp', 'http',
],
class: 'col-12 md:col-4',
from: {
Expand Down
16 changes: 15 additions & 1 deletion bin/ts/xray/outbounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ class OutboundStream {
case 'grpc':
result.network = 'grpc';
(result as GRPCStream).grpcSettings = {
serviceName: this._serverName(),
serviceName: this._serviceName(),
multiMode: this._multiMode(),
idle_timeout: 40,
}
break
Expand All @@ -296,6 +297,19 @@ class OutboundStream {
}
return result
}
private _multiMode(): boolean {
const fileds = this.opts.fileds
const val = fileds.mode ?? ''
return val == 'multi'
}
private _serviceName(): string {
const fileds = this.opts.fileds
const val = fileds.path ?? ''
if (val != '') {
return val
}
return ''
}
private _path(): string {
const fileds = this.opts.fileds
const val = fileds.path ?? ''
Expand Down
Loading

0 comments on commit 0b92c57

Please sign in to comment.