mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-18 04:54:38 +03:00
fix
This commit is contained in:
@@ -7,9 +7,9 @@ require (
|
||||
github.com/jsimonetti/rtnetlink v1.2.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/v2fly/v2ray-core/v5 v5.0.0
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
|
||||
google.golang.org/grpc v1.48.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
gvisor.dev/gvisor v0.0.0
|
||||
kernel.org/pub/linux/libs/security/libcap/cap v1.2.64
|
||||
libcore v1.0.0
|
||||
)
|
||||
@@ -23,11 +23,8 @@ require (
|
||||
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d // indirect
|
||||
github.com/cheekybits/genny v1.0.0 // indirect
|
||||
github.com/dgryski/go-camellia v0.0.0-20191119043421-69a8a13fb23d // indirect
|
||||
github.com/dgryski/go-idea v0.0.0-20170306091226-d2fb45a411fb // indirect
|
||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
|
||||
github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/geeksbaek/seed v0.0.0-20180909040025-2a7f5fb92e22 // indirect
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/btree v1.0.1 // indirect
|
||||
@@ -35,7 +32,6 @@ require (
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/jhump/protoreflect v1.12.0 // indirect
|
||||
github.com/josharian/native v1.0.0 // indirect
|
||||
github.com/kierdavis/cfb8 v0.0.0-20180105024805-3a17c36ee2f8 // indirect
|
||||
github.com/klauspost/cpuid v1.2.3 // indirect
|
||||
github.com/klauspost/reedsolomon v1.9.3 // indirect
|
||||
github.com/lucas-clemente/quic-go v0.28.1 // indirect
|
||||
@@ -75,13 +71,13 @@ require (
|
||||
golang.org/x/mod v0.5.1 // indirect
|
||||
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
|
||||
golang.org/x/tools v0.1.9 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
gvisor.dev/gvisor v0.0.0 // indirect
|
||||
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6 // indirect
|
||||
kernel.org/pub/linux/libs/security/libcap/psx v1.2.64 // indirect
|
||||
)
|
||||
|
||||
@@ -80,18 +80,13 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-camellia v0.0.0-20191119043421-69a8a13fb23d h1:CPqTNIigGweVPT4CYb+OO2E6XyRKFOmvTHwWRLgCAlE=
|
||||
github.com/dgryski/go-camellia v0.0.0-20191119043421-69a8a13fb23d/go.mod h1:QX5ZVULjAfZJux/W62Y91HvCh9hyW6enAwcrrv/sLj0=
|
||||
github.com/dgryski/go-idea v0.0.0-20170306091226-d2fb45a411fb h1:zXpN5126w/mhECTkqazBkrOJIMatbPP71aSIDR5UuW4=
|
||||
github.com/dgryski/go-idea v0.0.0-20170306091226-d2fb45a411fb/go.mod h1:F7WkpqJj9t98ePxB/WJGQTIDeOVPuSJ3qdn6JUjg170=
|
||||
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
|
||||
github.com/dgryski/go-metro v0.0.0-20200812162917-85c65e2d0165/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
|
||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 h1:y7y0Oa6UawqTFPCDw9JG6pdKt4F9pAhHv0B7FMGaGD0=
|
||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
|
||||
github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152 h1:ED31mPIxDJnrLt9W9dH5xgd/6KjzEACKHBVGQ33czc0=
|
||||
github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152/go.mod h1:I9fhc/EvSg88cDxmfQ47v35Ssz9rlFunL/KY0A1JAYI=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
|
||||
github.com/ebfe/rc2 v0.0.0-20131011165748-24b9757f5521 h1:fBHFH+Y/GPGFGo7LIrErQc3p2MeAhoIQNgaxPWYsSxk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
@@ -108,8 +103,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
|
||||
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
|
||||
github.com/geeksbaek/seed v0.0.0-20180909040025-2a7f5fb92e22 h1:CdVtqYWYGIEuYCbtyx6BVMKOcO0N6lKm99cR1DZubAs=
|
||||
github.com/geeksbaek/seed v0.0.0-20180909040025-2a7f5fb92e22/go.mod h1:YS1s0XuwU13tHT0WeYeUXUwGk1m8WZvSbK9cx/kY1SE=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
@@ -225,8 +218,6 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kierdavis/cfb8 v0.0.0-20180105024805-3a17c36ee2f8 h1:QxgFSDEqLP8ZsmVm/Qke0HP6JLV7EB93vtWK7noU1Sw=
|
||||
github.com/kierdavis/cfb8 v0.0.0-20180105024805-3a17c36ee2f8/go.mod h1:uL2TcUivilrs0kPsqUwIf8XHAcmkSjsfrzSgAJwS0TI=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs=
|
||||
|
||||
133
go/grpc.go
133
go/grpc.go
@@ -3,24 +3,17 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"libcore"
|
||||
"log"
|
||||
"nekoray_core/gen"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
_ "unsafe"
|
||||
|
||||
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -93,129 +86,3 @@ func NekorayCore() {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// PROXY
|
||||
|
||||
func getProxyHttpClient(_instance *libcore.V2RayInstance) *http.Client {
|
||||
dailContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dest, err := v2rayNet.ParseDestination(fmt.Sprintf("%s:%s", network, addr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return _instance.DialContext(ctx, dest)
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
TLSHandshakeTimeout: time.Second * 3,
|
||||
ResponseHeaderTimeout: time.Second * 3,
|
||||
}
|
||||
if _instance != nil {
|
||||
transport.DialContext = dailContext
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
|
||||
var update_download_url string
|
||||
|
||||
func (s *server) Update(ctx context.Context, in *gen.UpdateReq) (*gen.UpdateResp, error) {
|
||||
ret := &gen.UpdateResp{}
|
||||
|
||||
client := getProxyHttpClient(instance)
|
||||
|
||||
if in.Action == gen.UpdateAction_Check { // Check update
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/repos/MatsuriDayo/nekoray/releases", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
v := []struct {
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Assets []struct {
|
||||
Name string `json:"name"`
|
||||
BrowserDownloadUrl string `json:"browser_download_url"`
|
||||
} `json:"assets"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
Body string `json:"body"`
|
||||
}{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&v)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
nowVer := strings.TrimLeft(version_standalone, "nekoray-")
|
||||
|
||||
var search string
|
||||
if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
|
||||
search = "windows64"
|
||||
} else if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
|
||||
search = "linux64"
|
||||
} else {
|
||||
ret.Error = "Not official support platform"
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
for _, release := range v {
|
||||
if len(release.Assets) > 0 {
|
||||
for _, asset := range release.Assets {
|
||||
if strings.Contains(asset.Name, nowVer) {
|
||||
return ret, nil // No update
|
||||
}
|
||||
if strings.Contains(asset.Name, search) {
|
||||
if release.Prerelease {
|
||||
continue
|
||||
}
|
||||
update_download_url = asset.BrowserDownloadUrl
|
||||
ret.AssetsName = asset.Name
|
||||
ret.DownloadUrl = asset.BrowserDownloadUrl
|
||||
ret.ReleaseUrl = release.HtmlUrl
|
||||
ret.ReleaseNote = release.Body
|
||||
return ret, nil // update
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // Download update
|
||||
if update_download_url == "" {
|
||||
ret.Error = "?"
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", update_download_url, nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
f, err := os.OpenFile("../nekoray.zip", os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
f.Sync()
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
|
||||
if in.Config != nil {
|
||||
// Test instance
|
||||
i = libcore.NewV2rayInstance()
|
||||
i.ForTest = true
|
||||
defer i.Close()
|
||||
|
||||
err = i.LoadConfig(in.Config.CoreConfig)
|
||||
@@ -161,8 +162,19 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
|
||||
t, err = libcore.UrlTestV2ray(i, in.Inbound, in.Url, in.Timeout)
|
||||
out.Ms = t // sn: ms==0 是错误
|
||||
} else if in.Mode == gen.TestMode_TcpPing {
|
||||
host, port, err := net.SplitHostPort(in.Address)
|
||||
if err != nil {
|
||||
out.Error = err.Error()
|
||||
return
|
||||
}
|
||||
ip, err := net.ResolveIPAddr("ip", host)
|
||||
if err != nil {
|
||||
out.Error = err.Error()
|
||||
return
|
||||
}
|
||||
//
|
||||
startTime := time.Now()
|
||||
_, err = net.DialTimeout("tcp", in.Address, time.Duration(in.Timeout)*time.Millisecond)
|
||||
_, err = net.DialTimeout("tcp", net.JoinHostPort(ip.String(), port), time.Duration(in.Timeout)*time.Millisecond)
|
||||
endTime := time.Now()
|
||||
if err == nil {
|
||||
out.Ms = int32(endTime.Sub(startTime).Milliseconds())
|
||||
@@ -174,6 +186,7 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
|
||||
|
||||
// Test instance
|
||||
i := libcore.NewV2rayInstance()
|
||||
i.ForTest = true
|
||||
defer i.Close()
|
||||
|
||||
err = i.LoadConfig(in.Config.CoreConfig)
|
||||
144
go/grpc_update.go
Normal file
144
go/grpc_update.go
Normal file
@@ -0,0 +1,144 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"libcore"
|
||||
"nekoray_core/gen"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
v2rayNet "github.com/v2fly/v2ray-core/v5/common/net"
|
||||
)
|
||||
|
||||
// PROXY
|
||||
|
||||
func getProxyHttpClient(_instance *libcore.V2RayInstance) *http.Client {
|
||||
dailContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dest, err := v2rayNet.ParseDestination(fmt.Sprintf("%s:%s", network, addr))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return _instance.DialContext(ctx, dest)
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
TLSHandshakeTimeout: time.Second * 3,
|
||||
ResponseHeaderTimeout: time.Second * 3,
|
||||
}
|
||||
if _instance != nil {
|
||||
transport.DialContext = dailContext
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
|
||||
var update_download_url string
|
||||
|
||||
func (s *server) Update(ctx context.Context, in *gen.UpdateReq) (*gen.UpdateResp, error) {
|
||||
ret := &gen.UpdateResp{}
|
||||
|
||||
client := getProxyHttpClient(instance)
|
||||
|
||||
if in.Action == gen.UpdateAction_Check { // Check update
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
|
||||
defer cancel()
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/repos/MatsuriDayo/nekoray/releases", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
v := []struct {
|
||||
HtmlUrl string `json:"html_url"`
|
||||
Assets []struct {
|
||||
Name string `json:"name"`
|
||||
BrowserDownloadUrl string `json:"browser_download_url"`
|
||||
} `json:"assets"`
|
||||
Prerelease bool `json:"prerelease"`
|
||||
Body string `json:"body"`
|
||||
}{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&v)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
nowVer := strings.TrimLeft(version_standalone, "nekoray-")
|
||||
|
||||
var search string
|
||||
if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
|
||||
search = "windows64"
|
||||
} else if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
|
||||
search = "linux64"
|
||||
} else {
|
||||
ret.Error = "Not official support platform"
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
for _, release := range v {
|
||||
if len(release.Assets) > 0 {
|
||||
for _, asset := range release.Assets {
|
||||
if strings.Contains(asset.Name, nowVer) {
|
||||
return ret, nil // No update
|
||||
}
|
||||
if strings.Contains(asset.Name, search) {
|
||||
if release.Prerelease {
|
||||
continue
|
||||
}
|
||||
update_download_url = asset.BrowserDownloadUrl
|
||||
ret.AssetsName = asset.Name
|
||||
ret.DownloadUrl = asset.BrowserDownloadUrl
|
||||
ret.ReleaseUrl = release.HtmlUrl
|
||||
ret.ReleaseNote = release.Body
|
||||
return ret, nil // update
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // Download update
|
||||
if update_download_url == "" {
|
||||
ret.Error = "?"
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", update_download_url, nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
f, err := os.OpenFile("../nekoray.zip", os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
if err != nil {
|
||||
ret.Error = err.Error()
|
||||
return ret, nil
|
||||
}
|
||||
f.Sync()
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
Reference in New Issue
Block a user