📄 peerutils.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: PeerUtils.java
package org.gudy.azureus2.core3.peer.util;
import java.util.HashSet;
import java.util.Set;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.util.Constants;
// Referenced classes of package org.gudy.azureus2.core3.peer.util:
// PeerIdentityManager, PeerIdentityDataID
public class PeerUtils
{
private static final String CONFIG_MAX_CONN_PER_TORRENT = "Max.Peer.Connections.Per.Torrent";
private static final String CONFIG_MAX_CONN_TOTAL = "Max.Peer.Connections.Total";
public static int MAX_CONNECTIONS_PER_TORRENT = COConfigurationManager.getIntParameter("Max.Peer.Connections.Per.Torrent");
public static int MAX_CONNECTIONS_TOTAL = COConfigurationManager.getIntParameter("Max.Peer.Connections.Total");
private static Set ignore_peer_ports = new HashSet();
static final String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public PeerUtils()
{
}
public static int numNewConnectionsAllowed(PeerIdentityDataID data_id, int specific_max)
{
int curConnPerTorrent = PeerIdentityManager.getIdentityCount(data_id);
int curConnTotal = PeerIdentityManager.getTotalIdentityCount();
int PER_TORRENT_LIMIT = specific_max;
int perTorrentAllowed = -1;
if (PER_TORRENT_LIMIT != 0)
{
int allowed = PER_TORRENT_LIMIT - curConnPerTorrent;
if (allowed < 0)
allowed = 0;
perTorrentAllowed = allowed;
}
int totalAllowed = -1;
int allowed;
if (MAX_CONNECTIONS_TOTAL != 0)
{
allowed = MAX_CONNECTIONS_TOTAL - curConnTotal;
if (allowed < 0)
allowed = 0;
totalAllowed = allowed;
}
allowed = -1;
if (perTorrentAllowed > -1 && totalAllowed > -1)
allowed = Math.min(perTorrentAllowed, totalAllowed);
else
if (perTorrentAllowed == -1 || totalAllowed == -1)
allowed = Math.max(perTorrentAllowed, totalAllowed);
return allowed;
}
private static void readIgnorePeerPorts()
{
String str = COConfigurationManager.getStringParameter("Ignore.peer.ports").trim();
ignore_peer_ports.clear();
if (str.length() > 0)
{
String ports[] = str.split("\\;");
if (ports != null && ports.length > 0)
{
for (int i = 0; i < ports.length; i++)
{
String port = ports[i];
int spreadPos = port.indexOf('-');
if (spreadPos > 0 && spreadPos < port.length() - 1)
try
{
int iMin = Integer.parseInt(port.substring(0, spreadPos).trim());
int iMax = Integer.parseInt(port.substring(spreadPos + 1).trim());
for (int j = iMin; j <= iMax; j++)
ignore_peer_ports.add((new StringBuilder()).append("").append(j).toString());
}
catch (Exception e) { }
else
ignore_peer_ports.add(port.trim());
}
}
}
}
public static boolean ignorePeerPort(int port)
{
return ignore_peer_ports.contains((new StringBuilder()).append("").append(port).toString());
}
public static byte[] createPeerID()
{
byte peerId[] = new byte[20];
byte version[] = Constants.VERSION_ID;
for (int i = 0; i < 8; i++)
peerId[i] = version[i];
for (int i = 8; i < 20; i++)
{
int pos = (int)(Math.random() * (double)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".length());
peerId[i] = (byte)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".charAt(pos);
}
return peerId;
}
public static byte[] createWebSeedPeerID()
{
byte peerId[] = new byte[20];
peerId[0] = 45;
peerId[1] = 87;
peerId[2] = 83;
for (int i = 3; i < 20; i++)
{
int pos = (int)(Math.random() * (double)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".length());
peerId[i] = (byte)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".charAt(pos);
}
return peerId;
}
static
{
COConfigurationManager.addParameterListener("Max.Peer.Connections.Per.Torrent", new ParameterListener() {
public void parameterChanged(String parameterName)
{
PeerUtils.MAX_CONNECTIONS_PER_TORRENT = COConfigurationManager.getIntParameter("Max.Peer.Connections.Per.Torrent");
}
});
COConfigurationManager.addParameterListener("Max.Peer.Connections.Total", new ParameterListener() {
public void parameterChanged(String parameterName)
{
PeerUtils.MAX_CONNECTIONS_TOTAL = COConfigurationManager.getIntParameter("Max.Peer.Connections.Total");
}
});
COConfigurationManager.addParameterListener("Ignore.peer.ports", new ParameterListener() {
public void parameterChanged(String parameterName)
{
PeerUtils.readIgnorePeerPorts();
}
});
readIgnorePeerPorts();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -