@Override
 public void handleResponseMessage(ResponseMessage responseMessage) {
   String receivedSecret = (String) responseMessage.getContent();
   Number160 lKey = Number160.createHash(networkManager.getNodeId());
   Number160 cKey = Number160.createHash(contentKey);
   try {
     networkManager
         .getDataManager()
         .put(lKey, Number160.ZERO, cKey, new H2HTestData(receivedSecret), null)
         .awaitUninterruptibly();
   } catch (NoPeerConnectionException e) {
     Assert.fail();
   }
 }
Пример #2
0
  public P2PClient() throws Exception {

    this.localIP = getLocalPeerIP();
    this.serviceID = "medical";
    this.peerID = Number160.createHash(localIP);
    this.peer = new Peer(peerID);
    this.peer.listen(4000, 4000);
    PeerAddress superAddr = new PeerAddress(Number160.createHash(1), "109.231.77.242", 8888, 8888);
    FutureDiscover future = this.peer.discover(superAddr);
    future.awaitUninterruptibly();
    FutureBootstrap fb = this.peer.bootstrap(superAddr);
    fb.awaitUninterruptibly();
    peer.discover(fb.getBootstrapTo().iterator().next()).awaitUninterruptibly();
  }
Пример #3
0
 private FutureDHT put(String key, String domain, String content, String data)
     throws IOException {
   Number160 locationKey = Number160.createHash(key);
   Number160 domainKey = Number160.createHash(domain);
   Number160 contentKey = Number160.createHash(content);
   MyData myData = new MyData();
   myData.setKey(key);
   myData.setDomain(domain);
   myData.setContent(content);
   myData.setData(data);
   return peer.put(locationKey)
       .setDomainKey(domainKey)
       .setData(contentKey, new Data(myData))
       .start();
 }
Пример #4
0
 private String get(String name) throws ClassNotFoundException, IOException {
   FutureDHT futureDHT = peer.get(Number160.createHash(name));
   futureDHT.awaitUninterruptibly();
   if (futureDHT.isSuccess()) {
     return futureDHT.getData().values().iterator().next().getObject().toString();
   } else return "Not Found";
 }
Пример #5
0
 @SuppressWarnings("unchecked")
 private Vector<Number160> getPeerList(String name) throws ClassNotFoundException, IOException {
   FutureDHT futureDHT = peer.get(Number160.createHash(name));
   futureDHT.awaitUninterruptibly();
   if (futureDHT.isSuccess()) {
     return (Vector<Number160>) futureDHT.getData().values().iterator().next().getObject();
   } else return null;
 }
  @Override
  public void run() {
    String secret = NetworkTestUtil.randomString();

    Number160 lKey = Number160.createHash(networkManager.getNodeId());
    Number160 cKey = Number160.createHash(contentKey);
    try {
      networkManager
          .getDataManager()
          .put(lKey, Number160.ZERO, cKey, new H2HTestData(secret), null)
          .awaitUninterruptibly();
    } catch (NoPeerConnectionException e) {
      Assert.fail();
    }

    sendDirectResponse(createResponse(secret));
  }
Пример #7
0
 private void store(String key, String val) throws IOException {
   peer.put(Number160.createHash(key), new Data(val)).awaitUninterruptibly();
 }
Пример #8
0
 private FutureDHT get(String key, String domain, String content) {
   Number160 locationKey = Number160.createHash(key);
   Number160 domainKey = Number160.createHash(domain);
   Number160 contentKey = Number160.createHash(content);
   return peer.get(locationKey).setDomainKey(domainKey).setContentKey(contentKey).start();
 }