Skip to content

Commit

Permalink
优化多连接版本内网穿透连接释放逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Aug 30, 2018
1 parent f9a2c3c commit 187a3f5
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ curl -L https://raw.githubusercontent.com/snail007/goproxy/master/install_auto.s
下载地址:https://github.com/snail007/goproxy/releases
```shell
cd /root/proxy/
wget https://github.com/snail007/goproxy/releases/download/v5.4/proxy-linux-amd64.tar.gz
wget https://github.com/snail007/goproxy/releases/download/v5.5/proxy-linux-amd64.tar.gz
```
#### **2.下载自动安装脚本**
```shell
Expand Down
2 changes: 1 addition & 1 deletion install_auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if [ -e /tmp/proxy ]; then
fi
mkdir /tmp/proxy
cd /tmp/proxy
wget https://github.com/snail007/goproxy/releases/download/v5.4/proxy-linux-amd64.tar.gz
wget https://github.com/snail007/goproxy/releases/download/v5.5/proxy-linux-amd64.tar.gz

# #install proxy
tar zxvf proxy-linux-amd64.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/snail007/goproxy/services"
)

const APP_VERSION = "5.4"
const APP_VERSION = "5.5"

func main() {
err := initConfig()
Expand Down
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
VER="5.4"
VER="5.5"
RELEASE="release-${VER}"
rm -rf .cert
mkdir .cert
Expand Down
2 changes: 1 addition & 1 deletion sdk/android-ios/release_android.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
VER="v5.4"
VER="v5.5"
rm -rf sdk-android-*.tar.gz
rm -rf android
mkdir android
Expand Down
2 changes: 1 addition & 1 deletion sdk/android-ios/release_ios.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
VER="v5.4"
VER="v5.5"
rm -rf sdk-ios-*.tar.gz
rm -rf ios
mkdir ios
Expand Down
2 changes: 1 addition & 1 deletion sdk/android-ios/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

const SDK_VERSION = "5.4"
const SDK_VERSION = "5.5"

var (
app *kingpin.Application
Expand Down
2 changes: 1 addition & 1 deletion sdk/windows-linux/release_linux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
VER="v5.4"
VER="v5.5"

rm -rf sdk-linux-*.tar.gz
rm -rf README.md libproxy-sdk.so libproxy-sdk.h libproxy-sdk.a
Expand Down
2 changes: 1 addition & 1 deletion sdk/windows-linux/release_mac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
VER="v5.4"
VER="v5.5"

rm -rf *.tar.gz
rm -rf README.md libproxy-sdk.dylib libproxy-sdk.h
Expand Down
2 changes: 1 addition & 1 deletion sdk/windows-linux/release_windows.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
VER="v5.4"
VER="v5.5"

#sudo rm /usr/local/go
#sudo ln -s /usr/local/go1.10.1 /usr/local/go
Expand Down
15 changes: 14 additions & 1 deletion services/tunnel/tunnel_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@ func (s *TunnelBridge) callback(inConn net.Conn) {
s.log.Printf("mux server conn accept error,ERR:%s", err)
return
}

go func() {
defer func() {
_ = recover()
}()
timer := time.NewTicker(time.Second * 3)
for {
<-timer.C
if sess.NumStreams() == 0 {
sess.Close()
timer.Stop()
return
}
}
}()
var buf = make([]byte, 1024)
n, _ := inConn.Read(buf)
reader := bytes.NewReader(buf[:n])
Expand Down
18 changes: 16 additions & 2 deletions services/tunnel/tunnel_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *TunnelClient) GetConn() (conn net.Conn, err error) {
}
}
if err == nil {
c, e := smux.Client(conn, &smux.Config{
sess, e := smux.Client(conn, &smux.Config{
AcceptBacklog: 256,
EnableKeepAlive: true,
KeepAliveInterval: 9 * time.Second,
Expand All @@ -196,12 +196,26 @@ func (s *TunnelClient) GetConn() (conn net.Conn, err error) {
err = e
return
}
conn, e = c.OpenStream()
conn, e = sess.OpenStream()
if e != nil {
s.log.Printf("mux client conn open stream error,ERR:%s", e)
err = e
return
}
go func() {
defer func() {
_ = recover()
}()
timer := time.NewTicker(time.Second * 3)
for {
<-timer.C
if sess.NumStreams() == 0 {
sess.Close()
timer.Stop()
return
}
}
}()
}
return
}
Expand Down

0 comments on commit 187a3f5

Please sign in to comment.