-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4076017
commit e2702e2
Showing
6 changed files
with
839 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package v2rayControl | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
core "github.com/v2fly/v2ray-core/v5" | ||
|
||
// Mandatory features | ||
_ "github.com/v2fly/v2ray-core/v5/app/dispatcher" | ||
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/inbound" | ||
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/outbound" | ||
|
||
// Inbound and outbound proxies | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/blackhole" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/dns" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/dokodemo" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/freedom" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/http" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/shadowsocks" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/socks" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/trojan" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/vless/inbound" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/vless/outbound" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound" | ||
_ "github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound" | ||
|
||
// Transport headers | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/http" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/noop" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/srtp" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/tls" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/utp" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/wechat" | ||
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/wireguard" | ||
|
||
// JSON, TOML, YAML config support | ||
_ "github.com/v2fly/v2ray-core/v5/main/formats" | ||
) | ||
|
||
type Instance struct { | ||
server *core.Instance | ||
} | ||
|
||
var ( | ||
locker sync.Mutex | ||
v2rayInstance *Instance | ||
) | ||
|
||
func Start(jsonConfig string) (*Instance, error) { | ||
locker.Lock() | ||
defer locker.Unlock() | ||
|
||
config, err := core.LoadConfig("json", []byte(jsonConfig)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
server, err := core.New(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = server.Start() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
v2rayInstance = &Instance{server: server} | ||
|
||
return v2rayInstance, nil | ||
} | ||
|
||
func Stop(instance *Instance) error { | ||
locker.Lock() | ||
defer locker.Unlock() | ||
|
||
if instance.server == nil { | ||
return fmt.Errorf("server instance is nil") | ||
} | ||
|
||
if v2rayInstance != nil { | ||
v2rayInstance.server.Close() | ||
v2rayInstance = nil | ||
} | ||
|
||
if instance != nil { | ||
err := instance.server.Close() | ||
if err != nil { | ||
return err | ||
} | ||
instance = nil | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module v2rayControl | ||
|
||
go 1.20 | ||
|
||
require github.com/v2fly/v2ray-core/v5 v5.7.0 | ||
|
||
require ( | ||
github.com/adrg/xdg v0.4.0 // indirect | ||
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 // indirect | ||
github.com/ajg/form v1.5.1 // indirect | ||
github.com/andybalholm/brotli v1.0.4 // indirect | ||
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d // indirect | ||
github.com/bufbuild/protocompile v0.2.1-0.20230123224550-da57cd758c2f // indirect | ||
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165 // indirect | ||
github.com/ebfe/bcrypt_pbkdf v0.0.0-20140212075826-3c8d2dcb253a // indirect | ||
github.com/gaukas/godicttls v0.0.3 // indirect | ||
github.com/go-chi/chi/v5 v5.0.8 // indirect | ||
github.com/go-chi/render v1.0.2 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.11.2 // indirect | ||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect | ||
github.com/golang/mock v1.6.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect | ||
github.com/gorilla/websocket v1.5.0 // indirect | ||
github.com/jhump/protoreflect v1.15.0 // indirect | ||
github.com/klauspost/compress v1.15.15 // indirect | ||
github.com/klauspost/cpuid v1.2.3 // indirect | ||
github.com/klauspost/reedsolomon v1.9.3 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect | ||
github.com/mustafaturan/bus v1.0.2 // indirect | ||
github.com/mustafaturan/monoton v1.0.0 // indirect | ||
github.com/onsi/ginkgo/v2 v2.2.0 // indirect | ||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pion/dtls/v2 v2.2.4 // indirect | ||
github.com/pion/logging v0.2.2 // indirect | ||
github.com/pion/sctp v1.7.6 // indirect | ||
github.com/pion/transport/v2 v2.0.0 // indirect | ||
github.com/pion/udp v0.1.4 // indirect | ||
github.com/pires/go-proxyproto v0.6.2 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect | ||
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect | ||
github.com/quic-go/quic-go v0.33.0 // indirect | ||
github.com/refraction-networking/utls v1.3.2 // indirect | ||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect | ||
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 // indirect | ||
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect | ||
github.com/v2fly/BrowserBridge v0.0.0-20210430233438-0570fc1d7d08 // indirect | ||
github.com/v2fly/VSign v0.0.0-20201108000810-e2adc24bf848 // indirect | ||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect | ||
github.com/xiaokangwang/VLite v0.0.0-20220418190619-cff95160a432 // indirect | ||
github.com/xtaci/smux v1.5.15 // indirect | ||
go.starlark.net v0.0.0-20220817180228-f738f5508c12 // indirect | ||
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d // indirect | ||
golang.org/x/crypto v0.15.0 // indirect | ||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect | ||
golang.org/x/mobile v0.0.0-20231108233038-35478a0c49da // indirect | ||
golang.org/x/mod v0.14.0 // indirect | ||
golang.org/x/net v0.18.0 // indirect | ||
golang.org/x/sync v0.5.0 // indirect | ||
golang.org/x/sys v0.14.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/tools v0.15.0 // indirect | ||
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect | ||
google.golang.org/grpc v1.53.0 // indirect | ||
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.