@Override
 public String toString() {
   StringBuilder sb = new StringBuilder("sig[");
   sb.append(number1.toString()).append('/');
   sb.append(number2.toString()).append(']');
   return sb.toString();
 }
Exemplo n.º 2
0
 private Data deserializeFile(DataInput in) throws IOException, FileNotFoundException {
   byte[] me = new byte[Number160.BYTE_ARRAY_SIZE];
   in.readFully(me);
   Number160 hash = new Number160(me);
   RandomAccessFile file = new RandomAccessFile(new File(path, hash.toString()), "r");
   FileChannel inChannel = file.getChannel();
   MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
   buffer.load();
   ByteBuf buf = Unpooled.wrappedBuffer(buffer);
   Data data = Data.decodeHeader(buf, signatureFactory);
   data.decodeBuffer(buf);
   data.decodeDone(buf, signatureFactory);
   file.close();
   return data;
 }
Exemplo n.º 3
0
  public static void main(String[] args) throws Exception {

    P2PClient client = new P2PClient();
    System.out.println(
        client.localIP + "   " + client.serviceID + "  " + client.peer.getPeerID().toString());

    System.out.println("Getting peerIDs for the serviceID \"medical\"");
    Vector<Number160> vec = client.getPeerList(client.serviceID);
    if (vec == null) {
      vec = new Vector<Number160>();
      System.out.println("vec was null, now is empty: " + vec.isEmpty());
      vec.add(client.peerID);
      client.store(client.serviceID, vec);
    } else {
      for (Number160 number160 : vec) {
        System.out.println("PeerID = " + number160.toString());
        for (String string : client.get(number160)) {
          System.out.print("\t" + string);
        }
        System.out.println("");
      }
      if (!vec.contains(client.peerID)) {
        vec.add(client.peerID);
        client.store(client.serviceID, vec);
      }
    }
    ///////////////////////////////////////////////////
    String[] localVals = {client.localIP, "IPSecrets"};
    client.store(client.peerID, localVals);

    for (String string : client.get(client.peerID)) {
      System.out.println(string);
    }

    ///////////////////////////////////////////////////
    if (args.length > 1) client.store(args[0], args[1]);
    if (args.length == 1) System.out.println("Name: " + args[0] + " IP:" + client.get(args[0]));
  }
Exemplo n.º 4
0
  private void serializeFile(DataOutput out, Data value) throws IOException, FileNotFoundException {
    Number160 hash = value.hash();
    // store file name
    out.write(hash.toByteArray());
    // store as external file, create path
    RandomAccessFile file = null;
    FileChannel rwChannel = null;
    try {
      file = new RandomAccessFile(new File(path, hash.toString()), "rw");
      rwChannel = file.getChannel();
      AlternativeCompositeByteBuf acb = AlternativeCompositeByteBuf.compBuffer();
      // store data to disk
      // header first
      value.encodeHeader(acb, signatureFactory);
      rwChannel.write(acb.nioBuffers());
      // next data - no need to copy to another buffer, just take the
      // data from memory
      rwChannel.write(value.toByteBuffers());
      // rest
      try {
        value.encodeDone(acb, signatureFactory);
        rwChannel.write(acb.nioBuffers());
      } catch (InvalidKeyException e) {
        throw new IOException(e);
      } catch (SignatureException e) {
        throw new IOException(e);
      }
    } finally {

      if (rwChannel != null) {
        rwChannel.close();
      }
      if (file != null) {
        file.close();
      }
    }
  }