Skip to content

Commit

Permalink
temp: save code
Browse files Browse the repository at this point in the history
  • Loading branch information
DVKunion committed Sep 9, 2024
1 parent 74ec02f commit 70d8b71
Show file tree
Hide file tree
Showing 144 changed files with 3,804 additions and 5,651 deletions.
8 changes: 1 addition & 7 deletions .github/ISSUE_TEMPLATE/bug--系统出现异常.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ assignees: DVKunion
**问题描述**


**如何复现**
复现步骤如下:
1. xxxxxx
2. xxxxxx
3. xxxxxx
4. xxxxxxx
**复现步骤**

**预期的结果**

**截图**
注意隐私信息

**其他信息**
+ Seamoon版本:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22
id: go
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
Expand Down
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# CHANGELOG

## SeaMoon 2.1.0

这个版本开始,seamoon 不再追求过于底层的网络思考了。开始回归初心,接入 + 适配常用且有用的工具了。

网络层的架构从原本的手写协议,经过多个模块的参考和历史的一些故事,最终还是选择了 xray-core 作为了 seamoon 的网络层核心。不再花过多的时间去适配各种各样的协议和手写加解密相关、线程并发相关的东西了。

开发确实是一门艺术,需要深练更多的基本功才行,现阶段作者的代码能力完全不及成熟的网络工具,对 buffer 的操作和把控很容易出各种问题。

因此,最终还是舍弃了原始的网络层字节操作,直接引入应用级别的依赖,来解决和实现需要去做的事情。

不过 seamoon 的定位一开始就是:"月出于云而引于海", 所以后续将引入更多的工具类型的代码进来,更多的去实现场景和应用需求。 不再挖过于底层的东西了,收益过低且能力不足 QAQ。

当然,手写网络层的这段历史的版本加固了对网络协议和 tcp 的理解,对于个人而言,收益还是很大的。只是不再适合这个产品了。

## SeaMoon 2.0.1

2.0.1 主要解决腾讯云的更新问题,以及一些其他的小修复

## ❤️ What's New
* 🔧 fix: 修正了 ci 打包时没有带上 commit 信息的问题
* 🔧 fix:修正了一处编译错误
* 🔧 fix:修复腾讯云弃用 api_gw 导致的触发器失败问题
* 📝 chore:license 更新

