Skip to content

Commit

Permalink
More bits of code for DhtStorageBase
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 12, 2016
1 parent 78defdd commit ab024a9
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorageBase.java
Expand Up @@ -4,8 +4,10 @@
import com.frostwire.jlibtorrent.DhtSettings;
import com.frostwire.jlibtorrent.Sha1Hash;
import com.frostwire.jlibtorrent.TcpEndpoint;
import com.frostwire.jlibtorrent.swig.address;
import com.frostwire.jlibtorrent.swig.bloom_filter_256;
import com.frostwire.jlibtorrent.swig.entry;
import com.frostwire.jlibtorrent.swig.sha1_hash;

import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -42,27 +44,26 @@ public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry
if (!v.name.isEmpty()) {
peers.set("n", v.name);
}
/*
if (scrape)
{

if (scrape) {
bloom_filter_256 downloaders = new bloom_filter_256();
bloom_filter_256 seeds = new bloom_filter_256();
for (std::set<peer_entry>::const_iterator peer_it = v.peers.begin()
, end(v.peers.end()); peer_it != end; ++peer_it)
{
/*
for (PeerEntry peer : v.peers) {
sha1_hash iphash;
hash_address(peer_it->addr.address(), iphash);
if (peer_it->seed) seeds.set(iphash);
else downloaders.set(iphash);
}
peers.set["BFpe"] = downloaders.to_string();
peers["BFsd"] = seeds.to_string();
}
else
{
int num = (std::min)(int(v.peers.size()), m_settings.max_peers_reply);
hash_address(peer_it -> addr.address(), iphash);
if (peer.seed) {
seeds.set(iphash);
} else {
downloaders.set(iphash);
}
}*/

peers.set("BFpe", downloaders.to_bytes());
peers.set("BFsd", seeds.to_bytes());
} else {
/*
int num = Math.min(v.peers.size(), settings.maxPeersReply());
std::set<peer_entry>::const_iterator iter = v.peers.begin();
entry::list_type& pe = peers["values"].list();
std::string endpoint;
Expand All @@ -78,8 +79,8 @@ public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry
pe.push_back(entry(endpoint));
++m;
}
}*/
}*/
}

return true;
}
Expand Down Expand Up @@ -124,6 +125,20 @@ public Counters counters() {
return counters;
}

private static void hash_address(address ip, sha1_hash h)
{/*
if (ip.is_v6())
{
address_v6::bytes_type b = ip.to_v6().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}
else
{
address_v4::bytes_type b = ip.to_v4().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}*/
}

static final class PeerEntry {

public static final Comparator COMPARATOR = new Comparator();
Expand Down

0 comments on commit ab024a9

Please sign in to comment.