remove tcp keep-alive and update socks5 udp

This commit is contained in:
unknown
2019-12-02 14:27:50 +08:00
parent 91c1ffc6ce
commit 2e5b1bd1e3
4 changed files with 57 additions and 16 deletions

View File

@@ -3,7 +3,6 @@ package proxy
import (
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"strconv"
@@ -174,12 +173,7 @@ func (s *Sock5ModeServer) sendUdpReply(writeConn net.Conn, c net.Conn, rep uint8
}
var serveExternalIp string
func (s *Sock5ModeServer) handleUDP(c net.Conn) {
if serveExternalIp == "" {
serveExternalIp = common.GetExternalIp()
}
defer c.Close()
addrType := make([]byte, 1)
c.Read(addrType)
@@ -206,7 +200,7 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
//读取端口
var port uint16
binary.Read(c, binary.BigEndian, &port)
fmt.Println(host, string(port))
logs.Warn(host, string(port))
replyAddr, err := net.ResolveUDPAddr("udp", s.task.ServerIp+":0")
if err != nil {
logs.Error("build local reply addr error", err)
@@ -219,9 +213,8 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
return
}
// reply the local addr
s.sendUdpReply(c, reply, succeeded, serveExternalIp)
s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(c.RemoteAddr().(*net.TCPAddr).IP))
defer reply.Close()
// new a tunnel to client
link := conn.NewLink("udp", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false)
target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task)