예제 #1
0
 /**
  * --V0 Address ::= SEQUENCE { address UTF8String, type PrintableString, priority INTEGER IF
  * certified }
  *
  * @return
  */
 public Encoder getEncoder_V0() {
   Encoder enc = new Encoder().initSequence();
   String port = "" + tcp_port;
   // if (tcp_port <= 0) port = "" + udp_port;
   // else port = "" + tcp_port;
   String __address = domain + ":" + port;
   String ___address = pure_protocol + "://" + domain + ":" + port;
   if (!Util.equalStrings_null_or_not(__address, address)
       && !Util.equalStrings_null_or_not(__address + ":" + udp_port, address)
       && !Util.equalStrings_null_or_not(
           ___address, address)) { // eventually I want to migrate to __address from address
     System.out.println(
         "Address:getEncoder_V0: computed="
             + __address
             + " vs expected="
             + address
             + " in="
             + this.toLongString());
     Util.printCallPath("Address:" + this.toLongString());
   }
   enc.addToSequence(new Encoder(address).setASN1Type(Encoder.TAG_UTF8String));
   enc.addToSequence(new Encoder(pure_protocol).setASN1Type(Encoder.TAG_PrintableString));
   if (certified) {
     enc.addToSequence(new Encoder(priority));
   }
   return enc;
 }
예제 #2
0
 @Override
 public boolean equals(Object o) {
   if (!(o instanceof KEY)) return false;
   KEY k = (KEY) o;
   if (!Util.equalStrings_null_or_not(hash, k.hash)) return false;
   if (!Util.equalStrings_null_or_not(instance, k.instance)) return false;
   return true;
 }
예제 #3
0
 public void store(String peer_ID, String instance_ID) throws P2PDDSQLException {
   // boolean DEBUG = true;
   if (DEBUG) System.out.println("Address: store: " + peer_ID + " inst=" + instance_ID);
   String params[];
   assert (Util.equalStrings_null_or_not(instance_ID, this.instance_ID_str));
   if (instance_ID_str == null) setInstanceID(instance_ID);
   if (peer_address_ID == null) params = new String[table.peer_address.FIELDS_NOID];
   else params = new String[table.peer_address.FIELDS];
   params[table.peer_address.PA_INSTANCE_ID] = instance_ID_str;
   params[table.peer_address.PA_PEER_ID] = peer_ID;
   params[table.peer_address.PA_TYPE] = pure_protocol;
   params[table.peer_address.PA_DOMAIN] = domain;
   params[table.peer_address.PA_CERTIFIED] = Util.bool2StringInt(certified);
   params[table.peer_address.PA_PRIORITY] = "" + priority;
   params[table.peer_address.PA_CONTACT] = last_contact;
   params[table.peer_address.PA_ARRIVAL] = arrival_date;
   params[table.peer_address.PA_TCP_PORT] = "" + this.tcp_port;
   params[table.peer_address.PA_UDP_PORT] = "" + this.udp_port;
   params[table.peer_address.PA_ADDRESS] = address;
   if (peer_address_ID == null) {
     peer_address_ID =
         ""
             + Application.db.insert(
                 table.peer_address.TNAME, table.peer_address.fields_noID_list, params, DEBUG);
   } else {
     params[table.peer_address.PA_PEER_ADDR_ID] = peer_address_ID;
     Application.db.update(
         table.peer_address.TNAME,
         table.peer_address.fields_noID_list,
         new String[] {table.peer_address.peer_address_ID},
         params,
         DEBUG);
   }
 }
예제 #4
0
    /**
     * Set needs_saving on only differences
     *
     * @param da
     */
    public void load(DirectoryAnnouncement da, boolean TCP) {
      if (DEBUG) System.out.println("DSCache: load: start " + da);

      boolean need_saving = false;
      if (da.globalID != null) {
        if (!Util.equalStrings_null_or_not(globalID, da.globalID)) {
          need_saving = true;
          globalID = da.globalID;
        }
      }
      if (da.globalIDhash != null) {
        if (!Util.equalStrings_null_or_not(globalIDhash, da.globalIDhash)) {
          need_saving = true;
          globalIDhash = da.globalIDhash;
        }
      }
      if (!Util.equalStrings_null_or_not(instance, da.instance)) {
        need_saving = true;
        instance = da.instance;
      }
      if (!Util.equalBytes_null_or_not(certificate, da.certificate)) {
        need_saving = true;
        certificate = da.certificate;
      }
      if (!Util.equalBytes_null_or_not(signature, da.signature)) {
        need_saving = true;
        signature = da.signature;
      }
      set_NAT(da.address._addresses, get_NAT(addresses, TCP), TCP);
      String _addresses = Address.joinAddresses(addresses);
      String _addresses_ = Address.joinAddresses(da.address._addresses);
      if (!Util.equalStrings_null_or_not(_addresses, _addresses_)) {
        need_saving = true;
        addresses = da.address._addresses;
      }
      timestamp = da.date;
      // need_saving = true;
      if (need_saving) {
        D_Directory_Storage.discardMessage(this);
        D_Directory_Storage.need_saving_add(globalIDhash, instance);
        known = true;
      }
      if (DEBUG) System.out.println("DSCache: load: end " + this);
    }
