mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 10:24:40 +01:00
53 lines
969 B
Go
53 lines
969 B
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type CryptoConstruction uint16
|
|
|
|
const (
|
|
UndefinedConstruction CryptoConstruction = iota
|
|
XSalsa20Poly1305
|
|
XChacha20Poly1305
|
|
)
|
|
|
|
var (
|
|
CertMagic = [4]byte{0x44, 0x4e, 0x53, 0x43}
|
|
ServerMagic = [8]byte{0x72, 0x36, 0x66, 0x6e, 0x76, 0x57, 0x6a, 0x38}
|
|
MinDNSPacketSize = 12
|
|
MaxDNSPacketSize = 4096
|
|
MaxDNSUDPPacketSize = 1252
|
|
InitialMinQuestionSize = 256
|
|
TimeoutMin = 1 * time.Second
|
|
TimeoutMax = 5 * time.Second
|
|
)
|
|
|
|
type ServerInfo struct {
|
|
MagicQuery [8]byte
|
|
ServerPk [32]byte
|
|
SharedKey [32]byte
|
|
CryptoConstruction CryptoConstruction
|
|
Timeout time.Duration
|
|
UDPAddr *net.UDPAddr
|
|
TCPAddr *net.TCPAddr
|
|
}
|
|
|
|
func HasTCFlag(packet []byte) bool {
|
|
return packet[2]&2 == 2
|
|
}
|
|
|
|
func Min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func Max(a, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|