Print stamps; require an env variable for debug level
This commit is contained in:
parent
0fe21b2d57
commit
88414e1448
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue