Stamps are not expected to include a name

This commit is contained in:
Frank Denis 2018-01-09 18:27:04 +01:00
parent 4dc3fee9a0
commit 00a6b64575
3 changed files with 17 additions and 14 deletions

View File

@ -21,6 +21,7 @@ var (
InitialMinQuestionSize = 256
TimeoutMin = 1 * time.Second
TimeoutMax = 5 * time.Second
CertRefreshDelay = 30 * time.Minute
)
func HasTCFlag(packet []byte) bool {

View File

@ -21,16 +21,16 @@ type Proxy struct {
func main() {
log.SetFlags(0)
NewProxy("127.0.0.1:5399", "dnscrypt.org-fr", "212.47.228.136:443", "E801:B84E:A606:BFB0:BAC0:CE43:445B:B15E:BA64:B02F:A3C4:AA31:AE10:636A:0790:324D", "2.dnscrypt-cert.fr.dnscrypt.org")
stamp, _ := NewServerStampFromLegacy("212.47.228.136:443", "E801:B84E:A606:BFB0:BAC0:CE43:445B:B15E:BA64:B02F:A3C4:AA31:AE10:636A:0790:324D", "2.dnscrypt-cert.fr.dnscrypt.org")
NewProxy("127.0.0.1:5399", "dnscrypt.org-fr", stamp)
}
func NewProxy(listenAddrStr string, serverName string, serverAddrStr string, serverPkStr string, providerName string) {
func NewProxy(listenAddrStr string, serverName string, stamp ServerStamp) {
proxy := Proxy{questionSizeEstimator: NewQuestionSizeEstimator(), timeout: TimeoutMax}
if _, err := rand.Read(proxy.proxySecretKey[:]); err != nil {
log.Fatal(err)
}
curve25519.ScalarBaseMult(&proxy.proxyPublicKey, &proxy.proxySecretKey)
stamp, _ := NewServerStampFromLegacy(serverName, serverAddrStr, serverPkStr, providerName)
proxy.serversInfo.registerServer(&proxy, serverName, stamp)
listenUDPAddr, err := net.ResolveUDPAddr("udp", listenAddrStr)
if err != nil {
@ -47,7 +47,7 @@ func NewProxy(listenAddrStr string, serverName string, serverAddrStr string, ser
proxy.tcpListener(listenTCPAddr)
}()
for {
time.Sleep(30 * time.Minute)
time.Sleep(CertRefreshDelay)
proxy.serversInfo.refresh(&proxy)
}
}

View File

@ -14,15 +14,18 @@ import (
)
type ServerStamp struct {
name string
serverAddrStr string
serverPkStr string
providerName string
}
func NewServerStampFromLegacy(name string, serverAddrStr string, serverPkStr string, providerName string) (ServerStamp, error) {
type RegisteredServer struct {
name string
stamp ServerStamp
}
func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, providerName string) (ServerStamp, error) {
return ServerStamp{
name: name,
serverAddrStr: serverAddrStr,
serverPkStr: serverPkStr,
providerName: providerName,
@ -42,8 +45,8 @@ type ServerInfo struct {
type ServersInfo struct {
sync.RWMutex
inner []ServerInfo
serverStamps []ServerStamp
inner []ServerInfo
registeredServers []RegisteredServer
}
func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp ServerStamp) error {
@ -60,18 +63,17 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
}
}
serversInfo.inner = append(serversInfo.inner, newServer)
serversInfo.serverStamps = append(serversInfo.serverStamps, stamp)
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
return nil
}
func (serversInfo *ServersInfo) refresh(proxy *Proxy) {
fmt.Println("Refreshing certificates")
serversInfo.RLock()
stamps := serversInfo.serverStamps
registeredServers := serversInfo.registeredServers
serversInfo.RUnlock()
for _, stamp := range stamps {
serversInfo.registerServer(proxy, stamp.name, stamp)
_ = stamp
for _, registeredServer := range registeredServers {
serversInfo.registerServer(proxy, registeredServer.name, registeredServer.stamp)
}
}