@Override
 public void preStart() {
   this.currentAuthId = keyStorage.getAuthKey();
   if (currentAuthId == 0) {
     self().send(new RequestAuthId());
   } else {
     if (isEnableLog) {
       Log.d(TAG, "Key loaded: " + currentAuthId);
     }
     self().send(new InitMTProto(currentAuthId));
   }
 }
  private void onAuthIdInvalidated(long authId) {
    if (authId != currentAuthId) {
      return;
    }

    Log.w(TAG, "Auth id invalidated");

    keyStorage.saveAuthKey(0);
    currentAuthId = 0;
    proto = null;

    callback.onAuthIdInvalidated();

    self().send(new RequestAuthId());
  }
  private void createMtProto(long key) {
    Log.d(TAG, "Creating proto");
    keyStorage.saveAuthKey(key);
    currentAuthId = key;

    proto =
        new MTProto(
            key,
            RandomUtils.nextRid(),
            endpoints,
            new ProtoCallback(key),
            networkProvider,
            isEnableLog,
            getPath() + "/proto#" + NEXT_PROTO_ID.incrementAndGet(),
            minDelay,
            maxDelay,
            maxFailureCount);

    for (RequestHolder holder : requests.values()) {
      holder.protoId = proto.sendRpcMessage(holder.message);
      idMap.put(holder.protoId, holder.publicId);
      // Log.d(TAG, holder.message + " rid#" + holder.publicId + " <- mid#" + holder.protoId);
    }
  }