Skip to content

Commit

Permalink
Merge pull request #41 from wolf-joe/refactor
Browse files Browse the repository at this point in the history
v1.0
  • Loading branch information
wolf-joe authored Dec 7, 2022
2 parents fd984ff + 3c05924 commit f7ac1b2
Show file tree
Hide file tree
Showing 66 changed files with 5,290 additions and 3,896 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: "--out-${NO_FUTURE}format colored-line-number"

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./... -gcflags=all=-l -coverprofile=coverage.txt -covermode=atomic -race

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ src/
pkg/
bin/
dist/
go.sum

delegated-apnic-latest
cnip.txt
gfwlist*.txt
/gfwlist*.txt
coverage.txt
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# Telescope DNS

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wolf-joe/ts-dns)](https://github.com/wolf-joe/ts-dns/releases)
[![Build Status](https://travis-ci.org/wolf-joe/ts-dns.svg?branch=master)](https://travis-ci.org/wolf-joe/ts-dns)
[![Go](https://github.com/wolf-joe/ts-dns/actions/workflows/go.yml/badge.svg)](https://github.com/wolf-joe/ts-dns/actions/workflows/go.yml)
[![codecov](https://codecov.io/gh/wolf-joe/ts-dns/branch/master/graph/badge.svg)](https://codecov.io/gh/wolf-joe/ts-dns)
[![Go Report Card](https://goreportcard.com/badge/github.com/wolf-joe/ts-dns)](https://goreportcard.com/report/github.com/wolf-joe/ts-dns)
![GitHub](https://img.shields.io/github/license/wolf-joe/ts-dns)

> 简单易用的DNS分组/转发器
> 灵活快速的DNS分组转发器
## 基本特性
## 设计目标
### 灵活解析
* 支持按ABP风格规则/`GFWList`对DNS请求进行分组
* 支持按CIDR对DNS请求进行重定向
* 支持DNS over UDP/TCP/TLS/HTTPS、socks5代理、ECS
* 支持将查询结果中的IPv4地址添加至IPSet
### 快速解析
* 支持并发请求上游DNS,选择最快响应
* 选择ping值最低的IPv4地址(tcp/icmp ping)
* 支持hosts/DNS缓存/屏蔽指定查询类型
* 支持热重载配置文件

* 默认基于`CN IP列表` + `GFWList`进行域名分组;
* 支持DNS over UDP/TCP/TLS/HTTPS、非标准端口DNS;
* 支持选择ping值最低的IPv4地址(tcp/icmp ping);
* 支持并发请求/socks5代理请求上游DNS,支持附带指定ECS信息;
* 支持多Hosts文件 + 自定义Hosts、通配符Hosts;
* 支持配置文件自动重载,支持监听TCP/UDP端口;
* 支持DNS查询缓存(IP乱序、TTL倒计时、ECS);
* 支持屏蔽指定查询类型;
* 支持将查询结果中的IPv4地址添加至IPSet。
## 解析流程
![arch.drawio.svg](doc/arch.drawio.svg)

## DNS查询请求处理流程

1. 当域名匹配指定规则(配置文件里各组的`rules`)时,将请求转发至对应组上游DNS并直接返回;
2. 如未匹配规则,则假设域名为`clean`组,向`clean`组的上游DNS转发查询请求,并做如下判断:
* 如果查询结果中所有IPv4地址均为`CN IP`,则直接返回;
* 如果查询结果中出现非`CN IP`,进一步判断:
* 如果该域名匹配GFWList列表,则向`dirty`组的上游DNS转发查询请求并返回;
* 否则返回查询结果。
```
查找hosts -> 查找缓存 -> 匹配规则 -> 指定group处理 -> 重定向 -> 设置缓存
```

## 使用说明

Expand All @@ -36,8 +34,8 @@
```shell
# ./ts-dns -h # 显示命令行帮助信息
# ./ts-dns -c ts-dns.toml # 指定配置文件名
# ./ts-dns -r # 自动重载配置文件
./ts-dns
kill -SIGHUP <PID> # 重载配置文件
```

## 配置示例
Expand All @@ -47,16 +45,15 @@
1. 默认配置(`ts-dns.toml`),开箱即用
```toml
listen = ":53"
gfwlist = "gfwlist.txt"
cnip = "cnip.txt"

[groups]
[groups.clean]
dns = ["223.5.5.5", "114.114.114.114"]
concurrent = true

[groups.dirty]
dns = [""] # 省略
dns = [""] # 省略
gfwlist_file = "gfwlist.txt"
```

2. 选择ping值最低的IPv4地址(启用时建议以root权限运行本程序)
Expand Down Expand Up @@ -112,9 +109,12 @@
```


## TODO
## 未来规划

* 设置fallback DNS
- [ ] 支持定期拉取最新gfwlist
- [ ] 支持http接口管理
- [ ] 降低gfwlist的匹配优先级
- [ ] DoT/GFWList域名解析自闭环

## 特别鸣谢
* [github.com/arloan/prdns](https://github.com/arloan/prdns)
Expand Down
Loading

0 comments on commit f7ac1b2

Please sign in to comment.