diff --git a/go.mod b/go.mod index c3e8c685..8a91fcd2 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,11 @@ go 1.15 replace github.com/TeaOSLab/EdgeCommon => ../EdgeCommon - require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/TeaOSLab/EdgeCommon v0.0.0-00010101000000-000000000000 github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183 + github.com/andybalholm/brotli v1.0.4 github.com/cespare/xxhash/v2 v2.1.1 github.com/go-acme/lego/v4 v4.5.2 github.com/go-ole/go-ole v1.2.4 // indirect diff --git a/go.sum b/go.sum index 5cec0d5c..89224e2e 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183 h1:dkj8/dxOQ4L1XpwCzRLqukvUBbxuNdz3FeyvHFnRjmo= github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183/go.mod h1:pUKYbK5JQ+1Dfxk80P0qxGqe5dkxDoabbZS7zOcouyA= +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= diff --git a/internal/rpc/services/service_node.go b/internal/rpc/services/service_node.go index a1eb56da..50d9066a 100644 --- a/internal/rpc/services/service_node.go +++ b/internal/rpc/services/service_node.go @@ -1,6 +1,7 @@ package services import ( + "bytes" "context" "encoding/json" "github.com/TeaOSLab/EdgeAPI/internal/db/models" @@ -14,6 +15,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + "github.com/andybalholm/brotli" "github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/types" stringutil "github.com/iwind/TeaGo/utils/string" @@ -631,7 +633,29 @@ func (this *NodeService) FindCurrentNodeConfig(ctx context.Context, req *pb.Find return nil, err } - return &pb.FindCurrentNodeConfigResponse{IsChanged: true, NodeJSON: data}, nil + var isCompressed = false + if req.Compress { + var buf = &bytes.Buffer{} + writer := brotli.NewWriterLevel(buf, 5) + _, err = writer.Write(data) + if err != nil { + _ = writer.Close() + } else { + err = writer.Close() + if err == nil { + isCompressed = true + data = buf.Bytes() + buf.Reset() + } + } + } + + return &pb.FindCurrentNodeConfigResponse{ + IsChanged: true, + NodeJSON: data, + DataSize: int64(len(data)), + IsCompressed: isCompressed, + }, nil } // UpdateNodeStatus 更新节点状态