mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 07:42:38 +08:00 
			
		
		
		
	ss: remove unused codes
This commit is contained in:
		
							parent
							
								
									aab127d901
								
							
						
					
					
						commit
						9fef98fd5b
					
				
							
								
								
									
										81
									
								
								ss.go
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								ss.go
									
									
									
									
									
								
							@ -5,11 +5,8 @@ import (
 | 
				
			|||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
					 | 
				
			||||||
	"time"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/shadowsocks/go-shadowsocks2/core"
 | 
						"github.com/shadowsocks/go-shadowsocks2/core"
 | 
				
			||||||
	"github.com/shadowsocks/go-shadowsocks2/socks"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const udpBufSize = 65536
 | 
					const udpBufSize = 65536
 | 
				
			||||||
@ -40,12 +37,6 @@ func NewSS(addr, method, pass string, cDialer Dialer, sDialer Dialer) (*SS, erro
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// ListenAndServe serves ss requests.
 | 
					// ListenAndServe serves ss requests.
 | 
				
			||||||
func (s *SS) ListenAndServe() {
 | 
					func (s *SS) ListenAndServe() {
 | 
				
			||||||
	// go s.ListenAndServeUDP()
 | 
					 | 
				
			||||||
	s.ListenAndServeTCP()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// ListenAndServeTCP serves tcp ss requests.
 | 
					 | 
				
			||||||
func (s *SS) ListenAndServeTCP() {
 | 
					 | 
				
			||||||
	l, err := net.Listen("tcp", s.addr)
 | 
						l, err := net.Listen("tcp", s.addr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logf("proxy-ss failed to listen on %s: %v", s.addr, err)
 | 
							logf("proxy-ss failed to listen on %s: %v", s.addr, err)
 | 
				
			||||||
@ -60,12 +51,12 @@ func (s *SS) ListenAndServeTCP() {
 | 
				
			|||||||
			logf("proxy-ss failed to accept: %v", err)
 | 
								logf("proxy-ss failed to accept: %v", err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		go s.ServeTCP(c)
 | 
							go s.Serve(c)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ServeTCP .
 | 
					// Serve .
 | 
				
			||||||
func (s *SS) ServeTCP(c net.Conn) {
 | 
					func (s *SS) Serve(c net.Conn) {
 | 
				
			||||||
	defer c.Close()
 | 
						defer c.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if c, ok := c.(*net.TCPConn); ok {
 | 
						if c, ok := c.(*net.TCPConn); ok {
 | 
				
			||||||
@ -106,7 +97,7 @@ func (s *SS) ServeTCP(c net.Conn) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		c.Write(buf[:n])
 | 
							c.Write(buf[:n])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		logf("proxy-ss %s <-tcp-> %s <-> %s <-udp-> %s ", c.RemoteAddr(), c.LocalAddr(), rc.LocalAddr(), tgt)
 | 
							logf("proxy-ss %s <-tcp-> %s - %s <-udp-> %s ", c.RemoteAddr(), c.LocalAddr(), rc.LocalAddr(), tgt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -130,70 +121,6 @@ func (s *SS) ServeTCP(c net.Conn) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ListenAndServeUDP serves udp ss requests.
 | 
					 | 
				
			||||||
func (s *SS) ListenAndServeUDP() {
 | 
					 | 
				
			||||||
	c, err := net.ListenPacket("udp", s.addr)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		logf("proxy-ss failed to listen on %s: %v", s.addr, err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	defer c.Close()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	logf("proxy-ss listening UDP on %s", s.addr)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c = s.PacketConn(c)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var nm sync.Map
 | 
					 | 
				
			||||||
	buf := make([]byte, udpBufSize)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		n, raddr, err := c.ReadFrom(buf)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logf("UDP remote read error: %v", err)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tgtAddr := socks.SplitAddr(buf[:n])
 | 
					 | 
				
			||||||
		if tgtAddr == nil {
 | 
					 | 
				
			||||||
			logf("failed to split target address from packet: %q", buf[:n])
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		tgtUDPAddr, err := net.ResolveUDPAddr("udp", tgtAddr.String())
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logf("failed to resolve target UDP address: %v", err)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		payload := buf[len(tgtAddr):n]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var pc net.PacketConn
 | 
					 | 
				
			||||||
		v, _ := nm.Load(raddr.String())
 | 
					 | 
				
			||||||
		if v == nil {
 | 
					 | 
				
			||||||
			pc, err = net.ListenPacket("udp", "")
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				logf("UDP remote listen error: %v", err)
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			nm.Store(raddr.String(), pc)
 | 
					 | 
				
			||||||
			go func() {
 | 
					 | 
				
			||||||
				timedCopy(c, raddr, pc, 5*time.Minute, true)
 | 
					 | 
				
			||||||
				pc.Close()
 | 
					 | 
				
			||||||
				nm.Delete(raddr.String())
 | 
					 | 
				
			||||||
			}()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		pc = pc.(net.PacketConn)
 | 
					 | 
				
			||||||
		_, err = pc.WriteTo(payload, tgtUDPAddr) // accept only UDPAddr despite the signature
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			logf("UDP remote write error: %v", err)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Dial connects to the address addr on the network net via the proxy.
 | 
					// Dial connects to the address addr on the network net via the proxy.
 | 
				
			||||||
func (s *SS) Dial(network, addr string) (net.Conn, error) {
 | 
					func (s *SS) Dial(network, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user