From feca582da028289dad77d367dbda8aaacd162773 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 13:28:02 +0300 Subject: [PATCH 1/3] =?UTF-8?q?[FIX]=20BinaryFileAuthHandler=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/BinaryFileAuthHandler.java | 228 ++++++++++++++++- .../auth/handler/FileAuthHandler.java | 233 ------------------ 2 files changed, 224 insertions(+), 237 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java index 820bfd0c..a68b71ea 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java @@ -1,19 +1,240 @@ package ru.gravit.launchserver.auth.handler; +import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; +import ru.gravit.launcher.serialize.stream.StreamObject; +import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; +import ru.gravit.utils.helper.VerifyHelper; +import java.io.File; import java.io.IOException; +import java.security.SecureRandom; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.locks.ReentrantReadWriteLock; -public final class BinaryFileAuthHandler extends FileAuthHandler { +public final class BinaryFileAuthHandler extends AuthHandler { + public static final class Entry extends StreamObject { + private String username; + private String accessToken; + private String serverID; + + + public Entry(HInput input) throws IOException { + username = VerifyHelper.verifyUsername(input.readString(64)); + if (input.readBoolean()) { + accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); + if (input.readBoolean()) + serverID = VerifyHelper.verifyServerID(input.readASCII(41)); + } + } + + + public Entry(String username) { + this.username = VerifyHelper.verifyUsername(username); + } + + + public Entry(String username, String accessToken, String serverID) { + this(username); + if (accessToken == null && serverID != null) + throw new IllegalArgumentException("Can't set access token while server ID is null"); + + // Set and verify access token + this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); + this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); + } + + private void auth(String username, String accessToken) { + this.username = username; // Update username case + this.accessToken = accessToken; + serverID = null; + } + + private boolean checkServer(String username, String serverID) { + return username.equals(this.username) && serverID.equals(this.serverID); + } + + + public String getAccessToken() { + return accessToken; + } + + + public String getServerID() { + return serverID; + } + + + public String getUsername() { + return username; + } + + private boolean joinServer(String username, String accessToken, String serverID) { + if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) + return false; // Username or access token mismatch + + // Update server ID + this.serverID = serverID; + return true; + } + + @Override + public void write(HOutput output) throws IOException { + output.writeString(username, 64); + output.writeBoolean(accessToken != null); + if (accessToken != null) { + output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); + output.writeBoolean(serverID != null); + if (serverID != null) + output.writeASCII(serverID, 41); + } + } + } + + + public String file; + + public String fileTmp; + + + public boolean offlineUUIDs; + // Instance + private final SecureRandom random = SecurityHelper.newRandom(); + + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + // Storage + private final Map entryMap = new HashMap<>(256); + + private final Map usernamesMap = new HashMap<>(256); + + + protected final void addAuth(UUID uuid, Entry entry) { + lock.writeLock().lock(); + try { + Entry previous = entryMap.put(uuid, entry); + if (previous != null) + usernamesMap.remove(CommonHelper.low(previous.username)); + usernamesMap.put(CommonHelper.low(entry.username), uuid); + } finally { + lock.writeLock().unlock(); + } + } @Override + public final UUID auth(AuthProviderResult authResult) { + lock.writeLock().lock(); + try { + UUID uuid = usernameToUUID(authResult.username); + Entry entry = entryMap.get(uuid); + + // Not registered? Fix it! + if (entry == null) { + entry = new Entry(authResult.username); + + // Generate UUID + uuid = genUUIDFor(authResult.username); + entryMap.put(uuid, entry); + usernamesMap.put(CommonHelper.low(authResult.username), uuid); + } + + // Authenticate + entry.auth(authResult.username, authResult.accessToken); + return uuid; + } finally { + lock.writeLock().unlock(); + } + } + + @Override + public final UUID checkServer(String username, String serverID) { + lock.readLock().lock(); + try { + UUID uuid = usernameToUUID(username); + Entry entry = entryMap.get(uuid); + + // Check server (if has such account of course) + return entry != null && entry.checkServer(username, serverID) ? uuid : null; + } finally { + lock.readLock().unlock(); + } + } + + @Override + public final void close() throws IOException { + lock.readLock().lock(); + try { + LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); + writeAuthFileTmp(); + IOHelper.move(new File(fileTmp).toPath(), new File(file).toPath()); + } finally { + lock.readLock().unlock(); + } + } + + + protected final Set> entrySet() { + return Collections.unmodifiableMap(entryMap).entrySet(); + } + + private UUID genUUIDFor(String username) { + if (offlineUUIDs) { + UUID md5UUID = PlayerProfile.offlineUUID(username); + if (!entryMap.containsKey(md5UUID)) + return md5UUID; + LogHelper.warning("Offline UUID collision, using random: '%s'", username); + } + + // Pick random UUID + UUID uuid; + do + uuid = new UUID(random.nextLong(), random.nextLong()); + while (entryMap.containsKey(uuid)); + return uuid; + } + + @Override + public final boolean joinServer(String username, String accessToken, String serverID) { + lock.writeLock().lock(); + try { + Entry entry = entryMap.get(usernameToUUID(username)); + return entry != null && entry.joinServer(username, accessToken, serverID); + } finally { + lock.writeLock().unlock(); + } + } + + @Override + public final UUID usernameToUUID(String username) { + lock.readLock().lock(); + try { + return usernamesMap.get(CommonHelper.low(username)); + } finally { + lock.readLock().unlock(); + } + } + + @Override + public final String uuidToUsername(UUID uuid) { + lock.readLock().lock(); + try { + Entry entry = entryMap.get(uuid); + return entry == null ? null : entry.username; + } finally { + lock.readLock().unlock(); + } + } + protected void readAuthFile() throws IOException { - try (HInput input = new HInput(IOHelper.newInput(file))) { + try (HInput input = new HInput(IOHelper.newInput(new File(file).toPath()))) { int count = input.readLength(0); for (int i = 0; i < count; i++) { UUID uuid = input.readUUID(); @@ -23,10 +244,9 @@ protected void readAuthFile() throws IOException { } } - @Override protected void writeAuthFileTmp() throws IOException { Set> entrySet = entrySet(); - try (HOutput output = new HOutput(IOHelper.newOutput(fileTmp))) { + try (HOutput output = new HOutput(IOHelper.newOutput(new File(fileTmp).toPath()))) { output.writeLength(entrySet.size(), 0); for (Map.Entry entry : entrySet) { output.writeUUID(entry.getKey()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java deleted file mode 100644 index 90dd12bf..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/FileAuthHandler.java +++ /dev/null @@ -1,233 +0,0 @@ -package ru.gravit.launchserver.auth.handler; - -import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.stream.StreamObject; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.*; - -import java.io.IOException; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.*; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public abstract class FileAuthHandler extends AuthHandler { - public static final class Entry extends StreamObject { - private String username; - private String accessToken; - private String serverID; - - - public Entry(HInput input) throws IOException { - username = VerifyHelper.verifyUsername(input.readString(64)); - if (input.readBoolean()) { - accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); - if (input.readBoolean()) - serverID = VerifyHelper.verifyServerID(input.readASCII(41)); - } - } - - - public Entry(String username) { - this.username = VerifyHelper.verifyUsername(username); - } - - - public Entry(String username, String accessToken, String serverID) { - this(username); - if (accessToken == null && serverID != null) - throw new IllegalArgumentException("Can't set access token while server ID is null"); - - // Set and verify access token - this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); - this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); - } - - private void auth(String username, String accessToken) { - this.username = username; // Update username case - this.accessToken = accessToken; - serverID = null; - } - - private boolean checkServer(String username, String serverID) { - return username.equals(this.username) && serverID.equals(this.serverID); - } - - - public String getAccessToken() { - return accessToken; - } - - - public String getServerID() { - return serverID; - } - - - public String getUsername() { - return username; - } - - private boolean joinServer(String username, String accessToken, String serverID) { - if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) - return false; // Username or access token mismatch - - // Update server ID - this.serverID = serverID; - return true; - } - - @Override - public void write(HOutput output) throws IOException { - output.writeString(username, 64); - output.writeBoolean(accessToken != null); - if (accessToken != null) { - output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); - output.writeBoolean(serverID != null); - if (serverID != null) - output.writeASCII(serverID, 41); - } - } - } - - - public Path file; - - public Path fileTmp; - - - public boolean offlineUUIDs; - // Instance - private final SecureRandom random = SecurityHelper.newRandom(); - - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - // Storage - private final Map entryMap = new HashMap<>(256); - - private final Map usernamesMap = new HashMap<>(256); - - - protected final void addAuth(UUID uuid, Entry entry) { - lock.writeLock().lock(); - try { - Entry previous = entryMap.put(uuid, entry); - if (previous != null) - usernamesMap.remove(CommonHelper.low(previous.username)); - usernamesMap.put(CommonHelper.low(entry.username), uuid); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID auth(AuthProviderResult authResult) { - lock.writeLock().lock(); - try { - UUID uuid = usernameToUUID(authResult.username); - Entry entry = entryMap.get(uuid); - - // Not registered? Fix it! - if (entry == null) { - entry = new Entry(authResult.username); - - // Generate UUID - uuid = genUUIDFor(authResult.username); - entryMap.put(uuid, entry); - usernamesMap.put(CommonHelper.low(authResult.username), uuid); - } - - // Authenticate - entry.auth(authResult.username, authResult.accessToken); - return uuid; - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID checkServer(String username, String serverID) { - lock.readLock().lock(); - try { - UUID uuid = usernameToUUID(username); - Entry entry = entryMap.get(uuid); - - // Check server (if has such account of course) - return entry != null && entry.checkServer(username, serverID) ? uuid : null; - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final void close() throws IOException { - lock.readLock().lock(); - try { - LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); - writeAuthFileTmp(); - IOHelper.move(fileTmp, file); - } finally { - lock.readLock().unlock(); - } - } - - - protected final Set> entrySet() { - return Collections.unmodifiableMap(entryMap).entrySet(); - } - - private UUID genUUIDFor(String username) { - if (offlineUUIDs) { - UUID md5UUID = PlayerProfile.offlineUUID(username); - if (!entryMap.containsKey(md5UUID)) - return md5UUID; - LogHelper.warning("Offline UUID collision, using random: '%s'", username); - } - - // Pick random UUID - UUID uuid; - do - uuid = new UUID(random.nextLong(), random.nextLong()); - while (entryMap.containsKey(uuid)); - return uuid; - } - - @Override - public final boolean joinServer(String username, String accessToken, String serverID) { - lock.writeLock().lock(); - try { - Entry entry = entryMap.get(usernameToUUID(username)); - return entry != null && entry.joinServer(username, accessToken, serverID); - } finally { - lock.writeLock().unlock(); - } - } - - - protected abstract void readAuthFile() throws IOException; - - @Override - public final UUID usernameToUUID(String username) { - lock.readLock().lock(); - try { - return usernamesMap.get(CommonHelper.low(username)); - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final String uuidToUsername(UUID uuid) { - lock.readLock().lock(); - try { - Entry entry = entryMap.get(uuid); - return entry == null ? null : entry.username; - } finally { - lock.readLock().unlock(); - } - } - - - protected abstract void writeAuthFileTmp() throws IOException; -} From 7c5c4faa75cc709db89a09c1e46b211fc4f04d1b Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 13:45:36 +0300 Subject: [PATCH 2/3] =?UTF-8?q?[FIX]=20BinaryFileAuthHandler=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20=D0=B2=20LegacySupport.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/AuthHandler.java | 3 - .../auth/handler/BinaryFileAuthHandler.java | 257 ------------------ modules | 2 +- 3 files changed, 1 insertion(+), 261 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 1f3e9dba..5f30924f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -41,9 +41,6 @@ public static void registerHandlers() { if (!registredHandl) { registerHandler("null", NullAuthHandler.class); registerHandler("memory", MemoryAuthHandler.class); - - // Auth handler that doesn't do nothing :D - registerHandler("binaryFile", BinaryFileAuthHandler.class); registerHandler("mysql", MySQLAuthHandler.class); registredHandl = true; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java deleted file mode 100644 index a68b71ea..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/BinaryFileAuthHandler.java +++ /dev/null @@ -1,257 +0,0 @@ -package ru.gravit.launchserver.auth.handler; - -import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; -import ru.gravit.launcher.serialize.stream.StreamObject; -import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.SecurityHelper; -import ru.gravit.utils.helper.VerifyHelper; - -import java.io.File; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public final class BinaryFileAuthHandler extends AuthHandler { - public static final class Entry extends StreamObject { - private String username; - private String accessToken; - private String serverID; - - - public Entry(HInput input) throws IOException { - username = VerifyHelper.verifyUsername(input.readString(64)); - if (input.readBoolean()) { - accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); - if (input.readBoolean()) - serverID = VerifyHelper.verifyServerID(input.readASCII(41)); - } - } - - - public Entry(String username) { - this.username = VerifyHelper.verifyUsername(username); - } - - - public Entry(String username, String accessToken, String serverID) { - this(username); - if (accessToken == null && serverID != null) - throw new IllegalArgumentException("Can't set access token while server ID is null"); - - // Set and verify access token - this.accessToken = accessToken == null ? null : SecurityHelper.verifyToken(accessToken); - this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); - } - - private void auth(String username, String accessToken) { - this.username = username; // Update username case - this.accessToken = accessToken; - serverID = null; - } - - private boolean checkServer(String username, String serverID) { - return username.equals(this.username) && serverID.equals(this.serverID); - } - - - public String getAccessToken() { - return accessToken; - } - - - public String getServerID() { - return serverID; - } - - - public String getUsername() { - return username; - } - - private boolean joinServer(String username, String accessToken, String serverID) { - if (!username.equals(this.username) || !accessToken.equals(this.accessToken)) - return false; // Username or access token mismatch - - // Update server ID - this.serverID = serverID; - return true; - } - - @Override - public void write(HOutput output) throws IOException { - output.writeString(username, 64); - output.writeBoolean(accessToken != null); - if (accessToken != null) { - output.writeASCII(accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); - output.writeBoolean(serverID != null); - if (serverID != null) - output.writeASCII(serverID, 41); - } - } - } - - - public String file; - - public String fileTmp; - - - public boolean offlineUUIDs; - // Instance - private final SecureRandom random = SecurityHelper.newRandom(); - - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - // Storage - private final Map entryMap = new HashMap<>(256); - - private final Map usernamesMap = new HashMap<>(256); - - - protected final void addAuth(UUID uuid, Entry entry) { - lock.writeLock().lock(); - try { - Entry previous = entryMap.put(uuid, entry); - if (previous != null) - usernamesMap.remove(CommonHelper.low(previous.username)); - usernamesMap.put(CommonHelper.low(entry.username), uuid); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID auth(AuthProviderResult authResult) { - lock.writeLock().lock(); - try { - UUID uuid = usernameToUUID(authResult.username); - Entry entry = entryMap.get(uuid); - - // Not registered? Fix it! - if (entry == null) { - entry = new Entry(authResult.username); - - // Generate UUID - uuid = genUUIDFor(authResult.username); - entryMap.put(uuid, entry); - usernamesMap.put(CommonHelper.low(authResult.username), uuid); - } - - // Authenticate - entry.auth(authResult.username, authResult.accessToken); - return uuid; - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID checkServer(String username, String serverID) { - lock.readLock().lock(); - try { - UUID uuid = usernameToUUID(username); - Entry entry = entryMap.get(uuid); - - // Check server (if has such account of course) - return entry != null && entry.checkServer(username, serverID) ? uuid : null; - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final void close() throws IOException { - lock.readLock().lock(); - try { - LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); - writeAuthFileTmp(); - IOHelper.move(new File(fileTmp).toPath(), new File(file).toPath()); - } finally { - lock.readLock().unlock(); - } - } - - - protected final Set> entrySet() { - return Collections.unmodifiableMap(entryMap).entrySet(); - } - - private UUID genUUIDFor(String username) { - if (offlineUUIDs) { - UUID md5UUID = PlayerProfile.offlineUUID(username); - if (!entryMap.containsKey(md5UUID)) - return md5UUID; - LogHelper.warning("Offline UUID collision, using random: '%s'", username); - } - - // Pick random UUID - UUID uuid; - do - uuid = new UUID(random.nextLong(), random.nextLong()); - while (entryMap.containsKey(uuid)); - return uuid; - } - - @Override - public final boolean joinServer(String username, String accessToken, String serverID) { - lock.writeLock().lock(); - try { - Entry entry = entryMap.get(usernameToUUID(username)); - return entry != null && entry.joinServer(username, accessToken, serverID); - } finally { - lock.writeLock().unlock(); - } - } - - @Override - public final UUID usernameToUUID(String username) { - lock.readLock().lock(); - try { - return usernamesMap.get(CommonHelper.low(username)); - } finally { - lock.readLock().unlock(); - } - } - - @Override - public final String uuidToUsername(UUID uuid) { - lock.readLock().lock(); - try { - Entry entry = entryMap.get(uuid); - return entry == null ? null : entry.username; - } finally { - lock.readLock().unlock(); - } - } - - protected void readAuthFile() throws IOException { - try (HInput input = new HInput(IOHelper.newInput(new File(file).toPath()))) { - int count = input.readLength(0); - for (int i = 0; i < count; i++) { - UUID uuid = input.readUUID(); - Entry entry = new Entry(input); - addAuth(uuid, entry); - } - } - } - - protected void writeAuthFileTmp() throws IOException { - Set> entrySet = entrySet(); - try (HOutput output = new HOutput(IOHelper.newOutput(new File(fileTmp).toPath()))) { - output.writeLength(entrySet.size(), 0); - for (Map.Entry entry : entrySet) { - output.writeUUID(entry.getKey()); - entry.getValue().write(output); - } - } - } -} diff --git a/modules b/modules index 9a7e59fb..14d93a04 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9a7e59fb8df543305a2b708822a398dcabcac4b9 +Subproject commit 14d93a04d551ae36f68bd74d61445d8c7d7bd076 From 90b91a9635cde5a5ffc9ba87ba2ff50e4f418c6d Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 14 Feb 2019 14:03:50 +0300 Subject: [PATCH 3/3] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=20=D0=BD=D0=B0=20ThreadPool.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/LauncherEngine.java | 2 -- .../ru/gravit/launcher/RequestWorker.java | 30 ------------------- .../launcher/client/FunctionalBridge.java | 12 +++----- 3 files changed, 4 insertions(+), 40 deletions(-) delete mode 100644 Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 273cc5a2..37a794fa 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -71,8 +71,6 @@ public void start(String... args) throws Throwable { throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); runtimeProvider.preLoad(); - FunctionalBridge.worker = new RequestWorker(); - CommonHelper.newThread("Task Worker", true, FunctionalBridge.worker).start(); FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java deleted file mode 100644 index bbb44ead..00000000 --- a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.gravit.launcher; - -import ru.gravit.utils.helper.LogHelper; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -public class RequestWorker implements Runnable { - public RequestWorker() { - queue = new LinkedBlockingQueue<>(64); - } - - public BlockingQueue queue; - - @Override - public void run() { - LogHelper.debug("FX Task Thread start"); - while (!Thread.interrupted()) { - try { - Runnable task; - task = queue.take(); - task.run(); - } catch (InterruptedException e) { - LogHelper.error(e); - return; - } - } - LogHelper.debug("FX Task Thread done"); - } -} diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 882855e0..3b1acf9c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -3,7 +3,6 @@ import javafx.concurrent.Task; import ru.gravit.launcher.HWID; import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.RequestWorker; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hwid.OshiHWIDProvider; @@ -13,17 +12,18 @@ import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.helper.LogHelper; import java.io.IOException; import java.nio.file.Path; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; public class FunctionalBridge { @LauncherAPI public static LauncherSettings settings; @LauncherAPI - public static RequestWorker worker; + public static ExecutorService worker = Executors.newWorkStealingPool(); @LauncherAPI public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider(); @LauncherAPI @@ -64,11 +64,7 @@ public static void makeJsonRequest(RequestInterface request, Runnable callback) @LauncherAPI public static void startTask(@SuppressWarnings("rawtypes") Task task) { - try { - worker.queue.put(task); - } catch (InterruptedException e) { - LogHelper.error(e); - } + worker.execute(task); } @LauncherAPI