forked from I2P_Developers/i2p.i2p
- Concurrent PeerCoordinatorSet
- final infoHash in Snark
This commit is contained in:
@@ -117,9 +117,8 @@ public class PeerAcceptor
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// multitorrent capable, so lets see what we can handle
|
// multitorrent capable, so lets see what we can handle
|
||||||
for (Iterator iter = coordinators.iterator(); iter.hasNext(); ) {
|
PeerCoordinator cur = coordinators.get(peerInfoHash);
|
||||||
PeerCoordinator cur = (PeerCoordinator)iter.next();
|
if (cur != null) {
|
||||||
|
|
||||||
if (DataHelper.eq(cur.getInfoHash(), peerInfoHash)) {
|
if (DataHelper.eq(cur.getInfoHash(), peerInfoHash)) {
|
||||||
if (cur.needPeers())
|
if (cur.needPeers())
|
||||||
{
|
{
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
package org.klomp.snark;
|
package org.klomp.snark;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import net.i2p.crypto.SHA1Hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hmm, any guesses as to what this is? Used by the multitorrent functionality
|
* Hmm, any guesses as to what this is? Used by the multitorrent functionality
|
||||||
@@ -12,26 +13,28 @@ import java.util.Set;
|
|||||||
* from it there too)
|
* from it there too)
|
||||||
*/
|
*/
|
||||||
public class PeerCoordinatorSet {
|
public class PeerCoordinatorSet {
|
||||||
private final Set _coordinators;
|
private final Map<SHA1Hash, PeerCoordinator> _coordinators;
|
||||||
|
|
||||||
public PeerCoordinatorSet() {
|
public PeerCoordinatorSet() {
|
||||||
_coordinators = new HashSet();
|
_coordinators = new ConcurrentHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator iterator() {
|
public Iterator<PeerCoordinator> iterator() {
|
||||||
synchronized (_coordinators) {
|
return _coordinators.values().iterator();
|
||||||
return new ArrayList(_coordinators).iterator();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(PeerCoordinator coordinator) {
|
public void add(PeerCoordinator coordinator) {
|
||||||
synchronized (_coordinators) {
|
_coordinators.put(new SHA1Hash(coordinator.getInfoHash()), coordinator);
|
||||||
_coordinators.add(coordinator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(PeerCoordinator coordinator) {
|
public void remove(PeerCoordinator coordinator) {
|
||||||
synchronized (_coordinators) {
|
_coordinators.remove(new SHA1Hash(coordinator.getInfoHash()));
|
||||||
_coordinators.remove(coordinator);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @since 0.9.2
|
||||||
|
*/
|
||||||
|
public PeerCoordinator get(byte[] infoHash) {
|
||||||
|
return _coordinators.get(new SHA1Hash(infoHash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -252,7 +252,7 @@ public class Snark
|
|||||||
private boolean stopped;
|
private boolean stopped;
|
||||||
private boolean starting;
|
private boolean starting;
|
||||||
private byte[] id;
|
private byte[] id;
|
||||||
private byte[] infoHash;
|
private final byte[] infoHash;
|
||||||
private String additionalTrackerURL;
|
private String additionalTrackerURL;
|
||||||
private final I2PSnarkUtil _util;
|
private final I2PSnarkUtil _util;
|
||||||
private final PeerCoordinatorSet _peerCoordinatorSet;
|
private final PeerCoordinatorSet _peerCoordinatorSet;
|
||||||
@@ -340,6 +340,7 @@ public class Snark
|
|||||||
meta = null;
|
meta = null;
|
||||||
File f = null;
|
File f = null;
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
|
byte[] x_infoHash = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
f = new File(torrent);
|
f = new File(torrent);
|
||||||
@@ -362,7 +363,7 @@ public class Snark
|
|||||||
throw new IOException("not found");
|
throw new IOException("not found");
|
||||||
}
|
}
|
||||||
meta = new MetaInfo(in);
|
meta = new MetaInfo(in);
|
||||||
infoHash = meta.getInfoHash();
|
x_infoHash = meta.getInfoHash();
|
||||||
}
|
}
|
||||||
catch(IOException ioe)
|
catch(IOException ioe)
|
||||||
{
|
{
|
||||||
@@ -403,6 +404,7 @@ public class Snark
|
|||||||
try { in.close(); } catch (IOException ioe) {}
|
try { in.close(); } catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infoHash = x_infoHash; // final
|
||||||
debug(meta.toString(), INFO);
|
debug(meta.toString(), INFO);
|
||||||
|
|
||||||
// When the metainfo torrent was created from an existing file/dir
|
// When the metainfo torrent was created from an existing file/dir
|
||||||
@@ -1239,8 +1241,8 @@ public class Snark
|
|||||||
if (_peerCoordinatorSet == null || uploaders <= 0)
|
if (_peerCoordinatorSet == null || uploaders <= 0)
|
||||||
return false;
|
return false;
|
||||||
int totalUploaders = 0;
|
int totalUploaders = 0;
|
||||||
for (Iterator iter = _peerCoordinatorSet.iterator(); iter.hasNext(); ) {
|
for (Iterator<PeerCoordinator> iter = _peerCoordinatorSet.iterator(); iter.hasNext(); ) {
|
||||||
PeerCoordinator c = (PeerCoordinator)iter.next();
|
PeerCoordinator c = iter.next();
|
||||||
if (!c.halted())
|
if (!c.halted())
|
||||||
totalUploaders += c.uploaders;
|
totalUploaders += c.uploaders;
|
||||||
}
|
}
|
||||||
@@ -1253,8 +1255,8 @@ public class Snark
|
|||||||
if (_peerCoordinatorSet == null)
|
if (_peerCoordinatorSet == null)
|
||||||
return false;
|
return false;
|
||||||
long total = 0;
|
long total = 0;
|
||||||
for (Iterator iter = _peerCoordinatorSet.iterator(); iter.hasNext(); ) {
|
for (Iterator<PeerCoordinator> iter = _peerCoordinatorSet.iterator(); iter.hasNext(); ) {
|
||||||
PeerCoordinator c = (PeerCoordinator)iter.next();
|
PeerCoordinator c = iter.next();
|
||||||
if (!c.halted())
|
if (!c.halted())
|
||||||
total += c.getCurrentUploadRate();
|
total += c.getCurrentUploadRate();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user