mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
chore: refine code struct
This commit is contained in:
parent
c324d3af70
commit
5f6031b1e8
@ -1,4 +1,4 @@
|
|||||||
package tun
|
package gvisor
|
||||||
|
|
||||||
import "github.com/v2fly/v2ray-core/v5/common/errors"
|
import "github.com/v2fly/v2ray-core/v5/common/errors"
|
||||||
|
|
@ -1,3 +1,3 @@
|
|||||||
package tun
|
package gvisor
|
||||||
|
|
||||||
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
|
@ -2,7 +2,7 @@
|
|||||||
// +build linux
|
// +build linux
|
||||||
// +build linux,amd64 linux,arm64
|
// +build linux,amd64 linux,arm64
|
||||||
|
|
||||||
package tun
|
package gvisor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -21,7 +21,7 @@ const (
|
|||||||
ifReqSize = unix.IFNAMSIZ + 64
|
ifReqSize = unix.IFNAMSIZ + 64
|
||||||
)
|
)
|
||||||
|
|
||||||
type TUN struct {
|
type GvisorTUN struct {
|
||||||
stack.LinkEndpoint
|
stack.LinkEndpoint
|
||||||
|
|
||||||
options device.Options
|
options device.Options
|
||||||
@ -31,7 +31,7 @@ type TUN struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(options device.Options) (device.Device, error) {
|
func New(options device.Options) (device.Device, error) {
|
||||||
t := &TUN{options: options}
|
t := &GvisorTUN{options: options}
|
||||||
|
|
||||||
if len(options.Name) > unix.IFNAMSIZ {
|
if len(options.Name) > unix.IFNAMSIZ {
|
||||||
return nil, newError("name too long").AtError()
|
return nil, newError("name too long").AtError()
|
||||||
@ -72,7 +72,7 @@ func New(options device.Options) (device.Device, error) {
|
|||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TUN) Close() error {
|
func (t *GvisorTUN) Close() error {
|
||||||
return unix.Close(t.fd)
|
return unix.Close(t.fd)
|
||||||
}
|
}
|
||||||
|
|
10
app/tun/device/gvisor/gvisor_others.go
Normal file
10
app/tun/device/gvisor/gvisor_others.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//go:build !linux || (linux && !(amd64 || arm64))
|
||||||
|
// +build !linux linux,!amd64,!arm64
|
||||||
|
|
||||||
|
package gvisor
|
||||||
|
|
||||||
|
import "github.com/v2fly/v2ray-core/v5/app/tun/device"
|
||||||
|
|
||||||
|
func New(options device.Options) (device.Device, error) {
|
||||||
|
return nil, newError("not supported").AtError()
|
||||||
|
}
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v5"
|
core "github.com/v2fly/v2ray-core/v5"
|
||||||
"github.com/v2fly/v2ray-core/v5/app/tun/device"
|
"github.com/v2fly/v2ray-core/v5/app/tun/device"
|
||||||
"github.com/v2fly/v2ray-core/v5/app/tun/device/tun"
|
"github.com/v2fly/v2ray-core/v5/app/tun/device/gvisor"
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/features/policy"
|
"github.com/v2fly/v2ray-core/v5/features/policy"
|
||||||
"github.com/v2fly/v2ray-core/v5/features/routing"
|
"github.com/v2fly/v2ray-core/v5/features/routing"
|
||||||
@ -31,7 +31,7 @@ func (t *TUN) Type() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TUN) Start() error {
|
func (t *TUN) Start() error {
|
||||||
DeviceConstructor := tun.New
|
DeviceConstructor := gvisor.New
|
||||||
device, err := DeviceConstructor(device.Options{
|
device, err := DeviceConstructor(device.Options{
|
||||||
Name: t.config.Name,
|
Name: t.config.Name,
|
||||||
MTU: t.config.Mtu,
|
MTU: t.config.Mtu,
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
_ "github.com/v2fly/v2ray-core/v5/app/instman"
|
_ "github.com/v2fly/v2ray-core/v5/app/instman"
|
||||||
_ "github.com/v2fly/v2ray-core/v5/app/observatory"
|
_ "github.com/v2fly/v2ray-core/v5/app/observatory"
|
||||||
_ "github.com/v2fly/v2ray-core/v5/app/restfulapi"
|
_ "github.com/v2fly/v2ray-core/v5/app/restfulapi"
|
||||||
|
_ "github.com/v2fly/v2ray-core/v5/app/tun"
|
||||||
|
|
||||||
// Inbound and outbound proxies.
|
// Inbound and outbound proxies.
|
||||||
_ "github.com/v2fly/v2ray-core/v5/proxy/blackhole"
|
_ "github.com/v2fly/v2ray-core/v5/proxy/blackhole"
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
//go:build linux && ((linux && amd64) || (linux && arm64))
|
|
||||||
// +build linux
|
|
||||||
// +build linux,amd64 linux,arm64
|
|
||||||
|
|
||||||
package all
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "github.com/v2fly/v2ray-core/v5/app/tun"
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user