예제 #1
0
  public static void main(String[] args) throws InterruptedException {
    Scanner cin = new Scanner(System.in);
    Peers p1 = new Peers(P1ID, P1UploadPort, P1DownloadPort, CheckPort[0]);
    p1.sum = new File("C:/users/ben/Desktop/Peers/P" + p1.PeerID + "/summary" + ".txt");
    p1.downloadfromServer();

    Uploading upload = new Uploading(p1);
    Thread t1 = new Thread(upload);
    Downloading t2 = new Downloading(p1);

    t1.start();
    p1.waitforDownloading();

    Thread.sleep(1000); // 否则会downloadPort开了,但是对应的uploadPort还没开启。
    t2.start();
  }
예제 #2
0
  /**
   * Reads the state model from disk.
   *
   * @return The {@link Model} instance as read from disk.
   */
  @Override
  public Model read() {
    try {
      final Model read = super.read();
      read.setCountryService(countryService);
      if (!LanternUtils.persistCredentials()) {
        if (read.getModal() != Modal.welcome) {
          read.setModal(Modal.authorize);
        }
      }

      // Make sure all peers are considered offline at startup.
      final Peers peers = read.getPeerCollector();
      peers.reset();
      if (read.getModal() == Modal.settingsLoadFailure) {
        read.setModal(Modal.none);
      }
      boolean isCensored = false;
      String countryCode = read.getLocation().getCountry();
      if (countryCode != null) {
        Country country = countryService.getCountryByCode(countryCode);
        if (country != null) {
          isCensored = country.isCensors();
        }
      }
      if (!isCensored && read.getModal() == Modal.giveModeForbidden) {
        read.setModal(Modal.none);
      }
      LanternUtils.setModel(read);
      processCommandLine(this.commandLine, read);
      return read;
    } catch (final ModelReadFailedException e) {
      log.error("Failed to read model", e);
      Model blank = blank();
      blank.setModal(Modal.settingsLoadFailure);
      return blank;
    } catch (final Exception e) {
      log.error("Failed to read model for some other reason", e);
      Model blank = blank();
      return blank;
    }
  }
예제 #3
0
 private Hallmark(
     String hallmarkString,
     byte[] publicKey,
     byte[] signature,
     String host,
     int weight,
     int date,
     boolean isValid)
     throws URISyntaxException {
   this.hallmarkString = hallmarkString;
   URI uri = new URI("http://" + host);
   this.host = uri.getHost();
   this.port = uri.getPort() == -1 ? Peers.getDefaultPeerPort() : uri.getPort();
   this.publicKey = publicKey;
   this.accountId = Account.getId(publicKey);
   this.signature = signature;
   this.weight = weight;
   this.date = date;
   this.isValid = isValid;
 }