This commit is contained in:
esrrhs committed 2019-10-30 19:45:19 +08:00
1 parent a4573f1540
commit 160d6efc89
3 files changed
+44 -10

No files matched your search

+22 -4
View File
@@ -8,6 +8,7 @@ import (
"math"
"math/rand"
"net"
"sync"
"time"
)
@@ -65,9 +66,10 @@ func NewClient(addr string, server string, target string, timeout int, key int,
}
type Client struct {
exit bool
rtt time.Duration
interval *time.Ticker
exit bool
rtt time.Duration
interval *time.Ticker
workResultLock sync.WaitGroup
id int
sequence int
@@ -176,11 +178,14 @@ func (p *Client) Run() error {
}
recv := make(chan *Packet, 10000)
go recvICMP(*p.conn, recv)
go recvICMP(&p.workResultLock, &p.exit, *p.conn, recv)
p.interval = time.NewTicker(time.Second)
go func() {
p.workResultLock.Add(1)
defer p.workResultLock.Done()
for !p.exit {
select {
case <-p.interval.C:
@@ -198,6 +203,7 @@ func (p *Client) Run() error {
func (p *Client) Stop() {
p.exit = true
p.workResultLock.Wait()
p.conn.Close()
if p.tcplistenConn != nil {
p.tcplistenConn.Close()
@@ -210,6 +216,9 @@ func (p *Client) Stop() {
func (p *Client) AcceptTcp() error {
p.workResultLock.Add(1)
defer p.workResultLock.Done()
loggo.Info("client waiting local accept tcp")
for !p.exit {
@@ -237,6 +246,9 @@ func (p *Client) AcceptTcp() error {
func (p *Client) AcceptTcpConn(conn *net.TCPConn, targetAddr string) {
p.workResultLock.Add(1)
defer p.workResultLock.Done()
uuid := UniqueId()
tcpsrcaddr := conn.RemoteAddr().(*net.TCPAddr)
@@ -426,6 +438,9 @@ func (p *Client) AcceptTcpConn(conn *net.TCPConn, targetAddr string) {
func (p *Client) Accept() error {
p.workResultLock.Add(1)
defer p.workResultLock.Done()
loggo.Info("client waiting local accept udp")
bytes := make([]byte, 10240)
@@ -580,6 +595,9 @@ func (p *Client) showNet() {
func (p *Client) AcceptSock5Conn(conn *net.TCPConn) {
p.workResultLock.Add(1)
defer p.workResultLock.Done()
var err error = nil
if err = sock5Handshake(conn); err != nil {
loggo.Error("socks handshake: %s", err)