Skip to content

Commit

Permalink
chore: refine code struct
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 29, 2023
1 parent b380d1e commit 2f63326
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tun
package gvisor

import "github.com/v2fly/v2ray-core/v5/common/errors"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tun
package gvisor

//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// +build linux
// +build linux,amd64 linux,arm64

package tun
package gvisor

import (
"fmt"
Expand All @@ -21,7 +21,7 @@ const (
ifReqSize = unix.IFNAMSIZ + 64
)

type TUN struct {
type GvisorTUN struct {
stack.LinkEndpoint

options device.Options
Expand All @@ -31,7 +31,7 @@ type TUN struct {
}

func New(options device.Options) (device.Device, error) {
t := &TUN{options: options}
t := &GvisorTUN{options: options}

if len(options.Name) > unix.IFNAMSIZ {
return nil, newError("name too long").AtError()
Expand Down Expand Up @@ -72,7 +72,7 @@ func New(options device.Options) (device.Device, error) {
return t, nil
}

func (t *TUN) Close() error {
func (t *GvisorTUN) Close() error {
return unix.Close(t.fd)
}

Expand Down
10 changes: 10 additions & 0 deletions app/tun/device/gvisor/gvisor_others.go
Original file line number Diff line number Diff line change
@@ -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()
}
4 changes: 2 additions & 2 deletions app/tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

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/tun"
"github.com/v2fly/v2ray-core/v5/app/tun/device/gvisor"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/features/routing"
Expand All @@ -31,7 +31,7 @@ func (t *TUN) Type() interface{} {
}

func (t *TUN) Start() error {
DeviceConstructor := tun.New
DeviceConstructor := gvisor.New
device, err := DeviceConstructor(device.Options{
Name: t.config.Name,
MTU: t.config.Mtu,
Expand Down
1 change: 1 addition & 0 deletions main/distro/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
_ "github.com/v2fly/v2ray-core/v5/app/instman"
_ "github.com/v2fly/v2ray-core/v5/app/observatory"
_ "github.com/v2fly/v2ray-core/v5/app/restfulapi"
_ "github.com/v2fly/v2ray-core/v5/app/tun"

// Inbound and outbound proxies.
_ "github.com/v2fly/v2ray-core/v5/proxy/blackhole"
Expand Down
9 changes: 0 additions & 9 deletions main/distro/all/tun.go

This file was deleted.

0 comments on commit 2f63326

Please sign in to comment.