func (this *DispatcherOutComponent) sendToService(msg *protocol.Message, buffPool *buffpool.BuffPool) (*net.Conn, error) {
	if msg == nil || buffPool == nil {
		err := errors.New("DispatcherOutComponent.sendToService() Error: invalid argument")
		fmt.Println(err.Error())
		return nil, err
	}
	var conn *net.Conn
	if msg.DestUuid == P_UID {
		conn = buffPool.GetService(msg.Number)
	} else {
		conn = buffPool.QueryService(msg.Number, msg.DestUuid)
		if conn == nil {
			conn = buffPool.GetService(msg.Number)
		}
	}

	if conn == nil {
		err := errors.New("DispatcherOutComponent.sendToService() Error:  can not get a server connection from buffpool")
		fmt.Println(err.Error())
		return nil, err
	}

	err := this.sendMessage(msg, conn)
	if err != nil {
		err = errors.New("DispatcherOutComponent.sendToService() Error:  can not send message to server's connection")
		fmt.Println(err.Error())
		return conn, err
	}
	return conn, nil
}
예제 #2
0
func (this *RegisterComponent) checkAccountServer(buffPool *buffpool.BuffPool, message *protocol.Message, conn *net.Conn) bool {
	if buffPool == nil || message == nil || conn == nil {
		fmt.Println("RegisterComponent checkAccountServer() Error: invalid argument")
		return false
	}
	connService := buffPool.GetService(protocol.N_ACCOUNT_SYS)
	if connService == nil {
		fmt.Println("RegisterComponent checkAccountServer() Error: can not get the account_sys server")
		response, _ := protocol.NewMessage(protocol.VERSION, protoocl.MT_ERROR, protocol.PT_PUSHSERVER, message.Token, message.Number, 0, P_UID,
			message.UserUuid, 0, nil)
		err := sendResponse(conn, response)
		if err != nil {
			err = fmt.Errorf("RegisterComponent checkAccountServer() Error:%v", err)
			fmt.Println(err.Error())
		}
		return false
	}
	return true
}
func (this *DispatcherOutComponent) sendToService2(msg *protocol.Message, forward bool, buffPool *buffpool.BuffPool) (*net.Conn, error) {
	if msg == nil || buffPool == nil {
		err := errors.New("DispatcherOutComponent.sendToService() Error: invalid argument")
		fmt.Println(err.Error())
		return nil, err
	}
	var conn *net.Conn
	if msg.DestUuid == P_UID {
		conn = buffPool.GetService(msg.Number)
	} else {
		conn = buffPool.QueryService(msg.Number, msg.DestUuid)
		if conn == nil && forward && GetRunWithSnode().Flag {
			buf, err := msg.Encode()
			if err != nil {
				fmt.Println(err)
				return nil, err
			}
			snode_component.GetNodeComponent().Forward(stree_define.FORWARD, msg.DestUuid, msg.DeviceId, buf)
			return nil, nil
		}
	}

	if conn == nil {
		err := errors.New("DispatcherOutComponent.sendToService() Error:  can not find dest server")
		fmt.Println(err.Error())
		return nil, err
	}

	err := this.sendMessage(msg, conn)
	if err != nil {
		err = errors.New("DispatcherOutComponent.sendToService() Error: can not send message to server's connection")
		fmt.Println(err.Error())
		return conn, err
	}
	if msg.MsgType == protocol.MT_PUBLISH {
		fmt.Println("\n", time.Now().String(), "MT_PUBLISH: sendToService2 Directly OK", "\n")
	}
	return conn, nil
}