优化:新增隧道时,不指定服务端口时,将自动生成端口号 优化:API返回ID, /client/add/, /index/addhost/,/index/add/ 优化:域名解析、隧道页面,增加[唯一验证密钥],方便搜查
54 lines
747 B
Go
54 lines
747 B
Go
package nps_mux
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type connMap struct {
|
|
cMap map[int32]*conn
|
|
//closeCh chan struct{}
|
|
sync.RWMutex
|
|
}
|
|
|
|
func NewConnMap() *connMap {
|
|
cMap := &connMap{
|
|
cMap: make(map[int32]*conn),
|
|
}
|
|
return cMap
|
|
}
|
|
|
|
func (s *connMap) Size() (n int) {
|
|
s.RLock()
|
|
n = len(s.cMap)
|
|
s.RUnlock()
|
|
return
|
|
}
|
|
|
|
func (s *connMap) Get(id int32) (*conn, bool) {
|
|
s.RLock()
|
|
v, ok := s.cMap[id]
|
|
s.RUnlock()
|
|
if ok && v != nil {
|
|
return v, true
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func (s *connMap) Set(id int32, v *conn) {
|
|
s.Lock()
|
|
s.cMap[id] = v
|
|
s.Unlock()
|
|
}
|
|
|
|
func (s *connMap) Close() {
|
|
for _, v := range s.cMap {
|
|
_ = v.Close() // close all the connections in the mux
|
|
}
|
|
}
|
|
|
|
func (s *connMap) Delete(id int32) {
|
|
s.Lock()
|
|
delete(s.cMap, id)
|
|
s.Unlock()
|
|
}
|