### What's Changed
* 99adf1a fix: change tecent api_gw to http sfc url (#92)
* e933b3f fix: ci && structure changes (#85)
* 6910fe3 fix: compile error (#86)

**Full Changelog**: https://github.com/DVKunion/SeaMoon/compare/2.0.0...2.0.1

## SeaMoon 2.0.0

2.0.0 版本终于算是完成了一个小的里程碑,打出来第一个版本,在稳定性和使用上可能还是有一定的问题,预计在几个版本内实现fix。
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Serverless 的动态实例不同的出口IP,从而获取到了干净(非威胁
| Vmess | []() |||
| Vless | []() |||
| shadowsocks | []() |||
|

**网络隧道**

Expand All @@ -57,6 +58,12 @@ Serverless 的动态实例不同的出口IP,从而获取到了干净(非威胁
| grpc | []() ||
| oss | []() | 🐷调研中 |


**代理模式**
+ 正向代理
+ 反向代理
+ 端口转发

**其他**

+ 💻 多客户端支持,clash/shadowrocket 等。
Expand Down Expand Up @@ -105,9 +112,3 @@ Serverless 的动态实例不同的出口IP,从而获取到了干净(非威胁
本工具仅用于学习serverless以及云原生相关技术,请勿用于其他用途。

如您在使用本工具的过程中存在任何非法行为,您需自行承担相应后果,我们将不承担任何法律及连带责任。

## ✨ CTStack

<img src="https://ctstack-oss.oss-cn-beijing.aliyuncs.com/CT%20Stack-2.png" width="30%" />

SeaMoon 现已加入 [CTStack](https://stack.chaitin.com/tool/detail?id=186) 社区
50 changes: 47 additions & 3 deletions cmd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ import (
"github.com/DVKunion/SeaMoon/cmd/client/static"
"github.com/DVKunion/SeaMoon/pkg/api/service"
"github.com/DVKunion/SeaMoon/pkg/api/signal"
"github.com/DVKunion/SeaMoon/pkg/system/errors"
"github.com/DVKunion/SeaMoon/pkg/system/version"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
"github.com/DVKunion/SeaMoon/plugins/xray"
"github.com/DVKunion/SeaMoon/plugins/xray/config"

_ "github.com/xtls/xray-core/main/distro/all"
)

func Serve(ctx context.Context, debug bool) {
// Signal 异步服务
runSignal(ctx)
// Xray API 服务
runXray()
// Restful API 服务
runApi(ctx, debug)
}
Expand All @@ -38,6 +45,43 @@ func runSignal(ctx context.Context) {
signal.Signal().Recover(ctx, rec.Value)
}

func runXray() {
xServe, err := xray.StartServer(
// 日志
config.WithLogs("Debug"),
// 策略
config.WithDefaultPolicy(),
// 开启 API 控制
config.WithApiConfig(),
// 开启默认出站:freedom
config.WithFreedomOutbound(),
// 开启 流量统计
config.WithInboundCalculate(),
config.WithOutboundCalculate(),
)
if err != nil {
xlog.Error("xray failed to start", "err", err.Error())
// Configuration error. Exit with a special value to prevent systemd from restarting.
return
}
// copy
if err := xServe.Start(); err != nil {
xlog.Error("xray failed to start", "err", err.Error())
return
}
//defer xServe.Close()

/*
conf.FileCache = nil
conf.IPCache = nil
conf.SiteCache = nil
*/

//// Explicitly triggering GC to remove garbage from config loading.
//runtime.GC()
//debug.FreeOSMemory()
}

func runApi(ctx context.Context, debug bool) {
logPath, err := service.SVC.GetConfigByName(ctx, "control_log")
addr, err := service.SVC.GetConfigByName(ctx, "control_addr")
Expand All @@ -51,9 +95,9 @@ func runApi(ctx context.Context, debug bool) {

webLogger, err := os.OpenFile(logPath.Value, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
gin.DefaultWriter = io.MultiWriter(xlog.Logger())
gin.DefaultWriter = io.MultiWriter(xlog.GetLogger())
} else {
gin.DefaultWriter = io.MultiWriter(xlog.Logger(), webLogger)
gin.DefaultWriter = io.MultiWriter(xlog.GetLogger(), webLogger)
}

server := gin.Default()
Expand All @@ -70,7 +114,7 @@ func runApi(ctx context.Context, debug bool) {
c.FileFromFS(c.Request.URL.Path, http.FS(subFS))
})

if err := server.Run(strings.Join([]string{addr.Value, port.Value}, ":")); err != http.ErrServerClosed {
if err := server.Run(strings.Join([]string{addr.Value, port.Value}, ":")); !errors.Is(err, http.ErrServerClosed) {
xlog.Error(xlog.ApiServeError, "err", err)
}
}
43 changes: 27 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/DVKunion/SeaMoon/cmd/client"
"github.com/DVKunion/SeaMoon/cmd/server"
"github.com/DVKunion/SeaMoon/pkg/api/database/drivers"
"github.com/DVKunion/SeaMoon/pkg/api/service"
"github.com/DVKunion/SeaMoon/pkg/system/version"
)

Expand All @@ -25,7 +26,7 @@ var (
serverCommand = &cobra.Command{
Use: "server",
Short: "SeaMoon server mod",
RunE: Server,
RunE: serve,
}

clientCommand = &cobra.Command{
Expand All @@ -36,13 +37,23 @@ var (
clientWebCommand = &cobra.Command{
Use: "web",
Short: "SeaMoon client web mod",
Run: Client,
Run: webClient,
}

clientCliCommand = &cobra.Command{
Use: "cli",
Short: "SeaMoon client cli mod",
Run: cliClient,
}

generateCommand = &cobra.Command{
Use: "generate",
Short: "SeaMoon generate devs code",
RunE: drivers.Drive().Generate,
RunE: func(cmd *cobra.Command, args []string) error {
service.Init()
drivers.Init()
return drivers.Drive().Generate()
},
}

versionCommand = &cobra.Command{
Expand All @@ -52,35 +63,34 @@ var (
fmt.Println("SeaMoon Powered By DVK")
fmt.Printf("Version: %s\n", version.Version)
fmt.Printf("Commit: %s\n", version.Commit)
fmt.Printf("V2rayCoreVersion: %s\n", version.V2rayCoreVersion)
fmt.Printf("XrayVersion: %s\n", version.XrayVersion)
},
}
)

func Client(cmd *cobra.Command, args []string) {
func webClient(cmd *cobra.Command, args []string) {
// 先初始化 db 服务
service.Init()
// 初始化 db
drivers.Init()
client.Serve(cmd.Context(), debug)
}

func Server(cmd *cobra.Command, args []string) error {
s, err := server.New(
server.WithHost("0.0.0.0"),
server.WithPort(port),
server.WithProto(proto),
)

if err != nil {
return err
}
// sometimes we just want a simple cli tools
func cliClient(cmd *cobra.Command, args []string) {
// todo
}

return s.Serve(cmd.Context())
func serve(cmd *cobra.Command, args []string) error {
return server.Serve(cmd.Context(), "")
}

func init() {
clientWebCommand.Flags().BoolVarP(&debug, "debug", "d", false, "proxy detail log")

serverCommand.Flags().StringVarP(&addr, "addr", "a", "0.0.0.0", "server listen addr")
serverCommand.Flags().StringVarP(&port, "port", "p", "9000", "server listen port")

serverCommand.Flags().StringVarP(&proto, "proto", "t", "websocket", "server listen proto: (websocket/grpc)")

rootCommand.AddCommand(versionCommand)
Expand All @@ -89,6 +99,7 @@ func init() {
rootCommand.AddCommand(generateCommand)

clientCommand.AddCommand(clientWebCommand)
clientCommand.AddCommand(clientCliCommand)
}

func main() {
Expand Down
47 changes: 0 additions & 47 deletions cmd/server/options.go

This file was deleted.

Loading

0 comments on commit 70d8b71

Please sign in to comment.