-
Notifications
You must be signed in to change notification settings - Fork 15
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
0 parents
commit e7c45cc
Showing
61 changed files
with
5,782 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,27 @@ | ||
name: releaser | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
env: | ||
NODE_OPTIONS: "--max-old-space-size=4096" # 增加 Node.js 可用的最大内存,防止构建失败 | ||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,29 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
/.idea/ | ||
build/bin | ||
node_modules | ||
frontend/dist | ||
run.log | ||
dist/ | ||
config.json | ||
.dev |
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,13 @@ | ||
builds: | ||
- id: box | ||
dir: server | ||
main: ./cmd/gpp/main.go | ||
binary: gpp | ||
tags: with_quic | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 danbai | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,51 @@ | ||
# gpp | ||
|
||
基于[sing-box](https://github.com/SagerNet/sing-box)的加速器,使用golang编写,支持windows、linux、macos | ||
|
||
- 使用vless+ws协议传输 | ||
- 支持tcp、udp | ||
- http分流 | ||
- gui客户端 | ||
- 基于tun代理 | ||
![微信图片_20240424204203.png](https://imgc.cc/2024/04/24/6628fecfb8f06.png) | ||
|
||
建议禁用ipv6使用加速器,[qq交流群936204503](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=syMCYJm6Isz_yAxUfrQetpNGioUdpdjO&authKey=lkUyXpKkdAzUwOZYq0m%2BH5Y%2FvAU3XegyxWTm5fM1%2BxOZDdBHJUF%2BODVeNg9MraDl&noverify=0&group_code=936204503) | ||
|
||
# 下载 | ||
|
||
# 服务端 | ||
|
||
[下载服务端](https://github.com/danbai225/gpp/releases) | ||
|
||
# 客户端 | ||
|
||
[下载客户端](https://danbai.lanzouq.com/b0064z1wuf) | ||
|
||
密码:gpi8 | ||
# 编译 | ||
|
||
## 编译服务端 | ||
|
||
使用`golang`编译 `cmd/gpp/main.go`获得服务端可执行文件。 | ||
|
||
## 编译GUI客户端 | ||
|
||
gui的客户端需要自建构建,需要安装`wails`、`npm`和`golang`,安装方法如下 | ||
|
||
- 安装`golang`,[下载地址](https://golang.org/dl/) | ||
- 安装`npm` [下载地址](https://nodejs.org/en/download/) | ||
- 安装`wails`,`go install github.com/wailsapp/wails/v2/cmd/wails@latest` | ||
|
||
使用`wails`编译 | ||
|
||
``` | ||
wails build | ||
``` | ||
|
||
# 快速安装服务端脚本(仅支持linux) | ||
|
||
```bash | ||
wget https://raw.githubusercontent.com/danbai225/gpp/main/server/install.sh | ||
chmod +x install.sh | ||
./install.sh | ||
``` |
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,238 @@ | ||
package main | ||
|
||
import ( | ||
"client/backend/client" | ||
"client/backend/config" | ||
"client/backend/data" | ||
"context" | ||
"crypto/sha256" | ||
"fmt" | ||
"github.com/cloverstd/tcping/ping" | ||
box "github.com/sagernet/sing-box" | ||
"github.com/shirou/gopsutil/v3/net" | ||
"github.com/wailsapp/wails/v2/pkg/runtime" | ||
"io" | ||
"net/http" | ||
"os" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// App struct | ||
type App struct { | ||
ctx context.Context | ||
conf *config.Config | ||
gamePeer *config.Peer | ||
httpPeer *config.Peer | ||
box *box.Box | ||
processList []string | ||
} | ||
|
||
// NewApp creates a new App application struct | ||
func NewApp() *App { | ||
conf := config.Config{} | ||
app := App{ | ||
conf: &conf, | ||
processList: make([]string, 0), | ||
} | ||
return &app | ||
} | ||
func (a *App) testPing() { | ||
a.PingAll() | ||
tick := time.Tick(time.Second * 60) | ||
for range tick { | ||
a.PingAll() | ||
} | ||
} | ||
func (a *App) startup(ctx context.Context) { | ||
a.ctx = ctx | ||
loadConfig, err := config.LoadConfig() | ||
if err != nil { | ||
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ | ||
Type: runtime.WarningDialog, | ||
Title: "配置加载错误", | ||
Message: err.Error(), | ||
}) | ||
} else { | ||
a.conf = loadConfig | ||
} | ||
if len(a.conf.PeerList) > 0 { | ||
a.gamePeer = a.conf.PeerList[0] | ||
a.httpPeer = a.conf.PeerList[0] | ||
} | ||
go a.testPing() | ||
home, _ := os.UserHomeDir() | ||
geoPath := fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, ".gpp", os.PathSeparator, "geoip.db") | ||
file, err := os.ReadFile(geoPath) | ||
if err == nil { | ||
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db.sha256sum") | ||
if err2 == nil { | ||
sum256 := sha256.Sum256(file) | ||
fmt.Println(fmt.Sprintf("%x", sum256), string(rdata)) | ||
if fmt.Sprintf("%x", sum256) != string(rdata) { | ||
rdata, err2 = httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db") | ||
if err2 == nil { | ||
_ = os.WriteFile(geoPath, rdata, 0644) | ||
} | ||
} | ||
} | ||
} else { | ||
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db") | ||
if err2 == nil { | ||
_ = os.WriteFile(geoPath, rdata, 0644) | ||
} | ||
} | ||
geoPath = fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, ".gpp", os.PathSeparator, "geosite.db") | ||
file, err = os.ReadFile(geoPath) | ||
if err == nil { | ||
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db.sha256sum") | ||
if err2 == nil { | ||
sum256 := sha256.Sum256(file) | ||
fmt.Println(fmt.Sprintf("%x", sum256), string(rdata)) | ||
if fmt.Sprintf("%x", sum256) != string(rdata) { | ||
rdata, err2 = httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db") | ||
if err2 == nil { | ||
_ = os.WriteFile(geoPath, rdata, 0644) | ||
} | ||
} | ||
} | ||
} else { | ||
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db") | ||
if err2 == nil { | ||
_ = os.WriteFile(geoPath, rdata, 0644) | ||
} | ||
} | ||
} | ||
func (a *App) PingAll() { | ||
group := sync.WaitGroup{} | ||
for i := range a.conf.PeerList { | ||
group.Add(1) | ||
peer := a.conf.PeerList[i] | ||
go func() { | ||
defer group.Done() | ||
peer.Ping = pingPort(peer.Addr, peer.Port) | ||
}() | ||
} | ||
group.Wait() | ||
} | ||
|
||
func (a *App) Status() *data.Status { | ||
status := data.Status{ | ||
Running: a.box != nil, | ||
GamePeer: a.gamePeer, | ||
HttpPeer: a.httpPeer, | ||
} | ||
|
||
counters, _ := net.IOCounters(true) | ||
for _, counter := range counters { | ||
if counter.Name == "utun225" { | ||
status.Up = counter.BytesSent | ||
status.Down = counter.BytesRecv | ||
} | ||
} | ||
return &status | ||
} | ||
|
||
func (a *App) List() []*config.Peer { | ||
return a.conf.PeerList | ||
} | ||
func (a *App) Add(token string) string { | ||
if a.conf.PeerList == nil { | ||
a.conf.PeerList = make([]*config.Peer, 0) | ||
} | ||
err, peer := config.ParsePeer(token) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
for _, p := range a.conf.PeerList { | ||
if p.Name == peer.Name { | ||
return fmt.Sprintf("peer %s already exists", peer.Name) | ||
} | ||
} | ||
a.conf.PeerList = append(a.conf.PeerList, peer) | ||
err = config.SaveConfig(a.conf) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
return "ok" | ||
} | ||
func (a *App) Del(Name string) string { | ||
for i, peer := range a.conf.PeerList { | ||
if peer.Name == Name { | ||
a.conf.PeerList = append(a.conf.PeerList[:i], a.conf.PeerList[i+1:]...) | ||
break | ||
} | ||
} | ||
err := config.SaveConfig(a.conf) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
return "ok" | ||
} | ||
func (a *App) SetPeer(game, http string) string { | ||
for _, peer := range a.conf.PeerList { | ||
if peer.Name == game { | ||
a.gamePeer = peer | ||
break | ||
} | ||
} | ||
for _, peer := range a.conf.PeerList { | ||
if peer.Name == http { | ||
a.httpPeer = peer | ||
break | ||
} | ||
} | ||
return "ok" | ||
} | ||
|
||
// Start 启动加速 | ||
func (a *App) Start() string { | ||
if a.box != nil { | ||
return "running" | ||
} | ||
var err error | ||
a.box, err = client.Client(a.gamePeer, a.httpPeer, a.processList) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
err = a.box.Start() | ||
if err != nil { | ||
return err.Error() | ||
} | ||
return "ok" | ||
} | ||
|
||
// Stop 停止加速 | ||
func (a *App) Stop() string { | ||
if a.box == nil { | ||
return "not running" | ||
} | ||
err := a.box.Close() | ||
if err != nil { | ||
return err.Error() | ||
} | ||
a.box = nil | ||
return "ok" | ||
} | ||
func pingPort(host string, port uint16) uint { | ||
tcPing := ping.NewTCPing() | ||
tcPing.SetTarget(&ping.Target{ | ||
Host: host, | ||
Port: int(port), | ||
Counter: 3, | ||
Interval: time.Millisecond * 200, | ||
Timeout: time.Second, | ||
}) | ||
start := tcPing.Start() | ||
<-start | ||
result := tcPing.Result() | ||
return uint(result.Avg().Milliseconds()) | ||
} | ||
func httpGet(url string) ([]byte, error) { | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
return io.ReadAll(resp.Body) | ||
} |
Oops, something went wrong.