private void initGID(String _globalID) {
      // boolean DEBUG = true;
      if (DEBUG) System.out.println("DirServC: initGID " + _globalID);
      clean();
      String sql =
          "SELECT "
              + table.registered.fields
              + " FROM "
              + table.registered.TNAME
              + " WHERE "
              + table.registered.global_peer_ID
              + " = ?;";
      ArrayList<ArrayList<Object>> d;
      try {
        d = Application.db_dir.select(sql, new String[] {_globalID}, DEBUG);
      } catch (P2PDDSQLException e) {
        e.printStackTrace();
        this.globalID = _globalID;
        this.globalIDhash = D_Peer.getGIDHashFromGID(globalID);
        return;
      }
      if (DEBUG) System.out.println("DirServC: initGID #" + d.size());
      if (d.size() > 0) {
        initAll(d);
        if (DEBUG) System.out.println("DirServC: initGID got " + this);
      }

      if (this.globalID == null) this.globalID = _globalID;
      if (this.globalIDhash == null) this.globalIDhash = D_Peer.getGIDHashFromGID(globalID);
    }
Example #2
0
  // 	public static boolean validateSignature(URL url){
  //
  // 	}
  public static void main(String[] args) {
    String site =
        args[
            0]; // "wsdl:http://localhost:6060/ddWS_doc5.php?wsdll&123331c847ba3a5d6a52e817a4d0109fe65ffbc2038f68c8db1c3f9793b50c0d"
    System.out.println("URL " + args[0]);
    Hashtable<Object, Object> context = new Hashtable<Object, Object>();
    URL url = isWSVersionInfoService(args[0]);

    try {
      config.Application.db = new util.DBInterface("deliberation-app.db" /*args[1]*/);
    } catch (P2PDDSQLException e) {
      e.printStackTrace();
      return;
    }
    if (url == null) return;
    updates.VersionInfo response = null;
    while (response == null) {
      response = getWSVersionInfo(url, "gid:1111", data.HandlingMyself_Peer.getMyPeerSK(), context);
      if (response != null) {
        System.out.println("Web service response getVersion: " + response.version);
        System.out.println("Web service response getUrl: " + response.data[0].url);
      } else System.out.println("Response = null");
    }
    //        ArrayList<Downloadable> l = (ArrayList<Downloadable>)response.getData();
    //        Downloadable d= (Downloadable) l.toArray()[0];
    //        System.out.println("Web service response getUrl: " + "  "+d.getUrl() + d.getFilename()
    // );
  }
