mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	节点获取配置时进行压缩传输,至少减少80%的传输带宽
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,11 +4,11 @@ go 1.15
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
replace github.com/TeaOSLab/EdgeCommon => ../EdgeCommon
 | 
					replace github.com/TeaOSLab/EdgeCommon => ../EdgeCommon
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
 | 
						github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
 | 
				
			||||||
	github.com/TeaOSLab/EdgeCommon v0.0.0-00010101000000-000000000000
 | 
						github.com/TeaOSLab/EdgeCommon v0.0.0-00010101000000-000000000000
 | 
				
			||||||
	github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183
 | 
						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/cespare/xxhash/v2 v2.1.1
 | 
				
			||||||
	github.com/go-acme/lego/v4 v4.5.2
 | 
						github.com/go-acme/lego/v4 v4.5.2
 | 
				
			||||||
	github.com/go-ole/go-ole v1.2.4 // indirect
 | 
						github.com/go-ole/go-ole v1.2.4 // indirect
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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/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 h1:dkj8/dxOQ4L1XpwCzRLqukvUBbxuNdz3FeyvHFnRjmo=
 | 
				
			||||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1183/go.mod h1:pUKYbK5JQ+1Dfxk80P0qxGqe5dkxDoabbZS7zOcouyA=
 | 
					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/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-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=
 | 
					github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package services
 | 
					package services
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
						"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
				
			||||||
@@ -14,6 +15,7 @@ import (
 | 
				
			|||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
						"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
				
			||||||
 | 
						"github.com/andybalholm/brotli"
 | 
				
			||||||
	"github.com/iwind/TeaGo/logs"
 | 
						"github.com/iwind/TeaGo/logs"
 | 
				
			||||||
	"github.com/iwind/TeaGo/types"
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
	stringutil "github.com/iwind/TeaGo/utils/string"
 | 
						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 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 更新节点状态
 | 
					// UpdateNodeStatus 更新节点状态
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user