Skip to content

Commit

Permalink
vendor: models/msg
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed May 11, 2018
1 parent 1464836 commit a0fe2fc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 377 deletions.
46 changes: 46 additions & 0 deletions models/msg/ctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018 fatedier, [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package msg

import (
"io"

jsonMsg "github.com/fatedier/golib/msg/json"
)

type Message = jsonMsg.Message

var (
msgCtl *jsonMsg.MsgCtl
)

func init() {
msgCtl = jsonMsg.NewMsgCtl()
for typeByte, msg := range msgTypeMap {
msgCtl.RegisterMsg(typeByte, msg)
}
}

func ReadMsg(c io.Reader) (msg Message, err error) {
return msgCtl.ReadMsg(c)
}

func ReadMsgInto(c io.Reader, msg Message) (err error) {
return msgCtl.ReadMsgInto(c, msg)
}

func WriteMsg(c io.Writer, msg interface{}) (err error) {
return msgCtl.WriteMsg(c, msg)
}
56 changes: 20 additions & 36 deletions models/msg/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

package msg

import (
"net"
"reflect"
)
import "net"

const (
TypeLogin = 'o'
Expand All @@ -40,39 +37,26 @@ const (
)

var (
TypeMap map[byte]reflect.Type
TypeStringMap map[reflect.Type]byte
)

func init() {
TypeMap = make(map[byte]reflect.Type)
TypeStringMap = make(map[reflect.Type]byte)

TypeMap[TypeLogin] = reflect.TypeOf(Login{})
TypeMap[TypeLoginResp] = reflect.TypeOf(LoginResp{})
TypeMap[TypeNewProxy] = reflect.TypeOf(NewProxy{})
TypeMap[TypeNewProxyResp] = reflect.TypeOf(NewProxyResp{})
TypeMap[TypeCloseProxy] = reflect.TypeOf(CloseProxy{})
TypeMap[TypeNewWorkConn] = reflect.TypeOf(NewWorkConn{})
TypeMap[TypeReqWorkConn] = reflect.TypeOf(ReqWorkConn{})
TypeMap[TypeStartWorkConn] = reflect.TypeOf(StartWorkConn{})
TypeMap[TypeNewVisitorConn] = reflect.TypeOf(NewVisitorConn{})
TypeMap[TypeNewVisitorConnResp] = reflect.TypeOf(NewVisitorConnResp{})
TypeMap[TypePing] = reflect.TypeOf(Ping{})
TypeMap[TypePong] = reflect.TypeOf(Pong{})
TypeMap[TypeUdpPacket] = reflect.TypeOf(UdpPacket{})
TypeMap[TypeNatHoleVisitor] = reflect.TypeOf(NatHoleVisitor{})
TypeMap[TypeNatHoleClient] = reflect.TypeOf(NatHoleClient{})
TypeMap[TypeNatHoleResp] = reflect.TypeOf(NatHoleResp{})
TypeMap[TypeNatHoleSid] = reflect.TypeOf(NatHoleSid{})

for k, v := range TypeMap {
TypeStringMap[v] = k
msgTypeMap = map[byte]interface{}{
TypeLogin: Login{},
TypeLoginResp: LoginResp{},
TypeNewProxy: NewProxy{},
TypeNewProxyResp: NewProxyResp{},
TypeCloseProxy: CloseProxy{},
TypeNewWorkConn: NewWorkConn{},
TypeReqWorkConn: ReqWorkConn{},
TypeStartWorkConn: StartWorkConn{},
TypeNewVisitorConn: NewVisitorConn{},
TypeNewVisitorConnResp: NewVisitorConnResp{},
TypePing: Ping{},
TypePong: Pong{},
TypeUdpPacket: UdpPacket{},
TypeNatHoleVisitor: NatHoleVisitor{},
TypeNatHoleClient: NatHoleClient{},
TypeNatHoleResp: NatHoleResp{},
TypeNatHoleSid: NatHoleSid{},
}
}

// Message wraps socket packages for communicating between frpc and frps.
type Message interface{}
)

// When frpc start, client send this message to login to server.
type Login struct {
Expand Down
69 changes: 0 additions & 69 deletions models/msg/pack.go

This file was deleted.

87 changes: 0 additions & 87 deletions models/msg/pack_test.go

This file was deleted.

88 changes: 0 additions & 88 deletions models/msg/process.go

This file was deleted.

Loading

0 comments on commit a0fe2fc

Please sign in to comment.