コード例 #1
0
 public T get(AxolotlAddress address) {
   synchronized (MAP_LOCK) {
     Map<Integer, T> devices = map.get(address.getName());
     if (devices == null) {
       return null;
     }
     return devices.get(address.getDeviceId());
   }
 }
コード例 #2
0
  private String getSessionName(AxolotlAddress axolotlAddress) {
    Recipient recipient =
        RecipientFactory.getRecipientsFromString(context, axolotlAddress.getName(), true)
            .getPrimaryRecipient();
    long recipientId = recipient.getRecipientId();
    int deviceId = axolotlAddress.getDeviceId();

    return recipientId + (deviceId == TextSecureAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
  }
コード例 #3
0
 public void put(AxolotlAddress address, T value) {
   synchronized (MAP_LOCK) {
     Map<Integer, T> devices = map.get(address.getName());
     if (devices == null) {
       devices = new HashMap<>();
       map.put(address.getName(), devices);
     }
     devices.put(address.getDeviceId(), value);
   }
 }
コード例 #4
0
  private void buildSessionFromPEP(final AxolotlAddress address) {
    Log.i(
        Config.LOGTAG,
        AxolotlService.getLogprefix(account)
            + "Building new sesstion for "
            + address.getDeviceId());

    try {
      IqPacket bundlesPacket =
          mXmppConnectionService
              .getIqGenerator()
              .retrieveBundlesForDevice(Jid.fromString(address.getName()), address.getDeviceId());
      Log.d(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account) + "Retrieving bundle: " + bundlesPacket);
      mXmppConnectionService.sendIqPacket(
          account,
          bundlesPacket,
          new OnIqPacketReceived() {
            private void finish() {
              AxolotlAddress ownAddress =
                  new AxolotlAddress(account.getJid().toBareJid().toString(), 0);
              if (!fetchStatusMap.getAll(ownAddress).containsValue(FetchStatus.PENDING)
                  && !fetchStatusMap.getAll(address).containsValue(FetchStatus.PENDING)) {
                mXmppConnectionService.keyStatusUpdated();
              }
            }

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
              Log.d(
                  Config.LOGTAG,
                  AxolotlService.getLogprefix(account)
                      + "Received preKey IQ packet, processing...");
              final IqParser parser = mXmppConnectionService.getIqParser();
              final List<PreKeyBundle> preKeyBundleList = parser.preKeys(packet);
              final PreKeyBundle bundle = parser.bundle(packet);
              if (preKeyBundleList.isEmpty() || bundle == null) {
                Log.e(
                    Config.LOGTAG,
                    AxolotlService.getLogprefix(account) + "preKey IQ packet invalid: " + packet);
                fetchStatusMap.put(address, FetchStatus.ERROR);
                finish();
                return;
              }
              Random random = new Random();
              final PreKeyBundle preKey =
                  preKeyBundleList.get(random.nextInt(preKeyBundleList.size()));
              if (preKey == null) {
                // should never happen
                fetchStatusMap.put(address, FetchStatus.ERROR);
                finish();
                return;
              }

              final PreKeyBundle preKeyBundle =
                  new PreKeyBundle(
                      0,
                      address.getDeviceId(),
                      preKey.getPreKeyId(),
                      preKey.getPreKey(),
                      bundle.getSignedPreKeyId(),
                      bundle.getSignedPreKey(),
                      bundle.getSignedPreKeySignature(),
                      bundle.getIdentityKey());

              axolotlStore.saveIdentity(address.getName(), bundle.getIdentityKey());

              try {
                SessionBuilder builder = new SessionBuilder(axolotlStore, address);
                builder.process(preKeyBundle);
                XmppAxolotlSession session =
                    new XmppAxolotlSession(
                        account,
                        axolotlStore,
                        address,
                        bundle.getIdentityKey().getFingerprint().replaceAll("\\s", ""));
                sessions.put(address, session);
                fetchStatusMap.put(address, FetchStatus.SUCCESS);
              } catch (UntrustedIdentityException | InvalidKeyException e) {
                Log.e(
                    Config.LOGTAG,
                    AxolotlService.getLogprefix(account)
                        + "Error building session for "
                        + address
                        + ": "
                        + e.getClass().getName()
                        + ", "
                        + e.getMessage());
                fetchStatusMap.put(address, FetchStatus.ERROR);
              }

              finish();
            }
          });
    } catch (InvalidJidException e) {
      Log.e(
          Config.LOGTAG,
          AxolotlService.getLogprefix(account)
              + "Got address with invalid jid: "
              + address.getName());
    }
  }