Exemplo n.º 1
0
  private static byte[] _monitor_handleAnnouncement(
      DirectoryAnnouncement da, String detected_sa, DBInterface db, boolean storeNAT)
      throws P2PDDSQLException {
    if (DEBUG) System.out.println("Got announcement: " + da);
    if (da.getGID() != null)
      db.deleteNoSyncNULL(
          table.registered.TNAME,
          new String[] {table.registered.global_peer_ID, table.registered.instance},
          new String[] {da.getGID(), da.instance},
          DEBUG);
    else
      db.deleteNoSyncNULL(
          table.registered.TNAME,
          new String[] {table.registered.global_peer_ID_hash, table.registered.instance},
          new String[] {da.getGIDH(), da.instance},
          DEBUG);
    String adr = da.address.addresses();
    // da.address.domain+":"+da.address.port+ADDR_SEP+detected_sa,
    if (storeNAT) adr = Address.joinAddresses(detected_sa, adr);

    String params[] = new String[table.registered.fields_noID_list.length];
    params[table.registered.REG_GID] = da.getGID();
    params[table.registered.REG_GID_HASH] = da.getGIDH();
    params[table.registered.REG_INSTANCE] = da.instance;
    params[table.registered.REG_BRANCH] = da.branch;
    params[table.registered.REG_AGENT_VERSION] = Util.getVersion(da.agent_version);
    params[table.registered.REG_NAME] = da.name;
    params[table.registered.REG_CERT] =
        (da.certificate.length == 0) ? null : Util.stringSignatureFromByte(da.certificate);
    params[table.registered.REG_ADDR] = adr;
    params[table.registered.REG_SIGN] =
        (da.signature.length == 0) ? null : Util.stringSignatureFromByte(da.signature);
    Calendar timestamp = da.date;
    if (timestamp == null) timestamp = Util.CalendargetInstance();
    params[table.registered.REG_TIME] =
        Encoder.getGeneralizedTime(
            timestamp); // (Util.CalendargetInstance().getTimeInMillis()/1000)+"";

    long id =
        db.insert(
            table.registered.TNAME,
            table.registered.fields_noID_list,
            //				new
            // String[]{table.registered.global_peer_ID,table.registered.certificate,table.registered.addresses,table.registered.signature,table.registered.timestamp},
            params);
    if (DEBUG) out.println("DirectoryServer: mon_handleAnnoncement:inserted with ID=" + id);
    byte[] answer = new DirectoryAnnouncement_Answer(detected_sa).encode();
    if (DEBUG) out.println("sending answer: " + Util.byteToHexDump(answer));
    return answer;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
 public static DBInterface getDirDB(String dbfile) {
   synchronized (db_monitor) {
     if (db_dir == null) {
       try {
         db_dir = new DBInterface(dbfile);
         ArrayList<ArrayList<Object>> a =
             db_dir._select(
                 "SELECT * FROM " + table.registered.TNAME + " LIMIT 1", new String[] {}, DEBUG);
         if (DEBUG) {
           System.out.println("DirectoryServer:getDBDir got " + a.size());
           for (ArrayList<Object> t : a) {
             System.out.println("DirectoryServer:getDBDir table " + t.size());
           }
         }
       } catch (P2PDDSQLException e) {
         System.out.println("Failure to open directory database: " + dbfile);
         e.printStackTrace();
       }
     }
   }
   return db_dir;
 }