예제 #1
0
  public void testUDPPingRequest() {
    PingRequest pr = pingRequestFactory.createUDPPing();
    assertTrue(pr.supportsCachedPongs());

    // Test +UP +TLS
    UltrapeerSettings.MIN_CONNECT_TIME.setValue(0);
    UltrapeerSettings.FORCE_ULTRAPEER_MODE.setValue(true);
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ConnectionSettings.LOCAL_IS_PRIVATE.setValue(false);
    UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.setValue(true);
    UltrapeerSettings.NEED_MIN_CONNECT_TIME.setValue(false);
    tlsManager.setIncomingTLSEnabled(true);
    assertTrue(connectionServices.isSupernode());
    pr = pingRequestFactory.createUDPPing();
    assertFalse(pr.requestsIP());
    byte[] data = pr.getSupportsCachedPongData();
    assertEquals(0x1, data[0] & 0x1);
    assertEquals(0x2, data[0] & 0x2);

    // +UP -TLS
    tlsManager.setIncomingTLSEnabled(false);
    assertTrue(connectionServices.isSupernode());
    pr = pingRequestFactory.createUDPPing();
    assertFalse(pr.requestsIP());
    data = pr.getSupportsCachedPongData();
    assertEquals(0x1, data[0] & 0x1);
    assertEquals(0x0, data[0] & 0x2);

    // Test -UP +TLS
    UltrapeerSettings.DISABLE_ULTRAPEER_MODE.setValue(true);
    UltrapeerSettings.FORCE_ULTRAPEER_MODE.setValue(false);
    tlsManager.setIncomingTLSEnabled(true);
    assertFalse(connectionServices.isSupernode());
    pr = pingRequestFactory.createUDPPing();
    assertFalse(pr.requestsIP());
    data = pr.getSupportsCachedPongData();
    assertEquals(0x0, data[0] & 0x1);
    assertEquals(0x2, data[0] & 0x2);

    // Test -UP -TLS
    tlsManager.setIncomingTLSEnabled(false);
    assertFalse(connectionServices.isSupernode());
    pr = pingRequestFactory.createUDPPing();
    assertFalse(pr.requestsIP());
    data = pr.getSupportsCachedPongData();
    assertEquals(0x0, data[0] & 0x1);
    assertEquals(0x0, data[0] & 0x2);

    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(false);
    pr = pingRequestFactory.createUDPPing();
    assertTrue(pr.requestsIP());
  }
예제 #2
0
  public void testDoesNotAssignPassiveLeafIfDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    DHTSettings.ENABLE_PASSIVE_LEAF_DHT_MODE.setValue(false);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_PASSIVE_LEAF_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            false, // can't receive unsolicited
            DHTSettings.MIN_PASSIVE_LEAF_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
예제 #3
0
  public void testStopsDHTWhenDisabled() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.ACTIVE,
            false,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            one(dhtManager).stop();
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
예제 #4
0
  public void testDoesNotAssignLowAverageUptime() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            0, // no average uptime
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
예제 #5
0
  public void testDoesNotAssignLowInitialUptime() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);

    // no initial uptime
    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(
        buildDHTExpectations(
            DHTMode.INACTIVE,
            true,
            true,
            true,
            DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1,
            false,
            false));

    mockery.checking(
        new Expectations() {
          {
            never(dhtManager).start(with(Matchers.any(DHTMode.class)));
          }
        });

    assignerRunnable.run();
    mockery.assertIsSatisfied();
  }
 /**
  * @param l list to put the standard extentions we add to UDP pings
  * @return the guid to use for the ping
  */
 private GUID populateUDPGGEPList(List<NameValue<?>> l) {
   GUID guid;
   if (ConnectionSettings.EVER_ACCEPTED_INCOMING.getValue()) {
     guid = PingRequest.UDP_GUID;
   } else {
     l.add(new NameValue(GGEPKeys.GGEP_HEADER_IPPORT));
     guid = networkManager.getSolicitedGUID();
   }
   l.add(new NameValue<byte[]>(GGEPKeys.GGEP_HEADER_SUPPORT_CACHE_PONGS, getSCPData()));
   return guid;
 }