예제 #5
0
 /**
  * Satisfied if the client offer is at least as good as the server request
  *
  * @param client_proposed_terms
  * @param server_requested_terms
  * @return
  */
 private static boolean termsMatch(
     DIR_Terms_Preaccepted[] client_proposed_terms, DIR_Terms_Requested[] server_requested_terms) {
   // boolean DEBUG = true;
   if (DEBUG)
     System.out.println(
         "DirectoryServer: termsMatch: enter client ptr"
             + client_proposed_terms
             + " server ptr="
             + server_requested_terms);
   if ((server_requested_terms == null) || (server_requested_terms.length == 0)) {
     if (_DEBUG) System.out.println("DirectoryServer: termsMatch: no server terms");
     return false;
   }
   if (((client_proposed_terms == null) || (client_proposed_terms.length == 0))
       && (server_requested_terms.length > 0)) {
     client_proposed_terms =
         new DIR_Terms_Preaccepted[] {new DIR_Terms_Preaccepted().setExpectFree()};
   }
   if (DEBUG)
     System.out.println(
         "DirectoryServer: termsMatch: enter client #"
             + client_proposed_terms.length
             + " server #"
             + server_requested_terms.length);
   boolean matchFound = false;
   for (DIR_Terms_Preaccepted from_client : client_proposed_terms) {
     if (DEBUG) System.out.println("DirectoryServer: termsMatch: from_client" + from_client);
     for (DIR_Terms_Requested from_server : server_requested_terms) {
       if (DEBUG)
         System.out.println("DirectoryServer: termsMatch: from_client" + server_requested_terms);
       if ((from_client.ad >= from_server.ad)
           && ((from_server.payment == null)
               || ((from_client.payment != null)
                   && (from_client.payment.satisfies(from_server.payment))))
           && (from_client.plaintext >= from_server.plaintext)
           && ((from_server.topic == null)
               || Util.equalStrings_null_or_not(from_client.topic, from_server.topic))) {
         if (DEBUG) System.out.println("DirectoryServer: termsMatch: match");
         matchFound = true;
         return matchFound;
       }
     }
   }
   return matchFound;
 }
예제 #6
0
 public boolean equals(Object _a) {
   final boolean DBG = false;
   if (DBG) System.out.print("Address:equals: " + this + " vs " + _a + " :");
   if ((!(_a instanceof Address)) || (_a == null)) {
     if (DBG) System.out.println("1->" + _a);
     return false;
   }
   Address a = (Address) _a;
   if (!Util.equalStrings_null_or_not(a.domain, this.domain)) {
     if (DBG) System.out.println("3->" + a.domain + " vs " + this.domain);
     return false;
   }
   /*
   if((a.domain==null)||(this.domain==null))
   	if(! ((a.domain==null)&&(this.domain==null))){
   		if(DBG) System.out.println("2->"+a.domain+" or "+this.domain);
   		return false;
   	}
   if((a.domain!=null) && !a.domain.equals(this.domain)){
   	if(DBG) System.out.println("3->");
   	return false;
   }
   */
   if (a.tcp_port != this.tcp_port) {
     if (DBG) System.out.println("4->" + a.tcp_port + " vs " + this.tcp_port);
     return false;
   }
   if (a.udp_port != this.udp_port) {
     if (DBG) System.out.println("5->" + a.udp_port + " vs " + this.udp_port);
     return false;
   }
   if (!Util.equalStrings_null_or_not(this.getProtocolVersion(), a.getProtocolVersion())) {
     if (DBG)
       System.out.println("6->" + a.getProtocolVersion() + " vs " + this.getProtocolVersion());
     return false;
   }
   /*
   if(DBG) if((a.pure_protocol!=null)||(this.pure_protocol!=null)) Util.printCallPath("adr?");
   if((a.pure_protocol==null)&&(this.pure_protocol!=null))
   	if(!Address.SOCKET.equals(this.pure_protocol)){
   		if(DBG) System.out.println("6a->"+a.pure_protocol+" or "+this.pure_protocol);
   		if(DBG) Util.printCallPath("adr?");
   		return false;
   	}
   if((a.pure_protocol!=null)&&(this.pure_protocol==null))
   	if(!Address.SOCKET.equals(a.pure_protocol)){
   		if(DBG) System.out.println("6b->"+a.pure_protocol+" or "+this.pure_protocol);
   		if(DBG) Util.printCallPath("adr?");
   		return false;
   	}
   	*/
   /*
   if((a.protocol==null)||(this.protocol==null))
   	if(! ((a.protocol==null)&&(this.protocol==null))){
   		System.out.println("6->"+a.protocol+" or "+this.protocol);
   		return false;
   	}
   */
   /*
   if((a.pure_protocol!=null) && (this.pure_protocol!=null) && !a.pure_protocol.equals(this.pure_protocol)){
   	if(DBG) System.out.println("7->");
   	return false;
   }
   */
   // if(DBG) System.out.println("=");
   return true;
 }