Skip to content

Commit

Permalink
DhtShell get operation
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 4, 2016
1 parent ffa2770 commit 7cf9fbf
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/test/java/com/frostwire/jlibtorrent/demo/DhtShell.java
Expand Up @@ -26,7 +26,6 @@ public int[] types() {
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.getType();
log(alert.getMessage());

if (type == AlertType.LISTEN_SUCCEEDED) {
ListenSucceededAlert a = (ListenSucceededAlert) alert;
Expand Down Expand Up @@ -68,6 +67,8 @@ public void alert(Alert<?> alert) {
quit(s);
} else if (is_put(line)) {
put(dht, line);
} else if (is_get(line)) {
get(dht, line);
} else if (is_invalid(line)) {
invalid(line);
}
Expand Down Expand Up @@ -118,6 +119,17 @@ private static void put(DHT dht, String s) {
print("Wait for completion of put for key: " + key);
}

private static boolean is_get(String s) {
return s.startsWith("get ");
}

private static void get(DHT dht, String s) {
String sha1 = s.split(" ")[1];
Entry data = dht.get(sha1, 20000);
print("Waiting a max of 20 seconds to get data for key: " + sha1);
print(data.toString());
}

private static boolean is_invalid(String s) {
return !s.isEmpty();
}
Expand Down

0 comments on commit 7cf9fbf

Please sign in to comment.