Esempio n. 1
1
 // Makes sure QueryKeys have no problem going in and out of GGEP blocks
 public void testQueryKeysAndGGEP() throws Exception {
   MACCalculatorRepositoryManager macManager = new MACCalculatorRepositoryManager();
   Random rand = new Random();
   for (int i = 4; i < 17; i++) {
     byte[] qk = new byte[i];
     Arrays.sort(qk);
     // make sure the bytes have offensive characters....
     while ((Arrays.binarySearch(qk, (byte) 0x1c) < 0)
         || (Arrays.binarySearch(qk, (byte) 0x00) < 0)) {
       rand.nextBytes(qk);
       Arrays.sort(qk);
     }
     AddressSecurityToken addressSecurityToken = new AddressSecurityToken(qk, macManager);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     addressSecurityToken.write(baos);
     GGEP in = new GGEP(true);
     in.put(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT, baos.toByteArray());
     baos = new ByteArrayOutputStream();
     in.write(baos);
     GGEP out = new GGEP(baos.toByteArray(), 0, null);
     AddressSecurityToken queryKey2 =
         new AddressSecurityToken(
             out.getBytes(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT), macManager);
     assertEquals("qks not equal, i = " + i, addressSecurityToken, queryKey2);
   }
 }
Esempio n. 2
0
  public void testGGEPPing() throws Exception {
    // first make a GGEP block....
    GGEP ggepBlock = new GGEP(true);
    ggepBlock.put(GGEPKeys.GGEP_HEADER_QUERY_KEY_SUPPORT);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ggepBlock.write(baos);

    byte[] ggepBytes = baos.toByteArray();

    // Headers plus payload(6 bytes)
    byte[] buffer = new byte[23 + ggepBytes.length + 1];
    byte[] guid = GUID.makeGuid(); // get a GUID
    System.arraycopy(guid, 0, buffer, 0, guid.length); // copy GUID
    int currByte = guid.length;
    buffer[currByte] = Message.F_PING;
    currByte++;
    buffer[currByte] = 0x0001; // TTL
    currByte++;
    buffer[currByte] = 0x0000; // Hops
    currByte++;
    buffer[currByte] = (byte) (ggepBytes.length + 1); // 1st byte = 6
    currByte++;
    buffer[currByte] = 0x0000; // 2nd byte = 0
    currByte++;
    buffer[currByte] = 0x0000; // 3rd byte = 0
    currByte++;
    buffer[currByte] = 0x0000; // 4th byte = 0 - remember it's little endian
    currByte++;
    // stick in GGEP
    for (int i = 0; i < ggepBytes.length; i++) buffer[currByte++] = ggepBytes[i];
    buffer[currByte++] = 0; // trailing 0
    assertGreaterThanOrEquals(buffer.length, currByte);

    // OK, ggep ping ready
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
    Message m;
    m = messageFactory.read(stream, Network.TCP);
    PingRequest pr;
    pr = (PingRequest) m;
    assertTrue(!pr.isQueryKeyRequest());
    pr.hop();
    assertTrue(pr.isQueryKeyRequest());
    // Came this far means its all OK
  }