migrate mux to nps-mux

This commit is contained in:
ffdfgdfg
2020-01-09 22:59:24 +08:00
parent 211f15882a
commit 5fedde1475
24 changed files with 62 additions and 3045 deletions

View File

@@ -3,6 +3,7 @@ package client
import (
"bufio"
"bytes"
"ehang.io/nps-mux"
"net"
"net/http"
"strconv"
@@ -15,7 +16,6 @@ import (
"ehang.io/nps/lib/config"
"ehang.io/nps/lib/conn"
"ehang.io/nps/lib/crypt"
"ehang.io/nps/lib/mux"
)
type TRPClient struct {
@@ -24,7 +24,7 @@ type TRPClient struct {
proxyUrl string
vKey string
p2pAddr map[string]string
tunnel *mux.Mux
tunnel *nps_mux.Mux
signal *conn.Conn
ticker *time.Ticker
cnf *config.Config
@@ -138,7 +138,7 @@ func (s *TRPClient) newUdpConn(localAddr, rAddr string, md5Password string) {
conn.SetUdpSession(udpTunnel)
logs.Trace("successful connection with client ,address %s", udpTunnel.RemoteAddr().String())
//read link info from remote
conn.Accept(mux.NewMux(udpTunnel, s.bridgeConnType), func(c net.Conn) {
conn.Accept(nps_mux.NewMux(udpTunnel, s.bridgeConnType), func(c net.Conn) {
go s.handleChan(c)
})
break
@@ -146,14 +146,14 @@ func (s *TRPClient) newUdpConn(localAddr, rAddr string, md5Password string) {
}
}
//mux tunnel
//pmux tunnel
func (s *TRPClient) newChan() {
tunnel, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_CHAN, s.proxyUrl)
if err != nil {
logs.Error("connect to ", s.svrAddr, "error:", err)
return
}
s.tunnel = mux.NewMux(tunnel.Conn, s.bridgeConnType)
s.tunnel = nps_mux.NewMux(tunnel.Conn, s.bridgeConnType)
for {
src, err := s.tunnel.Accept()
if err != nil {

View File

@@ -1,6 +1,7 @@
package client
import (
"ehang.io/nps-mux"
"errors"
"net"
"net/http"
@@ -13,7 +14,6 @@ import (
"ehang.io/nps/lib/conn"
"ehang.io/nps/lib/crypt"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/mux"
"ehang.io/nps/server/proxy"
"github.com/astaxie/beego/logs"
"github.com/xtaci/kcp-go"
@@ -22,7 +22,7 @@ import (
var (
LocalServer []*net.TCPListener
udpConn net.Conn
muxSession *mux.Mux
muxSession *nps_mux.Mux
fileServer []*http.Server
p2pNetBridge *p2pBridge
lock sync.RWMutex
@@ -73,7 +73,7 @@ func startLocalFileServer(config *config.CommonConfig, t *file.Tunnel, vkey stri
}
logs.Info("start local file system, local path %s, strip prefix %s ,remote port %s ", t.LocalPath, t.StripPre, t.Ports)
fileServer = append(fileServer, srv)
listener := mux.NewMux(remoteConn.Conn, common.CONN_TCP)
listener := nps_mux.NewMux(remoteConn.Conn, common.CONN_TCP)
logs.Error(srv.Serve(listener))
}
@@ -214,6 +214,6 @@ func newUdpConn(localAddr string, config *config.CommonConfig, l *config.LocalSe
logs.Trace("successful create a connection with server", remoteAddress)
conn.SetUdpSession(udpTunnel)
udpConn = udpTunnel
muxSession = mux.NewMux(udpConn, "kcp")
muxSession = nps_mux.NewMux(udpConn, "kcp")
p2pNetBridge = &p2pBridge{}
}