コード例 #1
0
    long update() throws P2PDDSQLException {
      // System.out.println("=================================>update "+this);
      if (registered_ID <= 0) return this.storeNew();
      D_Directory_Storage.need_saving_remove(globalIDhash, instance); // need_saving = false;
      String params[] = new String[table.registered.fields_list.length];
      params[table.registered.REG_GID] = globalID;
      params[table.registered.REG_GID_HASH] = globalIDhash;
      params[table.registered.REG_INSTANCE] = instance;
      params[table.registered.REG_CERT] =
          (certificate.length == 0) ? null : Util.stringSignatureFromByte(certificate);
      params[table.registered.REG_ADDR] = Address.joinAddresses(addresses);
      params[table.registered.REG_SIGN] =
          (signature.length == 0) ? null : Util.stringSignatureFromByte(signature);
      if (timestamp == null) timestamp = Util.CalendargetInstance();
      params[table.registered.REG_TIME] =
          Encoder.getGeneralizedTime(
              timestamp); // (Util.CalendargetInstance().getTimeInMillis()/1000)+"";
      params[table.registered.REG_ID] = Util.getStringID(this.registered_ID);

      Application.db_dir.update(
          table.registered.TNAME,
          table.registered.fields_noID_list,
          new String[] {table.registered.registeredID},
          params,
          DEBUG);
      //					new
      // String[]{table.registered.global_peer_ID,table.registered.certificate,table.registered.addresses,table.registered.signature,table.registered.timestamp},
      return registered_ID;
    }
コード例 #2
0
ファイル: DirectoryServer.java プロジェクト: Rfinley93/DDP2P
  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;
  }
