mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-03 20:40:25 +08:00
删除不必要的文件
This commit is contained in:
1
pkg/dnsconfigs/.gitignore
vendored
Normal file
1
pkg/dnsconfigs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ns_*
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import "github.com/iwind/TeaGo/maps"
|
||||
|
||||
// 一组系统默认值
|
||||
// 修改单个IP相关限制值时要考虑到NAT中每个IP会代表很多个主机,并非1对1的关系
|
||||
|
||||
const (
|
||||
DefaultMaxThreads = 20000 // 单节点最大线程数
|
||||
DefaultMaxThreadsMin = 1000 // 单节点最大线程数最小值
|
||||
DefaultMaxThreadsMax = 100_000 // 单节点最大线程数最大值
|
||||
|
||||
DefaultTCPMaxConnections = 100_000 // 单节点TCP最大连接数
|
||||
DefaultTCPMaxConnectionsPerIP = 1000 // 单IP最大连接数
|
||||
DefaultTCPMinConnectionsPerIP = 5 // 单IP最小连接数
|
||||
|
||||
DefaultTCPNewConnectionsMinutelyRate = 500 // 单IP连接速率限制(按分钟)
|
||||
DefaultTCPNewConnectionsMinMinutelyRate = 3 // 单IP最小连接速率
|
||||
|
||||
DefaultTCPNewConnectionsSecondlyRate = 300 // 单IP连接速率限制(按秒)
|
||||
DefaultTCPNewConnectionsMinSecondlyRate = 3 // 单IP最小连接速率
|
||||
|
||||
DefaultTCPLinger = 3 // 单节点TCP Linger值
|
||||
DefaultTLSHandshakeTimeout = 3 // TLS握手超时时间
|
||||
)
|
||||
|
||||
var DefaultConfigs = maps.Map{
|
||||
"tcpMaxConnections": DefaultTCPMaxConnections,
|
||||
"tcpMaxConnectionsPerIP": DefaultTCPMaxConnectionsPerIP,
|
||||
"tcpMinConnectionsPerIP": DefaultTCPMinConnectionsPerIP,
|
||||
"tcpNewConnectionsMinutelyRate": DefaultTCPNewConnectionsMinutelyRate,
|
||||
"tcpNewConnectionsMinMinutelyRate": DefaultTCPNewConnectionsMinMinutelyRate,
|
||||
"tcpNewConnectionsSecondlyRate": DefaultTCPNewConnectionsSecondlyRate,
|
||||
"tcpNewConnectionsMinSecondlyRate": DefaultTCPNewConnectionsMinSecondlyRate,
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type NSAccessLogRef struct {
|
||||
IsPrior bool `yaml:"isPrior" json:"isPrior"` // 是否覆盖
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
LogMissingDomains bool `yaml:"logMissingDomains" json:"logMissingDomains"` // 是否记录找不到的域名
|
||||
MissingRecordsOnly bool `yaml:"missingRecordsOnly" json:"missingRecordsOnly"` // 只记录找不到解析记录的访问
|
||||
}
|
||||
|
||||
func (this *NSAccessLogRef) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
|
||||
// NSDomainStatus 域名状态
|
||||
type NSDomainStatus = string
|
||||
|
||||
const (
|
||||
NSDomainStatusNone NSDomainStatus = "none" // 初始状态
|
||||
NSDomainStatusVerified NSDomainStatus = "verified" // 已验证
|
||||
NSDomainStatusRejected NSDomainStatus = "rejected" // 已驳回(可以重新提交)
|
||||
NSDomainStatusForbidden NSDomainStatus = "forbidden" // 已禁止(禁止继续使用此域名)
|
||||
)
|
||||
|
||||
func FindAllNSDomainStatusList() []*shared.Definition {
|
||||
return []*shared.Definition{
|
||||
{
|
||||
Name: "未验证",
|
||||
Code: NSDomainStatusNone,
|
||||
},
|
||||
{
|
||||
Name: "已验证",
|
||||
Code: NSDomainStatusVerified,
|
||||
},
|
||||
{
|
||||
Name: "已驳回",
|
||||
Code: NSDomainStatusRejected,
|
||||
},
|
||||
{
|
||||
Name: "已禁止",
|
||||
Code: NSDomainStatusForbidden,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NSDomainStatusIsValid(status string) bool {
|
||||
for _, def := range FindAllNSDomainStatusList() {
|
||||
if def.Code == status {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func NSDomainStatusName(status string) string {
|
||||
for _, def := range FindAllNSDomainStatusList() {
|
||||
if def.Code == status {
|
||||
return def.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type KeyAlgorithmType = string
|
||||
|
||||
const (
|
||||
KeyAlgorithmTypeHmacSHA1 KeyAlgorithmType = "hmac-sha1."
|
||||
KeyAlgorithmTypeHmacSHA224 KeyAlgorithmType = "hmac-sha224."
|
||||
KeyAlgorithmTypeHmacSHA256 KeyAlgorithmType = "hmac-sha256."
|
||||
KeyAlgorithmTypeHmacSHA384 KeyAlgorithmType = "hmac-sha384."
|
||||
KeyAlgorithmTypeHmacSHA512 KeyAlgorithmType = "hmac-sha512."
|
||||
)
|
||||
|
||||
type KeyAlgorithmDefinition struct {
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
func FindAllKeyAlgorithmTypes() []*KeyAlgorithmDefinition {
|
||||
return []*KeyAlgorithmDefinition{
|
||||
{
|
||||
Name: "HmacSHA1",
|
||||
Code: KeyAlgorithmTypeHmacSHA1,
|
||||
},
|
||||
{
|
||||
Name: "HmacSHA224",
|
||||
Code: KeyAlgorithmTypeHmacSHA224,
|
||||
},
|
||||
{
|
||||
Name: "HmacSHA256",
|
||||
Code: KeyAlgorithmTypeHmacSHA256,
|
||||
},
|
||||
{
|
||||
Name: "HmacSHA384",
|
||||
Code: KeyAlgorithmTypeHmacSHA384,
|
||||
},
|
||||
{
|
||||
Name: "HmacSHA512",
|
||||
Code: KeyAlgorithmTypeHmacSHA512,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func FindKeyAlgorithmTypeName(algoType KeyAlgorithmType) string {
|
||||
for _, def := range FindAllKeyAlgorithmTypes() {
|
||||
if def.Code == algoType {
|
||||
return def.Name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type NSKeySecretType = string
|
||||
|
||||
const (
|
||||
NSKeySecretTypeClear NSKeySecretType = "clear"
|
||||
NSKeySecretTypeBase64 NSKeySecretType = "base64"
|
||||
)
|
||||
|
||||
func FindKeySecretTypeName(secretType NSKeySecretType) string {
|
||||
switch secretType {
|
||||
case NSKeySecretTypeClear:
|
||||
return "明文"
|
||||
case NSKeySecretTypeBase64:
|
||||
return "BASE64"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
|
||||
)
|
||||
|
||||
type NSNodeConfig struct {
|
||||
Id int64 `yaml:"id" json:"id"`
|
||||
NodeId string `yaml:"nodeId" json:"nodeId"`
|
||||
Secret string `yaml:"secret" json:"secret"`
|
||||
ClusterId int64 `yaml:"clusterId" json:"clusterId"`
|
||||
AccessLogRef *NSAccessLogRef `yaml:"accessLogRef" json:"accessLogRef"`
|
||||
RecursionConfig *NSRecursionConfig `yaml:"recursionConfig" json:"recursionConfig"`
|
||||
DDoSProtection *ddosconfigs.ProtectionConfig `yaml:"ddosProtection" json:"ddosProtection"`
|
||||
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"`
|
||||
TimeZone string `yaml:"timeZone" json:"timeZone"` // 自动设置时区
|
||||
|
||||
TCP *serverconfigs.TCPProtocolConfig `yaml:"tcp" json:"tcp"` // TCP配置
|
||||
TLS *serverconfigs.TLSProtocolConfig `yaml:"tls" json:"tls"` // TLS配置
|
||||
UDP *serverconfigs.UDPProtocolConfig `yaml:"udp" json:"udp"` // UDP配置
|
||||
|
||||
paddedId string
|
||||
}
|
||||
|
||||
func (this *NSNodeConfig) Init() error {
|
||||
this.paddedId = fmt.Sprintf("%08d", this.Id)
|
||||
|
||||
// accessLog
|
||||
if this.AccessLogRef != nil {
|
||||
err := this.AccessLogRef.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 递归DNS
|
||||
if this.RecursionConfig != nil {
|
||||
err := this.RecursionConfig.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// DDoS
|
||||
if this.DDoSProtection != nil {
|
||||
err := this.DDoSProtection.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// tcp
|
||||
if this.TCP != nil {
|
||||
err := this.TCP.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// tls
|
||||
if this.TLS != nil {
|
||||
err := this.TLS.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// udp
|
||||
if this.UDP != nil {
|
||||
err := this.UDP.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *NSNodeConfig) PaddedId() string {
|
||||
return this.paddedId
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type NSPlanConfig struct {
|
||||
SupportCountryRoutes bool `json:"supportCountryRoutes"` // 支持全球国家/地区线路
|
||||
SupportChinaProvinceRoutes bool `json:"supportChinaProvinceRoutes"` // 支持国内省份线路
|
||||
SupportISPRoutes bool `json:"supportISPRoutes"` // 支持ISP运营商线路
|
||||
MaxCustomRoutes int32 `json:"maxCustomRoutes"` // 自定义的线路数量
|
||||
MinTTL int32 `json:"minTTL"` // 最小TTL
|
||||
MaxDomains int32 `json:"maxDomains"` // 域名数量
|
||||
MaxRecordsPerDomain int32 `json:"maxRecordsPerDomain"` // 单域名记录数量
|
||||
MaxLoadBalanceRecordsPerRecord int32 `json:"maxLoadBalanceRecordsPerRecord"` // 单记录负载均衡条数
|
||||
SupportRecordStats bool `json:"supportRecordStats"` // 支持记录统计
|
||||
SupportDomainAlias bool `json:"supportDomainAlias"` // 支持域名别名 TODO
|
||||
|
||||
SupportAPI bool `json:"supportAPI"` // 是否支持API操作 TODO
|
||||
}
|
||||
|
||||
func DefaultNSPlanConfig() *NSPlanConfig {
|
||||
return &NSPlanConfig{}
|
||||
}
|
||||
|
||||
func (this *NSPlanConfig) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type NSDNSHost struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Protocol string `json:"protocol"`
|
||||
}
|
||||
|
||||
// NSRecursionConfig 递归DNS设置
|
||||
type NSRecursionConfig struct {
|
||||
IsOn bool `json:"isOn"`
|
||||
Hosts []*NSDNSHost `json:"hosts"`
|
||||
UseLocalHosts bool `json:"useLocalHosts"` // 自动从本机读取DNS
|
||||
AllowDomains []string `json:"allowDomains"`
|
||||
DenyDomains []string `json:"denyDomains"`
|
||||
}
|
||||
|
||||
func (this *NSRecursionConfig) Init() error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
)
|
||||
|
||||
type NSRouteRangeType = string
|
||||
|
||||
const (
|
||||
NSRouteRangeTypeIP NSRouteRangeType = "ipRange" // IP范围
|
||||
NSRouteRangeTypeCIDR NSRouteRangeType = "cidr" // CIDR
|
||||
NSRouteRangeTypeRegion NSRouteRangeType = "region" // 区域
|
||||
)
|
||||
|
||||
func AllNSRouteRangeTypes() []*shared.Definition {
|
||||
return []*shared.Definition{
|
||||
{
|
||||
Name: "IP范围",
|
||||
Code: NSRouteRangeTypeIP,
|
||||
},
|
||||
{
|
||||
Name: "CIDR",
|
||||
Code: NSRouteRangeTypeCIDR,
|
||||
},
|
||||
{
|
||||
Name: "区域",
|
||||
Code: NSRouteRangeTypeRegion,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NSRouteRegionResolver 解析IP接口
|
||||
type NSRouteRegionResolver interface {
|
||||
Resolve(ip net.IP) (countryId int64, provinceId int64, cityId int64, providerId int64)
|
||||
}
|
||||
|
||||
// NSRouteRangeInterface 线路范围接口
|
||||
type NSRouteRangeInterface interface {
|
||||
// Init 初始化
|
||||
Init() error
|
||||
|
||||
// Contains 判断是否包含
|
||||
Contains(ip net.IP) bool
|
||||
|
||||
// SetRegionResolver 设置IP解析接口
|
||||
SetRegionResolver(resolver NSRouteRegionResolver)
|
||||
|
||||
// IsExcluding 是否为排除
|
||||
IsExcluding() bool
|
||||
}
|
||||
|
||||
type NSBaseRouteRange struct {
|
||||
IsReverse bool `json:"isReverse"`
|
||||
|
||||
routeRegionResolver NSRouteRegionResolver
|
||||
}
|
||||
|
||||
func (this *NSBaseRouteRange) SetRegionResolver(resolver NSRouteRegionResolver) {
|
||||
this.routeRegionResolver = resolver
|
||||
}
|
||||
|
||||
func (this *NSBaseRouteRange) IsExcluding() bool {
|
||||
return this.IsReverse
|
||||
}
|
||||
|
||||
// NSRouteRangeIPRange IP范围配置
|
||||
// IPv4和IPv6不能混用
|
||||
type NSRouteRangeIPRange struct {
|
||||
NSBaseRouteRange
|
||||
|
||||
IPFrom string `json:"ipFrom"`
|
||||
IPTo string `json:"ipTo"`
|
||||
|
||||
ipFromLong uint64
|
||||
ipToLong uint64
|
||||
|
||||
ipVersion int // 4|6
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeIPRange) Init() error {
|
||||
var ipFrom = net.ParseIP(this.IPFrom)
|
||||
var ipTo = net.ParseIP(this.IPTo)
|
||||
if ipFrom == nil {
|
||||
return errors.New("invalid ipFrom '" + this.IPFrom + "'")
|
||||
}
|
||||
if ipTo == nil {
|
||||
return errors.New("invalid ipTo '" + this.IPTo + "'")
|
||||
}
|
||||
|
||||
var ipFromVersion = configutils.IPVersion(ipFrom)
|
||||
var ipToVersion = configutils.IPVersion(ipTo)
|
||||
if ipFromVersion != ipToVersion {
|
||||
return errors.New("ipFrom and ipTo version are not same")
|
||||
}
|
||||
this.ipVersion = ipFromVersion
|
||||
|
||||
this.ipFromLong = configutils.IP2Long(ipFrom)
|
||||
this.ipToLong = configutils.IP2Long(ipTo)
|
||||
|
||||
if this.ipFromLong > this.ipToLong {
|
||||
this.ipFromLong, this.ipToLong = this.ipToLong, this.ipFromLong
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeIPRange) Contains(netIP net.IP) bool {
|
||||
if len(netIP) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
var version = configutils.IPVersion(netIP)
|
||||
if version != this.ipVersion {
|
||||
return false
|
||||
}
|
||||
|
||||
var ipLong = configutils.IP2Long(netIP)
|
||||
return ipLong >= this.ipFromLong && ipLong <= this.ipToLong
|
||||
}
|
||||
|
||||
// NSRouteRangeCIDR CIDR范围配置
|
||||
type NSRouteRangeCIDR struct {
|
||||
NSBaseRouteRange
|
||||
|
||||
CIDR string `json:"cidr"`
|
||||
|
||||
cidr *net.IPNet
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeCIDR) Init() error {
|
||||
_, ipNet, err := net.ParseCIDR(this.CIDR)
|
||||
if err != nil {
|
||||
return errors.New("parse cidr failed: " + err.Error())
|
||||
}
|
||||
|
||||
this.cidr = ipNet
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeCIDR) Contains(netIP net.IP) bool {
|
||||
if netIP == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if this.cidr == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return this.cidr.Contains(netIP)
|
||||
}
|
||||
|
||||
// NSRouteRangeRegion 区域范围
|
||||
// country:ID, province:ID, city:ID, isp:ID
|
||||
type NSRouteRangeRegion struct {
|
||||
NSBaseRouteRange
|
||||
|
||||
Regions []*routeRegion `json:"regions"`
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeRegion) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *NSRouteRangeRegion) Contains(netIP net.IP) bool {
|
||||
if this.routeRegionResolver == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(this.Regions) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
countryId, provinceId, cityId, providerId := this.routeRegionResolver.Resolve(netIP)
|
||||
if countryId <= 0 && provinceId <= 0 && cityId <= 0 && providerId <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, region := range this.Regions {
|
||||
if region.Id <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
switch region.Type {
|
||||
case "country":
|
||||
if region.Id == countryId {
|
||||
return true
|
||||
}
|
||||
case "province":
|
||||
if region.Id == provinceId {
|
||||
return true
|
||||
}
|
||||
case "city":
|
||||
if region.Id == cityId {
|
||||
return true
|
||||
}
|
||||
case "isp":
|
||||
if region.Id == providerId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
type routeRegion struct {
|
||||
Type string `json:"type"` // country|province|city|isp
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// InitNSRangesFromJSON 从JSON中初始化线路范围
|
||||
func InitNSRangesFromJSON(rangesJSON []byte) (ranges []NSRouteRangeInterface, err error) {
|
||||
if len(rangesJSON) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var rangeMaps = []maps.Map{}
|
||||
err = json.Unmarshal(rangesJSON, &rangeMaps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, rangeMap := range rangeMaps {
|
||||
var rangeType = rangeMap.GetString("type")
|
||||
paramsJSON, err := json.Marshal(rangeMap.Get("params"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r NSRouteRangeInterface
|
||||
|
||||
switch rangeType {
|
||||
case NSRouteRangeTypeIP:
|
||||
r = &NSRouteRangeIPRange{}
|
||||
case NSRouteRangeTypeCIDR:
|
||||
r = &NSRouteRangeCIDR{}
|
||||
case NSRouteRangeTypeRegion:
|
||||
r = &NSRouteRangeRegion{}
|
||||
default:
|
||||
return nil, errors.New("invalid route line type '" + rangeType + "'")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(paramsJSON, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = r.Init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ranges = append(ranges, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNSRouteRangeIPRange_Contains(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
|
||||
// ipv4
|
||||
{
|
||||
var r = &NSRouteRangeIPRange{
|
||||
IPFrom: "192.168.1.100",
|
||||
IPTo: "192.168.3.200",
|
||||
}
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(r.Contains(net.ParseIP("aaa")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.1.200")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.3.200")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.4.1")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("::1")))
|
||||
}
|
||||
|
||||
// ipv6
|
||||
{
|
||||
var prefix = "1:2:3:4:5:6"
|
||||
var r = &NSRouteRangeIPRange{
|
||||
IPFrom: prefix + ":1:8",
|
||||
IPTo: prefix + ":5:10",
|
||||
}
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(r.Contains(net.ParseIP("aaa")))
|
||||
a.IsTrue(r.Contains(net.ParseIP(prefix + ":3:4")))
|
||||
a.IsTrue(r.Contains(net.ParseIP(prefix + ":5:9")))
|
||||
a.IsTrue(r.Contains(net.ParseIP(prefix + ":5:10")))
|
||||
a.IsTrue(r.Contains(net.ParseIP(prefix + ":4:8")))
|
||||
a.IsFalse(r.Contains(net.ParseIP(prefix + ":5:11")))
|
||||
}
|
||||
|
||||
{
|
||||
var r = &NSRouteRangeCIDR{
|
||||
CIDR: "192.168.2.1/24",
|
||||
}
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(r.Contains(net.ParseIP("aaa")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.1")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.254")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.100")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.3.1")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.1.1")))
|
||||
}
|
||||
|
||||
// reverse ipv4
|
||||
{
|
||||
var r = &NSRouteRangeIPRange{
|
||||
IPFrom: "192.168.1.100",
|
||||
IPTo: "192.168.3.200",
|
||||
}
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(r.Contains(net.ParseIP("aaa")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.1.200")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.3.200")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.4.1")))
|
||||
}
|
||||
|
||||
// reverse cidr
|
||||
{
|
||||
var r = &NSRouteRangeCIDR{
|
||||
CIDR: "192.168.2.1/24",
|
||||
}
|
||||
err := r.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(r.Contains(net.ParseIP("aaa")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.1")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.254")))
|
||||
a.IsTrue(r.Contains(net.ParseIP("192.168.2.100")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.3.1")))
|
||||
a.IsFalse(r.Contains(net.ParseIP("192.168.1.1")))
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,86 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRoutes(t *testing.T) {
|
||||
// 检查代号是否有空,或者代号是否重复
|
||||
|
||||
var codeMap = map[string]bool{} // code => true
|
||||
|
||||
for _, routes := range [][]*Route{
|
||||
AllDefaultChinaProvinceRoutes,
|
||||
AllDefaultISPRoutes,
|
||||
AllDefaultWorldRegionRoutes,
|
||||
} {
|
||||
for _, route := range routes {
|
||||
if len(route.Name) == 0 {
|
||||
t.Fatal("route name should not empty:", route)
|
||||
}
|
||||
if len(route.AliasNames) == 0 {
|
||||
t.Fatal("route alias names should not empty:", route)
|
||||
}
|
||||
if len(route.Code) == 0 || route.Code == "world:" {
|
||||
t.Fatal("route code should not empty:", route)
|
||||
}
|
||||
|
||||
_, ok := codeMap[route.Code]
|
||||
if ok {
|
||||
t.Fatal("code duplicated:", route)
|
||||
}
|
||||
|
||||
codeMap[route.Code] = true
|
||||
|
||||
if strings.HasPrefix(route.Code, "world:sp:") || (strings.HasPrefix(route.Code, "world:") && route.Code != "world:UAR" && len(route.Code) != 8) {
|
||||
t.Log("no shorten code:", route)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindDefaultRoute(t *testing.T) {
|
||||
t.Log(FindDefaultRoute("isp:china_unicom"))
|
||||
t.Log(FindDefaultRoute("china:province:beijing"))
|
||||
t.Log(FindDefaultRoute("world:CN"))
|
||||
t.Log(FindDefaultRoute("world:US"))
|
||||
}
|
||||
|
||||
func TestRoutes_Markdown(t *testing.T) {
|
||||
var markdown = ""
|
||||
|
||||
for index, routes := range [][]*Route{
|
||||
AllDefaultRoutes,
|
||||
AllDefaultChinaProvinceRoutes,
|
||||
AllDefaultISPRoutes,
|
||||
AllDefaultWorldRegionRoutes,
|
||||
} {
|
||||
switch index {
|
||||
case 0:
|
||||
markdown += "## 默认线路\n"
|
||||
case 1:
|
||||
markdown += "## 中国省市\n"
|
||||
case 2:
|
||||
markdown += "## 运营商\n"
|
||||
case 3:
|
||||
markdown += "## 全球地区\n"
|
||||
}
|
||||
|
||||
markdown += "| 名称 | 代号 |\n"
|
||||
markdown += "|-----------|-----------|\n"
|
||||
for _, route := range routes {
|
||||
markdown += "| " + route.Name + " | " + route.Code + " |\n"
|
||||
}
|
||||
markdown += "\n"
|
||||
}
|
||||
t.Log(markdown)
|
||||
}
|
||||
|
||||
func BenchmarkFindDefaultRoute(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = FindDefaultRoute("world:CN")
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type NSSetting struct {
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
// NSTSIGConfig 配置
|
||||
type NSTSIGConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
func DefaultNSUserConfig() *NSUserConfig {
|
||||
return &NSUserConfig{
|
||||
DefaultClusterId: 0,
|
||||
DefaultPlanConfig: DefaultNSUserPlanConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultNSUserPlanConfig() *NSPlanConfig {
|
||||
return &NSPlanConfig{
|
||||
SupportCountryRoutes: true,
|
||||
SupportChinaProvinceRoutes: true,
|
||||
SupportISPRoutes: true,
|
||||
MaxCustomRoutes: 0,
|
||||
MaxLoadBalanceRecordsPerRecord: 100,
|
||||
MinTTL: 60,
|
||||
MaxDomains: 100,
|
||||
MaxRecordsPerDomain: 1000,
|
||||
SupportRecordStats: true,
|
||||
SupportDomainAlias: false,
|
||||
SupportAPI: false,
|
||||
}
|
||||
}
|
||||
|
||||
type NSUserConfig struct {
|
||||
DefaultClusterId int64 `json:"defaultClusterId"` // 默认部署到的集群
|
||||
DefaultPlanConfig *NSPlanConfig `json:"defaultPlanConfig"` // 默认套餐设置
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package dnsconfigs
|
||||
|
||||
type RecordTTL struct {
|
||||
Name string `json:"name"`
|
||||
Value int `json:"value"`
|
||||
}
|
||||
|
||||
func FindAllRecordTTL() []*RecordTTL {
|
||||
return []*RecordTTL{
|
||||
{
|
||||
Name: "5秒",
|
||||
Value: 5,
|
||||
},
|
||||
{
|
||||
Name: "10秒",
|
||||
Value: 10,
|
||||
},
|
||||
{
|
||||
Name: "30秒",
|
||||
Value: 30,
|
||||
},
|
||||
{
|
||||
Name: "1分钟",
|
||||
Value: 60,
|
||||
},
|
||||
{
|
||||
Name: "3分钟",
|
||||
Value: 3 * 60,
|
||||
},
|
||||
{
|
||||
Name: "5分钟",
|
||||
Value: 5 * 60,
|
||||
},
|
||||
{
|
||||
Name: "10分钟",
|
||||
Value: 10 * 60,
|
||||
},
|
||||
{
|
||||
Name: "30分钟",
|
||||
Value: 30 * 60,
|
||||
},
|
||||
{
|
||||
Name: "1小时",
|
||||
Value: 3600,
|
||||
},
|
||||
{
|
||||
Name: "12小时",
|
||||
Value: 12 * 3600,
|
||||
},
|
||||
{
|
||||
Name: "1天",
|
||||
Value: 86400,
|
||||
},
|
||||
{
|
||||
Name: "30天",
|
||||
Value: 30 * 86400,
|
||||
},
|
||||
{
|
||||
Name: "一年",
|
||||
Value: 365 * 86400,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user