Skip to content

Commit

Permalink
feat(project):change some desp
Browse files Browse the repository at this point in the history
Signed-off-by: gitsrc <[email protected]>
  • Loading branch information
gitsrc committed Mar 16, 2024
1 parent 5ce873f commit 3a0a622
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 63 deletions.
11 changes: 6 additions & 5 deletions ca/ca/signer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions client/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions client/internal/bll/b_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions client/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions client/internal/schema/s_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions client/internal/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ 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"
"os"
"strconv"
)

// 登录状态
// Login status
type State int

const (
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion client/pkg/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions client/pkg/web3/w3s/w3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions fullnode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand 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
Expand Down
8 changes: 4 additions & 4 deletions fullnode/app/base/mdb/paginate.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions fullnode/app/v1/access/controller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// @Summary ClientList
// @Description 获取ZTA的client
// @Description Get ZTA client
// @Tags ZTA
// @Produce json
// @Success 200 {object} controller.Res
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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"
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 3a0a622

Please sign in to comment.