From 3a0a622a8d526dd211a11121a087ea8858f41b74 Mon Sep 17 00:00:00 2001 From: gitsrc <34047788+gitsrc@users.noreply.github.com> Date: Sat, 16 Mar 2024 16:52:14 +0800 Subject: [PATCH] feat(project):change some desp Signed-off-by: gitsrc <34047788+gitsrc@users.noreply.github.com> --- ca/ca/signer/handler.go | 11 +++++----- client/internal/app.go | 13 ++++++------ client/internal/bll/b_client.go | 21 ++++++++++--------- client/internal/config/config.go | 6 +++--- client/internal/schema/s_client.go | 10 ++++----- client/internal/start.go | 7 ++++--- client/pkg/certificate/certificate.go | 2 +- client/pkg/web3/w3s/w3s.go | 6 +++--- fullnode/Makefile | 12 +++++------ fullnode/app/base/mdb/paginate.go | 8 +++---- fullnode/app/v1/access/controller/client.go | 16 +++++++------- fullnode/app/v1/access/controller/resource.go | 18 ++++++++-------- 12 files changed, 67 insertions(+), 63 deletions(-) diff --git a/ca/ca/signer/handler.go b/ca/ca/signer/handler.go index 578f976..445653f 100644 --- a/ca/ca/signer/handler.go +++ b/ca/ca/signer/handler.go @@ -2,6 +2,11 @@ package signer import ( "encoding/json" + "io/ioutil" + "math/big" + "net/http" + "time" + "github.com/flowshield/cfssl/api" "github.com/flowshield/cfssl/auth" "github.com/flowshield/cfssl/bundler" @@ -11,10 +16,6 @@ import ( "github.com/flowshield/cfssl/log" "github.com/flowshield/cfssl/signer" "github.com/flowshield/flowshield/ca/pkg/attrmgr" - "io/ioutil" - "math/big" - "net/http" - "time" ) // NoBundlerMessage is used to alert the user that the server does not have a bundler initialized. @@ -312,7 +313,7 @@ func (h *AuthHandler) Handle(w http.ResponseWriter, r *http.Request) error { return api.SendResponse(w, result) } -// 添加过期时间 +// Add expiration time func genExpiryByCsr(sr *signer.SignRequest, profile *config.SigningProfile) error { csr, err := helpers.ParseCSRPEM([]byte(sr.Request)) if err != nil { diff --git a/client/internal/app.go b/client/internal/app.go index fac888a..74ff827 100644 --- a/client/internal/app.go +++ b/client/internal/app.go @@ -3,14 +3,15 @@ package internal import ( "context" "crypto/tls" - "github.com/flowshield/flowshield/client/internal/config" - "github.com/flowshield/flowshield/client/pkg/logger" - "github.com/flowshield/flowshield/client/pkg/web3/w3s" "net/http" "os" "os/signal" "syscall" "time" + + "github.com/flowshield/flowshield/client/internal/config" + "github.com/flowshield/flowshield/client/pkg/logger" + "github.com/flowshield/flowshield/client/pkg/web3/w3s" ) type options struct { @@ -83,7 +84,7 @@ func InitHttpClient() { } } -// Run 运行服务 +// Run service func Run(ctx context.Context, opts ...Option) error { state := 1 sc := make(chan os.Signal, 1) @@ -96,7 +97,7 @@ func Run(ctx context.Context, opts ...Option) error { EXIT: for { sig := <-sc - logger.WithContext(ctx).Infof("接收到信号[%s]", sig.String()) + logger.WithContext(ctx).Infof("signal received[%s]", sig.String()) switch sig { case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT: state = 0 @@ -108,7 +109,7 @@ EXIT: } cleanFunc() - logger.WithContext(ctx).Infof("服务退出") + logger.WithContext(ctx).Infof("Service exit") time.Sleep(time.Second) os.Exit(state) return nil diff --git a/client/internal/bll/b_client.go b/client/internal/bll/b_client.go index 171d01a..0e06e4b 100644 --- a/client/internal/bll/b_client.go +++ b/client/internal/bll/b_client.go @@ -5,6 +5,12 @@ import ( "context" "crypto/tls" "crypto/x509" + "net" + "net/http" + "net/http/httputil" + "strconv" + "strings" + "github.com/flowshield/flowshield/client/internal/config" "github.com/flowshield/flowshield/client/internal/contextx" "github.com/flowshield/flowshield/client/internal/schema" @@ -13,11 +19,6 @@ import ( "github.com/flowshield/flowshield/client/pkg/recover" "github.com/flowshield/flowshield/client/pkg/util/trace" "github.com/xtaci/smux" - "net" - "net/http" - "net/http/httputil" - "strconv" - "strings" ) type Client struct{} @@ -77,14 +78,14 @@ func (a *Client) GetDialMtlsConfig(client *schema.ClientConfig) (*tls.Config, er if err != nil { return nil, err } - // 加载ca证书 + // Load ca certificate pool := x509.NewCertPool() pool.AppendCertsFromPEM([]byte(client.CaPem)) tlsc := &tls.Config{ MinVersion: tls.VersionTLS13, - Certificates: []tls.Certificate{cert}, // 客户端证书 - ServerName: client.Server.Host, // 服务端证书通用名称 - RootCAs: pool, // 服务器证书所属ca + Certificates: []tls.Certificate{cert}, // client certificate + ServerName: client.Server.Host, // Server certificate common name + RootCAs: pool, // The server certificate belongs to ca } return tlsc, err } @@ -127,7 +128,7 @@ func (a *Client) handleConn(ctx context.Context, clientConn net.Conn, client *sc return } defer serverConn.Close() - // 多路复用 + // Multiplexing //Setup client side of smux session, err := smux.Client(serverConn, nil) if err != nil { diff --git a/client/internal/config/config.go b/client/internal/config/config.go index ebec652..2c0779d 100644 --- a/client/internal/config/config.go +++ b/client/internal/config/config.go @@ -27,14 +27,14 @@ type I struct { HttpClient *http.Client } -// 读取内置配置文件并创建 +// Read the built-in configuration file and create func createConfigFile(path string) error { ok, err := util.PathExists(path) if err != nil { return err } if !ok { - f, err := os.Create(path) //创建文件 + f, err := os.Create(path) //create file if err != nil { return err } @@ -56,7 +56,7 @@ func createConfigFile(path string) error { func MustLoad(fpaths ...string) error { if len(fpaths) <= 0 || fpaths[0] == "" { fpaths[0] = "config.toml" - // 无配置文件,读取默认配置文件 + // No configuration file, read the default configuration file err := createConfigFile(fpaths[0]) if err != nil { return err diff --git a/client/internal/schema/s_client.go b/client/internal/schema/s_client.go index b1af5fd..90cc7e1 100644 --- a/client/internal/schema/s_client.go +++ b/client/internal/schema/s_client.go @@ -109,13 +109,13 @@ type ControlClient struct { ClientCid string `json:"client_cid"` } -// ToClientOrder 解析客户端配置 +// ToClientOrder func (a *ControlClient) ToClientOrder(ctx context.Context, key []byte) (*ClientConfig, error) { data, err := w3s.Get(ctx, a.ClientCid, a.Uuid, key) if err != nil { return nil, err } - // 解析w3s数据 + // Parse w3s data var result ClientConfig err = json.Unmarshal(data, &result) if err != nil { @@ -136,15 +136,15 @@ func (a *ControlClient) ToClientOrder(ctx context.Context, key []byte) (*ClientC result.CaPem = string(capem) result.CertPem = string(certpem) result.KeyPem = string(keypem) - // 解析证书attr + // Parse certificate attr certConfig, attr, err := certificate.LoadCert([]byte(result.CertPem)) if err != nil { return nil, err } if certConfig.Type != certificate.TypeClient { - return nil, fmt.Errorf("证书类型错误,预期:%s, get:%s", certificate.TypeClient, certConfig.Type) + return nil, fmt.Errorf("Wrong certificate type, expected:%s, get:%s", certificate.TypeClient, certConfig.Type) } - // 加载server 和target信息 + // Load server and target information _, err = result.LoadServerTarget(attr) if err != nil { return nil, err diff --git a/client/internal/start.go b/client/internal/start.go index e8bbcc8..f75e52a 100644 --- a/client/internal/start.go +++ b/client/internal/start.go @@ -4,13 +4,14 @@ import ( "bufio" "context" "fmt" + "time" + "github.com/flowshield/flowshield/client/internal/bll" "github.com/flowshield/flowshield/client/internal/config" "github.com/flowshield/flowshield/client/internal/schema" "github.com/flowshield/flowshield/client/pkg/errors" "github.com/flowshield/flowshield/client/pkg/logger" "github.com/flowshield/flowshield/client/pkg/util/json" - "time" "io/ioutil" "net/http" @@ -18,7 +19,7 @@ import ( "strconv" ) -// 登录状态 +// Login status type State int const ( @@ -69,7 +70,7 @@ func InitClientServer(ctx context.Context) { func (a *Up) ParseW3sData(ctx context.Context, order *schema.ControlClient) (*schema.ClientConfig, error) { cfg := config.C.Web3 - // 解析配置 + // Parse configuration tryCount := 0 retry: ctx, cancel := context.WithTimeout(ctx, time.Duration(cfg.W3S.Timeout)*time.Second) diff --git a/client/pkg/certificate/certificate.go b/client/pkg/certificate/certificate.go index 240c480..3333098 100644 --- a/client/pkg/certificate/certificate.go +++ b/client/pkg/certificate/certificate.go @@ -62,7 +62,7 @@ func LoadCert(certData []byte) (*BasicCertConf, []byte, error) { return basicConf, []byte(str), nil } -// 自签证书 +//self-signed certificate func InitSelfCert() error { max := new(big.Int).Lsh(big.NewInt(1), 128) serialNumber, err := rand.Int(rand.Reader, max) diff --git a/client/pkg/web3/w3s/w3s.go b/client/pkg/web3/w3s/w3s.go index b7fc7e8..91f9362 100644 --- a/client/pkg/web3/w3s/w3s.go +++ b/client/pkg/web3/w3s/w3s.go @@ -75,7 +75,7 @@ func GetByW3sLink(cid string, filename string, key []byte) ([]byte, error) { if err != nil { return nil, err } - data, err := goEncrypt.DesCbcDecrypt(body, key[:], nil) // 解密得到密文,可以自己传入初始化向量,如果不传就使用默认的初始化向量,8字节 + data, err := goEncrypt.DesCbcDecrypt(body, key[:], nil) // To decrypt the ciphertext, you can pass in the initialization vector yourself. If not, use the default initialization vector, which is 8 bytes. if err != nil { return nil, err } @@ -111,7 +111,7 @@ func GetByW3sClient(ctx context.Context, cidStr string, key []byte) (data []byte if err != nil { return nil, err } - data, err = goEncrypt.DesCbcDecrypt(data, key[:], nil) // 解密得到密文,可以自己传入初始化向量,如果不传就使用默认的初始化向量,8字节 + data, err = goEncrypt.DesCbcDecrypt(data, key[:], nil) // To decrypt the ciphertext, you can pass in the initialization vector yourself. If not, use the default initialization vector, which is 8 bytes. if err != nil { return nil, err } @@ -127,7 +127,7 @@ func dataToFile(data interface{}, filename string, key []byte) (file *os.File, e if err != nil { return } - // 对数据进行加密 + // Encrypt data cryptText, err := goEncrypt.DesCbcEncrypt(jsonByes, key[:], nil) if err != nil { return diff --git a/fullnode/Makefile b/fullnode/Makefile index dfb5f7d..40ecc28 100644 --- a/fullnode/Makefile +++ b/fullnode/Makefile @@ -5,19 +5,19 @@ PROG=bin/fullnode SRCS=. -# 安装目录 +# installation INSTALL_PREFIX=/usr/local/fullnode -# 配置安装的目录 +# Configure the installation directory CONF_INSTALL_PREFIX=/usr/local/fullnode # git commit hash COMMIT_HASH=$(shell git rev-parse --short HEAD || echo "GitNotFound") -# 编译日期 +# Compilation date BUILD_DATE=$(shell date '+%Y-%m-%d %H:%M:%S') -# 编译条件 +# Compilation conditions CFLAGS = -ldflags "-s -w -X \"main.BuildVersion=${COMMIT_HASH}\" -X \"main.BuildDate=$(BUILD_DATE)\"" all: @@ -26,14 +26,14 @@ all: fi GOPROXY=$(GOPROXY) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(CFLAGS) -o $(PROG) $(SRCS) -# 编译race版本 +# Compile race version race: if [ ! -d "./bin/" ]; then \ mkdir bin; \ fi go build $(CFLAGS) -race -o $(PROG) $(SRCS) -# release 版本 +# release version RELEASE_DATE = $(shell date '+%Y%m%d%H%M%S') RELEASE_VERSION = $(shell git rev-parse --short HEAD || echo "GitNotFound") RELEASE_DIR=release_bin diff --git a/fullnode/app/base/mdb/paginate.go b/fullnode/app/base/mdb/paginate.go index fc7834f..33eea79 100755 --- a/fullnode/app/base/mdb/paginate.go +++ b/fullnode/app/base/mdb/paginate.go @@ -1,14 +1,14 @@ package mdb type Paginate struct { - Page int `json:"page" form:"page,default=1"` // 分页号 - LimitNum int `json:"limit_num" form:"limit_num,default=10"` // 每页限制数量 - Offset int // 计算获取offset + Page int `json:"page" form:"page,default=1"` // page number + LimitNum int `json:"limit_num" form:"limit_num,default=10"` // limit number of page + Offset int // Calculate and obtain offset } func (p *Paginate) Init() { if p.LimitNum == 0 { - p.LimitNum = 10 // 默认一页10条 + p.LimitNum = 10 // Default is 10 items per page } if p.Page == 0 { p.Page = 1 diff --git a/fullnode/app/v1/access/controller/client.go b/fullnode/app/v1/access/controller/client.go index b4887e8..08a219e 100644 --- a/fullnode/app/v1/access/controller/client.go +++ b/fullnode/app/v1/access/controller/client.go @@ -9,7 +9,7 @@ import ( ) // @Summary ClientList -// @Description 获取ZTA的client +// @Description Get ZTA client // @Tags ZTA // @Produce json // @Success 200 {object} controller.Res @@ -26,11 +26,11 @@ func ClientList(c *gin.Context) { } // @Summary AddClient -// @Description 新增ZTA的client +// @Description Added ZTA client // @Tags ZTA // @Accept json // @Produce json -// @Param Client body mparam.AddClient true "新增ZTA的client" +// @Param Client body mparam.AddClient true "Added ZTA client" // @Success 200 {object} controller.Res // @Router /access/client [post] func AddClient(c *gin.Context) { @@ -45,11 +45,11 @@ func AddClient(c *gin.Context) { } //// @Summary EditClient -//// @Description 修改ZTA的client +//// @Description Modify ZTA client //// @Tags ZTA //// @Accept json //// @Produce json -//// @Param Client body mparam.EditClient true "修改ZTA的client" +//// @Param Client body mparam.EditClient true "Modify ZTA client" //// @Success 200 {object} controller.Res //// @Router /access/client [put] //func EditClient(c *gin.Context) { @@ -64,7 +64,7 @@ func AddClient(c *gin.Context) { //} // //// @Summary DelClient -//// @Description 删除ZTA的client +//// @Description Delete ZTA client //// @Tags ZTA //// @Produce json //// @Param uuid path string true "uuid" @@ -76,11 +76,11 @@ func AddClient(c *gin.Context) { //} // @Summary NotifyClient -// @Description 接收client订单状态改变的通知 +// @Description Receive notifications of client order status changes // @Tags ZTA // @Accept json // @Produce json -// @Param NotifyClient body mparam.NotifyClient true "接收client订单状态改变的通知" +// @Param NotifyClient body mparam.NotifyClient true "Receive notifications of client order status changes" // @Success 200 {object} controller.Res // @Router /access/client/notify [post] func NotifyClient(c *gin.Context) { diff --git a/fullnode/app/v1/access/controller/resource.go b/fullnode/app/v1/access/controller/resource.go index aebfcc6..b2af07f 100644 --- a/fullnode/app/v1/access/controller/resource.go +++ b/fullnode/app/v1/access/controller/resource.go @@ -14,7 +14,7 @@ import ( ) // @Summary ResourceList -// @Description 获取ZTA的resource +// @Description Get ZTA resources // @Tags ZTA // @Produce json // @Success 200 {object} controller.Res @@ -31,11 +31,11 @@ func ResourceList(c *gin.Context) { } // @Summary AddResource -// @Description 新增ZTA的resource +// @Description Added ZTA resources // @Tags ZTA // @Accept json // @Produce json -// @Param Resource body mparam.AddResource true "新增ZTA的resource" +// @Param Resource body mparam.AddResource true "Added ZTA resources" // @Success 200 {object} controller.Res // @Router /access/resource [post] func AddResource(c *gin.Context) { @@ -46,7 +46,7 @@ func AddResource(c *gin.Context) { return } if len(param.Type) > 0 && param.Type == "cidr" { - // 判断是不是纯IP格式 + // Determine whether it is pure IP format if strings.Contains(param.Host, "/") { if !util.IsCIDR(param.Host) { response.UtilResponseReturnJsonFailed(c, pconst.CODE_COMMON_PARAMS_INCOMPLETE) @@ -64,11 +64,11 @@ func AddResource(c *gin.Context) { } //// @Summary EditResource -//// @Description 修改ZTA的resource +//// @Description Modify ZTA resources //// @Tags ZTA //// @Accept json //// @Produce json -//// @Param Resource body mparam.EditResource true "修改ZTA的resource" +//// @Param Resource body mparam.EditResource true "Modify ZTA resources" //// @Success 200 {object} controller.Res //// @Router /access/resource [put] //func EditResource(c *gin.Context) { @@ -79,7 +79,7 @@ func AddResource(c *gin.Context) { // return // } // if len(param.Type) > 0 && param.Type == "cidr" { -// // 判断是不是纯IP格式 +// // Determine whether it is pure IP format // if strings.Contains(param.Host, "/") { // if !util.IsCIDR(param.Host) { // response.UtilResponseReturnJsonFailed(c, pconst.CODE_COMMON_PARAMS_INCOMPLETE) @@ -97,10 +97,10 @@ func AddResource(c *gin.Context) { //} // @Summary DelResource -// @Description 删除ZTA的resource +// @Description Delete ZTA resources // @Tags ZTA // @Produce json -// @Param id path int true "主键ID" +// @Param id path int true "Primary key ID" // @Success 200 {object} controller.Res // @Router /access/resource/{uuid} [delete] func DelResource(c *gin.Context) {