Skip to content

Commit e4d958f

Browse files
committed
实现域名、记录同步等API
1 parent c725c9e commit e4d958f

19 files changed

+1399
-368
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/TeaOSLab/EdgeCommon
33
go 1.15
44

55
require (
6+
github.com/cespare/xxhash/v2 v2.1.1
67
github.com/go-yaml/yaml v2.1.0+incompatible
78
github.com/golang/protobuf v1.4.2
89
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
55
github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60=
66
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
77
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
8+
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
89
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
910
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1011
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=

pkg/configutils/ip.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package configutils
2+
3+
import (
4+
"encoding/binary"
5+
"github.com/cespare/xxhash/v2"
6+
"math"
7+
"net"
8+
"strings"
9+
)
10+
11+
// IP2Long 将IP转换为整型
12+
// 注意IPv6没有顺序
13+
func IP2Long(ip string) uint64 {
14+
if len(ip) == 0 {
15+
return 0
16+
}
17+
s := net.ParseIP(ip)
18+
if len(s) == 0 {
19+
return 0
20+
}
21+
22+
if strings.Contains(ip, ":") {
23+
return math.MaxUint32 + xxhash.Sum64(s)
24+
}
25+
return uint64(binary.BigEndian.Uint32(s.To4()))
26+
}

pkg/dnsconfigs/record_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func FindAllRecordTypeDefinitions() []*RecordTypeDefinition {
4848
},
4949
{
5050
Type: RecordTypeTXT,
51-
Description: "文本长度限制512,通常做SPF记录(反垃圾邮件)",
51+
Description: "文本长度限制512,通常做SPF记录或者校验域名所有者",
5252
},
5353
{
5454
Type: RecordTypeCAA,

pkg/dnsconfigs/route_ranges.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,39 @@
22

33
package dnsconfigs
44

5+
import "github.com/TeaOSLab/EdgeCommon/pkg/configutils"
6+
57
type RouteRangeType = string
68

79
const (
810
RouteRangeTypeIP RouteRangeType = "ipRange"
911
)
1012

13+
type RouteRangeInterface interface {
14+
Init() error
15+
Contains(ip uint64) bool
16+
}
17+
1118
// RouteRangeIPRange IP范围配置
1219
type RouteRangeIPRange struct {
1320
IPFrom string `json:"ipFrom"`
1421
IPTo string `json:"ipTo"`
22+
23+
ipFromLong uint64
24+
ipToLong uint64
25+
}
26+
27+
func (this *RouteRangeIPRange) Init() error {
28+
this.ipFromLong = configutils.IP2Long(this.IPFrom)
29+
this.ipToLong = configutils.IP2Long(this.IPTo)
30+
31+
if this.ipFromLong > this.ipToLong {
32+
this.ipFromLong, this.ipToLong = this.ipToLong, this.ipFromLong
33+
}
34+
35+
return nil
36+
}
37+
38+
func (this *RouteRangeIPRange) Contains(ip uint64) bool {
39+
return this.ipFromLong <= ip && this.ipToLong >= ip
1540
}

pkg/rpc/pb/model_ns_domain.pb.go

Lines changed: 27 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/rpc/pb/model_ns_record.pb.go

Lines changed: 37 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/rpc/pb/model_ns_route.pb.go

Lines changed: 38 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)