Compare commits

..

30 Commits

Author SHA1 Message Date
刘祥超
b0d1f2c8ea 版本号修改为1.3.9 2024-05-20 09:51:19 +08:00
刘祥超
94de773773 修改copyright 2024-05-17 18:30:33 +08:00
刘祥超
da8d7f1437 设置文件句柄最大缓存为65535 2024-05-16 20:40:41 +08:00
刘祥超
777bbdf50b 优化代码 2024-05-11 09:23:54 +08:00
刘祥超
f5596b4f0c 增加edge-node top命令,用来调用系统的top命令并传入edge-node进程ID 2024-05-08 19:42:55 +08:00
刘祥超
480d165538 WAF区域封禁增加“允许搜索引擎”选项 2024-05-08 17:52:20 +08:00
刘祥超
870d18a5ac 搜索引擎识别增加facebook 2024-05-08 17:18:48 +08:00
刘祥超
731f213310 WAF规则集中增加“允许搜索引擎”选项,可以快速允许搜索引擎访问 2024-05-08 16:45:28 +08:00
刘祥超
f1b3a7463d 优化ttlcache相关代码 2024-05-08 11:10:56 +08:00
刘祥超
5020985b96 KV缓存索引增加内存缓存 2024-05-08 10:57:36 +08:00
刘祥超
a0ac33af5a Partial Content新创建时不对比Content-MD5 2024-05-08 10:30:47 +08:00
刘祥超
ffe3f248a9 Partial Content每次写入缓存时都检查Content-MD5是否一致 2024-05-07 20:15:47 +08:00
刘祥超
02dc42d8e0 缓存策略增加“允许读取不完整的Partial Content”选项 2024-05-07 20:06:06 +08:00
刘祥超
b68d92d506 上传IP增加失败重试 2024-05-07 17:55:28 +08:00
刘祥超
1144ca8a8b Partial Content从源站读取数据时验证本地缓存的Content-MD5是否一致 2024-05-07 17:27:10 +08:00
刘祥超
0b216090f1 修复修改后的Partial Content Range范围多1字节的问题 2024-05-07 16:32:53 +08:00
刘祥超
b1e609b2b4 优化一处注释 2024-05-07 16:21:43 +08:00
刘祥超
8de74b62e7 优化Partial Content内容缓存,现在可以使用“部分文件缓存+部分回源”的方式提供内容 2024-05-07 16:20:22 +08:00
刘祥超
02da06dffd WAF增加“请求报头最大长度”参数 2024-05-06 21:06:55 +08:00
刘祥超
bd417a3795 网站全局设置中增加“XFF中最多地址数”选项 2024-05-06 14:05:12 +08:00
刘祥超
42e1e0c3df 再次提升节点默认读写线程数限制 2024-05-05 22:12:28 +08:00
刘祥超
216dacc348 IP名单优化
* 增加IP灰名单,用于仅记录并观察IP
* 优化IP名单同步版本号管理
* WAF记录IP动作优先记录到网站和策略相关的IP名单中
2024-05-05 19:10:46 +08:00
刘祥超
968eac6046 增加默认的并发读写线程数 2024-05-03 18:03:15 +08:00
刘祥超
9a3740dc00 自动安装nftables时尝试使用apt-get 2024-05-03 15:51:08 +08:00
刘祥超
ef1626de53 优化代码 2024-05-03 15:31:40 +08:00
刘祥超
5eb122f0a3 UDP连接也检查IP名单 2024-05-03 15:11:54 +08:00
刘祥超
6e2c5aabc2 自定义页面增加是否“启用系统自定义页面”选项 2024-05-03 11:22:50 +08:00
刘祥超
1a1ae239b3 版本号修改为1.3.8.2 2024-05-03 11:22:16 +08:00
刘祥超
95f42ebd37 如果已经有足够的硬盘写入速度测试数据,则不再执行测试 2024-05-02 11:49:51 +08:00
刘祥超
7111d23f11 edge-node accesslog命令输出增加发送内容字节数、请求来源、请求UserAgent 2024-05-01 19:29:07 +08:00
389 changed files with 1438 additions and 734 deletions

