-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
98 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package util | ||
|
||
import ( | ||
"blocky/config" | ||
"blocky/log" | ||
|
||
"context" | ||
"fmt" | ||
"net" | ||
"time" | ||
) | ||
|
||
// Dialer creates a new dialer instance with bootstrap DNS as resolver | ||
func Dialer(cfg *config.Config) *net.Dialer { | ||
var resolver *net.Resolver | ||
|
||
if cfg.BootstrapDNS != (config.Upstream{}) { | ||
if cfg.BootstrapDNS.Net == config.NetTCPUDP { | ||
dns := net.JoinHostPort(cfg.BootstrapDNS.Host, fmt.Sprint(cfg.BootstrapDNS.Port)) | ||
log.Log().Debugf("using %s as bootstrap dns server", dns) | ||
|
||
resolver = &net.Resolver{ | ||
PreferGo: true, | ||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) { | ||
d := net.Dialer{ | ||
Timeout: time.Millisecond * time.Duration(2000), | ||
} | ||
return d.DialContext(ctx, "udp", dns) | ||
}} | ||
} else { | ||
log.Log().Fatal("bootstrap dns net should be tcp+udp") | ||
} | ||
} | ||
|
||
return &net.Dialer{ | ||
Timeout: 5 * time.Second, | ||
Resolver: resolver, | ||
} | ||
} |