Security fixes

This commit is contained in:
Sotr
2018-06-03 16:15:18 +08:00
parent 44798a9371
commit a67f0dd3d9
5 changed files with 29 additions and 40 deletions

View File

@@ -134,11 +134,6 @@
<artifactId>mixin</artifactId> <artifactId>mixin</artifactId>
<version>0.7.8-SNAPSHOT</version> <version>0.7.8-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-queue</artifactId>
<version>4.16.1</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>

View File

@@ -1,8 +1,12 @@
package io.akarin.api; package io.akarin.api;
import java.util.concurrent.ThreadFactory;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
public abstract class LogWrapper { public abstract class LogWrapper {
/** /**
* A common logger used by mixin classes * A common logger used by mixin classes
@@ -13,4 +17,9 @@ public abstract class LogWrapper {
* Temporarily disable desync timings error, moreover it's worthless to trace async operation * Temporarily disable desync timings error, moreover it's worthless to trace async operation
*/ */
public static volatile boolean silentTiming; public static volatile boolean silentTiming;
/**
* A common thread pool factory
*/
public static final ThreadFactory STAGE_FACTORY = new ThreadFactoryBuilder().setNameFormat("Akarin Schedule Thread - %1$d").build();
} }

View File

@@ -157,9 +157,4 @@ public class AkarinGlobalConfig {
private static void registryTerminationSeconds() { private static void registryTerminationSeconds() {
registryTerminationSeconds = getSeconds(getString("bootstrap.parallel-registry-termination", "9s")); registryTerminationSeconds = getSeconds(getString("bootstrap.parallel-registry-termination", "9s"));
} }
public static boolean primaryWorldServer;
private static void primaryWorldServer() {
primaryWorldServer = getBoolean("bonus.primary-world-server", false);
}
} }

View File