View File

@@ -9,6 +9,7 @@ import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/nodes"
"github.com/TeaOSLab/EdgeNode/internal/utils"
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
@@ -22,8 +23,10 @@ import (
_ "net/http/pprof"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"syscall"
"time"
)
@@ -31,7 +34,7 @@ func main() {
var app = apps.NewAppCmd().
Version(teaconst.Version).
Product(teaconst.ProductName).
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|config|pprof|accesslog|uninstall]").
Usage(teaconst.ProcessName + " [-v|start|stop|restart|status|quit|test|reload|service|daemon|config|pprof|top|accesslog|uninstall]").
Usage(teaconst.ProcessName + " [trackers|goman|conns|gc|bandwidth|disk|cache.garbage]").
Usage(teaconst.ProcessName + " [ip.drop|ip.reject|ip.remove|ip.close] IP")
@@ -552,7 +555,7 @@ func main() {
return
}
err = os.WriteFile(Tea.Root + "/configs/api_node.yaml", configYAML, 0666)
err = os.WriteFile(Tea.Root+"/configs/api_node.yaml", configYAML, 0666)
if err != nil {
fmt.Println("[ERROR]write config failed: " + err.Error())
return
@@ -560,6 +563,37 @@ func main() {
fmt.Println("success")
})
app.On("top", func() {
var sock = gosock.NewTmpSock(teaconst.ProcessName)
reply, err := sock.Send(&gosock.Command{Code: "pid"})
if err != nil {
fmt.Println("[ERROR]not started yet")
return
}
var pid = maps.NewMap(reply.Params).GetInt("pid")
if pid <= 0 {
fmt.Println("[ERROR]invalid pid '" + types.String(pid) + "'")
return
}
topExe, _ := executils.LookPath("top")
if len(topExe) > 0 {
if runtime.GOOS == "linux" {
err = syscall.Exec(topExe, []string{topExe, "-p", types.String(pid)}, os.Environ())
} else if runtime.GOOS == "darwin" {
err = syscall.Exec(topExe, []string{topExe, "-pid", types.String(pid)}, os.Environ())
} else {
fmt.Println("[ERROR]not supported os '" + runtime.GOOS + "'")
return
}
if err != nil {
fmt.Println("[ERROR]start failed: " + err.Error())
}
} else {
fmt.Println("[ERROR]could not found 'top' command in this system")
}
})
app.Run(func() {
var node = nodes.NewNode()
node.Start()

View File

@@ -1,8 +1,8 @@
package apps
import (
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
timeutil "github.com/iwind/TeaGo/utils/time"

View File

@@ -1,4 +1,4 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package apps

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test
@@ -7,7 +7,7 @@ import (
"github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"runtime"

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches_test

View File

@@ -1,10 +1,10 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches
import (
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"math/big"
"sync"
)

View File

@@ -1,11 +1,11 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches_test
import (
"github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/rands"

View File

@@ -4,9 +4,12 @@ package caches
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/TeaOSLab/EdgeNode/internal/utils/ttlcache"
"github.com/iwind/TeaGo/types"
"strings"
"testing"
@@ -20,19 +23,31 @@ type KVFileList struct {
onAdd func(item *Item)
onRemove func(item *Item)
memCache *ttlcache.Cache[int64]
}
func NewKVFileList(dir string) *KVFileList {
var memGB = memutils.SystemMemoryGB()
if memGB <= 0 {
memGB = 1
}
var maxCachePieces = 32
var maxCacheItems = memGB << 15
var memCache = ttlcache.NewCache[int64](ttlcache.NewPiecesOption(maxCachePieces), ttlcache.NewMaxItemsOption(maxCacheItems))
dir = strings.TrimSuffix(dir, "/")
var stores = [countKVStores]*KVListFileStore{}
for i := 0; i < countKVStores; i++ {
stores[i] = NewKVListFileStore(dir + "/db-" + types.String(i) + ".store")
stores[i] = NewKVListFileStore(dir+"/db-"+types.String(i)+".store", memCache)
}
return &KVFileList{
dir: dir,
stores: stores,
dir: dir,
stores: stores,
memCache: memCache,
}
}
@@ -59,7 +74,7 @@ func (this *KVFileList) Init() error {
// Reset 重置数据
func (this *KVFileList) Reset() error {
// do nothing
this.memCache.Clean()
return nil
}
@@ -74,16 +89,31 @@ func (this *KVFileList) Add(hash string, item *Item) error {
this.onAdd(item)
}
if item.ExpiresAt > 0 {
this.memCache.Write(hash, item.HeaderSize+item.BodySize, min(item.ExpiresAt, fasttime.Now().Unix()+3600))
}
return nil
}
// Exist 检查内容是否存在
func (this *KVFileList) Exist(hash string) (bool, int64, error) {
// read from cache
var cacheItem = this.memCache.Read(hash)
if cacheItem != nil {
return true, cacheItem.Value, nil
}
return this.getStore(hash).ExistItem(hash)
}
// ExistQuick 快速检查内容是否存在
func (this *KVFileList) ExistQuick(hash string) (bool, error) {
// read from cache
if this.memCache.Read(hash) != nil {
return true, nil
}
return this.getStore(hash).ExistQuickItem(hash)
}
@@ -150,6 +180,9 @@ func (this *KVFileList) Remove(hash string) error {
this.onRemove(nil)
}
// remove from cache
this.memCache.Delete(hash)
return nil
}
@@ -204,6 +237,9 @@ func (this *KVFileList) CleanAll() error {
})
}
group.Wait()
this.memCache.Clean()
return lastErr
}
@@ -287,6 +323,9 @@ func (this *KVFileList) Close() error {
})
}
group.Wait()
this.memCache.Destroy()
return lastErr
}

