mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 02:30:05 +08:00
add an option to set cache size
This commit is contained in:
@@ -50,6 +50,7 @@ type CmdArgs struct {
|
||||
FakeIPRange *string
|
||||
FakeDnsAddr *string
|
||||
FakeDnsHosts *string
|
||||
DnsCacheSize *int
|
||||
ExceptionApps *string
|
||||
ExceptionSendThrough *string
|
||||
Stats *bool
|
||||
|
@@ -13,10 +13,11 @@ func init() {
|
||||
args.FakeDnsAddr = flag.String("fakeDnsAddr", ":53", "listen address of fake DNS")
|
||||
args.FakeIPRange = flag.String("fakeIPRange", "198.18.0.1/16", "fake IP CIDR range for DNS")
|
||||
args.FakeDnsHosts = flag.String("fakeDnsHosts", "", "Hosts mapping, e.g. 'a.com=1.1.1.1,b.net=2.2.2.2'")
|
||||
args.DnsCacheSize = flag.Int("dnsCacheSize", 100, "Size of LRU-Cache to store DNS msg")
|
||||
|
||||
addPostFlagsInitFn(func() {
|
||||
if *args.EnableFakeDns {
|
||||
fakeDnsServer, err := fakedns.NewServer(*args.FakeIPRange, *args.FakeDnsHosts)
|
||||
fakeDnsServer, err := fakedns.NewServer(*args.FakeIPRange, *args.FakeDnsHosts, *args.DnsCacheSize)
|
||||
if err != nil {
|
||||
panic("create fake dns server error")
|
||||
}
|
||||
|
@@ -18,8 +18,6 @@ const (
|
||||
|
||||
// var cacheDuration = time.Duration(dnsDefaultTTL) * time.Second
|
||||
|
||||
var cacheSize = 100
|
||||
|
||||
type Server struct {
|
||||
*D.Server
|
||||
c *cache.Cache
|
||||
@@ -68,7 +66,7 @@ func (s *Server) IPToHost(ip net.IP) (string, bool) {
|
||||
return strings.TrimRight(fqdn, "."), true
|
||||
}
|
||||
|
||||
func NewServer(fakeIPRange, hostsLine string) (*Server, error) {
|
||||
func NewServer(fakeIPRange, hostsLine string, size int) (*Server, error) {
|
||||
_, ipnet, err := net.ParseCIDR(fakeIPRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,7 +77,7 @@ func NewServer(fakeIPRange, hostsLine string) (*Server, error) {
|
||||
}
|
||||
|
||||
hosts := lineToHosts(hostsLine)
|
||||
cacheItem := cache.New(cacheSize)
|
||||
cacheItem := cache.New(size)
|
||||
handler := newHandler(hosts, cacheItem, pool)
|
||||
|
||||
return &Server{
|
||||
|
Reference in New Issue
Block a user