Esempio n. 1
0
  DirectoryAnswer getDA(DirectoryRequest dr) throws P2PDDSQLException {
    String sql =
        "select addresses, timestamp, strftime('%Y%m%d%H%M%fZ',timestamp,'unixepoch') from registered where global_peer_ID = ?;";
    ArrayList<ArrayList<Object>> adr = db_dir.select(sql, new String[] {dr.globalID}, DEBUG);
    if (DEBUG) System.out.println("Query: " + sql + " with ?= " + Util.trimmed(dr.globalID));
    if (DEBUG) System.out.println("Found addresses #: " + adr.size());
    DirectoryAnswer da = new DirectoryAnswer();
    da.version = dr.version;
    if (adr.size() != 0) {
      Integer time = Util.Ival(adr.get(0).get(1));
      if (time == null) {
        time = new Integer(0);
        out.println("EMPTY TIME. WHY?");
      }
      Date date = new Date();
      date.setTime(time.longValue());
      da.date.setTime(date);

      String addresses = (String) adr.get(0).get(0);
      if (DEBUG) System.out.println("This address: " + addresses);
      String a[] = Address.split(addresses);
      for (int k = 0; k < a.length; k++) {
        if ((a[k] == null) || ("".equals(a[k])) || ("null".equals(a[k]))) continue;
        if (DEBUG) System.out.println("This address [" + k + "]" + a[k]);
        da.addresses.add(new Address(a[k]));
      }
    } else {
      if (DEBUG) out.print("Empty ");
    }
    return da;
  }
Esempio n. 2
0
  private static DirectoryAnswer getDA_old(D_DirectoryEntry de, DirectoryRequest dr, int version) {
    DirectoryAnswer da = new DirectoryAnswer();
    if (de.addresses == null) {
      return da;
    }
    da.version = version;
    da.date = de.timestamp;
    if (da.date == null) {
      da.date = Util.CalendargetInstance();
    }

    if (de.addresses != null)
      for (int k = 0; k < de.addresses.length; k++) {
        da.addresses.add(de.addresses[k]);
      }
    return da;
  }