@@ -6,6 +6,7 @@ import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Mutable;
@@ -55,7 +56,7 @@ public class MixinMinecraftServer {
@Shadow public ServerConnection an() { return null; } @Shadow public ServerConnection an() { return null; }
@Shadow public CustomFunctionData aL() { return null; } @Shadow public CustomFunctionData aL() { return null; }
private final ExecutorCompletionService<Void> STAGE_WORLD_TICK = new ExecutorCompletionService<Void>(Executors.newWorkStealingPool(3)); private final ExecutorCompletionService<Void> STAGE_WORLD_TICK = new ExecutorCompletionService<Void>(Executors.newFixedThreadPool(2, LogWrapper.STAGE_FACTORY));
@Overwrite @Overwrite
public void D() throws InterruptedException { public void D() throws InterruptedException {
@@ -63,19 +64,14 @@ public class MixinMinecraftServer {
this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
MinecraftTimings.bukkitSchedulerTimer.stopTiming(); // Paper MinecraftTimings.bukkitSchedulerTimer.stopTiming(); // Paper
MinecraftTimings.minecraftSchedulerTimer.startTiming(); // Paper MinecraftTimings.minecraftSchedulerTimer.startTiming(); // Paper
Queue queue = this.j;
// Spigot start
FutureTask<?> entry; FutureTask<?> entry;
int count = this.j.size(); int count = this.j.size();
while (count-- > 0 && (entry = this.j.poll()) != null) { while (count-- > 0 && (entry = this.j.poll()) != null) {
SystemUtils.a(entry, MinecraftServer.LOGGER); SystemUtils.a(entry, MinecraftServer.LOGGER);
} }
// Spigot end
MinecraftTimings.minecraftSchedulerTimer.stopTiming(); // Paper MinecraftTimings.minecraftSchedulerTimer.stopTiming(); // Paper
// CraftBukkit start
// Run tasks that are waiting on processing
MinecraftTimings.processQueueTimer.startTiming(); // Spigot MinecraftTimings.processQueueTimer.startTiming(); // Spigot
while (!processQueue.isEmpty()) { while (!processQueue.isEmpty()) {
processQueue.remove().run(); processQueue.remove().run();
@@ -83,7 +79,7 @@ public class MixinMinecraftServer {
MinecraftTimings.processQueueTimer.stopTiming(); // Spigot MinecraftTimings.processQueueTimer.stopTiming(); // Spigot
MinecraftTimings.chunkIOTickTimer.startTiming(); // Spigot MinecraftTimings.chunkIOTickTimer.startTiming(); // Spigot
org.bukkit.craftbukkit.chunkio.ChunkIOExecutor.tick(); ChunkIOExecutor.tick();
MinecraftTimings.chunkIOTickTimer.stopTiming(); // Spigot MinecraftTimings.chunkIOTickTimer.stopTiming(); // Spigot
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot
@@ -96,13 +92,12 @@ public class MixinMinecraftServer {
} }
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot
int i; for (int i = 0; i < this.worlds.size(); ++i) { // CraftBukkit
for (i = 0; i < this.worlds.size(); ++i) { // CraftBukkit
WorldServer worldserver = this.worlds.get(i); WorldServer worldserver = this.worlds.get(i);
// TODO Fix this feature // TODO Fix this feature
// TileEntityHopper.skipHopperEvents = worldserver.paperConfig.disableHopperMoveEvents || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // TileEntityHopper.skipHopperEvents = worldserver.paperConfig.disableHopperMoveEvents || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0;
LogWrapper.silentTiming = true;
STAGE_WORLD_TICK.submit(() -> { STAGE_WORLD_TICK.submit(() -> {
try { try {
worldserver.doTick(); worldserver.doTick();
@@ -122,7 +117,7 @@ public class MixinMinecraftServer {
try { try {
worldserver.tickEntities(); worldserver.tickEntities();
} catch (Throwable throwable1) { } catch (Throwable throwable1) {
CrashReport crashreport = null; CrashReport crashreport;
try { try {
crashreport = CrashReport.a(throwable1, "Exception ticking world entities"); crashreport = CrashReport.a(throwable1, "Exception ticking world entities");
} catch (Throwable t){ } catch (Throwable t){
@@ -133,37 +128,36 @@ public class MixinMinecraftServer {
} }
}, null); }, null);
LogWrapper.silentTiming = true;
worldserver.timings.doTick.startTiming(); worldserver.timings.doTick.startTiming();
STAGE_WORLD_TICK.take(); // Block STAGE_WORLD_TICK.take(); // Block
worldserver.timings.doTick.stopTiming(); worldserver.timings.doTick.stopTiming();
worldserver.timings.tickEntities.startTiming(); worldserver.timings.tickEntities.startTiming();
STAGE_WORLD_TICK.take(); // Entity STAGE_WORLD_TICK.take(); // Entity
worldserver.timings.tickEntities.stopTiming();
LogWrapper.silentTiming = false; LogWrapper.silentTiming = false;
worldserver.timings.tickEntities.stopTiming();
worldserver.getTracker().updatePlayers(); worldserver.getTracker().updatePlayers();
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
} }
MinecraftTimings.connectionTimer.startTiming(); // Spigot MinecraftTimings.connectionTimer.startTiming();
this.an().c(); this.an().c();
MinecraftTimings.connectionTimer.stopTiming(); // Spigot MinecraftTimings.connectionTimer.stopTiming();
MinecraftTimings.playerListTimer.startTiming(); // Spigot MinecraftTimings.playerListTimer.startTiming();
this.v.tick(); this.v.tick();
MinecraftTimings.playerListTimer.stopTiming(); // Spigot MinecraftTimings.playerListTimer.stopTiming();
MinecraftTimings.commandFunctionsTimer.startTiming(); // Spigot MinecraftTimings.commandFunctionsTimer.startTiming();
this.aL().e(); this.aL().e();
MinecraftTimings.commandFunctionsTimer.stopTiming(); // Spigot MinecraftTimings.commandFunctionsTimer.stopTiming();
MinecraftTimings.tickablesTimer.startTiming(); // Spigot MinecraftTimings.tickablesTimer.startTiming();
for (i = 0; i < this.o.size(); ++i) { for (int i = 0; i < this.o.size(); ++i) {
this.o.get(i).e(); this.o.get(i).e();
} }
MinecraftTimings.tickablesTimer.stopTiming(); // Spigot MinecraftTimings.tickablesTimer.stopTiming();
} }
} }

View File

@@ -2,7 +2,6 @@ package io.akarin.server.mixin.core;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -11,8 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.akarin.api.LogWrapper;
import io.akarin.server.core.AkarinGlobalConfig; import io.akarin.server.core.AkarinGlobalConfig;
import net.minecraft.server.BiomeBase; import net.minecraft.server.BiomeBase;
import net.minecraft.server.Block; import net.minecraft.server.Block;
@@ -28,21 +26,19 @@ import net.minecraft.server.SoundEffect;
@Mixin(value = DispenserRegistry.class, remap = false) @Mixin(value = DispenserRegistry.class, remap = false)
public class ParallelRegistry { public class ParallelRegistry {
private static final ThreadFactory STAGE_FACTORY = new ThreadFactoryBuilder().setNameFormat("Akarin Parallel Registry Thread - %1$d").build();
/** /**
* Registry order: SoundEffect -> Block * Registry order: SoundEffect -> Block
*/ */
private static final ExecutorService STAGE_BLOCK = Executors.newSingleThreadExecutor(STAGE_FACTORY); private static final ExecutorService STAGE_BLOCK = Executors.newSingleThreadExecutor(LogWrapper.STAGE_FACTORY);
/** /**
* Registry order: Item -> PotionBrewer & orderless: BlockFire, BiomeBase (After STAGE_BLOCK) * Registry order: Item -> PotionBrewer & orderless: BlockFire, BiomeBase (After STAGE_BLOCK)
*/ */
private static final ExecutorService STAGE_BLOCK_BASE = Executors.newWorkStealingPool(3); private static final ExecutorService STAGE_BLOCK_BASE = Executors.newFixedThreadPool(3, LogWrapper.STAGE_FACTORY);
/** /**
* Registry order: MobEffectList -> PotionRegistry & orderless: Enchantment, EntityTypes * Registry order: MobEffectList -> PotionRegistry & orderless: Enchantment, EntityTypes
*/ */
private static final ExecutorService STAGE_STANDALONE = Executors.newWorkStealingPool(3); private static final ExecutorService STAGE_STANDALONE = Executors.newFixedThreadPool(3, LogWrapper.STAGE_FACTORY);
private static final int TERMINATION_IN_SEC = AkarinGlobalConfig.registryTerminationSeconds; private static final int TERMINATION_IN_SEC = AkarinGlobalConfig.registryTerminationSeconds;