⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipaddressrangemanager.java

📁 java 文件下载器。可自定义
💻 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:   IPAddressRangeManager.java

package org.gudy.azureus2.core3.ipfilter.impl;

import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import org.gudy.azureus2.core3.ipfilter.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.tracker.protocol.PRHelpers;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.ipfilter.impl:
//			IpRangeImpl

public class IPAddressRangeManager
{

	private static final LogIDs LOGID;
	protected ArrayList entries;
	protected long total_span;
	protected boolean rebuild_required;
	protected long last_rebuild_time;
	protected IpRange mergedRanges[];
	protected AEMonitor this_mon;

	protected IPAddressRangeManager()
	{
		entries = new ArrayList();
		mergedRanges = new IpRange[0];
		this_mon = new AEMonitor("IPAddressRangeManager");
	}

	public void addRange(IpRange range)
	{
		this_mon.enter();
		entries.add(range);
		rebuild_required = true;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_41;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void removeRange(IpRange range)
	{
		this_mon.enter();
		entries.remove(range);
		rebuild_required = true;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_41;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public Object isInRange(String ip)
	{
		if (entries.size() == 0)
			return null;
		Object obj;
		this_mon.enter();
		long address_long = addressToInt(ip);
		if (address_long < 0L)
			address_long += 0x100000000L;
		Object res = isInRange(address_long);
		obj = res;
		this_mon.exit();
		return obj;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public Object isInRange(InetAddress ip)
	{
		if (entries.size() == 0)
			return null;
		Object obj;
		this_mon.enter();
		long address_long = addressToInt(ip);
		if (address_long < 0L)
			address_long += 0x100000000L;
		Object res = isInRange(address_long);
		obj = res;
		this_mon.exit();
		return obj;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected Object isInRange(long address_long)
	{
		Object obj;
		this_mon.enter();
		checkRebuild();
		if (mergedRanges.length != 0)
			break MISSING_BLOCK_LABEL_30;
		obj = null;
		this_mon.exit();
		return obj;
		IpRange e;
		IpRange iprange;
		int bottom = 0;
		int top = mergedRanges.length - 1;
		int current = -1;
		do
		{
			if (top < 0 || bottom >= mergedRanges.length || bottom > top)
				break;
			current = (bottom + top) / 2;
			e = mergedRanges[current];
			long this_start = e.getStartIpLong();
			long this_end = e.getMergedEndLong();
			if (address_long == this_start)
				break;
			if (address_long > this_start)
			{
				if (address_long <= this_end)
					break;
				bottom = current + 1;
				continue;
			}
			if (address_long == this_end || address_long >= this_start)
				break;
			top = current - 1;
		} while (true);
		if (top < 0 || bottom >= mergedRanges.length || bottom > top)
			break MISSING_BLOCK_LABEL_317;
		e = mergedRanges[current];
		if (address_long > e.getEndIpLong())
			break MISSING_BLOCK_LABEL_218;
		iprange = e;
		this_mon.exit();
		return iprange;
		IpRange merged[];
		Object obj1;
		merged = e.getMergedEntries();
		if (merged != null)
			break MISSING_BLOCK_LABEL_250;
		Debug.out("IPAddressRangeManager: inconsistent merged details - no entries");
		obj1 = null;
		this_mon.exit();
		return obj1;
		int i = 0;
_L1:
		IpRange iprange1;
		if (i >= merged.length)
			break MISSING_BLOCK_LABEL_312;
		IpRange me = merged[i];
		if (me.getStartIpLong() > address_long || me.getEndIpLong() < address_long)
			break MISSING_BLOCK_LABEL_306;
		iprange1 = me;
		this_mon.exit();
		return iprange1;
		i++;
		  goto _L1
		Debug.out("IPAddressRangeManager: inconsistent merged details - entry not found");
		e = null;
		this_mon.exit();
		return e;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected int addressToInt(String address)
	{
		return PRHelpers.addressToInt(address);
		UnknownHostException e;
		e;
		return UnresolvableHostManager.getPseudoAddress(address);
	}

	protected int addressToInt(InetAddress address)
	{
		return PRHelpers.addressToInt(address);
	}

	protected void checkRebuild()
	{
		this_mon.enter();
		if (rebuild_required)
		{
			long now = SystemTime.getCurrentTime();
			long secs_since_last_build = (now - last_rebuild_time) / 1000L;
			if (secs_since_last_build > (long)(entries.size() / 2000))
			{
				last_rebuild_time = now;
				rebuild_required = false;
				rebuild();
			}
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_82;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void rebuild()
	{
		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("IPAddressRangeManager: rebuilding ").append(entries.size()).append(" entries starts").toString()));
		IpRange ents[] = new IpRange[entries.size()];
		entries.toArray(ents);
		for (int i = 0; i < ents.length; i++)
			ents[i].resetMergeInfo();

		Arrays.sort(ents, new Comparator() {

			final IPAddressRangeManager this$0;

			public int compare(Object o1, Object o2)
			{
				IpRange e1 = (IpRange)o1;
				IpRange e2 = (IpRange)o2;
				long diff = e1.getStartIpLong() - e2.getStartIpLong();
				if (diff == 0L)
					diff = e2.getEndIpLong() - e1.getEndIpLong();
				return signum(diff);
			}

			public boolean equals(Object obj)
			{
				return false;
			}

			
			{
				this$0 = IPAddressRangeManager.this;
				super();
			}
		});
		List me = new ArrayList(ents.length);
label0:
		for (int i = 0; i < ents.length; i++)
		{
			IpRange entry = ents[i];
			if (entry.getMerged())
				continue;
			me.add(entry);
			int pos = i + 1;
			do
			{
				long end_pos;
				IpRange e2;
				do
				{
					do
					{
						if (pos >= ents.length)
							continue label0;
						end_pos = entry.getMergedEndLong();
						e2 = ents[pos++];
					} while (e2.getMerged());
					if (end_pos < e2.getStartIpLong())
						continue label0;
					e2.setMerged();
				} while (e2.getEndIpLong() <= end_pos);
				entry.setMergedEnd(e2.getEndIpLong());
				entry.addMergedEntry(e2);
			} while (true);
		}

		mergedRanges = new IpRange[me.size()];
		me.toArray(mergedRanges);
		total_span = 0L;
		for (int i = 0; i < mergedRanges.length; i++)
		{
			IpRange e = mergedRanges[i];
			long span = (e.getMergedEndLong() - e.getStartIpLong()) + 1L;
			total_span += span;
		}

		if (Logger.isEnabled())
			Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("IPAddressRangeManager: rebuilding ").append(entries.size()).append(" entries ends").toString()));
	}

	protected int signum(long diff)
	{
		if (diff > 0L)
			return 1;
		return diff >= 0L ? 0 : -1;
	}

	protected long getTotalSpan()
	{
		checkRebuild();
		return total_span;
	}

	public static void main(String args[])
	{
		IPAddressRangeManager manager = new IPAddressRangeManager();
		Random r = new Random();
		for (int i = 0; i < 0xf4240; i++)
		{
			int ip1 = r.nextInt(0xfffffff);
			int ip2 = ip1 + r.nextInt(255);
			String start = PRHelpers.intToAddress(ip1);
			String end = PRHelpers.intToAddress(ip2);
			manager.addRange(new IpRangeImpl((new StringBuilder()).append("test_").append(i).toString(), start, end, true));
		}

		int num = 0;
		int hits = 0;
		do
		{
			Object res;
			do
			{
				if (num % 1000 == 0)
					System.out.println((new StringBuilder()).append(num).append("/").append(hits).toString());
				num++;
				int ip = r.nextInt();
				res = manager.isInRange(ip);
			} while (res == null);
			hits++;
		} while (true);
	}

	public ArrayList getEntries()
	{
		return entries;
	}

	public void clearAllEntries()
	{
		this_mon.enter();
		entries.clear();
		IpFilterManagerFactory.getSingleton().deleteAllDescriptions();
		rebuild_required = true;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_47;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	static 
	{
		LOGID = LogIDs.CORE;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -