diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index 1703a4a8..927d5c78 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -105,6 +105,9 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error { if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) { dlog.SetLogLevel(dlog.Severity(config.LogLevel)) } + if dlog.LogLevel() <= dlog.SeverityDebug && os.Getenv("DEBUG") == "" { + dlog.SetLogLevel(dlog.SeverityInfo) + } if config.UseSyslog { dlog.UseSyslog(true) } else if config.LogFile != nil { diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index ea2e5bcb..3829a007 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -2,7 +2,6 @@ package main import ( "encoding/hex" - "fmt" "math/rand" "net" "strings" @@ -26,30 +25,11 @@ const ( ServerInformalPropertyNoLog = ServerInformalProperties(1) << 1 ) -type ServerStamp struct { - serverAddrStr string - serverPkStr string - providerName string - props ServerInformalProperties -} - type RegisteredServer struct { name string stamp ServerStamp } -func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, providerName string, props ServerInformalProperties) (ServerStamp, error) { - if net.ParseIP(serverAddrStr) != nil { - serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort) - } - return ServerStamp{ - serverAddrStr: serverAddrStr, - serverPkStr: serverPkStr, - providerName: providerName, - props: props, - }, nil -} - type ServerInfo struct { sync.RWMutex MagicQuery [8]byte diff --git a/dnscrypt-proxy/sources.go b/dnscrypt-proxy/sources.go index 1e5fba8d..e4b5745c 100644 --- a/dnscrypt-proxy/sources.go +++ b/dnscrypt-proxy/sources.go @@ -187,6 +187,7 @@ func (source *Source) Parse() ([]RegisteredServer, error) { registeredServer := RegisteredServer{ name: name, stamp: stamp, } + dlog.Debugf("Registered [%s] with stamp [%s]", name, stamp.String()) registeredServers = append(registeredServers, registeredServer) } return registeredServers, nil diff --git a/dnscrypt-proxy/stamps.go b/dnscrypt-proxy/stamps.go new file mode 100644 index 00000000..a780a406 --- /dev/null +++ b/dnscrypt-proxy/stamps.go @@ -0,0 +1,53 @@ +package main + +import ( + "encoding/base64" + "encoding/binary" + "fmt" + "net" +) + +type ServerStamp struct { + serverAddrStr string + serverPkStr string + providerName string + props ServerInformalProperties +} + +func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, providerName string, props ServerInformalProperties) (ServerStamp, error) { + if net.ParseIP(serverAddrStr) != nil { + serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort) + } + return ServerStamp{ + serverAddrStr: serverAddrStr, + serverPkStr: serverPkStr, + providerName: providerName, + props: props, + }, nil +} + +// id(u8) props addrLen(1) serverAddr pkStrlen(1) pkStr providerNameLen(1) providerName + +func NewServerStampFromString(stampStr string) (ServerStamp, error) { + stamp := ServerStamp{} + return stamp, nil +} + +func (stamp *ServerStamp) String() string { + bin := make([]uint8, 9) + bin[0] = 0x01 + binary.LittleEndian.PutUint64(bin[1:9], uint64(stamp.props)) + + bin = append(bin, uint8(len(stamp.serverAddrStr))) + bin = append(bin, []uint8(stamp.serverAddrStr)...) + + bin = append(bin, uint8(len(stamp.serverPkStr))) + bin = append(bin, []uint8(stamp.serverPkStr)...) + + bin = append(bin, uint8(len(stamp.providerName))) + bin = append(bin, []uint8(stamp.providerName)...) + + str := base64.RawURLEncoding.EncodeToString(bin) + + return "dnsc://" + str +}