Signed-off-by: arraykeys@gmail.com <arraykeys@gmail.com>
This commit is contained in:
@ -11,7 +11,6 @@ import (
|
|||||||
"snail007/proxy/utils"
|
"snail007/proxy/utils"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/snappy"
|
"github.com/golang/snappy"
|
||||||
@ -19,13 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MuxServer struct {
|
type MuxServer struct {
|
||||||
cfg MuxServerArgs
|
cfg MuxServerArgs
|
||||||
udpChn chan MuxUDPItem
|
udpChn chan MuxUDPItem
|
||||||
sc utils.ServerChannel
|
sc utils.ServerChannel
|
||||||
sessions utils.ConcurrentMap
|
sessions utils.ConcurrentMap
|
||||||
userConns utils.ConcurrentMap
|
lockChn chan bool
|
||||||
lockChn chan bool
|
|
||||||
closeLock *sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MuxServerManager struct {
|
type MuxServerManager struct {
|
||||||
@ -119,12 +116,10 @@ func (s *MuxServerManager) InitService() {
|
|||||||
|
|
||||||
func NewMuxServer() Service {
|
func NewMuxServer() Service {
|
||||||
return &MuxServer{
|
return &MuxServer{
|
||||||
cfg: MuxServerArgs{},
|
cfg: MuxServerArgs{},
|
||||||
udpChn: make(chan MuxUDPItem, 50000),
|
udpChn: make(chan MuxUDPItem, 50000),
|
||||||
lockChn: make(chan bool, 1),
|
lockChn: make(chan bool, 1),
|
||||||
sessions: utils.NewConcurrentMap(),
|
sessions: utils.NewConcurrentMap(),
|
||||||
userConns: utils.NewConcurrentMap(),
|
|
||||||
closeLock: &sync.Mutex{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +165,6 @@ func (s *MuxServer) Start(args interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
inConnRemoteAddr := inConn.RemoteAddr().String()
|
inConnRemoteAddr := inConn.RemoteAddr().String()
|
||||||
s.userConns.Set(inConnRemoteAddr, &inConn)
|
|
||||||
var outConn net.Conn
|
var outConn net.Conn
|
||||||
var ID string
|
var ID string
|
||||||
for {
|
for {
|
||||||
@ -185,7 +179,6 @@ func (s *MuxServer) Start(args interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
outConnRemoteAddr := outConn.RemoteAddr().String()
|
outConnRemoteAddr := outConn.RemoteAddr().String()
|
||||||
s.userConns.Set(outConnRemoteAddr, &outConn)
|
|
||||||
|
|
||||||
log.Printf("%s stream %s created", *s.cfg.Key, ID)
|
log.Printf("%s stream %s created", *s.cfg.Key, ID)
|
||||||
if *s.cfg.IsCompress {
|
if *s.cfg.IsCompress {
|
||||||
@ -205,13 +198,9 @@ func (s *MuxServer) Start(args interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
outConn.Close()
|
outConn.Close()
|
||||||
inConn.Close()
|
inConn.Close()
|
||||||
s.userConns.Remove(inConnRemoteAddr)
|
|
||||||
s.userConns.Remove(outConnRemoteAddr)
|
|
||||||
log.Printf("%s stream %s released", *s.cfg.Key, ID)
|
log.Printf("%s stream %s released", *s.cfg.Key, ID)
|
||||||
} else {
|
} else {
|
||||||
utils.IoBind(inConn, outConn, func(err interface{}) {
|
utils.IoBind(inConn, outConn, func(err interface{}) {
|
||||||
s.userConns.Remove(inConnRemoteAddr)
|
|
||||||
s.userConns.Remove(outConnRemoteAddr)
|
|
||||||
log.Printf("%s stream %s released", *s.cfg.Key, ID)
|
log.Printf("%s stream %s released", *s.cfg.Key, ID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -284,15 +273,6 @@ func (s *MuxServer) GetConn(index string) (conn net.Conn, err error) {
|
|||||||
for {
|
for {
|
||||||
if session.IsClosed() {
|
if session.IsClosed() {
|
||||||
s.sessions.Remove(index)
|
s.sessions.Remove(index)
|
||||||
s.closeLock.Lock()
|
|
||||||
if len(s.userConns) > 0 {
|
|
||||||
for _, k := range s.userConns.Keys() {
|
|
||||||
c, _ := s.userConns.Get(k)
|
|
||||||
(*(c.(*net.Conn))).Close()
|
|
||||||
s.userConns.Remove(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.closeLock.Unlock()
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
|
|||||||
Reference in New Issue
Block a user