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(); }
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)); }
public boolean initMotionOrg(){ D_Motion mot = getMotion(); if(mot == null){ if(DEBUG)System.out.println("VEditor:initMotionOrg: null motion"); return false; } if((mot.organization == null) && (mot.global_organization_ID == null) && (mot.organization_ID == null)){ if(DEBUG)System.out.println("VEditor:initMotionOrg: null org motion: "+mot); return false; } try { long _oid = Util.lval(mot.organization_ID,-1); if(_oid>0) mot.organization = new D_Organization(_oid); else mot.organization = new D_Organization(mot.global_organization_ID, null); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
@SuppressWarnings("unchecked") private void update_signature(boolean _choices) { //boolean DEBUG = true; if(DEBUG)System.out.println("VoteEditor: update_signature: start"); if(signature == null){ if(DEBUG)System.out.println("VoteEditor: update_signature: null sign="+signature); return; } if(mode == JustificationEditor.ONLY){ if(DEBUG)System.out.println("VoteEditor: update_signature: mode justification only"); return; } //if(mode != CHOICE) throw new RuntimeException("Mode="+mode); vote_choice_field.removeItemListener(this); this.choices = getChoices(); vote_choice_field.removeAllItems(); for(D_MotionChoice c: this.choices) vote_choice_field.addItem(c); vote_choice_field.addItemListener(this); Object sel = getChoiceSelection(signature.choice, this.choices); if(sel!=null) { vote_choice_field.removeItemListener(this); vote_choice_field.setSelectedItem(sel); vote_choice_field.addItemListener(this); }else{ vote_choice_field.setSelectedIndex(-1); } long j_ID = Util.lval(signature.justification_ID, -1); if(j_ID <= 0) { this.vote_nojust_field.setSelected(true); this.just_old_just_field.setEnabled(false); } if(j_ID > 0) { D_Justification _just = getJustification(); if(DEBUG)System.out.println("VoteEditor: update_signature: just="+_just); if ((_just!=null)&&(_just.isEditable())&&(signature.constituent_ID.equals(_just.constituent_ID))) { this.vote_newjust_field.setSelected(true); this.just_old_just_field.setEnabled(false); }else{ this.vote_oldjust_field.setSelected(true); this.just_old_just_field.setEnabled(true); } } vote_date_field.getDocument().removeDocumentListener(this); vote_date_field.setText(Encoder.getGeneralizedTime(signature.creation_date)); vote_date_field.getDocument().addDocumentListener(this); if(_choices) { loadJustificationChoices(signature.motion_ID); } if(just_old_just_field != null) { this.just_old_just_field.removeItemListener(this); just_old_just_field.removeAllItems(); JustGIDItem osel=null; for(JustGIDItem i : combo_answerTo){ just_old_just_field.addItem(i); if((signature !=null) && (signature.justification_ID != null)) { if((i.id!=null)&&i.id.equals(signature.justification_ID)){ osel = i;} } } if(osel!=null)just_old_just_field.setSelectedItem(osel); just_old_just_field.addItemListener(this); } }
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(); } } }
public void setInstanceID(String instance_ID) { this.instance_ID_str = instance_ID; this._instance_ID = Util.lval(instance_ID, -1); }
public long get_peer_address_ID() { return Util.lval(this.peer_address_ID, -1); }