Browse Source

cleanup

pull/15/head
Jason 5 years ago
parent
commit
0be1c612ba
  1. 26
      common/lru-cache/cache.go
  2. 4
      proxy/direct/tcp.go
  3. 6
      proxy/direct/udp.go

26
common/lru-cache/cache.go

@ -1,26 +0,0 @@
package cache
import (
lru "github.com/hashicorp/golang-lru"
)
type Cache struct {
*lru.Cache
}
func (c *Cache) Add(key interface{}, payload interface{}) {
_ = c.Cache.Add(key, payload)
}
func (c *Cache) Get(key interface{}) interface{} {
item, ok := c.Cache.Get(key)
if !ok {
return nil
}
return item
}
func New(size int, onEvicted func(key interface{}, value interface{})) *Cache {
c, _ := lru.NewWithEvict(size, onEvicted)
return &Cache{c}
}

4
proxy/direct/tcp.go

@ -1,12 +1,8 @@
package direct
import (
"errors"
"fmt"
"io"
"net"
"sync"
"time"
"github.com/xjasonlyu/tun2socks/common/log"
"github.com/xjasonlyu/tun2socks/core"

6
proxy/direct/udp.go

@ -49,7 +49,7 @@ func (h *udpHandler) fetchUDPInput(conn core.UDPConn, pc *net.UDPConn) {
}
}
func (h *udpHandler) Connect(conn core.UDPConn, target net.Addr) error {
func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
bindAddr := &net.UDPAddr{IP: nil, Port: 0}
pc, err := net.ListenUDP("udp", bindAddr)
if err != nil {
@ -64,7 +64,7 @@ func (h *udpHandler) Connect(conn core.UDPConn, target net.Addr) error {
return nil
}
func (h *udpHandler) ReceiveTo(conn core.UDPConn, data []byte, addr net.Addr) error {
func (h *udpHandler) ReceiveTo(conn core.UDPConn, data []byte, addr *net.UDPAddr) error {
h.Lock()
pc, ok1 := h.udpConns[conn]
h.Unlock()
@ -77,7 +77,7 @@ func (h *udpHandler) ReceiveTo(conn core.UDPConn, data []byte, addr net.Addr) er
}
return nil
} else {
return errors.New(fmt.Sprintf("proxy connection %v->%v does not exists", conn.LocalAddr(), conn.RemoteAddr()))
return errors.New(fmt.Sprintf("proxy connection %v->%v does not exists", conn.LocalAddr(), addr))
}
}

Loading…
Cancel
Save