예제 #7
0
  public void testDoesNotPromoteIfNoUDP() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    mockery.checking(buildBandwdithExpectations(true));
    // no UDP support
    mockery.checking(buildUltrapeerExpectations(false, true, 0l, false, DHTMode.INACTIVE, false));
    // will not get promoted
    mockery.checking(buildPromotionExpectations(false));
    assignerRunnable.run();
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
예제 #8
0
  public void testDoesNotPromoteModemSpeed() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // everything else fine
    // setting up bad bandwidth to simulate a modem speed
    mockery.checking(buildBandwdithExpectations(false));
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, false, DHTMode.INACTIVE, false));
    mockery.checking(buildPromotionExpectations(false));

    assignerRunnable.run();
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
예제 #9
0
  public void testPromotesUltrapeer() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // set up some conditions for ultrapeer-ness
    // all of them are required
    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, false, DHTMode.INACTIVE, true));
    mockery.checking(buildPromotionExpectations(true));

    assignerRunnable.run();
    assertTrue(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
예제 #10
0
  public void testDoesNotPromoteIfAverageUptimeLow() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    // uptime bad
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() - 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    mockery.checking(buildBandwdithExpectations(true));
    mockery.checking(buildUltrapeerExpectations(true, true, 0L, false, DHTMode.INACTIVE, false));
    // will not get promoted
    mockery.checking(buildPromotionExpectations(false));
    assignerRunnable.run();

    // did not become capable this time either
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
예제 #11
0
  public void testDoesNotPromoteIfQueryTooSoon() throws Exception {
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    mockery.checking(buildBandwdithExpectations(true));
    // last query now
    mockery.checking(
        buildUltrapeerExpectations(
            true, true, System.currentTimeMillis(), false, DHTMode.INACTIVE, false));
    // will not get promoted
    mockery.checking(buildPromotionExpectations(false));
    assignerRunnable.run();

    // we are ever_capable because of last time
    assertTrue(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }
  @Override
  protected void setSettings() throws Exception {

    ConnectionSettings.NUM_CONNECTIONS.setValue(4);
    SearchSettings.GUESS_ENABLED.setValue(true);
    UltrapeerSettings.DISABLE_ULTRAPEER_MODE.setValue(false);
    UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.setValue(true);
    UltrapeerSettings.FORCE_ULTRAPEER_MODE.setValue(true);
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ConnectionSettings.CONNECT_ON_STARTUP.setValue(false);
    ConnectionSettings.LOCAL_IS_PRIVATE.setValue(false);
    FilterSettings.BLACK_LISTED_IP_ADDRESSES.set(new String[] {"*.*.*.*"});
    FilterSettings.WHITE_LISTED_IP_ADDRESSES.set(
        new String[] {"127.*.*.*", InetAddress.getLocalHost().getHostAddress()});

    ConnectionSettings.WATCHDOG_ACTIVE.setValue(false);
    ConnectionSettings.ALLOW_WHILE_DISCONNECTED.setValue(true);
    //        ConnectionSettings.PORT.setValue(6332);

    UltrapeerSettings.NEED_MIN_CONNECT_TIME.setValue(false);
  }
예제 #13
0
  public void testPromotesFromActiveDHTIfAllowed() throws Exception {
    // disallow switch to ultrapeer
    DHTSettings.SWITCH_TO_ULTRAPEER_PROBABILITY.setValue(1f);
    ConnectionSettings.EVER_ACCEPTED_INCOMING.setValue(true);
    ApplicationSettings.AVERAGE_UPTIME.setValue(UltrapeerSettings.MIN_AVG_UPTIME.getValue() + 1);
    assertFalse(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());

    // pretend some time passed - the uptime counter in NodeAssigner is very hacky
    long startTime =
        System.currentTimeMillis() - DHTSettings.MIN_ACTIVE_DHT_INITIAL_UPTIME.getValue();
    PrivilegedAccessor.setValue(nodeAssigner, "startTime", new Long(startTime));

    mockery.checking(buildBandwdithExpectations(true));
    // enabled and active DHT
    mockery.checking(buildUltrapeerExpectations(true, true, 0l, true, DHTMode.ACTIVE, false));

    // but we're not an active ultrapeer and can receive solicited
    // but we've been up long enough tob e active in the DHT
    mockery.checking(
        new Expectations() {
          {
            one(connectionServices).isActiveSuperNode();
            will(returnValue(false));
            one(networkManager).canReceiveSolicited();
            will(returnValue(true));
            atLeast(1).of(cManager).getCurrentAverageUptime();
            will(returnValue(DHTSettings.MIN_ACTIVE_DHT_AVERAGE_UPTIME.getValue() + 1));
          }
        });

    // will get promoted
    mockery.checking(buildPromotionExpectations(true));

    assignerRunnable.run();

    assertTrue(UltrapeerSettings.EVER_ULTRAPEER_CAPABLE.getValue());
    mockery.assertIsSatisfied();
  }