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

📄 ipfilterimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (external_handlers.size() <= 0)
				break label0;
			Iterator it = external_handlers.iterator();
			do
				if (!it.hasNext())
					break label0;
			while (!((IpFilterExternalHandler)it.next()).isBlocked(torrent_hash, address));
			return new IpRangeImpl("External handler", address, address, true);
		}
		return null;
	}

	protected IpRange checkExternalHandlers(byte torrent_hash[], InetAddress address)
	{
label0:
		{
			if (external_handlers.size() <= 0)
				break label0;
			Iterator it = external_handlers.iterator();
			do
				if (!it.hasNext())
					break label0;
			while (!((IpFilterExternalHandler)it.next()).isBlocked(torrent_hash, address));
			String ip = address.getHostAddress();
			return new IpRangeImpl("External handler", ip, ip, true);
		}
		return null;
	}

	private boolean addBlockedIP(BlockedIp ip, byte torrent_hash[], boolean loggable)
	{
		List listeners_ref;
		int j;
		if (torrent_hash == null)
			break MISSING_BLOCK_LABEL_70;
		listeners_ref = listeners;
		j = 0;
_L3:
		if (j >= listeners_ref.size()) goto _L2; else goto _L1
_L1:
		if (!((IPFilterListener)listeners_ref.get(j)).canIPBeBlocked(ip.getBlockedIp(), torrent_hash))
			return false;
		continue; /* Loop/switch isn't completed */
		Throwable e;
		e;
		Debug.printStackTrace(e);
		j++;
		  goto _L3
_L2:
		class_mon.enter();
		ipsBlocked.addLast(ip);
		num_ips_blocked++;
		if (loggable)
			num_ips_blocked_loggable++;
		if (ipsBlocked.size() > 500)
			ipsBlocked.removeFirst();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_149;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		return true;
	}

	private boolean isBanned(InetAddress ipAddress)
	{
		boolean flag;
		class_mon.enter();
		int address = range_manager.addressToInt(ipAddress);
		Integer i_address = new Integer(address);
		flag = bannedIps.get(i_address) != null;
		class_mon.exit();
		return flag;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	private boolean isBanned(String ipAddress)
	{
		boolean flag;
		class_mon.enter();
		int address = range_manager.addressToInt(ipAddress);
		Integer i_address = new Integer(address);
		flag = bannedIps.get(i_address) != null;
		class_mon.exit();
		return flag;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public boolean getInRangeAddressesAreAllowed()
	{
		return ip_filter_allow;
	}

	public void setInRangeAddressesAreAllowed(boolean b)
	{
		COConfigurationManager.setParameter("Ip Filter Allow", b);
	}

	/**
	 * @deprecated Method getIpRanges is deprecated
	 */

	public List getIpRanges()
	{
		ArrayList arraylist;
		class_mon.enter();
		arraylist = new ArrayList(range_manager.getEntries());
		class_mon.exit();
		return arraylist;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public IpRange[] getRanges()
	{
		IpRange aiprange[];
		class_mon.enter();
		List entries = range_manager.getEntries();
		IpRange res[] = new IpRange[entries.size()];
		entries.toArray(res);
		aiprange = res;
		class_mon.exit();
		return aiprange;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public IpRange createRange(boolean sessionOnly)
	{
		return new IpRangeImpl("", "", "", sessionOnly);
	}

	public void addRange(IpRange range)
	{
		class_mon.enter();
		((IpRangeImpl)range).setAddedToRangeList(true);
		range.checkValid();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_38;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		markAsUpToDate();
		return;
	}

	public void removeRange(IpRange range)
	{
		class_mon.enter();
		((IpRangeImpl)range).setAddedToRangeList(false);
		range_manager.removeRange(range);
		class_mon.exit();
		break MISSING_BLOCK_LABEL_40;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		markAsUpToDate();
		return;
	}

	public int getNbRanges()
	{
		List entries = range_manager.getEntries();
		return entries.size();
	}

	protected void setValidOrNot(IpRange range, boolean valid)
	{
		class_mon.enter();
		if (!range.getAddedToRangeList())
		{
			class_mon.exit();
			return;
		}
		class_mon.exit();
		break MISSING_BLOCK_LABEL_40;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		if (valid)
			range_manager.addRange(range);
		else
			range_manager.removeRange(range);
		return;
	}

	public int getNbIpsBlocked()
	{
		return num_ips_blocked;
	}

	public int getNbIpsBlockedAndLoggable()
	{
		return num_ips_blocked_loggable;
	}

	public boolean ban(String ipAddress, String torrent_name, boolean manual)
	{
		List listeners_ref;
		int j;
		if (manual)
			break MISSING_BLOCK_LABEL_64;
		listeners_ref = listeners;
		j = 0;
_L3:
		if (j >= listeners_ref.size()) goto _L2; else goto _L1
_L1:
		if (!((IPFilterListener)listeners_ref.get(j)).canIPBeBanned(ipAddress))
			return false;
		continue; /* Loop/switch isn't completed */
		Throwable e;
		e;
		Debug.printStackTrace(e);
		j++;
		  goto _L3
_L2:
		boolean block_ban;
		List new_bans;
		block_ban = false;
		new_bans = new ArrayList();
		class_mon.enter();
		int address = range_manager.addressToInt(ipAddress);
		Integer i_address = new Integer(address);
		if (bannedIps.get(i_address) == null)
		{
			BannedIpImpl new_ban = new BannedIpImpl(ipAddress, torrent_name);
			new_bans.add(new_ban);
			bannedIps.put(i_address, new_ban);
			if (!UnresolvableHostManager.isPseudoAddress(ipAddress))
			{
				long l_address = address;
				if (l_address < 0L)
					l_address += 0x100000000L;
				long start = l_address & -256L;
				long end = start + 256L;
				int hits = 0;
				for (long i = start; i < end; i++)
				{
					Integer a = new Integer((int)i);
					if (bannedIps.get(a) != null)
						hits++;
				}

				int hit_limit = COConfigurationManager.getIntParameter("Ip Filter Ban Block Limit");
				if (hits >= hit_limit)
				{
					block_ban = true;
					for (long i = start; i < end; i++)
					{
						Integer a = new Integer((int)i);
						if (bannedIps.get(a) == null)
						{
							BannedIpImpl new_block_ban = new BannedIpImpl(PRHelpers.intToAddress((int)i), (new StringBuilder()).append(torrent_name).append(" [block ban]").toString());
							new_bans.add(new_block_ban);
							bannedIps.put(a, new_block_ban);
						}
					}

				}
			}
			saveBannedIPs();
		}
		class_mon.exit();
		break MISSING_BLOCK_LABEL_394;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		List listeners_ref = listeners;
		for (int i = 0; i < new_bans.size(); i++)
		{
			BannedIp entry = (BannedIp)new_bans.get(i);
			for (int j = 0; j < listeners_ref.size(); j++)
				try
				{
					((IPFilterListener)listeners_ref.get(j)).IPBanned(entry);
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}

		}

		return block_ban;
	}

	public BannedIp[] getBannedIps()
	{
		BannedIp abannedip[];
		class_mon.enter();
		BannedIp res[] = new BannedIp[bannedIps.size()];
		bannedIps.values().toArray(res);
		abannedip = res;
		class_mon.exit();
		return abannedip;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public int getNbBannedIps()
	{
		return bannedIps.size();
	}

	public void clearBannedIps()
	{
		class_mon.enter();
		bannedIps.clear();
		saveBannedIPs();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_37;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void unban(String ipAddress)
	{
		class_mon.enter();
		int address = range_manager.addressToInt(ipAddress);
		Integer i_address = new Integer(address);
		if (bannedIps.remove(i_address) != null)
			saveBannedIPs();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_61;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void unban(String ipAddress, boolean block)
	{
		long start;
		long end;
		boolean hit;
		if (!block)
			break MISSING_BLOCK_LABEL_139;
		int address = range_manager.addressToInt(ipAddress);
		long l_address = address;
		if (l_address < 0L)
			l_address += 0x100000000L;
		start = l_address & -256L;
		end = start + 256L;
		hit = false;
		class_mon.enter();
		for (long i = start; i < end; i++)
		{
			Integer a = new Integer((int)i);
			if (bannedIps.remove(a) != null)
				hit = true;
		}

		if (hit)
			saveBannedIPs();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_202;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
		class_mon.enter();
		int address = range_manager.addressToInt(ipAddress);
		Integer i_address = new Integer(address);
		if (bannedIps.remove(i_address) != null)
			saveBannedIPs();
		class_mon.exit();
		break MISSING_BLOCK_LABEL_202;
		Exception exception1;
		exception1;
		class_mon.exit();
		throw exception1;
	}

	public BlockedIp[] getBlockedIps()
	{
		BlockedIp ablockedip[];
		class_mon.enter();
		BlockedIp res[] = new BlockedIp[ipsBlocked.size()];
		ipsBlocked.toArray(res);
		ablockedip = res;
		class_mon.exit();
		return ablockedip;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void clearBlockedIPs()
	{
		class_mon.enter();
		ipsBlocked.clear();
		num_ips_blocked = 0;
		num_ips_blocked_loggable = 0;
		class_mon.exit();
		break MISSING_BLOCK_LABEL_41;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public boolean isEnabled()
	{
		return ip_filter_enabled;
	}

	public void setEnabled(boolean enabled)
	{
		COConfigurationManager.setParameter("Ip Filter Enabled", enabled);
	}

	public void markAsUpToDate()
	{
		last_update_time = SystemTime.getCurrentTime();
		blockedListChangedDispatcher.dispatch();
	}

	public long getLastUpdateTime()
	{
		return last_update_time;
	}

	public long getTotalAddressesInRange()
	{
		return range_manager.getTotalSpan();
	}

	public void addListener(IPFilterListener l)
	{
		class_mon.enter();
		List new_listeners = new ArrayList(listeners);
		new_listeners.add(l);
		listeners = new_listeners;
		class_mon.exit();
		break MISSING_BLOCK_LABEL_49;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void removeListener(IPFilterListener l)
	{
		class_mon.enter();
		List new_listeners = new ArrayList(listeners);
		new_listeners.remove(l);
		listeners = new_listeners;
		class_mon.exit();
		break MISSING_BLOCK_LABEL_49;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void addExternalHandler(IpFilterExternalHandler h)
	{
		external_handlers.add(h);
	}

	public void removeExternalHandler(IpFilterExternalHandler h)
	{
		external_handlers.remove(h);
	}

	public static void main(String args[])
	{
		IpFilterImpl filter = new IpFilterImpl();
		filter.ban("255.1.1.1", "parp", true);
		filter.ban("255.1.1.2", "parp", true);
		filter.ban("255.1.2.2", "parp", true);
		System.out.println((new StringBuilder()).append("is banned:").append(filter.isBanned("255.1.1.4")).toString());
	}

	static 
	{
		LOGID = LogIDs.CORE;
	}



}

⌨️ 快捷键说明

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