Skip to content

Commit

Permalink
Implementing SwigDhtStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 10, 2016
1 parent 3900c0d commit 7fe6867
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorage.java
@@ -1,10 +1,38 @@
package com.frostwire.jlibtorrent.plugins;

import com.frostwire.jlibtorrent.Address;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.Sha1Hash;
import com.frostwire.jlibtorrent.TcpEndpoint;
import com.frostwire.jlibtorrent.swig.entry;

/**
* @author gubatron
* @author aldenml
*/
public interface DhtStorage {

boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry peers);

void announcePeer(Sha1Hash infoHash, TcpEndpoint endp, String name, boolean seed);

boolean getImmutableItem(Sha1Hash target, entry item);

void putImmutableItem(Sha1Hash target, byte[] buf, Address addr);

long getMutableItemSeq(Sha1Hash target);

boolean getMutableItem(Sha1Hash target, long seq, boolean forceFill, entry item);

void putMutableItem(Sha1Hash target, byte[] buf, byte[] sig, long seq, byte[] pk, byte[] salt, Address addr);

void tick();

long numTorrents();

long numPeers();

long numImmutableData();

long numMutableData();
}
@@ -1,7 +1,7 @@
package com.frostwire.jlibtorrent.plugins;

import com.frostwire.jlibtorrent.Logger;
import com.frostwire.jlibtorrent.swig.swig_dht_storage;
import com.frostwire.jlibtorrent.*;
import com.frostwire.jlibtorrent.swig.*;

/**
* @author gubatron
Expand All @@ -17,12 +17,71 @@ public SwigDhtStorage(DhtStorage s) {
this.s = s;
}

@Override
public boolean get_peers(sha1_hash info_hash, boolean noseed, boolean scrape, entry peers) {
return s.getPeers(new Sha1Hash(info_hash), noseed, scrape, peers);
}

@Override
public void announce_peer(sha1_hash info_hash, tcp_endpoint endp, String name, boolean seed) {
s.announcePeer(new Sha1Hash(info_hash), new TcpEndpoint(endp), name, seed);
}

@Override
public boolean get_immutable_item(sha1_hash target, entry item) {
return s.getImmutableItem(new Sha1Hash(target), item);
}

@Override
public void put_immutable_item(sha1_hash target, byte_vector buf, address addr) {
s.putImmutableItem(new Sha1Hash(target),
Vectors.byte_vector2bytes(buf),
new Address(addr));
}

@Override
public long get_mutable_item_seq_num(sha1_hash target) {
return s.getMutableItemSeq(new Sha1Hash(target));
}

@Override
public boolean get_mutable_item(sha1_hash target, long seq, boolean force_fill, entry item) {
return s.getMutableItem(new Sha1Hash(target), seq, force_fill, item);
}

@Override
public void put_mutable_item(sha1_hash target, byte_vector buf, byte_vector sig, long seq, byte_vector pk, byte_vector salt, address addr) {
s.putMutableItem(new Sha1Hash(target),
Vectors.byte_vector2bytes(buf),
Vectors.byte_vector2bytes(sig),
seq,
Vectors.byte_vector2bytes(pk),
Vectors.byte_vector2bytes(salt),
new Address(addr));
}

@Override
public void tick() {
try {
s.tick();
} catch (Throwable e) {
LOG.error("Error in plugin (tick)", e);
}
s.tick();
}

@Override
public long num_torrents() {
return s.numTorrents();
}

@Override
public long num_peers() {
return s.numPeers();
}

@Override
public long num_immutable_data() {
return s.numImmutableData();
}

@Override
public long num_mutable_data() {
return s.numMutableData();
}
}

0 comments on commit 7fe6867

Please sign in to comment.