Example #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;
  }
 public String toRecString(boolean _parent) {
   String r = "D_DirEntry[";
   r += "\n\t" + "known=" + known + " root=" + root;
   r += "\n\t" + "ID=" + registered_ID;
   r += "\n\t" + "GID=" + globalID;
   r += "\n\t" + "GIDH=" + globalIDhash;
   r += "\n\t" + "inst=" + instance;
   r += "\n\t" + "cert=" + certificate;
   r += "\n\t" + "addr=" + Util.concat(addresses, "\n\t\t", "NULL");
   r += "\n\t" + "sign=" + Util.byteToHexDump(signature);
   r += "\n\t" + "time=" + Encoder.getGeneralizedTime(timestamp);
   if (_parent && (parent != null) && (parent != this))
     r += "\n\t" + "parent=" + parent.toSummary();
   r += "\n\t" + "instances=" + Util.concat(instances.values(), "}{", "NULL") + "\n]";
   return r;
 }
 @Override
 public String toString() {
   String r = "DirAnsInst [";
   r += "\t\ninstance=" + instance;
   r += "\t\nbranch=" + branch;
   r += "\t\nagent_version=" + Util.concat(agent_version, ".", "NULL");
   r += "\t\nsignature_peer=" + Util.byteToHexDump(signature_peer);
   r += "\t\ndate_last_contact=" + Encoder.getGeneralizedTime(date_last_contact);
   if (instance_terms != null) {
     for (int i = 0; i < instance_terms.length; i++) {
       r += "\t\ninstance_terms=" + instance_terms[i];
     }
   }
   r += "\t\n addr=" + Util.concat(addresses, " , ", "NULL");
   return r + "]";
 }