Skip to content

Commit

Permalink
Coded getMutableItemSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 19, 2016
1 parent 1ab349b commit 9e62d61
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -17,6 +17,7 @@ public class DhtStorageBase implements DhtStorage {

private final HashMap<Sha1Hash, TorrentEntry> torrents;
private final HashMap<Sha1Hash, DhtImmutableItem> immutables;
private final HashMap<Sha1Hash, DhtMutableItem> mutables;

public DhtStorageBase(Sha1Hash id, DhtSettings settings) {
this.id = id;
Expand All @@ -25,6 +26,7 @@ public DhtStorageBase(Sha1Hash id, DhtSettings settings) {

this.torrents = new HashMap<Sha1Hash, TorrentEntry>();
this.immutables = new HashMap<Sha1Hash, DhtImmutableItem>();
this.mutables = new HashMap<Sha1Hash, DhtMutableItem>();
}

@Override
Expand Down Expand Up @@ -179,7 +181,8 @@ public void putImmutableItem(Sha1Hash target, byte[] buf, Address addr) {

@Override
public long getMutableItemSeq(Sha1Hash target) {
return -1;
DhtMutableItem i = mutables.get(target);
return i != null ? i.seq : -1;
}

@Override
Expand Down Expand Up @@ -244,7 +247,7 @@ public TorrentEntry() {
public TreeSet<PeerEntry> peers;
}

private static final class DhtImmutableItem {
private static class DhtImmutableItem {
// malloced space for the actual value
public byte[] value;
// this counts the number of IPs we have seen
Expand All @@ -257,6 +260,13 @@ private static final class DhtImmutableItem {
public int num_announcers;
}

private static final class DhtMutableItem extends DhtImmutableItem {
public byte[] sig = new byte[64];
public long seq;
public byte[] key = new byte[32];
public byte[] salt;
}

private static final class ImmutableItemComparator implements Comparator<Map.Entry<Sha1Hash, DhtImmutableItem>> {

private final Sha1Hash ourId;
Expand Down

0 comments on commit 9e62d61

Please sign in to comment.