Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# GoDNS
# xdns

[![madewithlove](https://img.shields.io/badge/made_with-%E2%9D%A4-red?style=for-the-badge&labelColor=orange&style=flat-square)](https://github.com/TochusC/godns)
![Go Version](https://img.shields.io/github/go-mod/go-version/tochusc/godns/master?filename=go.mod&style=flat-square)
![Latest Version](https://img.shields.io/github/v/tag/tochusc/godns?label=latest&style=flat-square)
![License](https://img.shields.io/github/license/tochusc/godns?style=flat-square)
[![GoDoc](https://godoc.org/github.com/tochusc/godns?status.svg)](https://godoc.org/github.com/tochusc/godns)
[![madewithlove](https://img.shields.io/badge/made_with-%E2%9D%A4-red?style=for-the-badge&labelColor=orange&style=flat-square)](https://github.com/TochusC/xdns)
![Go Version](https://img.shields.io/github/go-mod/go-version/tochusc/xdns/master?filename=go.mod&style=flat-square)
![Latest Version](https://img.shields.io/github/v/tag/tochusc/xdns?label=latest&style=flat-square)
![License](https://img.shields.io/github/license/tochusc/xdns?style=flat-square)
[![GoDoc](https://godoc.org/github.com/tochusc/xdns?status.svg)](https://godoc.org/github.com/tochusc/xdns)

[简体中文](README.md) | [English](docs/en/README.md)

GoDNS 是一个快速、灵活的**实验用** DNS 服务器,旨在帮助开发者和研究人员探索和实验 DNS 协议的各种特性。
xdns 是一个快速、灵活的**实验用** DNS 服务器,旨在帮助开发者和研究人员探索和实验 DNS 协议的各种特性。

## 目录

- [GoDNSServer](#godnsserver)
- [xdnsServer](#xdnsserver)
- [示例](#示例)
- [构造和生成 DNS 回复](#构造和生成-dns-回复)
- [dns 包](#dns-包)
- [xlayers 子包](#xlayers-子包)
- [xperi 子包](#xperi-子包)

## GoDNSServer
## xdnsServer

`GoDNSServer` 是对 DNS 服务器的最顶层封装, 其由三部分组成:
`xdnsServer` 是对 DNS 服务器的最顶层封装, 其由三部分组成:

1. **ServerConfig**: DNS 服务器配置。
2. **Netter**: 数据包处理器:接收、解析、发送数据包,并维护连接状态。
3. **Responser**: DNS回复器:响应、解析、构造DNS回复

```go
type GoDNSServer struct {
type xdnsServer struct {
ServerConfig DNSServerConfig
Netter Netter
Responer Responser
}

// GoDNSServer 启动!
func (s *GoDNSServer) Start()
// xdnsServer 启动!
func (s *xdnsServer) Start()
```

### Netter
Expand Down Expand Up @@ -84,14 +84,14 @@ type Responser interface { // size=16 (0x10)

## 示例

通过下述几行代码,可以一键启动一个基础的 GoDNS 服务器:
通过下述几行代码,可以一键启动一个基础的 xdns 服务器:

```go
// 创建一个 DNS 服务器
server := godns.GoDNSServer{
server := xdns.xdnsServer{
ServerConfig: sConf,
Netter: godns.Netter{
Config: godns.NetterConfig{
Netter: xdns.Netter{
Config: xdns.NetterConfig{
Port: sConf.Port,
MTU: sConf.MTU,
},
Expand Down Expand Up @@ -183,4 +183,4 @@ func (s *struct) Equal(other *struct) bool

---

如需更多信息或支持,请访问我们的 [GitHub 页面](https://github.com/TochusC/godns)。
如需更多信息或支持,请访问我们的 [GitHub 页面](https://github.com/TochusC/xdns)。
9 changes: 3 additions & 6 deletions cacher.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package godns
package xdns

import (
"encoding/binary"
Expand All @@ -8,28 +8,25 @@ import (
"os"
"path/filepath"

"github.com/panjf2000/ants/v2"
"github.com/tochusc/godns/dns"
"github.com/tochusc/xdns/dns"
)

type Cacher struct {
CacheLocation string
CacherLogger *log.Logger
CacherPool *ants.Pool
}

type CacherConfig struct {
CacheLocation string
LogWriter io.Writer
}

func NewCacher(conf CacherConfig, pool *ants.Pool) *Cacher {
func NewCacher(conf CacherConfig) *Cacher {
cacherLogger := log.New(conf.LogWriter, "Cacher: ", log.LstdFlags)

return &Cacher{
CacheLocation: conf.CacheLocation,
CacherLogger: cacherLogger,
CacherPool: pool,
}
}

Expand Down
10 changes: 2 additions & 8 deletions dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ func (dnsMessage *DNSMessage) String() string {
"### DNS Message ###\n",
dnsMessage.Header.String(), "\n",
dnsMessage.Question.String(),
"### Answer Section ###\n",
dnsMessage.Answer.String(),
"### Authority Section ###\n",
dnsMessage.Authority.String(),
"### Additional Section ###\n",
dnsMessage.Additional.String(),
"### DNS Message End ###",
)
Expand Down Expand Up @@ -497,7 +494,7 @@ func (section DNSQuestionSection) Size() int {
// String 以“易读的形式”返回DNS消息 的 问题部分的字符串表示。
// - 其返回值为 DNS消息 的 问题部分的字符串表示。
func (section DNSQuestionSection) String() string {
result := "### DNS Question Section ###\n"
var result string
for _, question := range section {
result += question.String() + "\n"
}
Expand Down Expand Up @@ -609,7 +606,7 @@ func (responseSection DNSResponseSection) Size() int {

// String 以“易读的形式”返回DNS响应部分的字符串表示。
func (responseSection DNSResponseSection) String() string {
result := ""
var result string
for _, record := range responseSection {
result += record.String() + "\n"
}
Expand Down Expand Up @@ -687,9 +684,6 @@ func (rr *DNSResourceRecord) Size() int {
// String 以*易读的形式*返回 DNS 资源记录的字符串表示。
// - 其返回值为 DNS 资源记录的字符串表示。
func (rr *DNSResourceRecord) String() string {
if IsPseudoRR(rr) {
return NewPseudoRR(rr).String()
}
return fmt.Sprint(
"### DNS Resource Record ###\n",
"Name:", rr.Name, "\n",
Expand Down
Loading
Loading