View File

@@ -6,6 +6,7 @@ import (
"errors"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/kvstore"
"github.com/TeaOSLab/EdgeNode/internal/utils/ttlcache"
"github.com/cockroachdb/pebble"
"regexp"
"strings"
@@ -20,11 +21,14 @@ type KVListFileStore struct {
itemsTable *kvstore.Table[*Item]
rawIsReady bool
memCache *ttlcache.Cache[int64]
}
func NewKVListFileStore(path string) *KVListFileStore {
func NewKVListFileStore(path string, memCache *ttlcache.Cache[int64]) *KVListFileStore {
return &KVListFileStore{
path: path,
path: path,
memCache: memCache,
}
}
@@ -106,7 +110,14 @@ func (this *KVListFileStore) ExistItem(hash string) (bool, int64, error) {
return false, -1, nil
}
return item.ExpiresAt > fasttime.Now().Unix(), item.HeaderSize + item.BodySize, nil
if item.ExpiresAt <= fasttime.Now().Unix() {
return false, 0, nil
}
// write to cache
this.memCache.Write(hash, item.HeaderSize+item.BodySize, min(item.ExpiresAt, fasttime.Now().Unix()+3600))
return true, item.HeaderSize + item.BodySize, nil
}
func (this *KVListFileStore) ExistQuickItem(hash string) (bool, error) {
@@ -168,6 +179,7 @@ func (this *KVListFileStore) PurgeItems(count int, callback func(hash string) er
if deleteErr != nil {
return deleteErr
}
this.memCache.Delete(hash)
}
return nil
})
@@ -214,6 +226,7 @@ func (this *KVListFileStore) PurgeLFUItems(count int, callback func(hash string)
if deleteErr != nil {
return deleteErr
}
this.memCache.Delete(hash)
}
return nil
})
@@ -276,6 +289,9 @@ func (this *KVListFileStore) CleanItemsWithPrefix(prefix string) error {
return false, setErr
}
// remove from cache
this.memCache.Delete(item.Key)
return true, nil
})
if err != nil {
@@ -334,6 +350,9 @@ func (this *KVListFileStore) CleanItemsWithWildcardPrefix(prefix string) error {
return false, setErr
}
// remove from cache
this.memCache.Delete(item.Key)
return true, nil
})
if err != nil {
@@ -402,6 +421,9 @@ func (this *KVListFileStore) CleanItemsWithWildcardKey(key string) error {
return false, setErr
}
// remove from cache
this.memCache.Delete(item.Key)
return true, nil
})
if err != nil {

View File

@@ -1,18 +1,18 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches
import (
"database/sql"
"errors"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/ttlcache"
"github.com/TeaOSLab/EdgeNode/internal/utils/dbs"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/ttlcache"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/iwind/TeaGo/types"
"os"
"strings"

View File

@@ -1,10 +1,10 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test
import (
"github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/rands"

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,10 +1,10 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/linkedlist"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"github.com/fsnotify/fsnotify"
@@ -38,6 +38,9 @@ func NewOpenFileCache(maxCount int) (*OpenFileCache, error) {
if maxCount <= 0 {
maxCount = 16384
}
if maxCount > 65535 {
maxCount = 65535
}
var cache = &OpenFileCache{
maxCount: maxCount,

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test

View File

@@ -1,26 +1,28 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches
import (
"bytes"
"encoding/json"
rangeutils "github.com/TeaOSLab/EdgeNode/internal/utils/ranges"
"github.com/iwind/TeaGo/types"
"strconv"
)
// PartialRanges 内容分区范围定义
type PartialRanges struct {
Version int `json:"version"` // 版本号
Ranges [][2]int64 `json:"ranges"` // 范围
BodySize int64 `json:"bodySize"` // 总长度
Version int `json:"version"` // 版本号
Ranges [][2]int64 `json:"ranges"` // 范围
BodySize int64 `json:"bodySize"` // 总长度
ContentMD5 string `json:"contentMD5"` // 内容md5
}
// NewPartialRanges 获取新对象
func NewPartialRanges(expiresAt int64) *PartialRanges {
return &PartialRanges{
Ranges: [][2]int64{},
Version: 1,
Version: 2,
}
}
@@ -45,6 +47,8 @@ func NewPartialRangesFromData(data []byte) (*PartialRanges, error) {
if commaIndex > 0 {
rs.Ranges = append(rs.Ranges, [2]int64{types.Int64(line[colonIndex+1 : commaIndex]), types.Int64(line[commaIndex+1:])})
}
case "m": // Content-MD5
rs.ContentMD5 = string(line[colonIndex+1:])
}
}
data = data[index+1:]
@@ -101,7 +105,6 @@ func (this *PartialRanges) Add(begin int64, end int64) {
}
// insert
// TODO 将来使用二分法改进
var index = -1
for i, r := range this.Ranges {
if r[0] > begin || (r[0] == begin && r[1] >= end) {
@@ -127,7 +130,6 @@ func (this *PartialRanges) Contains(begin int64, end int64) bool {
return false
}
// TODO 使用二分法查找改进性能
for _, r2 := range this.Ranges {
if r2[0] <= begin && r2[1] >= end {
return true
@@ -143,7 +145,6 @@ func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool)
return
}
// TODO 使用二分法查找改进性能
for _, r2 := range this.Ranges {
if r2[0] <= begin && r2[1] > begin {
r = [2]int64{begin, this.min(end, r2[1])}
@@ -154,10 +155,28 @@ func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool)
return
}
// FindRangeAtPosition 查找在某个位置上的范围
func (this *PartialRanges) FindRangeAtPosition(position int64) (r rangeutils.Range, ok bool) {
if len(this.Ranges) == 0 || position < 0 {
return
}
for _, r2 := range this.Ranges {
if r2[0] <= position && r2[1] > position {
return [2]int64{position, r2[1]}, true
}
}
return
}
// 转换为字符串
func (this *PartialRanges) String() string {
var s = "v:" + strconv.Itoa(this.Version) + "\n" + // version
"b:" + this.formatInt64(this.BodySize) + "\n" // bodySize
if len(this.ContentMD5) > 0 {
s += "m:" + this.ContentMD5 + "\n" // Content-MD5
}
for _, r := range this.Ranges {
s += "r:" + this.formatInt64(r[0]) + "," + this.formatInt64(r[1]) + "\n" // range
}

View File

@@ -4,10 +4,10 @@ package caches
import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
"sync"
)

View File

@@ -1,8 +1,10 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test
import (
"crypto/md5"
"encoding/base64"
"encoding/json"
"github.com/TeaOSLab/EdgeNode/internal/caches"
"github.com/iwind/TeaGo/assert"
@@ -167,8 +169,13 @@ func TestPartialRanges_Encode_String(t *testing.T) {
for i := 0; i < 10; i++ {
r.Ranges = append(r.Ranges, [2]int64{int64(i * 100), int64(i*100 + 100)})
}
var sum = md5.Sum([]byte("123456"))
r.ContentMD5 = base64.StdEncoding.EncodeToString(sum[:])
var before = time.Now()
var data = r.String()
t.Log(data)
t.Log(time.Since(before).Seconds()*1000, "ms")
t.Log(len(data))

View File

@@ -1,6 +1,9 @@
package caches
import "github.com/TeaOSLab/EdgeNode/internal/utils/ranges"
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/ranges"
"io"
)
type ReaderFunc func(n int) (goNext bool, err error)
@@ -41,6 +44,9 @@ type Reader interface {
// ContainsRange 是否包含某个区间内容
ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)
// SetNextReader 设置下一个内容Reader
SetNextReader(nextReader io.ReadCloser)
// Close 关闭
Close() error
}

View File

@@ -0,0 +1,14 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches
import "io"
type BaseReader struct {
nextReader io.ReadCloser
}
// SetNextReader 设置下一个内容Reader
func (this *BaseReader) SetNextReader(nextReader io.ReadCloser) {
this.nextReader = nextReader
}

View File

@@ -11,6 +11,8 @@ import (
)
type FileReader struct {
BaseReader
fp *fsutils.File
openFile *OpenFile
@@ -343,6 +345,33 @@ func (this *FileReader) ReadBodyRange(buf []byte, start int64, end int64, callba
isOk = true
// 读取下一个Reader
if this.nextReader != nil {
defer func() {
_ = this.nextReader.Close()
}()
for {
var n int
n, err = this.nextReader.Read(buf)
if n > 0 {
goNext, writeErr := callback(n)
if writeErr != nil {
return writeErr
}
if !goNext {
break
}
}
if err != nil {
if err != io.EOF {
return err
}
break
}
}
}
return nil
}

View File

@@ -2,6 +2,7 @@ package caches
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/iwind/TeaGo/Tea"
"os"
"testing"
@@ -36,7 +37,7 @@ func TestFileReader(t *testing.T) {
defer func() {
_ = fp.Close()
}()
reader := NewFileReader(fp)
reader := NewFileReader(fsutils.NewFile(fp, fsutils.FlagRead))
err = reader.Init()
if err != nil {
t.Fatal(err)
@@ -75,7 +76,7 @@ func TestFileReader_ReadHeader(t *testing.T) {
defer func() {
_ = fp.Close()
}()
var reader = NewFileReader(fp)
var reader = NewFileReader(fsutils.NewFile(fp, fsutils.FlagRead))
err = reader.Init()
if err != nil {
if os.IsNotExist(err) {
@@ -138,7 +139,7 @@ func TestFileReader_Range(t *testing.T) {
defer func() {
_ = fp.Close()
}()
reader := NewFileReader(fp)
reader := NewFileReader(fsutils.NewFile(fp, fsutils.FlagRead))
err = reader.Init()
if err != nil {
t.Fatal(err)

View File

@@ -7,6 +7,8 @@ import (
)
type MemoryReader struct {
BaseReader
item *MemoryItem
offset int

View File

@@ -10,15 +10,16 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/trackers"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/bytepool"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
setutils "github.com/TeaOSLab/EdgeNode/internal/utils/sets"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/trackers"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
@@ -1003,6 +1004,11 @@ func (this *FileStorage) CanSendfile() bool {
return this.options.EnableSendfile
}
// Options 获取当前缓存存储的选项
func (this *FileStorage) Options() *serverconfigs.HTTPFileCacheStorage {
return this.options
}
// 获取Key对应的文件路径
func (this *FileStorage) keyPath(key string) (hash string, path string, diskIsFull bool) {
hash = stringutil.Md5(key)
@@ -1285,9 +1291,9 @@ func (this *FileStorage) hotLoop() {
size = len(result) / 10
}
var buf = utils.BytePool16k.Get()
var buf = bytepool.Pool16k.Get()
defer utils.BytePool16k.Put(buf)
defer bytepool.Pool16k.Put(buf)
for _, item := range result[:size] {
reader, err := this.openReader(item.Key, false, false, false)
if err != nil {

View File

@@ -3,15 +3,15 @@ package caches
import (
"fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/trackers"
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
memutils "github.com/TeaOSLab/EdgeNode/internal/utils/mem"
setutils "github.com/TeaOSLab/EdgeNode/internal/utils/sets"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/trackers"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/cespare/xxhash/v2"
"github.com/iwind/TeaGo/types"
"math"

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package caches_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches
@@ -7,6 +7,7 @@ import (
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
"github.com/iwind/TeaGo/types"
"io"
"strings"
"sync"
)
@@ -30,6 +31,8 @@ type PartialFileWriter struct {
ranges *PartialRanges
rangePath string
writtenBytes int64
}
func NewPartialFileWriter(rawWriter *fsutils.File, key string, expiredAt int64, metaHeaderSize int, metaBodySize int64, isNew bool, isPartial bool, bodyOffset int64, ranges *PartialRanges, endFunc func()) *PartialFileWriter {
@@ -154,13 +157,25 @@ func (this *PartialFileWriter) WriteAt(offset int64, data []byte) error {
this.bodyOffset = SizeMeta + int64(keyLength) + this.headerSize
}
_, err := this.rawWriter.WriteAt(data, this.bodyOffset+offset)
n, err := this.rawWriter.WriteAt(data, this.bodyOffset+offset)
if err != nil {
return err
}
this.ranges.Add(offset, end)
// 保存ranges内容到文件当新增数据达到一定量时就更新是为了及时更新ranges文件以便于其他请求能够及时读取到已经缓存的部分内容
this.writtenBytes += int64(n)
if this.writtenBytes > (1 << 20) {
this.writtenBytes = 0
if len(this.rangePath) > 0 {
if this.bodySize > 0 {
this.ranges.BodySize = this.bodySize
}
_ = this.ranges.WriteToFile(this.rangePath)
}
}
return nil
}
@@ -169,6 +184,14 @@ func (this *PartialFileWriter) SetBodyLength(bodyLength int64) {
this.bodySize = bodyLength
}
// SetContentMD5 设置内容MD5
func (this *PartialFileWriter) SetContentMD5(contentMD5 string) {
if strings.Contains(contentMD5, "\n") || len(contentMD5) > 128 {
return
}
this.ranges.ContentMD5 = contentMD5
}
// WriteBodyLength 写入Body长度数据
func (this *PartialFileWriter) WriteBodyLength(bodyLength int64) error {
if this.metaBodySize > 0 && this.metaBodySize == bodyLength {
@@ -195,7 +218,9 @@ func (this *PartialFileWriter) Close() error {
this.endFunc()
})
this.ranges.BodySize = this.bodySize
if this.bodySize > 0 {
this.ranges.BodySize = this.bodySize
}
err := this.ranges.WriteToFile(this.rangePath)
if err != nil {
_ = this.rawWriter.Close()
@@ -269,6 +294,10 @@ func (this *PartialFileWriter) IsNew() bool {
return this.isNew && len(this.ranges.Ranges) == 0
}
func (this *PartialFileWriter) Ranges() *PartialRanges {
return this.ranges
}
func (this *PartialFileWriter) remove() {
_ = fsutils.Remove(this.rawWriter.Name())

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package caches_test
@@ -28,7 +28,7 @@ func TestPartialFileWriter_Write(t *testing.T) {
t.Fatal(err)
}
var ranges = caches.NewPartialRanges(0)
var writer = caches.NewPartialFileWriter(fp, "test", time.Now().Unix()+86500, -1, -1, true, true, 0, ranges, func() {
var writer = caches.NewPartialFileWriter(fsutils.NewFile(fp, fsutils.FlagWrite), "test", time.Now().Unix()+86500, -1, -1, true, true, 0, ranges, func() {
t.Log("end")
})
_, err = writer.WriteHeader([]byte("header"))

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build !plus || !linux
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build !plus || !linux
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,10 +1,10 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions
import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"io"
"time"
)

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package compressions_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package conns

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package conns

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build !plus
// +build !plus

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build plus
// +build plus

View File

@@ -1,14 +1,13 @@
package teaconst
const (
Version = "1.3.8.1"
Version = "1.3.9"
ProductName = "Edge Node"
ProcessName = "edge-node"
Role = "node"
EncryptKey = "8f983f4d69b83aaa0d74b21a212f6967"
EncryptMethod = "aes-256-cfb"
// SystemdServiceName systemd

View File

@@ -1,4 +1,4 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
package teaconst

View File

@@ -1,11 +0,0 @@
package encrypt
import "testing"
func TestMagicKeyEncode(t *testing.T) {
dst := MagicKeyEncode([]byte("Hello,World"))
t.Log("dst:", string(dst))
src := MagicKeyDecode(dst)
t.Log("src:", string(src))
}

View File

@@ -1,8 +0,0 @@
package encrypt
import "testing"
func TestFindMethodInstance(t *testing.T) {
t.Log(NewMethodInstance("a", "b", ""))
t.Log(NewMethodInstance("aes-256-cfb", "123456", ""))
}

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package firewalls
@@ -16,7 +16,7 @@ import (
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/TeaOSLab/EdgeNode/internal/utils"
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/types"
stringutil "github.com/iwind/TeaGo/utils/string"

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build !linux
// +build !linux

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package firewalls

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package firewalls

View File

@@ -1,13 +1,13 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package firewalls
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/conns"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/iwind/TeaGo/types"
"strings"
"time"

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package firewalls

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
package firewalls

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package firewalls
@@ -11,9 +11,9 @@ import (
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/firewalls/nftables"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/google/nftables/expr"
"github.com/iwind/TeaGo/types"
"net"

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build !linux
// +build !linux

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
// +build linux

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
// +build linux

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
// +build linux

View File

@@ -1,4 +1,4 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package nftables_test

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build linux
package nftables
@@ -8,9 +8,9 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/TeaOSLab/EdgeNode/internal/goman"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
"github.com/TeaOSLab/EdgeNode/internal/utils/goman"
"github.com/iwind/TeaGo/logs"
"os"
"runtime"
@@ -90,18 +90,26 @@ func (this *Installer) Install() error {
}
var cmd *executils.Cmd
var aptCmd *executils.Cmd
// check dnf
dnfExe, err := executils.LookPath("dnf")
if err == nil {
cmd = executils.NewCmd(dnfExe, "-y", "install", "nftables")
{
dnfExe, err := executils.LookPath("dnf")
if err == nil {
cmd = executils.NewCmd(dnfExe, "-y", "install", "nftables")
}
}
// check apt
if cmd == nil {
aptExe, err := executils.LookPath("apt")
aptGetExe, err := executils.LookPath("apt-get")
if err == nil {
cmd = executils.NewCmd(aptExe, "install", "nftables")
cmd = executils.NewCmd(aptGetExe, "install", "nftables")
}
aptExe, aptErr := executils.LookPath("apt")
if aptErr == nil {
aptCmd = executils.NewCmd(aptExe, "install", "nftables")
}
}
@@ -119,9 +127,19 @@ func (this *Installer) Install() error {
cmd.WithTimeout(10 * time.Minute)
cmd.WithStderr()
err = cmd.Run()
err := cmd.Run()
if err != nil {
return fmt.Errorf("%w: %s", err, cmd.Stderr())
// try 'apt-get' instead of 'apt'
if aptCmd != nil {
cmd = aptCmd
cmd.WithTimeout(10 * time.Minute)
cmd.WithStderr()
err = cmd.Run()
}
if err != nil {
return fmt.Errorf("%w: %s", err, cmd.Stderr())
}
}
remotelogs.Println("NFTABLES", "installed nftables with command '"+cmd.String()+"' successfully")

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

View File

@@ -1,4 +1,4 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved.
//go:build linux
package nftables

Some files were not shown because too many files have changed in this diff Show More