Browse Source

add cache size option

pull/15/head
Jason 5 years ago
parent
commit
0d8782c365
  1. 1
      cmd/tun2socks/main.go
  2. 3
      cmd/tun2socks/main_fakedns.go
  3. 6
      common/dns/fakedns/server.go

1
cmd/tun2socks/main.go

@ -50,6 +50,7 @@ type CmdArgs struct {
FakeIPRange *string
FakeDnsAddr *string
FakeDnsHosts *string
DnsCacheSize *int
ExceptionApps *string
ExceptionSendThrough *string
Stats *bool

3
cmd/tun2socks/main_fakedns.go

@ -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 DNS LRU Cache")
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")
}

6
common/dns/fakedns/server.go

@ -9,8 +9,6 @@ import (
)
const (
lruCacheSize = 1000
dnsFakeTTL uint32 = 1
dnsDefaultTTL uint32 = 600
)
@ -56,12 +54,12 @@ func (s *Server) IPToHost(ip net.IP) (string, bool) {
return s.p.LookBack(ip)
}
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
}
pool, err := fakeip.New(ipnet, lruCacheSize)
pool, err := fakeip.New(ipnet, size)
if err != nil {
return nil, err
}

Loading…
Cancel
Save