Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
add conditional compilation support
add multi core support
  • Loading branch information
Yuzuki616 committed Jun 7, 2023
1 parent 925542b commit d76c6a7
Show file tree
Hide file tree
Showing 36 changed files with 1,718 additions and 276 deletions.
41 changes: 27 additions & 14 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package cmd

import (
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/limiter"
"github.com/Yuzuki616/V2bX/node"
"github.com/spf13/cobra"
"log"
"os"
"os/signal"
"runtime"
"syscall"

vCore "github.com/Yuzuki616/V2bX/core"

"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/limiter"
"github.com/Yuzuki616/V2bX/node"
"github.com/spf13/cobra"
)

var (
Expand Down Expand Up @@ -44,33 +46,44 @@ func serverHandle(_ *cobra.Command, _ []string) {
}
limiter.Init()
log.Println("Start V2bX...")
x := core.New(c)
err = x.Start()
vc, err := vCore.NewCore(&c.CoreConfig)
if err != nil {
log.Fatalf("New core error: %s", err)
}
err = vc.Start()
if err != nil {
log.Fatalf("Start xray-core error: %s", err)
log.Fatalf("Start core error: %s", err)
}
defer x.Close()
defer vc.Close()
nodes := node.New()
err = nodes.Start(c.NodesConfig, x)
err = nodes.Start(c.NodesConfig, vc)
if err != nil {
log.Fatalf("Run nodes error: %s", err)
return
}
if watch {
err = c.Watch(config, func() {
nodes.Close()
err = x.Restart(c)
err = vc.Close()
if err != nil {
log.Fatalf("Failed to restart xray-core: %s", err)
}
err = nodes.Start(c.NodesConfig, x)
vc, err = vCore.NewCore(&c.CoreConfig)
if err != nil {
log.Fatalf("New core error: %s", err)
}
err = vc.Start()
if err != nil {
log.Fatalf("Start core error: %s", err)
}
err = nodes.Start(c.NodesConfig, vc)
if err != nil {
log.Fatalf("run nodes error: %s", err)
log.Fatalf("Run nodes error: %s", err)
}
runtime.GC()
})
if err != nil {
log.Fatalf("watch config file error: %s", err)
log.Fatalf("Watch config file error: %s", err)
}
}
// clear memory
Expand Down
5 changes: 3 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
version = "TempVersion" //use ldflags replace
codename = "V2bX"
intro = "A V2board backend based on Xray-core"
intro = "A V2board backend based on multi core"
)

var versionCommand = cobra.Command{
Use: "version",
Short: "Print version info",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
showVersion()
},
}
Expand Down
33 changes: 17 additions & 16 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@ package conf

import (
"fmt"
"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v3"
"io"
"log"
"os"
"path"
"time"

"github.com/fsnotify/fsnotify"
"gopkg.in/yaml.v3"
)

type Conf struct {
LogConfig *LogConfig `yaml:"Log"`
DnsConfigPath string `yaml:"DnsConfigPath"`
InboundConfigPath string `yaml:"InboundConfigPath"`
OutboundConfigPath string `yaml:"OutboundConfigPath"`
RouteConfigPath string `yaml:"RouteConfigPath"`
ConnectionConfig *ConnectionConfig `yaml:"ConnectionConfig"`
NodesConfig []*NodeConfig `yaml:"Nodes"`
CoreConfig CoreConfig `yaml:"CoreConfig"`
NodesConfig []*NodeConfig `yaml:"Nodes"`
}

func New() *Conf {
return &Conf{
LogConfig: NewLogConfig(),
DnsConfigPath: "",
InboundConfigPath: "",
OutboundConfigPath: "",
RouteConfigPath: "",
ConnectionConfig: NewConnectionConfig(),
NodesConfig: []*NodeConfig{},
CoreConfig: CoreConfig{
Type: "xray",
XrayConfig: &XrayConfig{
LogConfig: NewLogConfig(),
DnsConfigPath: "",
InboundConfigPath: "",
OutboundConfigPath: "",
RouteConfigPath: "",
ConnectionConfig: NewConnectionConfig(),
},
},
NodesConfig: []*NodeConfig{},
}
}

Expand Down
19 changes: 0 additions & 19 deletions conf/connetion.go

This file was deleted.

33 changes: 33 additions & 0 deletions conf/core.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package conf

type CoreConfig struct {
Type string `yaml:"Type"`
XrayConfig *XrayConfig `yaml:"Xray"`
}

type XrayConfig struct {
LogConfig *LogConfig `yaml:"Log"`
DnsConfigPath string `yaml:"DnsConfigPath"`
RouteConfigPath string `yaml:"RouteConfigPath"`
ConnectionConfig *ConnectionConfig `yaml:"ConnectionConfig"`
InboundConfigPath string `yaml:"InboundConfigPath"`
OutboundConfigPath string `yaml:"OutboundConfigPath"`
}

type ConnectionConfig struct {
Handshake uint32 `yaml:"handshake"`
ConnIdle uint32 `yaml:"connIdle"`
UplinkOnly uint32 `yaml:"uplinkOnly"`
DownlinkOnly uint32 `yaml:"downlinkOnly"`
BufferSize int32 `yaml:"bufferSize"`
}

func NewConnectionConfig() *ConnectionConfig {
return &ConnectionConfig{
Handshake: 4,
ConnIdle: 30,
UplinkOnly: 2,
DownlinkOnly: 4,
BufferSize: 64,
}
}
Loading

0 comments on commit d76c6a7

Please sign in to comment.