コード例 #3
0
ファイル: HandleService.java プロジェクト: Rfinley93/DDP2P
  public static updates.VersionInfo getWSVersionInfo(
      URL url, String GID, SK myPeerSK, Hashtable<Object, Object> context) {
    if (DEBUG_) System.out.println("call getWSVersionInfo on URL " + url);
    int i = url.toString().indexOf("&");
    if (i == -1) {
      if (DEBUG_) System.out.println("URL " + url + " has no PK hash");
      return null;
    }
    String PK_hex = url.toString().substring(i + 1);
    try {
      url = new URL(url.toString().substring(0, i));
    } catch (MalformedURLException ex) {
      System.out.println("error in url: " + url);
      return null;
    }
    if (DEBUG_) System.out.println("pk= " + PK_hex + "  url= " + url);
    DdWS service = new DdWS(url);
    if (DEBUG_) if (service == null) System.out.println("service=null");

    // service.getHandlerResolver().getHandlerChain(service.getDdWSPort()).add(new Handler());
    DdWSPortType DDver = service.getDdWSPort();
    // System.out.println("part: "+ service);

    BindingProvider bindingProvider = ((BindingProvider) DDver);

    List<javax.xml.ws.handler.Handler> handlerChain =
        bindingProvider.getBinding().getHandlerChain();
    Handler handler = new Handler();
    handler.setPK_Hex(PK_hex);
    handlerChain.add(handler);
    bindingProvider.getBinding().setHandlerChain(handlerChain);

    if (DEBUG_) if (DDver == null) System.out.println("DDver=null");
    // build history object
    Map<String, Object> c = bindingProvider.getRequestContext();
    Object URLloc = c.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    /* To change the location address
    *context.put(
      BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
      newAddress);
    */
    // System.out.println("loc: "+URLloc.toString());
    DateInfo d;
    if ((d = (DateInfo) context.get(url.toString())) == null) {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println(" Context = null");
      d = new DateInfo();
    } else {
      if (ClientUpdates.DEBUG || DEBUG) System.out.println("localtime: " + d.LocalDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        System.out.println("Caltime: " + d.CalculatedDate.getTime());
      if (ClientUpdates.DEBUG || DEBUG)
        if (d.ServerDate != null) System.out.println("Servertime: " + d.ServerDate.getTime());
    }
    if (d.ServerDate != null) // server date set only with error
    d.CalculatedDate = getUpdateDate(d.ServerDate, d.LocalDate);
    d.ServerDate = null;
    String lDate = Util.getGeneralizedTime();
    d.LocalDate = Util.getCalendar(lDate);
    if (d.CalculatedDate == null) d.CalculatedDate = d.LocalDate;
    Request rq = new Request(GID, URLloc.toString(), d.CalculatedDate);
    String signature = Util.stringSignatureFromByte(rq.sign(myPeerSK));
    History h = new History();
    h.setGID(rq.peerGID);
    h.setUrl(rq.url);
    h.setDate(Encoder.getGeneralizedTime(rq.date)); // date as generalized for server side
    h.setSignature(signature);
    VersionInfo response = null;
    context.put(url.toString(), d);
    try {
      response = DDver.getVersionInfo(h);
    } catch (SOAPFaultException e) {
      if (DEBUG)
        System.err.println(
            "WSUpdate:HandleService:Code: "
                + e.getFault().getFaultCode()
                + ", Actor: "
                + e.getFault().getFaultActor()
                + ", String: "
                + e.getFault().getFaultString());
      if (e.getFault().getFaultActor().trim().equals("date")) {
        statusCode = INVALID_DATE;
        errorString = e.getFault().getFaultString();
        d = (DateInfo) context.get(url.toString());
        d.ServerDate = Util.getCalendar(errorString + ".000Z"); // Calendar.getInstance();
        context.remove(url.toString());
        context.put(url.toString(), d);
        // d.ServerDate.setTime(new Date(Long.parseLong(errorString)));
        if (DEBUG)
          System.out.println(
              "WSUpdate:HandleService:Server: "
                  + d.ServerDate.getTime()
                  + "  Client: "
                  + d.LocalDate.getTime());
      } else if (e.getFault().getFaultActor().trim().equals("url")) {
        statusCode = INVALID_URL;
        errorString = e.getFault().getFaultString();
      }
      return null;
    }
    statusCode = handler.isValidSignature();
    if (statusCode == INVALID_SIGNATURE) {
      return null;
    }
    updates.VersionInfo v = new updates.VersionInfo();
    v.version = response.getVersion();
    v.script = response.getScript();
    v.date = Util.getCalendar(response.getDate());
    // v.signature = Util.byteSignatureFromString(response.getSignature());
    v.data = new updates.Downloadable[response.getData().size()];
    Downloadable downloadable = null;
    for (i = 0; i < v.data.length; i++) {
      v.data[i] = new updates.Downloadable();
      downloadable = (Downloadable) response.getData().get(i);
      v.data[i].filename = downloadable.getFileName();
      v.data[i].url = downloadable.getUrl();
      v.data[i].digest = Util.byteSignatureFromString(downloadable.getDigest());
    }
    v.releaseQD = new data.D_ReleaseQuality[response.getQOTD().size()];
    TestDef testDef = null;
    for (i = 0; i < v.releaseQD.length; i++) {
      testDef = (TestDef) response.getQOTD().get(i);
      //	int index = testDef.getRef().intValue() - 1;
      int index = testDef.getRef().intValue();
      v.releaseQD[index] = new data.D_ReleaseQuality();

      v.releaseQD[index]._quality = new String[testDef.getQualityStructure().size()];
      for (int j = 0; j < v.releaseQD[index]._quality.length; j++) {
        v.releaseQD[index]._quality[j] = testDef.getQualityStructure().get(j);
      }
      v.releaseQD[index].description = testDef.getDesc();
    }

    v.testers_data = new data.D_SoftwareUpdatesReleaseInfoByTester[response.getTesters().size()];
    TesterInfo testerInfo = null;
    for (i = 0; i < v.testers_data.length; i++) {
      testerInfo = (TesterInfo) response.getTesters().get(i);
      v.testers_data[i] = new data.D_SoftwareUpdatesReleaseInfoByTester();
      v.testers_data[i].name = testerInfo.getName();
      v.testers_data[i].public_key_hash = testerInfo.getDigestPK();
      v.testers_data[i].tester_QoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      v.testers_data[i].tester_RoT =
          new float[response.getQOTD().size()]; // not all array elements are used
      for (int j = 0; j < testerInfo.getTests().size(); j++) {
        // int index = ((Test)testerInfo.getTests().get(j)).getQualityRef().intValue() - 1;
        int index = ((Test) testerInfo.getTests().get(j)).getQualityRef().intValue();
        v.testers_data[i].tester_QoT[index] =
            ((Test) testerInfo.getTests().get(j)).getQoT().floatValue();
        v.testers_data[i].tester_RoT[index] =
            ((Test) testerInfo.getTests().get(j)).getRoT().floatValue();
      }
      v.testers_data[i].signature = Util.byteSignatureFromString(testerInfo.getSignature());
    }

    return v;
  }
コード例 #4
0
	@SuppressWarnings("unchecked")
	public void handleFieldEvent(Object source, DocumentEvent evt) {
		
		if(evt!=null){
			this.notifyChange(evt);
			return;
		}else{
			/*
			evt = new DocumentEvent(){ //placeholder for null
				public Document mySource = null;
				@Override
				public ElementChange getChange(Element arg0) {
					return null;
				}
				@Override
				public Document getDocument() {
					return mySource;
				}
				@Override
				public int getLength() {
					return 0;
				}
				@Override
				public int getOffset() {
					return 0;
				}
				@Override
				public EventType getType() {
					return null;
				}};
				*/
		}
		
		//boolean DEBUG = true;
		if(this.setTxtMode==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: setText");
			switchMode(D_Document.TXT_BODY_FORMAT);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.setHTMMode==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: setHTM");
			switchMode(D_Document.HTM_BODY_FORMAT);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.sync_changes==source) {
			if(DEBUG)System.err.println("MotionEditor:handleFieldEvent: sync");
			editor.updateDoc(data);
			this.notifyChange(evt);
			if(DEBUG) System.out.println("MotionEditor:handleFieldEvent: done");
		}
		if(this.load_field==source) {
			if(DEBUG)System.err.println("ControlPane:actionImport: import file");
			int returnVal = MotionEditor.fd.showOpenDialog(this);
			if(DEBUG)System.err.println("ControlPane:actionImport: Got: selected");
	        if (returnVal == JFileChooser.APPROVE_OPTION) {
	        	if(DEBUG)System.err.println("ControlPane:actionImport: Got: ok");
	            File file = MotionEditor.fd.getSelectedFile();
	            if(!file.exists()){
	            	Application_GUI.warning(_("The file does not exists: "+file),_("Importing Address")); return;
	            }
	            String ext = Util.getExtension(file);
	            if(ext!=null) ext = ext.toLowerCase();
	            try {
	            	boolean _DEBUG = true;
					if("pdf".equals(ext)) {
	            		if(DEBUG)System.err.println("ControlPane:actionImport: Got: pdf");
	            		try {
	            			// File f = new File("/home/msilaghi/CS_seminar_flyer.pdf");
	            			InputStream in = new FileInputStream(file); // "/home/msilaghi/CS_seminar_flyer.pdf");
	            			if(file.length() > DocumentEditor.MAX_PDF) {
	            				if(_DEBUG) System.out.println("OrgEditor: getText: bin size="+file.length()+" vs "+DocumentEditor.MAX_PDF);
	            				Application_GUI.warning(_("File too large! Current Limit:"+" "+file.length()+"/"+DocumentEditor.MAX_PDF),
	            						_("Document too large for import!"));
	            				in.close();
	            				return;
	            			}
	            			byte bin[] = new byte[(int)file.length()];
	            			int off = 0;
	            			do{
	            				int cnt = in.read(bin, off, bin.length-off);
	            				if(cnt == -1) {
	            					if(_DEBUG) System.out.println("OrgEditor: getText: crt="+cnt+" off="+off+"/"+bin.length);
	            					break;
	            				}
	            				off +=cnt;
            					if(_DEBUG) System.out.println("OrgEditor: getText: crt="+cnt+" off="+off+"/"+bin.length);
	            			}while(off < bin.length);
	            			in.close();
	            			if(DEBUG) System.out.println("DocumentEditor: handle: bin size="+bin.length);
	            			String data = Util.stringSignatureFromByte(bin);
	            			if(DEBUG) System.out.println("DocumentEditor: handle: txt size="+data.length());
	            			
	            			setMode(D_Document.PDF_BODY_FORMAT, data);
	            			
							this.notifyChange(evt);
	            		} catch (FileNotFoundException e) {
	            			e.printStackTrace();
	            		} catch (IOException e) {
	            			e.printStackTrace();
	            		}
	            	}else
	            		if(("html".equals(ext)) || ("htm".equals(ext))){
	            			if(_DEBUG)System.err.println("ControlPane:actionImport: Got: html: implement!");
	            			try{
	            				BufferedReader bri = new BufferedReader(new FileReader(file));
								String data = Util.readAll(bri);
								
								setMode(D_Document.HTM_BODY_FORMAT, data);
								
								this.notifyChange(evt);
	            			}catch(Exception e){
	            				e.printStackTrace();
	            			}
	            		}else
	            			if(("txt".equals(ext))){
	            				try{
		            				BufferedReader bri = new BufferedReader(new FileReader(file));
									String data = Util.readAll(bri);
									
									setMode(D_Document.TXT_BODY_FORMAT, data);
									
									this.notifyChange(evt);
		            			}catch(Exception e){
		            				e.printStackTrace();
		            			}
	            			}else
	            				if(_DEBUG)System.err.println("ControlPane:actionImport: Got: "+ext+": implement!");
	            }catch(Exception e){
	            	e.printStackTrace();
	            }
	        }
		}
	}