Skip to content

Commit

Permalink
fix: ci && structure changes (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
DVKunion committed Apr 17, 2024
1 parent 36afac7 commit e933b3f
Show file tree
Hide file tree
Showing 35 changed files with 62 additions and 65 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ jobs:
docker.io/dvkunion/seamoon:${{github.ref_name}}
build-args: |
VERSION=${{github.ref_name}}
SHA=${{github.sha}}
context: ./
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re
apk add tor && \
echo -e "RunAsDaemon 1\n\nAssumeReachable 1\n\nLog notice file /var/log/tor/tor.log" > /etc/tor/torrc &&\
chmod +x /app/entrypoint.sh && chmod +x /app/seamoon
EXPOSE 1080 8080 7777 9000
EXPOSE 1080 8000 8080 7777 9000
ENTRYPOINT ["/app/entrypoint.sh"]
5 changes: 0 additions & 5 deletions cmd/client/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import (

"github.com/DVKunion/SeaMoon/pkg/api/controller/middleware"
api_v1 "github.com/DVKunion/SeaMoon/pkg/api/controller/v1"
"github.com/DVKunion/SeaMoon/pkg/api/database/drivers"
)

func init() {
drivers.Init()
}

func Register(router *gin.Engine, debug bool) {
var middles = make([]gin.HandlerFunc, 0)

Expand Down
9 changes: 5 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ var (
}

proxyCommand = &cobra.Command{
Use: "proxy",
Short: "SeaMoon proxy mod",
Run: Proxy,
Use: "client",
Short: "SeaMoon client mod",
Run: Client,
}

generateCommand = &cobra.Command{
Expand All @@ -49,7 +49,8 @@ var (
}
)

func Proxy(cmd *cobra.Command, args []string) {
func Client(cmd *cobra.Command, args []string) {
drivers.Init()
client.Serve(cmd.Context(), debug)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/signal/handler_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/DVKunion/SeaMoon/pkg/api/enum"
"github.com/DVKunion/SeaMoon/pkg/api/models"
"github.com/DVKunion/SeaMoon/pkg/api/service"
"github.com/DVKunion/SeaMoon/pkg/listener"
"github.com/DVKunion/SeaMoon/pkg/network/listener"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/network/addr.go → pkg/network/basic/addr.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package basic

import (
"encoding/binary"
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/auth.go → pkg/network/basic/auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package basic

import (
"crypto/subtle"
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/buffer.go → pkg/network/basic/buffer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package basic

// fork from go-gost/core

Expand Down
2 changes: 1 addition & 1 deletion pkg/network/socks5.go → pkg/network/basic/socks5.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package basic

// This file is modified version from https://github.com/ginuerzh/gosocks5/blob/master/socks5.go

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package basic

import (
"io"
Expand Down
8 changes: 4 additions & 4 deletions pkg/listener/tcp.go → pkg/network/listener/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/DVKunion/SeaMoon/pkg/api/enum"
"github.com/DVKunion/SeaMoon/pkg/api/models"
db_service "github.com/DVKunion/SeaMoon/pkg/api/service"
"github.com/DVKunion/SeaMoon/pkg/network"
"github.com/DVKunion/SeaMoon/pkg/network/basic"
"github.com/DVKunion/SeaMoon/pkg/network/transfer"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel/service"
"github.com/DVKunion/SeaMoon/pkg/system/errors"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
"github.com/DVKunion/SeaMoon/pkg/transfer"
"github.com/DVKunion/SeaMoon/pkg/tunnel/service"
)

func TCPListen(ctx context.Context, py *models.Proxy) (net.Listener, error) {
Expand Down Expand Up @@ -57,7 +57,7 @@ func listen(ctx context.Context, server net.Listener, id uint, t *enum.ProxyType
continue
}
go func() {
in, out, err := network.Transport(conn, destConn)
in, out, err := basic.Transport(conn, destConn)
if err != nil {
xlog.Error(xlog.NetworkTransportError, "err", err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/transfer/auto.go → pkg/network/transfer/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import (
"bufio"
"net"

"github.com/DVKunion/SeaMoon/pkg/network"
"github.com/DVKunion/SeaMoon/pkg/network/basic"
)

// AutoTransport 自适应解析 http / socks
func AutoTransport(conn net.Conn) error {
br := &network.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
br := &basic.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
b, err := br.Peek(1)

if err != nil || b[0] != network.SOCKS5Version {
if err != nil || b[0] != basic.SOCKS5Version {
return HttpTransport(br)
}

return Socks5Transport(br, true)
}

func AutoTransportV2ray(conn net.Conn) error {
br := &network.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
br := &basic.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
b, err := br.Peek(1)

if err != nil || b[0] != network.SOCKS5Version {
if err != nil || b[0] != basic.SOCKS5Version {
return V2rayTransport(br, "http")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/transfer/http.go → pkg/network/transfer/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net"
"net/http"

"github.com/DVKunion/SeaMoon/pkg/network"
"github.com/DVKunion/SeaMoon/pkg/network/basic"
)

type HttpTransfer struct {
Expand Down Expand Up @@ -64,7 +64,7 @@ func HttpTransport(conn net.Conn) error {
}

// 同时处理客户端到服务器和服务器到客户端的数据传输
if _, _, err := network.Transport(destConn, conn); err != nil {
if _, _, err := basic.Transport(destConn, conn); err != nil {
return err
}

Expand Down
28 changes: 14 additions & 14 deletions pkg/transfer/socks5.go → pkg/network/transfer/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"net"
"time"

"github.com/DVKunion/SeaMoon/pkg/network"
"github.com/DVKunion/SeaMoon/pkg/network/basic"
"github.com/DVKunion/SeaMoon/pkg/system/errors"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
)

func Socks5Check(conn net.Conn) (net.Conn, error) {
br := &network.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
br := &basic.BufferedConn{Conn: conn, Br: bufio.NewReader(conn)}
b, err := br.Peek(1)

if err != nil || b[0] != network.SOCKS5Version {
if err != nil || b[0] != basic.SOCKS5Version {
return nil, errors.Wrap(err, xlog.ServiceProtocolNotSupportError)
}
return br, nil
Expand All @@ -31,27 +31,27 @@ func Socks5Transport(conn net.Conn, check bool) error {
// todo AUTH

// select method
if _, err = network.ReadMethods(conn); err != nil {
if _, err = basic.ReadMethods(conn); err != nil {
return errors.Wrap(err, xlog.ServiceSocks5ReadMethodError)
}

if err = network.WriteMethod(network.MethodNoAuth, conn); err != nil {
if err = basic.WriteMethod(basic.MethodNoAuth, conn); err != nil {
return errors.Wrap(err, xlog.ServiceSocks5WriteMethodError)
}

// read command
request, err := network.ReadSOCKS5Request(conn)
request, err := basic.ReadSOCKS5Request(conn)
if err != nil {
return errors.Wrap(err, xlog.ServiceSocks5ReadCmdError)
}
switch request.Cmd {
case network.SOCKS5CmdConnect:
case basic.SOCKS5CmdConnect:
handleConnect(conn, request)
case network.SOCKS5CmdBind:
case basic.SOCKS5CmdBind:
// todo: support cmd bind
xlog.Debug("unexpect not support cmd bind")
handleBind(conn, request)
case network.SOCKS5CmdUDPOverTCP:
case basic.SOCKS5CmdUDPOverTCP:
// todo: support upd proxy
xlog.Debug("unexpect not support upd")
handleUDPOverTCP(conn, request)
Expand All @@ -60,7 +60,7 @@ func Socks5Transport(conn net.Conn, check bool) error {
return nil
}

func handleConnect(conn net.Conn, req *network.SOCKS5Request) {
func handleConnect(conn net.Conn, req *basic.SOCKS5Request) {
xlog.Info(xlog.ServiceSocks5ConnectServer, "src", conn.RemoteAddr(), "dest", req.Addr)
// default socks timeout : 10
dialer := net.Dialer{Timeout: 10 * time.Second}
Expand All @@ -74,24 +74,24 @@ func handleConnect(conn net.Conn, req *network.SOCKS5Request) {
// if utils.Transport get out , then close conn of remote
defer destConn.Close()

if err := network.NewReply(network.SOCKS5RespSucceeded, nil).Write(conn); err != nil {
if err := basic.NewReply(basic.SOCKS5RespSucceeded, nil).Write(conn); err != nil {
xlog.Error(xlog.ServiceSocks5ReplyError, "err", err)
return
}

xlog.Info(xlog.ServiceSocks5Establish, "src", conn.RemoteAddr(), "dest", req.Addr)

if _, _, err := network.Transport(conn, destConn); err != nil {
if _, _, err := basic.Transport(conn, destConn); err != nil {
xlog.Error(xlog.NetworkTransportError, "err", err)
}

xlog.Info(xlog.ServiceSocks5DisConnect, "src", conn.RemoteAddr(), "dest", req.Addr)
}

func handleBind(conn net.Conn, req *network.SOCKS5Request) {
func handleBind(conn net.Conn, req *basic.SOCKS5Request) {
// TODO
}

func handleUDPOverTCP(conn net.Conn, req *network.SOCKS5Request) {
func handleUDPOverTCP(conn net.Conn, req *basic.SOCKS5Request) {
// TODO
}
4 changes: 2 additions & 2 deletions pkg/transfer/tor.go → pkg/network/transfer/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"time"

"github.com/DVKunion/SeaMoon/pkg/network"
"github.com/DVKunion/SeaMoon/pkg/network/basic"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
)

Expand All @@ -23,7 +23,7 @@ func TorTransport(conn net.Conn) error {

xlog.Info(xlog.ServiceTorConnectServer, "src", conn.RemoteAddr(), "dest", defaultTorAddr)

if _, _, err := network.Transport(conn, destConn); err != nil {
if _, _, err := basic.Transport(conn, destConn); err != nil {
xlog.Error(xlog.NetworkTransportError, "err", err)
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pkg/tunnel/grpc.go → pkg/network/tunnel/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"google.golang.org/grpc"

proto2 "github.com/DVKunion/SeaMoon/pkg/tunnel/service/proto"
proto2 "github.com/DVKunion/SeaMoon/pkg/network/tunnel/service/proto"
)

type grpcConn struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"google.golang.org/grpc/keepalive"

"github.com/DVKunion/SeaMoon/pkg/api/enum"
"github.com/DVKunion/SeaMoon/pkg/network/transfer"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel/service/proto"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel/service/proto/gost"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
"github.com/DVKunion/SeaMoon/pkg/transfer"
"github.com/DVKunion/SeaMoon/pkg/tunnel"
"github.com/DVKunion/SeaMoon/pkg/tunnel/service/proto"
"github.com/DVKunion/SeaMoon/pkg/tunnel/service/proto/gost"
)

type GRPCService struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/DVKunion/SeaMoon/pkg/api/enum"
"github.com/DVKunion/SeaMoon/pkg/tunnel"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel"
)

type Service interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/gorilla/websocket"

"github.com/DVKunion/SeaMoon/pkg/api/enum"
"github.com/DVKunion/SeaMoon/pkg/network/transfer"
"github.com/DVKunion/SeaMoon/pkg/network/tunnel"
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
"github.com/DVKunion/SeaMoon/pkg/transfer"
"github.com/DVKunion/SeaMoon/pkg/tunnel"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions pkg/sdk/aliyun/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ var (
type SDK struct {
}

type Resp struct {
StatusCode int `json:"statusCode"`
Headers map[string]interface{} `json:"headers"`
Body struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Data map[string]interface{} `json:"Data"`
} `json:"body"`
}

func (a *SDK) Auth(ca *models.CloudAuth, region string) (*models.ProviderInfo, error) {
amount, err := getBilling(ca)
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion pkg/sdk/aliyun/aliyun_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ import (
"github.com/DVKunion/SeaMoon/pkg/system/xlog"
)

type resp struct {
StatusCode int `json:"statusCode"`
Headers map[string]interface{} `json:"headers"`
Body struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Data map[string]interface{} `json:"Data"`
} `json:"body"`
}

func getBilling(ca *models.CloudAuth) (float64, error) {
config := &openapi.Config{
// 必填,您的 AccessKey ID
Expand Down Expand Up @@ -63,7 +75,7 @@ func getBilling(ca *models.CloudAuth) (float64, error) {
if err != nil {
return 0, err
}
var r Resp
var r resp
err = json.Unmarshal(bs, &r)
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CloudSDK interface {
// SyncFC 同步函数
SyncFC(ca *models.CloudAuth, regions []string) (models.TunnelCreateApiList, error)

// UpdateVersion 一键更新: 用本地的版本号请求远端服务更新至
// UpdateVersion 一键更新: 用本地的版本号请求远端服务更新至客户端版本
// UpdateVersion(auth models.CloudAuth) error
}

Expand Down

0 comments on commit e933b3f

Please sign in to comment.