zns

package module
v0.0.0-...-c20d5bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 28 Imported by: 0

README

ZNS - Simple DoH server in Go

安装

go install github.com/taoso/zns/cmd/zns@latest

运行

zns -c /etc/zns/zns.toml

配置文件格式参考 zns.toml

原理

https://taoshu.in/dns/diy-doh.html

星标趋势

Star History Chart

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author interface {
	Auth(token string) (bool, error)
}

type BlockList

type BlockList struct {
	// contains filtered or unexported fields
}

BlockList type Supports wildcard domains like "*.example.com" to block all subdomains. Supports suffix wildcards like "*-ad.example.com" to block domains ending with "-ad.example.com".

func NewBlockList

func NewBlockList() *BlockList

NewBlockList returns a new BlockList.

func (*BlockList) Exists

func (b *BlockList) Exists(key string) bool

(*BlockList).Exists exists returns whether or not a key exists in the cache.

func (*BlockList) Load

func (b *BlockList) Load(path string) error

func (*BlockList) ParseMosdnsV5

func (b *BlockList) ParseMosdnsV5(r io.Reader) error

type DBAuthor

type DBAuthor struct {
	Repo TicketRepo
}

func (DBAuthor) Auth

func (a DBAuthor) Auth(token string) (ok bool, err error)

type FileAuther

type FileAuther struct {
	Path string
	// contains filtered or unexported fields
}

func (*FileAuther) Auth

func (a *FileAuther) Auth(token string) (ok bool, err error)

func (*FileAuther) Load

func (a *FileAuther) Load() error

type FileLoader

type FileLoader struct {
	// contains filtered or unexported fields
}

func NewFileLoader

func NewFileLoader() *FileLoader

func (*FileLoader) Loop

func (l *FileLoader) Loop()

func (*FileLoader) Start

func (l *FileLoader) Start()

func (*FileLoader) Stop

func (l *FileLoader) Stop()

func (*FileLoader) Watch

func (l *FileLoader) Watch(file string, cb func(file string))

type Handler

type Handler struct {
	Upstream Upstream
	Auther   Author
	Root     http.Dir
	Blocker  *BlockList
}

func (*Handler) ServeDoT

func (p *Handler) ServeDoT(conn *tls.Conn)

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Handler) ServeMetrics

func (h *Handler) ServeMetrics(w http.ResponseWriter, r *http.Request)

type Node

type Node struct {
	Host string `json:"host" yaml:"host"`
	Flag string `json:"flag" yaml:"flag"`
	IPv6 bool   `json:"ipv6" yaml:"ipv6"`
	Tier int    `json:"tier" yaml:"tier"`
}

type Order

type Order struct {
	CentNum int    // 支付金额,单位分
	OrderNo string // 商户订单号
	TradeNo string // 支付宝交易号
	Tier    int    // 购买的套餐等级
}

type Pay

type Pay interface {
	NewQR(order Order, notifyURL string) (string, error)
	OnPay(req *http.Request) (Order, error)
}

func NewZzPay

func NewZzPay(znsPrivateKey, zzPublicKey string) Pay

type Ticket

type Ticket struct {
	ID       int    `db:"id" json:"id"`
	Token    string `db:"token" json:"-"`
	Cents    int    `db:"cents" json:"cents"`
	Tier     int    `db:"tier" json:"tier"`
	PayOrder string `db:"pay_order" json:"pay_order"` // 商户订单号
	BuyOrder string `db:"buy_order" json:"buy_order"` // 支付宝交易号

	Created time.Time `db:"created" json:"created"`
	Updated time.Time `db:"updated" json:"updated"`
	Expires time.Time `db:"expires" json:"expires"`
}

func (*Ticket) KeyName

func (_ *Ticket) KeyName() string

func (*Ticket) Schema

func (t *Ticket) Schema() string

func (*Ticket) TableName

func (_ *Ticket) TableName() string

type TicketHandler

type TicketHandler struct {
	Pay    Pay
	Repo   TicketRepo
	AltSvc string

	Nodes []Node
}

func (*TicketHandler) GetMyNodes

func (h *TicketHandler) GetMyNodes(w http.ResponseWriter, r *http.Request)

func (*TicketHandler) ServeHTTP

func (h *TicketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TicketRepo

type TicketRepo interface {
	// 新增购买记录
	NewTicket(ticket Ticket) error
	// List fetches all current Tickets with bytes available.
	List(token string, limit int) ([]Ticket, error)
}

func NewTicketRepo

func NewTicketRepo(path string) TicketRepo

type Upstream

type Upstream interface {
	Query(*dns.Msg) ([]byte, error)
}

type UpstreamHTTP

type UpstreamHTTP struct {
	Server  string
	HTTP3   bool
	Timeout time.Duration
	// contains filtered or unexported fields
}

UpstreamHTTP makes a DNS query over UpstreamHTTP(s)

func (*UpstreamHTTP) Query

func (h *UpstreamHTTP) Query(m *dns.Msg) ([]byte, error)

type UpstreamPlain

type UpstreamPlain struct {
	Server  string
	Timeout time.Duration
}

UpstreamPlain makes a DNS query over TCP or UDP (with TCP fallback)

func (*UpstreamPlain) Query

func (p *UpstreamPlain) Query(m *dns.Msg) ([]byte, error)

Directories

Path Synopsis
cmd
zns command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL