//握手包 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() + "]") }