Style: cleanup code
This commit is contained in:
parent
807d53c1e7
commit
d759d16944
9 changed files with 40 additions and 50 deletions
|
@ -16,25 +16,7 @@ func addrToMetadata(rawAddress string) (addr *C.Metadata, err error) {
|
|||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
if ip != nil {
|
||||
if ip.To4() != nil {
|
||||
addr = &C.Metadata{
|
||||
AddrType: C.AtypIPv4,
|
||||
Host: "",
|
||||
DstIP: ip,
|
||||
DstPort: port,
|
||||
}
|
||||
return
|
||||
} else {
|
||||
addr = &C.Metadata{
|
||||
AddrType: C.AtypIPv6,
|
||||
Host: "",
|
||||
DstIP: ip,
|
||||
DstPort: port,
|
||||
}
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if ip == nil {
|
||||
addr = &C.Metadata{
|
||||
AddrType: C.AtypDomainName,
|
||||
Host: host,
|
||||
|
@ -42,7 +24,23 @@ func addrToMetadata(rawAddress string) (addr *C.Metadata, err error) {
|
|||
DstPort: port,
|
||||
}
|
||||
return
|
||||
} else if ip4 := ip.To4(); ip4 != nil {
|
||||
addr = &C.Metadata{
|
||||
AddrType: C.AtypIPv4,
|
||||
Host: "",
|
||||
DstIP: ip4,
|
||||
DstPort: port,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
addr = &C.Metadata{
|
||||
AddrType: C.AtypIPv6,
|
||||
Host: "",
|
||||
DstIP: ip,
|
||||
DstPort: port,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func tcpKeepAlive(c net.Conn) {
|
||||
|
|
|
@ -40,7 +40,7 @@ func ParseProxyProvider(name string, mapping map[string]interface{}) (ProxyProvi
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var hcInterval uint = 0
|
||||
var hcInterval uint
|
||||
if schema.HealthCheck.Enable {
|
||||
hcInterval = uint(schema.HealthCheck.Interval)
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ func (s *searcher) searchSocketPid(socket uint64) (uint32, error) {
|
|||
}
|
||||
|
||||
func newSearcher(major int) *searcher {
|
||||
var s *searcher = nil
|
||||
var s *searcher
|
||||
switch major {
|
||||
case 11:
|
||||
s = &searcher{
|
||||
|
|
|
@ -22,8 +22,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
getExTcpTable uintptr
|
||||
getExUdpTable uintptr
|
||||
getExTCPTable uintptr
|
||||
getExUDPTable uintptr
|
||||
queryProcName uintptr
|
||||
|
||||
once sync.Once
|
||||
|
@ -35,12 +35,12 @@ func initWin32API() error {
|
|||
return fmt.Errorf("LoadLibrary iphlpapi.dll failed: %s", err.Error())
|
||||
}
|
||||
|
||||
getExTcpTable, err = windows.GetProcAddress(h, tcpTableFunc)
|
||||
getExTCPTable, err = windows.GetProcAddress(h, tcpTableFunc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetProcAddress of %s failed: %s", tcpTableFunc, err.Error())
|
||||
}
|
||||
|
||||
getExUdpTable, err = windows.GetProcAddress(h, udpTableFunc)
|
||||
getExUDPTable, err = windows.GetProcAddress(h, udpTableFunc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetProcAddress of %s failed: %s", udpTableFunc, err.Error())
|
||||
}
|
||||
|
@ -76,10 +76,10 @@ func findProcessName(network string, ip net.IP, srcPort int) (string, error) {
|
|||
var fn uintptr
|
||||
switch network {
|
||||
case TCP:
|
||||
fn = getExTcpTable
|
||||
fn = getExTCPTable
|
||||
class = tcpTablePidConn
|
||||
case UDP:
|
||||
fn = getExUdpTable
|
||||
fn = getExUDPTable
|
||||
class = udpTablePid
|
||||
default:
|
||||
return "", ErrInvalidNetwork
|
||||
|
|
|
@ -122,11 +122,7 @@ func (t *DomainTrie) search(node *Node, parts []string) *Node {
|
|||
}
|
||||
}
|
||||
|
||||
if c := node.getChild(dotWildcard); c != nil {
|
||||
return c
|
||||
}
|
||||
|
||||
return nil
|
||||
return node.getChild(dotWildcard)
|
||||
}
|
||||
|
||||
// New returns a new, empty Trie.
|
||||
|
|
|
@ -90,10 +90,7 @@ func (hc *h2Conn) Close() error {
|
|||
if err := hc.ClientConn.Shutdown(hc.res.Request.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hc.Conn.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return hc.Conn.Close()
|
||||
}
|
||||
|
||||
func StreamH2Conn(conn net.Conn, cfg *H2Config) (net.Conn, error) {
|
||||
|
|
|
@ -16,19 +16,19 @@ import (
|
|||
"github.com/Dreamacro/clash/tunnel"
|
||||
)
|
||||
|
||||
type HttpListener struct {
|
||||
type HTTPListener struct {
|
||||
net.Listener
|
||||
address string
|
||||
closed bool
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
func NewHttpProxy(addr string) (*HttpListener, error) {
|
||||
func NewHTTPProxy(addr string) (*HTTPListener, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hl := &HttpListener{l, addr, false, cache.New(30 * time.Second)}
|
||||
hl := &HTTPListener{l, addr, false, cache.New(30 * time.Second)}
|
||||
|
||||
go func() {
|
||||
log.Infoln("HTTP proxy listening at: %s", addr)
|
||||
|
@ -48,12 +48,12 @@ func NewHttpProxy(addr string) (*HttpListener, error) {
|
|||
return hl, nil
|
||||
}
|
||||
|
||||
func (l *HttpListener) Close() {
|
||||
func (l *HTTPListener) Close() {
|
||||
l.closed = true
|
||||
l.Listener.Close()
|
||||
}
|
||||
|
||||
func (l *HttpListener) Address() string {
|
||||
func (l *HTTPListener) Address() string {
|
||||
return l.address
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ var (
|
|||
|
||||
socksListener *socks.SockListener
|
||||
socksUDPListener *socks.SockUDPListener
|
||||
httpListener *http.HttpListener
|
||||
httpListener *http.HTTPListener
|
||||
redirListener *redir.RedirListener
|
||||
redirUDPListener *redir.RedirUDPListener
|
||||
tproxyListener *redir.TProxyListener
|
||||
|
@ -78,7 +78,7 @@ func ReCreateHTTP(port int) error {
|
|||
}
|
||||
|
||||
var err error
|
||||
httpListener, err = http.NewHttpProxy(addr)
|
||||
httpListener, err = http.NewHTTPProxy(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -316,9 +316,8 @@ func genAddr(host string, port int, allowLan bool) string {
|
|||
if allowLan {
|
||||
if host == "*" {
|
||||
return fmt.Sprintf(":%d", port)
|
||||
} else {
|
||||
return fmt.Sprintf("%s:%d", host, port)
|
||||
}
|
||||
return fmt.Sprintf("%s:%d", host, port)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("127.0.0.1:%d", port)
|
||||
|
|
|
@ -45,15 +45,15 @@ func (ps *Process) Match(metadata *C.Metadata) bool {
|
|||
return strings.EqualFold(cached.(string), ps.process)
|
||||
}
|
||||
|
||||
func (p *Process) Adapter() string {
|
||||
return p.adapter
|
||||
func (ps *Process) Adapter() string {
|
||||
return ps.adapter
|
||||
}
|
||||
|
||||
func (p *Process) Payload() string {
|
||||
return p.process
|
||||
func (ps *Process) Payload() string {
|
||||
return ps.process
|
||||
}
|
||||
|
||||
func (p *Process) ShouldResolveIP() bool {
|
||||
func (ps *Process) ShouldResolveIP() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue