Esempio n. 1
0
  /**
   * Called with a parameter "da" already verified and validated as new and possibly signed
   *
   * @param da
   * @param detected_sa
   * @param db
   * @param storeNAT
   * @return
   * @throws P2PDDSQLException
   */
  private static DirectoryAnnouncement_Answer _monitored_handleAnnouncement(
      DirectoryAnnouncement da,
      Address detected_sa,
      DBInterface db,
      boolean storeNAT,
      boolean TCP_not_UDP)
      throws P2PDDSQLException {

    if (DEBUG)
      System.out.println("DirectoryServer: _monitored_handleAnnouncement: Got announcement: " + da);
    if (da.address._addresses == null) {
      if (DEBUG)
        System.out.println(
            "DirectoryServer: _monitored_handleAnnouncement: Got empty announcement: "
                + da
                + " detected="
                + detected_sa);
    }

    String globalID = da.getGID();
    String globalIDhash = da.getGIDH();
    String instance = da.instance;

    // only use old NAT is current message is TCP
    if (TCP_not_UDP) {
      D_DirectoryEntry old_entry = DirectoryServerCache.getEntry(globalID, globalIDhash, instance);
      if (old_entry != null) {
        Address old_detected_NAT = old_entry.getNATAddress();
        if (detected_sa == null) detected_sa = old_detected_NAT;
        else {
          if (old_detected_NAT != null) {
            if (Address.sameDomain(detected_sa, old_detected_NAT)) {
              detected_sa = old_detected_NAT;
            } else {
              if (DEBUG)
                System.out.println(
                    "DirectoryServer: _monitored_handleAnnouncement: diff NATS: n="
                        + detected_sa
                        + " o="
                        + old_detected_NAT);
            }
          }
        }
      }
    }

    if (detected_sa != null)
      da.address._addresses = prependAddress(da.address._addresses, detected_sa);
    DirectoryServerCache.loadAndSetEntry(da, TCP_not_UDP);
    if (DEBUG)
      System.out.println(
          "DirectoryServer: _monitored_handleAnnouncement: loaded="
              + DirectoryServerCache.getEntry(globalID, globalIDhash, instance));

    // byte[] answer =
    return new DirectoryAnnouncement_Answer(Util.getString(detected_sa));
    // if (DEBUG) out.println("DS:_monitored_handleAnnouncement: sending answer:
    // "+Util.byteToHexDump(answer));
    // return answer;
  }
Esempio n. 2
0
 /**
  * Fills a D_DirEntry and its instances based on the result of a query in registered.fields
  *
  * @param d
  */
 public void initAll(ArrayList<ArrayList<Object>> d) {
   this.root = true;
   for (ArrayList<Object> a : d) {
     Object _instance = a.get(table.registered.REG_INSTANCE);
     if (_instance == null) {
       init(d.get(0), this);
       continue;
     }
     this.instances.put(Util.getString(_instance), new D_DirectoryEntry(a, this));
   }
 }
Esempio n. 3
0
	public void loadJustificationChoices(String motionID){
		String sql =
			"SELECT "+table.justification.justification_title+
			","+table.justification.global_justification_ID+
			","+table.justification.justification_ID+
			" FROM "+table.justification.TNAME+
			" WHERE "+table.justification.motion_ID+"=?;";
		try {
			ArrayList<ArrayList<Object>> j = Application.db.select(sql, new String[]{motionID}, DEBUG);
			combo_answerTo = new JustGIDItem[j.size()+1];
			int k=0;
			combo_answerTo[k++] = new JustGIDItem(null, null, "");
			for (ArrayList<Object> _j :j){
				String gid = Util.getString(_j.get(1));
				String id = Util.getString(_j.get(2));
				String name = Util.getString(_j.get(0));
				combo_answerTo[k++] = new JustGIDItem(gid, id, name);
			}
		} catch (P2PDDSQLException e1) {
			e1.printStackTrace();
		}	
}
Esempio n. 4
0
 public String toString_V1() {
   if (DEBUG) System.out.println("Address:toString: V1");
   if (domain == null) return address;
   String result = "";
   result += ((pure_protocol != null) ? (pure_protocol + ADDR_PROT_INTERN_SEP) : "");
   result += domain + ADDR_PART_SEP + tcp_port;
   if ((udp_port != tcp_port) || (name != null) || !active) {
     if (udp_port <= 0) result += ADDR_PART_SEP + tcp_port;
     else result += ADDR_PART_SEP + udp_port;
     if ((name != null) || (!active)) result += ADDR_PART_SEP + Util.getString(name, "");
   }
   return result;
 }
Esempio n. 5
0
 private void init(ArrayList<Object> in, D_Peer peer) {
   address = Util.getString(in.get(table.peer_address.PA_ADDRESS));
   instance_ID_str = Util.getString(in.get(table.peer_address.PA_INSTANCE_ID));
   _instance_ID = Util.lval(instance_ID_str, -1);
   if (_instance_ID > 0) {
     D_PeerInstance dpi = null;
     if (peer != null) {
       dpi = peer.getPeerInstance_ByID(instance_ID_str);
       // this._peer_ID = peer.get_ID();
     }
     if (dpi != null) {
       instance = dpi.peer_instance;
       this.branch = dpi.branch;
       this.agent_version = dpi.agent_version;
     } else {
       try {
         System.out.println("Address:init: should not come here!");
         ArrayList<ArrayList<Object>> inst =
             Application.db.select(
                 "SELECT "
                     + table.peer_instance.peer_instance
                     + " FROM "
                     + table.peer_instance.TNAME
                     + " WHERE "
                     + table.peer_instance.peer_instance_ID
                     + "=?;",
                 new String[] {instance_ID_str},
                 _DEBUG);
         if (inst.size() > 0) instance = Util.getString(inst.get(0));
       } catch (P2PDDSQLException e) {
         e.printStackTrace();
       }
     }
   }
   pure_protocol = Util.getString(in.get(table.peer_address.PA_TYPE));
   domain = Util.getString(in.get(table.peer_address.PA_DOMAIN));
   tcp_port = Util.ival(in.get(table.peer_address.PA_TCP_PORT), -1);
   udp_port = Util.ival(in.get(table.peer_address.PA_UDP_PORT), -1);
   certified = Util.stringInt2bool(in.get(table.peer_address.PA_CERTIFIED), false);
   priority = Util.ival(in.get(table.peer_address.PA_PRIORITY), 0);
   last_contact = Util.getString(in.get(table.peer_address.PA_CONTACT));
   arrival_date = Util.getString(in.get(table.peer_address.PA_ARRIVAL));
   peer_address_ID = Util.getString(in.get(table.peer_address.PA_PEER_ADDR_ID));
 }
Esempio n. 6
0
 private void init(ArrayList<Object> d, D_DirectoryEntry _parent) {
   parent = _parent;
   this.registered_ID = Util.lval(d.get(table.registered.REG_ID));
   // this.addresses =
   // TypedAddress.parseStringAddresses(Util.getString(d.get(table.registered.REG_ADDR)));
   this.addresses = Address.getAddresses(Util.getString(d.get(table.registered.REG_ADDR)));
   this.certificate =
       Util.byteSignatureFromString(Util.getString(d.get(table.registered.REG_CERT)));
   this.globalID = Util.getString(d.get(table.registered.REG_GID));
   this.globalIDhash = Util.getString(d.get(table.registered.REG_GID_HASH));
   this.instance = Util.getString(d.get(table.registered.REG_INSTANCE));
   this.signature =
       Util.byteSignatureFromString(Util.getString(d.get(table.registered.REG_SIGN)));
   this.timestamp = Util.getCalendar(Util.getString(d.get(table.registered.REG_TIME)));
   if (timestamp == null) timestamp = Util.CalendargetInstance();
 }
Esempio n. 7
0
    public void buildInstanceRequestedTerms() {
      // boolean DEBUG = true;
      if (DEBUG) System.out.println("DirServerCache: buildInstanceRequestedTerms: enter");
      if (instance_terms != null) return;
      String isNull = " IS NULL ;";
      String instanceType = " = ? ;";
      if (this.instance == null) instanceType = isNull;
      // a specific instance for a specific peer ID [sql1 and sql2]
      String sql1 =
          "SELECT "
              + table.subscriber.fields_subscribers
              + " FROM "
              + table.subscriber.TNAME
              + " WHERE "
              + table.subscriber.GID
              + " = ?"
              + " AND   "
              + table.subscriber.instance
              + instanceType;
      String sql2 =
          "SELECT "
              + table.subscriber.fields_subscribers
              + " FROM "
              + table.subscriber.TNAME
              + " WHERE "
              + table.subscriber.GID_hash
              + " = ?"
              + " AND   "
              + table.subscriber.instance
              + instanceType;
      // all instance for a specific peer ID [sql11 and sql22]
      String sql11 =
          "SELECT "
              + table.subscriber.fields_subscribers
              + " FROM "
              + table.subscriber.TNAME
              + " WHERE "
              + table.subscriber.GID
              + " = ?"
              + " AND   "
              + table.subscriber.all_instances
              + " = '1' ;";
      String sql22 =
          "SELECT "
              + table.subscriber.fields_subscribers
              + " FROM "
              + table.subscriber.TNAME
              + " WHERE "
              + table.subscriber.GID_hash
              + " = ?"
              + " AND   "
              + table.subscriber.all_instances
              + " = '1' ;";
      // default for all instance for all peer IDs [sql111]
      String sql111 =
          "SELECT "
              + table.subscriber.fields_subscribers
              + " FROM "
              + table.subscriber.TNAME
              + " WHERE "
              + table.subscriber.GID
              + " is NULL"
              + " AND   "
              + table.subscriber.GID_hash
              + " is NULL ;";
      String sql =
          "SELECT "
              + table.subscriber.subscriber_ID
              + " FROM "
              + table.subscriber.TNAME
              + " LIMIT 1;";

      ArrayList<ArrayList<Object>> d, any;
      try {

        // if (d == null || d.size()==0) {
        any = Application.db_dir.select(sql, new String[] {}, DEBUG);
        if ((any == null) || (any.size() == 0)) {
          DIR_Terms_Requested[] terms_any = new DIR_Terms_Requested[1];
          DIR_Terms_Requested t = new DIR_Terms_Requested();
          t.setServeLiberally();
          terms_any[0] = t;
          this.instance_terms = terms_any;

          return;
        }
        // }

        String params[] = new String[1];
        if (instance != null) {
          params = new String[2];
          params[1] = instance;
        }
        params[0] = this.globalID;
        d = Application.db_dir.select(sql1, params, DEBUG);

        if (d == null || d.size() == 0) {
          params[0] = this.globalIDhash;
          d = Application.db_dir.select(sql2, params, DEBUG);
        }

        if (d == null || d.size() == 0)
          d = Application.db_dir.select(sql11, new String[] {this.globalID}, DEBUG);

        if (d == null || d.size() == 0)
          d = Application.db_dir.select(sql22, new String[] {this.globalIDhash}, DEBUG);

        if (d == null || d.size() == 0)
          d = Application.db_dir.select(sql111, new String[] {}, DEBUG);

      } catch (P2PDDSQLException e) {
        e.printStackTrace();
        DIR_Terms_Requested[] terms_any = new DIR_Terms_Requested[1];
        DIR_Terms_Requested t = new DIR_Terms_Requested();
        t.setServeLiberally();
        terms_any[0] = t;
        this.instance_terms = terms_any;

        return;
      }

      // if (d==null || d.size()==0) return;
      DIR_Terms_Requested[] terms = new DIR_Terms_Requested[d.size()];
      int i = 0;
      for (ArrayList<Object> _u : d) {
        // D_SubscriberInfo s = new D_SubscriberInfo(_d, Application.db_dir );
        DIR_Terms_Requested t = new DIR_Terms_Requested();
        t.ad = Util.get_int(_u.get(table.subscriber.F_AD));
        t.payment = null; // not yet implemented
        t.plaintext = Util.get_int(_u.get(table.subscriber.F_PLAINTEXT));
        // ask?
        t.services_available = Util.getString(_u.get(table.subscriber.F_MODE)).getBytes();
        t.topic = Util.get_int(_u.get(table.subscriber.F_TOPIC)) + "";
        // t.version = 1; // ask??
        terms[i] = t;
      }
      this.instance_terms = terms;
    }