Skip to content

Commit

Permalink
Coding DhtStorageBase
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 11, 2016
1 parent d023bb9 commit 5d7b955
Showing 1 changed file with 23 additions and 0 deletions.
Expand Up @@ -6,6 +6,9 @@
import com.frostwire.jlibtorrent.TcpEndpoint;
import com.frostwire.jlibtorrent.swig.entry;

import java.util.HashMap;
import java.util.HashSet;

/**
* @author gubatron
* @author aldenml
Expand All @@ -16,14 +19,29 @@ public final class DhtStorageBase implements DhtStorage {
private final DhtSettings settings;
private final Counters counters;

private final HashMap<String, TorrentEntry> map;

public DhtStorageBase(Sha1Hash id, DhtSettings settings) {
this.id = id;
this.settings = settings;
this.counters = new Counters();

this.map = new HashMap<String, TorrentEntry>();
}

@Override
public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry peers) {
String hex = infoHash.toHex();
TorrentEntry v = map.get(hex);

if (v == null) {
return false;
}

if (!v.name.isEmpty()) {
peers.set("n", v.name);
}

return false;
}

Expand Down Expand Up @@ -91,4 +109,9 @@ public int compare(PeerEntry o1, PeerEntry o2) {
}
}
}

static final class TorrentEntry {
public String name;
public HashSet<PeerEntry> peers;
}
}

0 comments on commit 5d7b955

Please sign in to comment.