Example #3
0
	public void setNewJustificationID(String jID) {
		try{
			signature.justification_ID = jID;
			signature.global_justification_ID = null;
			//this.signature.creation_date = Util.getCalendar(creationTime);
			this.signature.setEditable();
			this.signature.storeVerified();
		} catch (P2PDDSQLException e) {
			e.printStackTrace();
		}			
	}
    /**
     * Here we manage the registered peers: - set crt as first in loaded_peers it may have been part
     * of the list before but we assume that its message was accounted in current_space
     *
     * @param crt
     */
    private static void register_loaded(D_DirectoryEntry crt) {
      ArrayList<D_DirectoryEntry> rem = new ArrayList<D_DirectoryEntry>();
      // crt.encoder = crt.getEncoder();
      // if(crt.loaded_globals) crt.component_node.message = crt.encode(); //crt.encoder.getBytes();
      synchronized (loaded_peers) {
        if (DEBUG) System.out.println("DSCache:register_loaded registering " + crt);
        if (crt.get_DDP2P_DoubleLinkedList_Node() == null) {
          boolean result = loaded_peers.offerFirst(crt);
          if (DEBUG) System.out.println("DSCache:register_loaded registered " + result);
          if (DEBUG) System.out.println("DSCache:register_loaded " + loaded_peers);
          // loaded_peer_By_LocalID.put(new Long(crt._peer_ID), crt);
          loaded_peer_By_GID.put(crt.globalID, crt);
          loaded_peer_By_GIDhash.put(crt.globalIDhash, crt);
          if (crt.component_node.message != null) {
            current_space += crt.component_node.message.length;
          }
        } else {
          loaded_peers.moveToFront(crt);
        }

        while ((loaded_peers.size() > MAX_LOADED_PEERS) || (current_space > MAX_PEERS_RAM)) {
          if (loaded_peers.size() <= MIN_PEERS_RAM) break; // at least _crt_peer and _myself
          //					D_DirectoryEntry candidate = loaded_peers.getTail();
          //					if((candidate == D_DirectoryEntry._crt_peer)||(candidate ==
          // D_DirectoryEntry._myself)){
          //						setRecent(candidate);
          //						continue;
          //					}

          D_DirectoryEntry removed = loaded_peers.removeTail(); // remove(loaded_peers.size()-1);
          // loaded_peer_By_LocalID.remove(new Long(removed._peer_ID));
          loaded_peer_By_GID.remove(removed.globalID);
          loaded_peer_By_GIDhash.remove(removed.globalIDhash);
          if (removed.component_node.message != null)
            current_space -= removed.component_node.message.length;
          if (D_Directory_Storage.need_saving_contains(removed.globalIDhash, removed.instance))
            rem.add(removed);
        }
      }
      if (DEBUG) System.out.println("DSCache:register_loaded cleaned " + loaded_peers);
      for (D_DirectoryEntry removed : rem) {
        try {
          synchronized (D_Directory_Storage.saver_thread_monitor) {
            if (D_Directory_Storage.need_saving_contains(removed.globalIDhash, removed.instance))
              removed.update();
          }
        } catch (P2PDDSQLException e) {
          e.printStackTrace();
        }
      }
      if (DEBUG) System.out.println("DSCache:register_loaded exit " + loaded_peers);
    }
Example #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));
 }
Example #6
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();
		}	
}
Example #7
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;
 }
