Java源码示例:com.sedmelluq.lava.extensions.youtuberotator.tools.ip.IpBlock
示例1
private MusicManager() {
this.audioPlayerManager = new DefaultAudioPlayerManager();
this.audioPlayerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new);
this.audioPlayerManager.getConfiguration().setFilterHotSwapEnabled(true);
AudioSourceManagers.registerRemoteSources(this.audioPlayerManager);
this.guildMusics = new ConcurrentHashMap<>();
this.guildJoining = new ConcurrentHashMap<>();
//IPv6 rotation config
final String ipv6Block = CredentialManager.getInstance().get(Credential.IPV6_BLOCK);
if (!Config.IS_SNAPSHOT && ipv6Block != null && !ipv6Block.isBlank()) {
LOGGER.info("Configuring YouTube IP rotator");
final List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(ipv6Block));
final AbstractRoutePlanner planner = new RotatingNanoIpRoutePlanner(blocks);
new YoutubeIpRotatorSetup(planner)
.forSource(this.audioPlayerManager.source(YoutubeAudioSourceManager.class))
.setup();
}
}
示例2
public NanoIpRoutePlanner(final List<IpBlock> ipBlocks, final boolean handleSearchFailure) {
super(ipBlocks, handleSearchFailure);
if (ipBlock.getSize().compareTo(Ipv6Block.BLOCK64_IPS) < 0)
throw new IllegalArgumentException("Nano IP Route planner requires an IPv6Block which is greater or equal to a /64");
startTime = BigInteger.valueOf(System.nanoTime());
maskBits = ipBlock.getMaskBits();
}
示例3
private InetAddress getRandomAddress(final IpBlock ipBlock) {
InetAddress localAddress;
BigInteger it = BigInteger.valueOf(0);
do {
if (ipBlock.getSize().multiply(BigInteger.valueOf(2)).compareTo(it) < 0) {
throw new RuntimeException("Can't find a free ip");
}
it = it.add(BigInteger.ONE);
localAddress = ipBlock.getRandomAddress();
} while (localAddress == null || !ipFilter.test(localAddress) || !isValidAddress(localAddress));
return localAddress;
}
示例4
/**
* @param ipBlocks the block to perform balancing over.
* @param ipFilter function to filter out certain IP addresses picked from the IP block, causing another random to be chosen.
* @param handleSearchFailure whether a search 429 should trigger the ip as failing
*/
public RotatingIpRoutePlanner(final List<IpBlock> ipBlocks, final Predicate<InetAddress> ipFilter, final boolean handleSearchFailure) {
super(ipBlocks, handleSearchFailure);
this.ipFilter = ipFilter;
this.next = new AtomicBoolean(false);
this.rotateIndex = new AtomicReference<>(BigInteger.valueOf(0));
this.index = new AtomicReference<>(BigInteger.valueOf(0));
this.lastFailingAddress = null;
}
示例5
protected AbstractRoutePlanner(final List<IpBlock> ipBlocks, final boolean handleSearchFailure) {
this.ipBlock = new CombinedIpBlock(ipBlocks);
this.failingAddresses = new HashMap<>();
this.schemePortResolver = DefaultSchemePortResolver.INSTANCE;
this.handleSearchFailure = handleSearchFailure;
log.info("Active RoutePlanner: {} using total of {} ips", getClass().getCanonicalName(), this.ipBlock.getSize());
}
示例6
public RotatingNanoIpRoutePlanner(final List<IpBlock> ipBlocks, final Predicate<InetAddress> ipFilter, final boolean handleSearchFailure) {
super(ipBlocks, handleSearchFailure);
this.ipFilter = ipFilter;
this.currentBlock = new AtomicReference<>(BigInteger.ZERO);
this.blockNanoStart = new AtomicReference<>(BigInteger.valueOf(System.nanoTime()));
this.next = new AtomicBoolean(false);
if (ipBlock.getType() != Inet6Address.class || ipBlock.getSize().compareTo(Ipv6Block.BLOCK64_IPS) < 0)
throw new IllegalArgumentException("Please use a bigger IPv6 Block!");
}
示例7
/**
* @param ipBlocks the block to perform balancing over.
*/
public BalancingIpRoutePlanner(List<IpBlock> ipBlocks) {
this(ipBlocks, i -> true);
}
示例8
/**
* @param ipBlocks the block to perform balancing over.
*/
public RotatingIpRoutePlanner(final List<IpBlock> ipBlocks) {
this(ipBlocks, i -> true);
}
示例9
public IpBlock getIpBlock() {
return ipBlock;
}
示例10
public RotatingNanoIpRoutePlanner(final List<IpBlock> ipBlocks) {
this(ipBlocks, ip -> true);
}
示例11
public RotatingNanoIpRoutePlanner(final List<IpBlock> ipBlocks, final Predicate<InetAddress> ipFilter) {
this(ipBlocks, ipFilter, true);
}
示例12
@SuppressWarnings("rawtypes")
public MantaroAudioManager() {
this.musicManagers = new ConcurrentHashMap<>();
this.playerManager = new DefaultAudioPlayerManager();
//Youtube is special because rotation stuff.
YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager(true);
//IPv6 rotation config start
Config config = MantaroData.config().get();
if (!config.getIpv6Block().isEmpty()) {
AbstractRoutePlanner planner;
String block = config.getIpv6Block();
List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(block));
//Damn you, YouTube.
if (config.getExcludeAddress().isEmpty())
planner = new RotatingNanoIpRoutePlanner(blocks);
else {
try {
InetAddress blacklistedGW = InetAddress.getByName(config.getExcludeAddress());
planner = new RotatingNanoIpRoutePlanner(blocks, inetAddress -> !inetAddress.equals(blacklistedGW));
} catch (Exception e) {
//Fallback: did I screw up putting the IP in? lmao
planner = new RotatingNanoIpRoutePlanner(blocks);
e.printStackTrace();
}
}
new YoutubeIpRotatorSetup(planner)
.forSource(youtubeAudioSourceManager)
.setup();
}
//IPv6 rotation config end
//Register source manager and configure the Player
playerManager.registerSourceManager(youtubeAudioSourceManager);
playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
playerManager.registerSourceManager(new BandcampAudioSourceManager());
playerManager.registerSourceManager(new VimeoAudioSourceManager());
playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
playerManager.registerSourceManager(new BeamAudioSourceManager());
if (!ExtraRuntimeOptions.DISABLE_NON_ALLOCATING_BUFFER) {
log.info("Enabled non-allocating audio buffer.");
playerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new);
}
}
示例13
/**
* @param ipBlocks the block to perform balancing over.
* @param ipFilter function to filter out certain IP addresses picked from the IP block, causing another random to be chosen.
*/
public BalancingIpRoutePlanner(List<IpBlock> ipBlocks, Predicate<InetAddress> ipFilter) {
this(ipBlocks, ipFilter, true);
}
示例14
/**
* @param ipBlocks the block to perform balancing over.
* @param ipFilter function to filter out certain IP addresses picked from the IP block, causing another random to be chosen.
* @param handleSearchFailure whether a search 429 should trigger the ip as failing
*/
public BalancingIpRoutePlanner(List<IpBlock> ipBlocks, Predicate<InetAddress> ipFilter, boolean handleSearchFailure) {
super(ipBlocks, handleSearchFailure);
this.ipFilter = ipFilter;
}
示例15
/**
* @param ipBlocks the block to perform balancing over.
* @param ipFilter function to filter out certain IP addresses picked from the IP block, causing another random to be chosen.
*/
public RotatingIpRoutePlanner(final List<IpBlock> ipBlocks, final Predicate<InetAddress> ipFilter) {
this(ipBlocks, ipFilter, true);
}