mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-31 01:19:43 +00:00
feat(server): Add DNS caching and centralized resolver configuration
This commit is contained in:
@@ -30,6 +30,8 @@ type Server struct {
|
||||
peerIdx atomic.Uint32
|
||||
wg sync.WaitGroup
|
||||
dnsServer string
|
||||
dnsCache sync.Map
|
||||
resolver *net.Resolver
|
||||
}
|
||||
|
||||
type ConnectRequest struct {
|
||||
@@ -74,6 +76,18 @@ func Run(ctx context.Context, roomURL, keyHex string, duo bool, dnsServer string
|
||||
peers: make([]*telemost.Peer, 0),
|
||||
dnsServer: dnsServer,
|
||||
}
|
||||
|
||||
if dnsServer == "" {
|
||||
dnsServer = "1.1.1.1:53"
|
||||
}
|
||||
|
||||
s.resolver = &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d := net.Dialer{Timeout: 3 * time.Second}
|
||||
return d.DialContext(ctx, network, dnsServer)
|
||||
},
|
||||
}
|
||||
|
||||
peerCount := 1
|
||||
if duo {
|
||||
@@ -305,18 +319,10 @@ func (s *Server) handleConnect(sid uint16, req ConnectRequest) {
|
||||
|
||||
dialStart := time.Now()
|
||||
|
||||
resolver := &net.Resolver{
|
||||
PreferGo: true,
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d := net.Dialer{Timeout: 2 * time.Second}
|
||||
return d.DialContext(ctx, network, s.dnsServer)
|
||||
},
|
||||
}
|
||||
|
||||
dialer := &net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
Timeout: 10 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
Resolver: resolver,
|
||||
Resolver: s.resolver,
|
||||
}
|
||||
|
||||
conn, err := dialer.Dial("tcp4", addr)
|
||||
|
||||
Reference in New Issue
Block a user