Example #8
0
 public void run() {
   String _wireless;
   String old_wireless = null;
   synchronized (WLAN_widget.wlanmonitor) {
     // System.out.println("1"+Refresh.START_REFRESH);
     while (START_REFRESH) {
       // System.out.println("2"+Refresh.START_REFRESH);
       try {
         _wireless = wireless.Detect_interface.detect_wlan();
         if ((_wireless != null) && !_wireless.equals(old_wireless)) {
           DD.setAppText(DD.APP_NET_INTERFACES, _wireless);
           old_wireless = _wireless;
         }
         if (DEBUG) System.out.println("Refresh : run : ");
         Thread.sleep(DD.ADHOC_REFRESH_TIMEOUT_MILLISECONDS);
       } catch (P2PDDSQLException e) {
         e.printStackTrace();
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   }
 }
 public void _run() {
   for (; ; ) {
     if (stop) return;
     synchronized (saver_thread_monitor) {
       D_DirectoryEntry de = need_saving_next();
       if (de != null) {
         Application_GUI.ThreadsAccounting_ping("Saving");
         need_saving_remove(de.globalIDhash, de.instance);
         // try 3 times to save
         for (int k = 0; k < 3; k++) {
           try {
             de.update();
             break;
           } catch (P2PDDSQLException e) {
             e.printStackTrace();
             synchronized (this) {
               try {
                 wait(SAVER_SLEEP_ON_ERROR);
               } catch (InterruptedException e2) {
                 e2.printStackTrace();
               }
             }
           }
         }
       } else {
         Application_GUI.ThreadsAccounting_ping("Nothing to do!");
       }
     }
     synchronized (this) {
       try {
         wait(SAVER_SLEEP);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   }
 }
Example #10
0
    /**
     * Add a new instance to an existing peer cache.
     *
     * <p>Since the peer is assumed preloaded in the cache, instance not needed in global
     * hashtables.
     *
     * @param crt
     */
    public static void register_loaded_instance(D_DirectoryEntry crt) {
      ArrayList<D_DirectoryEntry> rem = new ArrayList<D_DirectoryEntry>();
      synchronized (loaded_peers) {
        loaded_peers.offerFirst(crt);
        if (crt.component_node.message != null) current_space += crt.component_node.message.length;

        /** Disconnect overflowing instances from list, set them in "removed" */
        while ((loaded_peers.size() > MAX_LOADED_PEERS) || (current_space > MAX_PEERS_RAM)) {
          if (loaded_peers.size() <= MIN_PEERS_RAM) break; // at least _crt_peer and _myself
          D_DirectoryEntry removed = loaded_peers.removeTail(); // remove(loaded_peers.size()-1);
          if (removed.component_node.message != null)
            current_space -= removed.component_node.message.length;
          if (D_Directory_Storage.need_saving_contains(removed.globalIDhash, removed.instance))
            rem.add(removed);
          else {
            for (D_DirectoryEntry a : removed.instances.values()) {
              if (D_Directory_Storage.need_saving_contains(a.globalIDhash, a.instance)) rem.add(a);
            }
          }
        }
      }
      /** Do the saving */
      for (D_DirectoryEntry removed : rem) {
        try {
          synchronized (D_Directory_Storage.saver_thread_monitor) {
            if (D_Directory_Storage.need_saving_contains(removed.globalIDhash, removed.instance))
              removed.update();
            for (D_DirectoryEntry a : removed.instances.values()) {
              if (D_Directory_Storage.need_saving_contains(a.globalIDhash, a.instance)) a.update();
            }
          }
        } catch (P2PDDSQLException e) {
          e.printStackTrace();
        }
      }
    }
Example #11
0
	private void handleChoiceEvent(Object source) {
		//boolean DEBUG = true;
		if(DEBUG) out.println("JustificationEditor:handleFieldEvent: start");
		/*
		String creationTime;
		if(vote_date_field != null) {
			creationTime = vote_date_field.getText();
		}else{
			creationTime = Util.getGeneralizedTime();
		}
		*/
		if((this.vote_date_field==source)||(this.vote_date_field.getDocument()==source)) {
			if(DEBUG) out.println("JustificationEditor:handleFieldEvent: date title");
			String new_text = this.vote_date_field.getText();
			Calendar cal = Util.getCalendar(new_text);
			if(cal == null) return;
			this.signature.creation_date = cal;
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_dategen_field==source) {
			this.signature.creation_date = Util.CalendargetInstance();
			this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
			this.signature.setEditable();
			try {
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
			return;			
		}
		if(this.vote_newjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio");
			this.just_old_just_field.setEnabled(false);
			//setChoiceOldJustification(creationTime);
			//enable_just();
			if(motionEditor!=null){
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in motioneditor");
				motionEditor.enableNewJustification(true);
				signature.justification_ID = motionEditor.getNewJustificationID();
				signature.global_justification_ID = null;
			}else{
				if(_DEBUG) out.println("VoteEditor:handleFieldEvent: choice newjust_radio, in justeditor");
				this.justificationEditor.make_new();
				this.enable_just();
				signature.justification_ID = justification.justification_ID;
				signature.global_justification_ID = null;
			}
			return;
		}
		if(this.vote_oldjust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice oldjust_radio");
			this.just_old_just_field.setEnabled(true);
			setChoiceOldJustification();
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			return;
		}
		if(this.vote_nojust_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice nojust_radio");
			this.just_old_just_field.setEnabled(false);
			if(motionEditor!=null){
				motionEditor.enableNewJustification(false);
			}else{
				this.disable_just();
			}
			try{
				signature.justification_ID = null;
				signature.global_justification_ID = null;
				//this.signature.creation_date = Util.getCalendar(creationTime);
				this.signature.setEditable();
				this.signature.storeVerified();
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}	
		}
		if(just_old_just_field==source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice old_just_combo");
			//if(DEBUG) Util.printCallPath("Linux tracing");
			setChoiceOldJustification();
			return;
		}
		if(this.vote_choice_field == source) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: choice vote_choice_field combo");
			setChoice();
			return;
		}
		if((just_submit_field == source)) {
			if(DEBUG) out.println("VoteEditor:handleFieldEvent: submit");
			try {
				long j_id=-1;
				D_Justification justification =null;
				if(signature.choice==null){
					Application.warning(_("No voting choice made.\nPlease return and make a voting choice."), _("No Choice Made"));
					return;
				}
				if(vote_newjust_field.isSelected()) {
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification");
					justification = justificationEditor.just;
					if(motionEditor!=null){
						justification = motionEditor.getNewJustification();
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from motionEditor="+justification);
					}else{
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: new justification from justEditor="+justification);						
					}
					
					if(justification.global_constituent_ID==null){
						if(DEBUG) out.println("VoteEditor:handleFieldEvent: reget justification");
						justification.global_constituent_ID = Application.constituents.tree.getModel().getConstituentGIDMyself();
						justification.constituent_ID = Util.getStringID(Application.constituents.tree.getModel().getConstituentIDMyself());
						if(justification.global_constituent_ID==null) {
							Application.warning(_("You should first select a constituent identity for this organization!"), _("No Constituent ID for this org!"));
							return;
						}
					}

					
					justification.global_justificationID = justification.make_ID();
					justification.sign();
					j_id = justification.storeVerified(DEBUG);
					if(j_id<=0){
						if(_DEBUG) out.println("VoteEditor:handleFieldEvent: failed saving no new justif");
						return;					
					}
				}else{
					if(DEBUG) out.println("VoteEditor:handleFieldEvent: no new justification selected");
				}
				
				//signature = signature;
				//signature.global_motion_ID = null;
				//signature.motion_ID = justificationEditor.just.motion_ID;
				if(vote_newjust_field.isSelected()) {
					signature.global_justification_ID = justification.global_justificationID;
					signature.justification_ID = Util.getStringID(j_id);//justificationEditor.just.justification_ID;
				}
				signature.global_vote_ID = signature.make_ID();
				
				D_Vote old = new D_Vote(signature.global_vote_ID);
				if(old.vote_ID!=null){
					String old_date = Encoder.getGeneralizedTime(old.creation_date);
					String new_date = Encoder.getGeneralizedTime(signature.creation_date);
					if(old_date.equals(new_date)){
						int attack = Application.ask(
								_("Are you sure you want to create a new vote \n" +
								"with the same date as your previous vote? \n" +
								"This can amount to an attack where you give different people different votes!\n" +
								"Except if they order such votes by signature (to be implemented)\n" +
								"On selecting NO, we will update the creation date to now."),
								_("Votes from you on the same issue and with same date!"), JOptionPane.YES_NO_CANCEL_OPTION);
						switch(attack) {
						case 0: //YES
							break;
						case 1: // NO
							signature.creation_date = Util.CalendargetInstance();
							this.vote_date_field.setText(Encoder.getGeneralizedTime(this.signature.creation_date));
							break;
						case 2: // CANCEL
						default:
							return;
						}
					}
				}
				
				signature.sign();
				long v_id = this.signature.storeVerified();
				if(v_id<=0){
					if(_DEBUG) out.println("VoteEditor:handleFieldEvent: submit sign got no local ID");
					return;
				}
				
				/*
				justificationEditor.just.global_justificationID = justificationEditor.just.make_ID();
				justificationEditor.just.sign();
				long id = justificationEditor.just.storeVerified();
				if(id<=0) return;
				*/
				disable_it();
				justificationEditor.disable_it();
				try{
					D_Motion m = new D_Motion(Util.lval(signature.motion_ID));
					m.broadcasted = true;
					m.storeVerified();
				}catch(Exception e){e.printStackTrace();}
			} catch (P2PDDSQLException e) {
				e.printStackTrace();
			}
		}
	}
Example #12
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;
    }