feat: support mux and tcpFastOpen

This commit is contained in:
mzz2017 committed 2019-11-18 02:32:00 +08:00
1 parent 9b1a212b3c
commit e07f1794b0
15 files changed
+530 -14

No files matched your search

+1 -1
View File
@@ -29,12 +29,12 @@ V2RayA是V2Ray的一个Web客户端。
- [x] 二维码、地址分享
- [x] 自定义PAC模式(GFWList、大陆白名单、自定义路由规则)
- [x] 服务端启动自动检查PAC、订阅更新
- [x] 多路复用、TCPFastOpen支持
待开发:
- [ ] 手动添加/修改节点
- [ ] 测试节点HTTP时延
- [ ] 多路复用、TCPFastOpen支持
- [ ] VPN模式全局代理支持
- [ ] QUIC协议支持
- [ ] 登陆与安全
+1 -1
View File
@@ -222,7 +222,7 @@ export default {
</script>
<style>
@import "https://at.alicdn.com/t/font_1467288_0g54ffvhenqu.css";
@import "https://at.alicdn.com/t/font_1467288_gx22ipe6nuo.css";
</style>
<style lang="scss" scoped>
+80 -6
View File
@@ -51,7 +51,7 @@
></b-field
>
<hr class="dropdown-divider" style="margin: 1.25rem 0 1.25rem" />
<b-field label="PAC模式使用" label-position="on-border">
<b-field label="PAC模式" label-position="on-border">
<b-select v-model="pacMode" expanded style="flex-shrink: 0">
<option value="whitelist">大陆白名单</option>
<option value="gfwlist">GFWList</option>
@@ -79,14 +79,14 @@
label-position="on-border"
>
<b-select v-model="pacAutoUpdateMode" expanded>
<option value="none">关闭自动更新</option>
<option value="auto_update">服务端启动时更新</option>
<option value="none">不自动更新GFWList</option>
<option value="auto_update">服务端启动时更新GFWList</option>
</b-select>
</b-field>
<b-field label="自动更新订阅" label-position="on-border">
<b-select v-model="subscriptionAutoUpdateMode" expanded>
<option value="none">关闭自动更新</option>
<option value="auto_update">服务端启动时更新</option>
<option value="none">不自动更新订阅</option>
<option value="auto_update">服务端启动时更新订阅</option>
</b-select>
</b-field>
<b-field label="解析订阅链接/更新时优先使用" label-position="on-border">
@@ -96,6 +96,59 @@
<option value="proxy">代理模式</option>
</b-select>
</b-field>
<b-field label-position="on-border">
<template slot="label">
TCPFastOpen
<b-tooltip
type="is-dark"
label="简化TCP握手流程以加速建立连接,可能会增加封包的特征。"
position="is-right"
>
<b-icon
size="is-small"
icon=" iconfont icon-help-circle-outline"
style="position:relative;top:2px;right:3px;font-weight:normal"
></b-icon>
</b-tooltip>
</template>
<b-select v-model="tcpFastOpen" expanded>
<option value="default">保持系统默认</option>
<option value="yes">启用</option>
<option value="no">禁用</option>
</b-select>
</b-field>
<b-field label-position="on-border" class="mux">
<template slot="label">
多路复用
<b-tooltip
type="is-dark"
label="复用TCP连接以减少握手延迟而非提高吞吐量,可能有反效果。"
position="is-right"
>
<b-icon
size="is-small"
icon=" iconfont icon-help-circle-outline"
style="position:relative;top:2px;right:3px;font-weight:normal"
></b-icon>
</b-tooltip>
</template>
<b-select v-model="muxOn" expanded style="flex: 1">
<option value="no">关闭多路复用</option>
<option value="yes">启用多路复用</option>
</b-select>
<cus-b-input
v-if="muxOn === 'yes'"
ref="muxinput"
v-model="mux"
placeholder="最大并发连接数"
custom-class="no-shadow"
type="number"
min="1"
max="1024"
validation-icon=" iconfont icon-alert"
style="flex: 1"
></cus-b-input>
</b-field>
<!-- <b-field label="SERVER列表" label-position="on-border">-->
<!-- <b-select v-model="serverListMode" expanded>-->
<!-- <option value="noSubscription">仅显示非订阅节点</option>-->
@@ -118,11 +171,16 @@
import { handleResponse } from "@/assets/js/utils";
import dayjs from "dayjs";
import ModalConfigurePac from "@/components/ModalConfigurePac";
import CusBInput from "./input/Input.vue";
export default {
name: "ModalSetting",
components: { CusBInput },
data: () => ({
proxyModeWhenSubscribe: "direct",
tcpFastOpen: "default",
muxOn: "no",
mux: "8",
pacAutoUpdateMode: "none",
pacAutoUpdateTime: null,
subscriptionAutoUpdateMode: "none",
@@ -183,6 +241,9 @@ export default {
});
},
handleClickSubmit() {
if (this.muxOn === "yes" && !this.$refs.muxinput.checkHtml5Validity()) {
return;
}
if (this.pacMode === "custom" && this.customPac.url.length <= 0) {
this.$buefy.toast.open({
message: "自定义PAC模式下,SiteDAT file URL不能为空",
@@ -217,7 +278,10 @@ export default {
? this.subscriptionAutoUpdateTime.getTime()
: 0,
customPac: this.customPac,
pacMode: this.pacMode
pacMode: this.pacMode,
tcpFastOpen: this.tcpFastOpen,
muxOn: this.muxOn,
mux: parseInt(this.mux)
}
}).then(res => {
handleResponse(res, this, () => {
@@ -282,4 +346,14 @@ export default {
.no-shadow {
box-shadow: none !important;
}
.mux {
p.help {
position: absolute;
bottom: -18px;
right: 0;
}
.icon-alert {
font-size: 18px;
}
}
</style>
+166
View File
@@ -0,0 +1,166 @@
import { shallowMount, mount } from '@vue/test-utils'
import BInput from '@components/input/Input'
import BIcon from '@components/icon/Icon'
describe('BInput', () => {
it('render correctly', () => {
const wrapper = shallowMount(BInput)
expect(wrapper.html()).toMatchSnapshot()
})
it('is vue instance', () => {
const wrapper = shallowMount(BInput)
expect(wrapper.name()).toBe('BInput')
expect(wrapper.isVueInstance()).toBeTruthy()
})
it('renders input element by default', () => {
const wrapper = shallowMount(BInput)
expect(wrapper.contains('input')).toBeTruthy()
expect(wrapper.classes()).toContain('control')
})
it('render textarea element when type is textarea', () => {
const wrapper = shallowMount(BInput, {
propsData: { type: 'textarea' }
})
const target = wrapper.find('textarea')
expect(target.exists()).toBeTruthy()
expect(target.classes()).toContain('textarea')
})
it('displays the icon when the icon property is true', () => {
const wrapper = shallowMount(BInput, {
propsData: { icon: 'magnify' }
})
const target = wrapper.find(BIcon)
expect(target.exists()).toBeTruthy()
})
it('display counter when the maxlength property is passed', () => {
const wrapper = shallowMount(BInput, {
propsData: { value: 'foo', maxlength: 100 }
})
const counter = wrapper.find('small.counter')
expect(counter.exists()).toBeTruthy()
expect(counter.text()).toBe('3 / 100')
})
it('no display counter when hasCounter property set for false', () => {
const wrapper = shallowMount(BInput, {
propsData: { maxlength: 100 }
})
expect(wrapper.find('small.counter').exists()).toBeTruthy()
wrapper.setProps({ hasCounter: false })
expect(wrapper.find('small.counter').exists()).toBeFalsy()
})
it('render field password when the type property is password', () => {
const wrapper = shallowMount(BInput, {
propsData: {
type: 'password',
passwordReveal: true
}
})
const target = wrapper.find('input')
expect(target.exists()).toBeTruthy()
expect(target.attributes().type).toBe('password')
})
it('toggles the visibility of the password to true when the togglePasswordVisibility method is called', (done) => {
const wrapper = mount(BInput, {
propsData: {
value: 'foo',
type: 'password',
passwordReveal: true
}
})
wrapper.setProps({ value: 'bar' })
expect(wrapper.find('input').exists()).toBeTruthy()
expect(wrapper.find('input').attributes().type).toBe('password')
const visibilityIcon = wrapper.find('.icon.is-clickable')
expect(visibilityIcon.exists()).toBeTruthy()
visibilityIcon.trigger('click')
wrapper.setProps({ passwordReveal: false })
expect(wrapper.find('input').attributes().type).toBe('text')
wrapper.vm.$nextTick(done)
})
it('render the placeholder and readonly attribute when passed', () => {
const wrapper = shallowMount(BInput, {
attrs: { placeholder: 'Awesome!', readonly: true }
})
const target = wrapper.find('input')
expect(target.element.getAttribute('placeholder')).toBe('Awesome!')
expect(target.element.getAttribute('readonly')).toBe('readonly')
})
it('expands input when expanded property is passed', () => {
const wrapper = shallowMount(BInput, {
propsData: { expanded: true }
})
expect(wrapper.classes()).toContain('is-expanded')
})
it('display loading icon when loading property passed', () => {
const wrapper = shallowMount(BInput, {
propsData: { loading: true, icon: 'magnify' }
})
expect(wrapper.classes()).toContain('is-loading')
})
it('keep its value on blur', async () => {
const wrapper = mount(BInput, {
propsData: {
value: 'foo'
},
methods: {
checkHtml5Validity: () => true
}
})
const input = wrapper.find('input')
input.element.value = 'bar'
input.trigger('input')
input.trigger('blur')
expect(input.element.value).toBe('bar')
})
it('change status icon when statusType updated', () => {
const parent = {
data: () => ({
newType: 'is-success',
_isField: true
}),
components: {BInput},
template: `<b-input />`
}
const wrapper = mount(parent)
const input = wrapper.find(BInput)
expect(input.vm.statusTypeIcon).toBe('check')
wrapper.setData({ newType: 'is-danger' })
expect(input.vm.statusTypeIcon).toBe('alert-circle')
wrapper.setData({ newType: 'is-info' })
expect(input.vm.statusTypeIcon).toBe('information')
wrapper.setData({ newType: 'is-warning' })
expect(input.vm.statusTypeIcon).toBe('alert')
})
})
+221
View File
@@ -0,0 +1,221 @@
<template>
<div class="control" :class="rootClasses">
<input
v-if="type !== 'textarea'"
ref="input"
class="input"
:class="[inputClasses, customClass]"
:type="newType"
:autocomplete="newAutocomplete"
:maxlength="maxlength"
:value="computedValue"
v-bind="$attrs"
@input="onInput"
@blur="onBlur"
@focus="onFocus"
/>
<textarea
v-else
ref="textarea"
class="textarea"
:class="[inputClasses, customClass]"
:maxlength="maxlength"
:value="computedValue"
v-bind="$attrs"
@input="onInput"
@blur="onBlur"
@focus="onFocus"
></textarea>
<b-icon
v-if="icon"
class="is-left"
:icon="icon"
:pack="iconPack"
:size="iconSize"
/>
<b-icon
v-if="!loading && (passwordReveal || statusTypeIcon)"
class="is-right"
:class="{ 'is-clickable': passwordReveal }"
:icon="passwordReveal ? passwordVisibleIcon : statusTypeIcon"
:pack="iconPack"
:size="iconSize"
:type="!passwordReveal ? statusType : 'is-primary'"
both
@click.native="togglePasswordVisibility"
/>
<small
v-if="maxlength && hasCounter && type !== 'number'"
class="help counter"
:class="{ 'is-invisible': !isFocused }"
>
{{ valueLength }} / {{ maxlength }}
</small>
</div>
</template>
<script>
import Icon from "buefy/src/components/icon/Icon";
import config from "buefy/src/utils/config";
import FormElementMixin from "buefy/src/utils/FormElementMixin";
export default {
name: "CusBInput",
components: {
[Icon.name]: Icon
},
mixins: [FormElementMixin],
inheritAttrs: false,
props: {
// eslint-disable-next-line vue/require-default-prop
value: [Number, String],
type: {
type: String,
default: "text"
},
passwordReveal: Boolean,
hasCounter: {
type: Boolean,
default: () => config.defaultInputHasCounter
},
customClass: {
type: String,
default: ""
}
},
data() {
return {
newValue: this.value,
newType: this.type,
newAutocomplete: this.autocomplete || config.defaultInputAutocomplete,
isPasswordVisible: false,
// eslint-disable-next-line vue/no-reserved-keys
_elementRef: this.type === "textarea" ? "textarea" : "input"
};
},
computed: {
computedValue: {
get() {
return this.newValue;
},
set(value) {
this.newValue = value;
this.$emit("input", value);
!this.isValid && this.checkHtml5Validity();
}
},
rootClasses() {
return [
this.iconPosition,
this.size,
{
"is-expanded": this.expanded,
"is-loading": this.loading,
"is-clearfix": !this.hasMessage
}
];
},
inputClasses() {
return [this.statusType, this.size, { "is-rounded": this.rounded }];
},
hasIconRight() {
return this.passwordReveal || this.loading || this.statusTypeIcon;
},
/**
* Position of the icon or if it's both sides.
*/
// eslint-disable-next-line vue/return-in-computed-property
iconPosition() {
if (this.icon && this.hasIconRight) {
return "has-icons-left has-icons-right";
} else if (!this.icon && this.hasIconRight) {
return "has-icons-right";
} else if (this.icon) {
return "has-icons-left";
}
},
/**
* Icon name (MDI) based on the type.
*/
// eslint-disable-next-line vue/return-in-computed-property
statusTypeIcon() {
switch (this.statusType) {
case "is-success":
return "check";
case "is-danger":
return " iconfont icon-alert";
case "is-info":
return "information";
case "is-warning":
return "alert";
}
},
/**
* Check if have any message prop from parent if it's a Field.
*/
hasMessage() {
return !!this.statusMessage;
},
/**
* Current password-reveal icon name.
*/
passwordVisibleIcon() {
return !this.isPasswordVisible ? "eye" : "eye-off";
},
/**
* Get value length
*/
valueLength() {
if (typeof this.computedValue === "string") {
return this.computedValue.length;
} else if (typeof this.computedValue === "number") {
return this.computedValue.toString().length;
}
return 0;
}
},
watch: {
/**
* When v-model is changed:
* 1. Set internal value.
*/
value(value) {
this.newValue = value;
}
},
methods: {
/**
* Toggle the visibility of a password-reveal input
* by changing the type and focus the input right away.
*/
togglePasswordVisibility() {
this.isPasswordVisible = !this.isPasswordVisible;
this.newType = this.isPasswordVisible ? "text" : "password";
this.$nextTick(() => {
this.$refs.input.focus();
});
},
/**
* Input's 'input' event listener, 'nextTick' is used to prevent event firing
* before ui update, helps when using masks (Cleavejs and potentially others).
*/
onInput(event) {
this.$nextTick(() => {
if (event.target) {
this.computedValue = event.target.value;
}
});
}
}
};
</script>
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`BInput render correctly 1`] = `
<div class="control is-clearfix"><input type="text" autocomplete="on" class="input">
<!---->
<!---->
<!---->
</div>
`;
+13
View File
@@ -0,0 +1,13 @@
import Input from "./Input";
import { use, registerComponent } from "buefy/src/utils/plugins";
const Plugin = {
install(Vue) {
registerComponent(Vue, Input);
}
};
use(Plugin);
export default Plugin;
+5 -1
View File
@@ -31,7 +31,11 @@ func PutSetting(ctx *gin.Context) {
var data configure.Setting
err := ctx.ShouldBindJSON(&data)
if err != nil {
tools.ResponseError(ctx, errors.New("参数有误"))
tools.ResponseError(ctx, errors.New("参数有误"+err.Error()))
return
}
if data.MuxOn == configure.Yes && (data.Mux < 1 || data.Mux > 1024) {
tools.ResponseError(ctx, errors.New("多路复用最大并发连接数必须介于1到1024之间"))
return
}
err = service.UpdateSetting(&data)
+1 -1
View File
@@ -59,7 +59,7 @@ func hello() {
}
}
func checkUpdate() {
setting := configure.GetSetting()
setting := service.GetSetting()
if setting.GFWListAutoUpdateMode == configure.AutoUpdate {
go func() {
update, tRemote, err := service.IsUpdate()
+18 -2
View File
@@ -103,6 +103,12 @@ type StreamSettings struct {
KcpSettings *KcpSettings `json:"kcpSettings"`
WsSettings *WsSettings `json:"wsSettings"`
HTTPSettings *HttpSettings `json:"httpSettings"`
Sockopt *Sockopt `json:"sockopt"`
}
type Sockopt struct {
Mark *int `json:"mark"`
TCPFastOpen *bool `json:"tcpFastOpen"`
Tproxy *string `json:"tproxy"`
}
type Mux struct {
Enabled bool `json:"enabled"`
@@ -190,6 +196,7 @@ func (t *Template) FillWithVmessInfo(v vmessInfo.VmessInfo) error {
t.Outbounds[0].Protocol = v.Protocol
port, _ := strconv.Atoi(v.Port)
aid, _ := strconv.Atoi(v.Aid)
setting := configure.GetSetting()
switch strings.ToLower(v.Protocol) {
case "vmess":
t.Outbounds[0].Settings.Vnext = []Vnext{
@@ -230,7 +237,17 @@ func (t *Template) FillWithVmessInfo(v vmessInfo.VmessInfo) error {
t.Outbounds[0].StreamSettings.Security = "tls"
t.Outbounds[0].StreamSettings.TLSSettings = &tmplJson.TLSSettings
}
t.Outbounds[0].Mux = &tmplJson.Mux
//是否在设置里开启了TCPFastOpen
if setting.TcpFastOpen != configure.Default {
t.Outbounds[0].StreamSettings.Sockopt = new(Sockopt)
tmp := setting.TcpFastOpen == configure.Yes
t.Outbounds[0].StreamSettings.Sockopt.TCPFastOpen = &tmp
}
//是否在设置了里开启了mux
t.Outbounds[0].Mux = &Mux{
Enabled: setting.MuxOn == configure.Yes,
Concurrency: setting.Mux,
}
case "shadowsocks":
t.Outbounds[0].Settings.Servers = []Server{
{
@@ -245,7 +262,6 @@ func (t *Template) FillWithVmessInfo(v vmessInfo.VmessInfo) error {
return errors.New("不支持的协议: " + v.Protocol)
}
//根据设置修改路由部分json配置
setting := configure.GetSetting()
switch setting.PacMode {
case configure.WhitelistMode:
t.Routing.Rules = append(t.Routing.Rules, tmplJson.Whitelist...)
+5
View File
@@ -8,9 +8,14 @@ type (
PacMatchType string
RoutingDefaultProxyMode string
TouchType string
DefaultYesNo string
)
const (
Default = DefaultYesNo("default")
Yes = DefaultYesNo("yes")
No = DefaultYesNo("no")
NotAutoUpdate = AutoUpdateMode("none")
AutoUpdate = AutoUpdateMode("auto_update")
+6
View File
@@ -11,6 +11,9 @@ type Setting struct {
GFWListAutoUpdateMode AutoUpdateMode `json:"pacAutoUpdateMode"`
CustomAutoUpdateMode AutoUpdateMode `json:"pacAutoUpdateMode"`
SubscriptionAutoUpdateMode AutoUpdateMode `json:"subscriptionAutoUpdateMode"`
TcpFastOpen DefaultYesNo `json:"tcpFastOpen"`
MuxOn DefaultYesNo `json:"muxOn"`
Mux int `json:"mux"`
}
func NewSetting() (setting *Setting) {
@@ -25,6 +28,9 @@ func NewSetting() (setting *Setting) {
GFWListAutoUpdateMode: NotAutoUpdate,
CustomAutoUpdateMode: NotAutoUpdate,
SubscriptionAutoUpdateMode: NotAutoUpdate,
TcpFastOpen: Default,
MuxOn: No,
Mux: 8,
}
}
+2
View File
@@ -2,6 +2,7 @@ package logs
import (
"V2RayA/persistence"
"log"
"time"
)
@@ -11,4 +12,5 @@ func format(s string) string {
func Print(s string) {
persistence.DoAndSave("rpush", "V2RayA.log", format(s))
log.Println(s)
}
-1
View File
@@ -31,7 +31,6 @@ func GetRemoteGFWListUpdateTime(c *http.Client) (t time.Time, err error) {
log.Println(doc.Html())
return time.Time{}, errors.New("获取最新GFWList版本失败")
}
log.Println("timeraw", timeRaw)
return time.Parse(time.RFC3339, timeRaw)
}
func IsUpdate() (update bool, remoteTime time.Time, err error) {
+2 -1
View File
@@ -10,6 +10,7 @@ func GetSetting() *configure.Setting {
s := configure.GetSetting()
if s == nil {
s = configure.NewSetting()
_ = configure.SetSetting(s)
}
return s
}
@@ -30,7 +31,7 @@ func UpdateSetting(setting *configure.Setting) (err error) {
if err != nil {
return
}
//如果当前有连接,则重写配置并重启连接,使得对PAC的修改立即生效
//如果当前有连接,则重写配置并重启连接,使得对PAC模式、TCPFastOpen等配置的修改立即生效
if cs := configure.GetConnectedServer(); cs != nil {
tsr, _ := cs.LocateServer()
err = v2ray.UpdateV2RayConfigAndRestart(&tsr.VmessInfo)