예제 #1
0
//握手包
func handshake(ga *c.GroupAuth, remoteClient *c.RemotingClient) (bool, error) {

	for i := 0; i < 3; i++ {
		p := protocol.MarshalConnMeta(ga.GroupId, ga.SecretKey)
		rpacket := packet.NewPacket(protocol.CMD_CONN_META, p)
		resp, err := remoteClient.WriteAndGet(*rpacket, 5*time.Second)
		if nil != err {
			//两秒后重试
			time.Sleep(2 * time.Second)
			log.Warn("kiteClient|handShake|FAIL|%s|%s\n", ga.GroupId, err)
		} else {
			authAck, ok := resp.(*protocol.ConnAuthAck)
			if !ok {
				return false, errors.New("Unmatches Handshake Ack Type! ")
			} else {
				if authAck.GetStatus() {
					log.Info("kiteClient|handShake|SUCC|%s|%s\n", ga.GroupId, authAck.GetFeedback())
					return true, nil
				} else {
					log.Warn("kiteClient|handShake|FAIL|%s|%s\n", ga.GroupId, authAck.GetFeedback())
					return false, errors.New("Auth FAIL![" + authAck.GetFeedback() + "]")
				}
			}
		}
	}

	return false, errors.New("handshake fail! [" + remoteClient.RemoteAddr() + "]")
}
예제 #2
0
func packetDispatcher(rclient *client.RemotingClient, p *packet.Packet) {

	resp := packet.NewRespPacket(p.Header.Opaque, p.Header.CmdType, p.Data)
	//直接回写回去
	rclient.Write(*resp)
	// log.Printf("packetDispatcher|WriteResponse|%s\n", string(resp.Data))
}
예제 #3
0
func packetDispatcher(rclient *client.RemotingClient, p *packet.Packet) {
	flow.ReadFlow.Incr(1)
	flow.DispatcherFlow.Incr(1)

	resp := packet.NewRespPacket(p.Opaque, p.CmdType, p.Data)
	//直接回写回去
	rclient.Write(*resp)
	flow.WriteFlow.Incr(1)
}
예제 #4
0
func clientPacketDispatcher(rclient *client.RemotingClient, resp *packet.Packet) {
	rclient.Attach(resp.Header.Opaque, resp.Data)
	// log.Printf("clientPacketDispatcher|%s\n", string(resp.Data))
}
예제 #5
0
func clientPacketDispatcher(rclient *client.RemotingClient, resp *packet.Packet) {
	clientf.ReadFlow.Incr(1)
	clientf.DispatcherFlow.Incr(1)
	rclient.Attach(resp.Opaque, resp.Data)
}