Explorar o código

change protocol name

Joyit hai 1 mes
pai
achega
5302b0a81c
Modificáronse 9 ficheiros con 89 adicións e 87 borrados
  1. 0 4
      conn/tcp2/README.md
  2. 30 30
      conn/tcp2/tcp2.go
  3. 0 0
      conn/ws2/README.md
  4. 28 28
      conn/ws2/ws2.go
  5. 2 2
      examples/README.md
  6. 2 2
      examples/client-tcp2.go
  7. 2 2
      examples/client-ws2.go
  8. 13 7
      examples/server.go
  9. 12 12
      hub.go

+ 0 - 4
conn/tpv2/README.md → conn/tcp2/README.md

@@ -15,7 +15,3 @@ V2 版本与 V1 版本不兼容,参考 V1 版本来完善新的协议。
 
 根据加密协议的不同,iv 的长度也不同
 iv 在连接成功后第一时间发送
-
-## 关于混淆
-
-暂时还没有混淆的功能,等有时间再处理。

+ 30 - 30
conn/tpv2/tpv2.go → conn/tcp2/tcp2.go

@@ -1,4 +1,4 @@
-package tpv2
+package tcp2
 
 import (
 	"crypto/rand"
@@ -16,14 +16,14 @@ import (
 	"git.me9.top/git/tinymq/conn/util"
 )
 
+const PROTO string = "tcp"
 const VERSION uint8 = 2
-const PROTO string = "tp"
 
 // 数据包的最大长度
 const MAX_LENGTH = 0xFFFF
 const MAX2_LENGTH = 0x1FFFFFFF // 500 M,避免申请过大内存
 
-type TpConnectV2 struct {
+type Tcp2 struct {
 	cf     *config.Config
 	conn   net.Conn
 	cipher *util.Cipher // 记录当前的加解密类
@@ -53,7 +53,7 @@ func Server(cf *config.Config, bind string, hash string, fn conn.ServerConnectFu
 	log.Printf("Listening and serving tcp on %s\n", bind)
 	l, err := net.Listen("tcp", bind)
 	if err != nil {
-		log.Println("[tpv2 Server ERROR]", err)
+		log.Println("[tcp2 Server ERROR]", err)
 		return
 	}
 	go func(l net.Listener) {
@@ -66,7 +66,7 @@ func Server(cf *config.Config, bind string, hash string, fn conn.ServerConnectFu
 			}
 			go func(conn net.Conn) {
 				if ci == nil {
-					c := &TpConnectV2{
+					c := &Tcp2{
 						cf:   cf,
 						conn: conn,
 					}
@@ -80,36 +80,36 @@ func Server(cf *config.Config, bind string, hash string, fn conn.ServerConnectFu
 					eiv = make([]byte, ci.IvLen)
 					_, err = rand.Read(eiv)
 					if err != nil {
-						log.Println("[tpv2 Server rand.Read ERROR]", err)
+						log.Println("[tcp2 Server rand.Read ERROR]", err)
 						return
 					}
 					// 发送 IV
 					conn.SetWriteDeadline(time.Now().Add(time.Duration(cf.WriteWait) * time.Millisecond))
 					if _, err := conn.Write(eiv); err != nil {
-						log.Println("[tpv2 Server conn.Write ERROR]", err)
+						log.Println("[tcp2 Server conn.Write ERROR]", err)
 						return
 					}
 
 					// 读取 IV
 					err = conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(cf.ReadWait)))
 					if err != nil {
-						log.Println("[tpv2 Server SetReadDeadline ERROR]", err)
+						log.Println("[tcp2 Server SetReadDeadline ERROR]", err)
 						return
 					}
 					div = make([]byte, ci.IvLen)
 					_, err := io.ReadFull(conn, div)
 					if err != nil {
-						log.Println("[tpv2 Server ReadFull ERROR]", err)
+						log.Println("[tcp2 Server ReadFull ERROR]", err)
 						return
 					}
 				}
 				cipher, err := util.NewCipher(ci, encryptKey, eiv, div)
 				if err != nil {
-					log.Println("[tpv2 NewCipher ERROR]", err)
+					log.Println("[tcp2 NewCipher ERROR]", err)
 					return
 				}
 				// 初始化
-				c := &TpConnectV2{
+				c := &Tcp2{
 					cf:     cf,
 					conn:   conn,
 					cipher: cipher,
@@ -129,7 +129,7 @@ func Client(cf *config.Config, addr string, hash string) (conn.Connect, error) {
 		if err != nil {
 			return nil, err
 		}
-		c := &TpConnectV2{
+		c := &Tcp2{
 			cf:   cf,
 			conn: conn,
 		}
@@ -156,36 +156,36 @@ func Client(cf *config.Config, addr string, hash string) (conn.Connect, error) {
 		eiv = make([]byte, ci.IvLen)
 		_, err = rand.Read(eiv)
 		if err != nil {
-			log.Println("[tpv2 Client rand.Read ERROR]", err)
+			log.Println("[tcp2 Client rand.Read ERROR]", err)
 			return nil, err
 		}
 		// 发送 IV
 		conn.SetWriteDeadline(time.Now().Add(time.Duration(cf.WriteWait) * time.Millisecond))
 		if _, err := conn.Write(eiv); err != nil {
-			log.Println("[tpv2 Client conn.Write ERROR]", err)
+			log.Println("[tcp2 Client conn.Write ERROR]", err)
 			return nil, err
 		}
 
 		// 读取 IV
 		err = conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(cf.ReadWait)))
 		if err != nil {
-			log.Println("[tpv2 Client SetReadDeadline ERROR]", err)
+			log.Println("[tcp2 Client SetReadDeadline ERROR]", err)
 			return nil, err
 		}
 		div = make([]byte, ci.IvLen)
 		_, err := io.ReadFull(conn, div)
 		if err != nil {
-			log.Println("[tpv2 Client ReadFull ERROR]", err)
+			log.Println("[tcp2 Client ReadFull ERROR]", err)
 			return nil, err
 		}
 	}
 	cipher, err := util.NewCipher(ci, encryptKey, eiv, div)
 	if err != nil {
-		log.Println("[tpv2 NewCipher ERROR]", err)
+		log.Println("[tcp2 NewCipher ERROR]", err)
 		return nil, err
 	}
 	// 初始化
-	c := &TpConnectV2{
+	c := &Tcp2{
 		cf:     cf,
 		conn:   conn,
 		cipher: cipher,
@@ -195,7 +195,7 @@ func Client(cf *config.Config, addr string, hash string) (conn.Connect, error) {
 
 // 发送数据到网络
 // 如果有加密函数的话会直接修改源数据
-func (c *TpConnectV2) writeMessage(buf []byte) (err error) {
+func (c *Tcp2) writeMessage(buf []byte) (err error) {
 	if len(buf) > MAX2_LENGTH {
 		return fmt.Errorf("data length more than %d", MAX2_LENGTH)
 	}
@@ -218,7 +218,7 @@ func (c *TpConnectV2) writeMessage(buf []byte) (err error) {
 
 // 申请内存并写入数据长度信息
 // 还多申请一个字节用于保存crc
-func (c *TpConnectV2) writeDataLen(dlen int) (buf []byte, start int) {
+func (c *Tcp2) writeDataLen(dlen int) (buf []byte, start int) {
 	if dlen >= MAX_LENGTH {
 		buf = make([]byte, dlen+2+4+1)
 		start = 2 + 4
@@ -234,7 +234,7 @@ func (c *TpConnectV2) writeDataLen(dlen int) (buf []byte, start int) {
 
 // 发送Auth信息
 // 建立连接后第一个发送的消息
-func (c *TpConnectV2) WriteAuthInfo(channel string, auth []byte) (err error) {
+func (c *Tcp2) WriteAuthInfo(channel string, auth []byte) (err error) {
 	protoLen := len(PROTO)
 	channelLen := len(channel)
 	if channelLen > 0xFFFF {
@@ -261,7 +261,7 @@ func (c *TpConnectV2) WriteAuthInfo(channel string, auth []byte) (err error) {
 }
 
 // 从连接中读取信息
-func (c *TpConnectV2) readMessage(deadline int) ([]byte, error) {
+func (c *Tcp2) readMessage(deadline int) ([]byte, error) {
 	buf := make([]byte, 2)
 	err := c.conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(deadline)))
 	if err != nil {
@@ -313,7 +313,7 @@ func (c *TpConnectV2) readMessage(deadline int) ([]byte, error) {
 
 // 获取Auth信息
 // id(uint16)+version(uint8)+proto(string)+channel(string)+auth([]byte)
-func (c *TpConnectV2) ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error) {
+func (c *Tcp2) ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error) {
 	defer func() {
 		if r := recover(); r != nil {
 			err = fmt.Errorf("recovered from panic: %v", r)
@@ -368,7 +368,7 @@ func (c *TpConnectV2) ReadAuthInfo() (proto string, version uint8, channel strin
 }
 
 // 发送请求数据包到网络
-func (c *TpConnectV2) WriteRequest(id uint16, cmd string, data []byte) error {
+func (c *Tcp2) WriteRequest(id uint16, cmd string, data []byte) error {
 	// 为了区分请求还是响应包,命令字符串不能超过127个字节,如果超过则截断
 	cmdLen := len(cmd)
 	if cmdLen > 0x7F {
@@ -390,7 +390,7 @@ func (c *TpConnectV2) WriteRequest(id uint16, cmd string, data []byte) error {
 
 // 发送响应数据包到网络
 // 网络格式:[id, stateCode, data]
-func (c *TpConnectV2) WriteResponse(id uint16, state uint8, data []byte) error {
+func (c *Tcp2) WriteResponse(id uint16, state uint8, data []byte) error {
 	dlen := 2 + 1 + len(data)
 	buf, start := c.writeDataLen(dlen)
 	index := start
@@ -404,7 +404,7 @@ func (c *TpConnectV2) WriteResponse(id uint16, state uint8, data []byte) error {
 }
 
 // 发送ping包
-func (c *TpConnectV2) WritePing(id uint16) error {
+func (c *Tcp2) WritePing(id uint16) error {
 	dlen := 2
 	buf, start := c.writeDataLen(dlen)
 	index := start
@@ -415,7 +415,7 @@ func (c *TpConnectV2) WritePing(id uint16) error {
 }
 
 // 获取信息
-func (c *TpConnectV2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16, cmd string, state uint8, data []byte, err error) {
+func (c *Tcp2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16, cmd string, state uint8, data []byte, err error) {
 	msg, err := c.readMessage(deadline)
 	if err != nil {
 		return
@@ -451,15 +451,15 @@ func (c *TpConnectV2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16
 }
 
 // 获取远程的地址
-func (c *TpConnectV2) RemoteAddr() net.Addr {
+func (c *Tcp2) RemoteAddr() net.Addr {
 	return c.conn.RemoteAddr()
 }
 
 // 获取本地的地址
-func (c *TpConnectV2) LocalAddr() net.Addr {
+func (c *Tcp2) LocalAddr() net.Addr {
 	return c.conn.LocalAddr()
 }
 
-func (c *TpConnectV2) Close() error {
+func (c *Tcp2) Close() error {
 	return c.conn.Close()
 }

+ 0 - 0
conn/wsv2/README.md → conn/ws2/README.md


+ 28 - 28
conn/wsv2/wsv2.go → conn/ws2/ws2.go

@@ -1,4 +1,4 @@
-package wsv2
+package ws2
 
 import (
 	"crypto/rand"
@@ -18,11 +18,11 @@ import (
 	"github.com/gorilla/websocket"
 )
 
-const VERSION uint8 = 2
 const PROTO string = "ws"
 const PROTO_STL string = "wss"
+const VERSION uint8 = 2
 
-type WsConnectV2 struct {
+type Ws2 struct {
 	cf     *config.Config
 	conn   *websocket.Conn
 	cipher *util.Cipher // 记录当前的加解密类,可以保证在没有ssl的情况下数据安全
@@ -52,11 +52,11 @@ func Server(cf *config.Config, bind string, path string, hash string, fn conn.Se
 	http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
 		conn, err := upgrader.Upgrade(w, r, nil)
 		if err != nil {
-			log.Println("[wsv2 Server Upgrade ERROR]", err)
+			log.Println("[ws2 Server Upgrade ERROR]", err)
 			return
 		}
 		if ci == nil {
-			ws := &WsConnectV2{
+			ws := &Ws2{
 				cf:   cf,
 				conn: conn,
 			}
@@ -70,34 +70,34 @@ func Server(cf *config.Config, bind string, path string, hash string, fn conn.Se
 			eiv = make([]byte, ci.IvLen)
 			_, err = rand.Read(eiv)
 			if err != nil {
-				log.Println("[wsv2 Server rand.Read ERROR]", err)
+				log.Println("[ws2 Server rand.Read ERROR]", err)
 				return
 			}
 			// 发送 IV
 			conn.SetWriteDeadline(time.Now().Add(time.Duration(cf.WriteWait) * time.Millisecond))
 			if err := conn.WriteMessage(websocket.BinaryMessage, eiv); err != nil {
-				log.Println("[wsv2 Server conn.Write ERROR]", err)
+				log.Println("[ws2 Server conn.Write ERROR]", err)
 				return
 			}
 
 			// 读取 IV
 			err = conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(cf.ReadWait)))
 			if err != nil {
-				log.Println("[wsv2 Server SetReadDeadline ERROR]", err)
+				log.Println("[ws2 Server SetReadDeadline ERROR]", err)
 				return
 			}
 			_, div, err = conn.ReadMessage()
 			if err != nil {
-				log.Println("[wsv2 Server ReadFull ERROR]", err)
+				log.Println("[ws2 Server ReadFull ERROR]", err)
 				return
 			}
 		}
 		cipher, err := util.NewCipher(ci, encryptKey, eiv, div)
 		if err != nil {
-			log.Println("[wsv2 NewCipher ERROR]", err)
+			log.Println("[ws2 NewCipher ERROR]", err)
 			return
 		}
-		ws := &WsConnectV2{
+		ws := &Ws2{
 			cf:     cf,
 			conn:   conn,
 			cipher: cipher,
@@ -133,7 +133,7 @@ func Client(cf *config.Config, scheme string, addr string, path string, hash str
 		if err != nil {
 			return nil, err
 		}
-		ws := &WsConnectV2{
+		ws := &Ws2{
 			cf:   cf,
 			conn: conn,
 		}
@@ -160,34 +160,34 @@ func Client(cf *config.Config, scheme string, addr string, path string, hash str
 		eiv = make([]byte, ci.IvLen)
 		_, err = rand.Read(eiv)
 		if err != nil {
-			log.Println("[wsv2 Client rand.Read ERROR]", err)
+			log.Println("[ws2 Client rand.Read ERROR]", err)
 			return nil, err
 		}
 		// 发送 IV
 		conn.SetWriteDeadline(time.Now().Add(time.Duration(cf.WriteWait) * time.Millisecond))
 		if err := conn.WriteMessage(websocket.BinaryMessage, eiv); err != nil {
-			log.Println("[wsv2 Client conn.Write ERROR]", err)
+			log.Println("[ws2 Client conn.Write ERROR]", err)
 			return nil, err
 		}
 
 		// 读取 IV
 		err = conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(cf.ReadWait)))
 		if err != nil {
-			log.Println("[wsv2 Client SetReadDeadline ERROR]", err)
+			log.Println("[ws2 Client SetReadDeadline ERROR]", err)
 			return nil, err
 		}
 		_, div, err = conn.ReadMessage()
 		if err != nil {
-			log.Println("[wsv2 Client ReadFull ERROR]", err)
+			log.Println("[ws2 Client ReadFull ERROR]", err)
 			return nil, err
 		}
 	}
 	cipher, err := util.NewCipher(ci, encryptKey, eiv, div)
 	if err != nil {
-		log.Println("[wsv2 NewCipher ERROR]", err)
+		log.Println("[ws2 NewCipher ERROR]", err)
 		return nil, err
 	}
-	ws := &WsConnectV2{
+	ws := &Ws2{
 		cf:     cf,
 		conn:   conn,
 		cipher: cipher,
@@ -197,7 +197,7 @@ func Client(cf *config.Config, scheme string, addr string, path string, hash str
 
 // 发送数据到网络
 // 如果有加密函数的话会直接修改源数据
-func (c *WsConnectV2) writeMessage(buf []byte) (err error) {
+func (c *Ws2) writeMessage(buf []byte) (err error) {
 	if c.cipher != nil {
 		c.cipher.Encrypt(buf, buf)
 	}
@@ -207,7 +207,7 @@ func (c *WsConnectV2) writeMessage(buf []byte) (err error) {
 
 // 发送Auth信息
 // 建立连接后第一个发送的消息
-func (c *WsConnectV2) WriteAuthInfo(channel string, auth []byte) (err error) {
+func (c *Ws2) WriteAuthInfo(channel string, auth []byte) (err error) {
 	protoLen := len(PROTO)
 	channelLen := len(channel)
 	if channelLen > 0xFFFF {
@@ -234,7 +234,7 @@ func (c *WsConnectV2) WriteAuthInfo(channel string, auth []byte) (err error) {
 
 // 获取Auth信息
 // id(uint16)+version(uint8)+proto(string)+channel(string)+auth([]byte)
-func (c *WsConnectV2) ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error) {
+func (c *Ws2) ReadAuthInfo() (proto string, version uint8, channel string, auth []byte, err error) {
 	defer func() {
 		if r := recover(); r != nil {
 			err = fmt.Errorf("recovered from panic: %v", r)
@@ -297,7 +297,7 @@ func (c *WsConnectV2) ReadAuthInfo() (proto string, version uint8, channel strin
 }
 
 // 发送请求数据包到网络
-func (c *WsConnectV2) WriteRequest(id uint16, cmd string, data []byte) error {
+func (c *Ws2) WriteRequest(id uint16, cmd string, data []byte) error {
 	// 为了区分请求还是响应包,命令字符串不能超过127个字节,如果超过则报错
 	cmdLen := len(cmd)
 	if cmdLen > 0x7F {
@@ -314,7 +314,7 @@ func (c *WsConnectV2) WriteRequest(id uint16, cmd string, data []byte) error {
 
 // 发送响应数据包到网络
 // 网络格式:[id, stateCode, data]
-func (c *WsConnectV2) WriteResponse(id uint16, state uint8, data []byte) error {
+func (c *Ws2) WriteResponse(id uint16, state uint8, data []byte) error {
 	dlen := 2 + 1 + len(data)
 	buf := make([]byte, dlen)
 	binary.BigEndian.PutUint16(buf[0:2], id)
@@ -324,14 +324,14 @@ func (c *WsConnectV2) WriteResponse(id uint16, state uint8, data []byte) error {
 }
 
 // 发送ping包
-func (c *WsConnectV2) WritePing(id uint16) error {
+func (c *Ws2) WritePing(id uint16) error {
 	buf := make([]byte, 2)
 	binary.BigEndian.PutUint16(buf[0:2], id)
 	return c.writeMessage(buf)
 }
 
 // 获取信息
-func (c *WsConnectV2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16, cmd string, state uint8, data []byte, err error) {
+func (c *Ws2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16, cmd string, state uint8, data []byte, err error) {
 	err = c.conn.SetReadDeadline(time.Now().Add(time.Millisecond * time.Duration(deadline)))
 	if err != nil {
 		return
@@ -379,15 +379,15 @@ func (c *WsConnectV2) ReadMessage(deadline int) (msgType conn.MsgType, id uint16
 }
 
 // 获取远程的地址
-func (c *WsConnectV2) RemoteAddr() net.Addr {
+func (c *Ws2) RemoteAddr() net.Addr {
 	return c.conn.RemoteAddr()
 }
 
 // 获取本地的地址
-func (c *WsConnectV2) LocalAddr() net.Addr {
+func (c *Ws2) LocalAddr() net.Addr {
 	return c.conn.LocalAddr()
 }
 
-func (c *WsConnectV2) Close() error {
+func (c *Ws2) Close() error {
 	return c.conn.Close()
 }

+ 2 - 2
examples/README.md

@@ -9,6 +9,6 @@ go run server.go
 启动客户端
 
 ```
-go run client-tpv2.go
-go run client-wsv2.go
+go run client-tcp2.go
+go run client-ws2.go
 ```

+ 2 - 2
examples/client-tpv2.go → examples/client-tcp2.go

@@ -14,9 +14,9 @@ import (
 
 func main() {
 	cf := config.NewConfig()
-	channel := "/tinymq/client/tpv2"
+	channel := "/tinymq/client/tcp2"
 	host := &tinymq.HostInfo{
-		Proto:   "tp",
+		Proto:   "tcp",
 		Version: 2,
 		Host:    "127.0.0.1",
 		Port:    34222,

+ 2 - 2
examples/client-wsv2.go → examples/client-ws2.go

@@ -14,7 +14,7 @@ import (
 
 func main() {
 	cf := config.NewConfig()
-	localChannel := "/tinymq/client/wsv2"
+	localChannel := "/tinymq/client/ws2"
 	remoteChannel := "/tinymq/server"
 	host := &tinymq.HostInfo{
 		Proto:   "ws",
@@ -69,7 +69,7 @@ func main() {
 	log.Println("[RESULT]<-", string(rsp.Data))
 
 	time.Sleep(time.Second * 5)
-	hub.Push(regexp.MustCompile(remoteChannel), "hello", []byte(time.Now().GoString()))
+	hub.Push(regexp.MustCompile(remoteChannel), "push", []byte(time.Now().GoString()))
 
 	time.Sleep(time.Second * 300)
 	log.Println("client exit")

+ 13 - 7
examples/server.go

@@ -53,9 +53,9 @@ func main() {
 		},
 	)
 
-	// tpv2协议
+	// tcp2协议
 	bindTpv2Info := &tinymq.HostInfo{
-		Proto:   "tp",
+		Proto:   "tcp",
 		Version: 2,
 		Bind:    "127.0.0.1",
 		Port:    34222,
@@ -63,8 +63,8 @@ func main() {
 	}
 	hub.BindForServer(bindTpv2Info)
 
-	// wsv2协议
-	bindwsv2Info := &tinymq.HostInfo{
+	// ws2协议
+	bindws2Info := &tinymq.HostInfo{
 		Proto:   "ws",
 		Version: 2,
 		Bind:    "127.0.0.1",
@@ -72,9 +72,9 @@ func main() {
 		Path:    "/tinymq-xor",
 		Hash:    "xor:1qaz2wsx3edc",
 	}
-	hub.BindForServer(bindwsv2Info)
+	hub.BindForServer(bindws2Info)
 
-	// wsv2协议,没有加密算法
+	// ws2协议,没有加密算法
 	bindInfo := &tinymq.HostInfo{
 		Proto:   "ws",
 		Version: 2,
@@ -103,8 +103,14 @@ func main() {
 			return 1, nil
 		},
 	)
+	hub.Subscribe(regexp.MustCompile(remoteChannel), "push",
+		func(request *tinymq.RequestData) (state uint8, result []byte) {
+			log.Println("[server RECV]<-", string(request.Data))
+			return 1, nil
+		},
+	)
 
-	// log.Fatal(http.ListenAndServe(net.JoinHostPort(bindwsv2Info.Bind, strconv.Itoa(int(bindwsv2Info.Port))), nil))
+	// log.Fatal(http.ListenAndServe(net.JoinHostPort(bindws2Info.Bind, strconv.Itoa(int(bindws2Info.Port))), nil))
 
 	// 初始化一个channel
 	exit := make(chan os.Signal, 3)

+ 12 - 12
hub.go

@@ -14,8 +14,8 @@ import (
 
 	"git.me9.top/git/tinymq/config"
 	"git.me9.top/git/tinymq/conn"
-	"git.me9.top/git/tinymq/conn/tpv2"
-	"git.me9.top/git/tinymq/conn/wsv2"
+	"git.me9.top/git/tinymq/conn/tcp2"
+	"git.me9.top/git/tinymq/conn/ws2"
 )
 
 // 类似一个插座的功能,管理多个连接
@@ -533,14 +533,14 @@ func (h *Hub) BindForServer(info *HostInfo) (err error) {
 			h.addLine(line)
 		}
 	}
-	if info.Version == wsv2.VERSION && info.Proto == wsv2.PROTO {
+	if info.Version == ws2.VERSION && info.Proto == ws2.PROTO {
 		bind := ""
 		if info.Bind != "" {
 			bind = net.JoinHostPort(info.Bind, strconv.Itoa(int(info.Port)))
 		}
-		return wsv2.Server(h.cf, bind, info.Path, info.Hash, doConnectFunc)
-	} else if info.Version == tpv2.VERSION && info.Proto == tpv2.PROTO {
-		return tpv2.Server(h.cf, net.JoinHostPort(info.Bind, strconv.Itoa(int(info.Port))), info.Hash, doConnectFunc)
+		return ws2.Server(h.cf, bind, info.Path, info.Hash, doConnectFunc)
+	} else if info.Version == tcp2.VERSION && info.Proto == tcp2.PROTO {
+		return tcp2.Server(h.cf, net.JoinHostPort(info.Bind, strconv.Itoa(int(info.Port))), info.Hash, doConnectFunc)
 	}
 	return errors.New("not connect protocol and version found")
 }
@@ -564,12 +564,12 @@ func (h *Hub) ConnectToServer(channel string, force bool) (err error) {
 	var conn conn.Connect
 	var runProto string
 	addr := net.JoinHostPort(host.Host, strconv.Itoa(int(host.Port)))
-	if host.Version == wsv2.VERSION && (host.Proto == wsv2.PROTO || host.Proto == wsv2.PROTO_STL) {
-		runProto = wsv2.PROTO
-		conn, err = wsv2.Client(h.cf, host.Proto, addr, host.Path, host.Hash)
-	} else if host.Version == tpv2.VERSION && host.Proto == tpv2.PROTO {
-		runProto = tpv2.PROTO
-		conn, err = tpv2.Client(h.cf, addr, host.Hash)
+	if host.Version == ws2.VERSION && (host.Proto == ws2.PROTO || host.Proto == ws2.PROTO_STL) {
+		runProto = ws2.PROTO
+		conn, err = ws2.Client(h.cf, host.Proto, addr, host.Path, host.Hash)
+	} else if host.Version == tcp2.VERSION && host.Proto == tcp2.PROTO {
+		runProto = tcp2.PROTO
+		conn, err = tcp2.Client(h.cf, addr, host.Hash)
 	} else {
 		return fmt.Errorf("not correct protocol and version found in: %+v", host)
 	}