diff --git a/src/main/java/com/lbry/globe/Main.java b/src/main/java/com/lbry/globe/Main.java index 35be96a..48af4f1 100644 --- a/src/main/java/com/lbry/globe/Main.java +++ b/src/main/java/com/lbry/globe/Main.java @@ -11,7 +11,8 @@ import com.lbry.globe.util.GeoIP; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.MultiThreadIoEventLoopGroup; +import io.netty.channel.nio.NioIoHandler; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http.HttpRequestDecoder; @@ -34,7 +35,7 @@ public class Main implements Runnable{ @Override public void run(){ - EventLoopGroup group = new NioEventLoopGroup(); + EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory()); this.runTCPServerHTTP(group); } diff --git a/src/main/java/com/lbry/globe/handler/HTTPHandler.java b/src/main/java/com/lbry/globe/handler/HTTPHandler.java index 2e70af7..b8ad824 100644 --- a/src/main/java/com/lbry/globe/handler/HTTPHandler.java +++ b/src/main/java/com/lbry/globe/handler/HTTPHandler.java @@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; import java.net.URI; +import java.security.MessageDigest; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -27,6 +28,8 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ public static final AttributeKey> ATTR_CONTENT = AttributeKey.newInstance("content"); private static final Logger LOGGER = Logger.getLogger("Handler"); + private static byte[] jsHash; + @Override public void channelRead(ChannelHandlerContext ctx,Object msg){ if(msg instanceof HttpRequest){ @@ -62,7 +65,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ status = 500; indexData = "Some error occured.".getBytes(); } - indexData = new String(indexData).replace("
","
"+Main.class.getPackage().getImplementationVersion()+"
").getBytes(); + indexData = new String(indexData).replace("${GLOBE_JS_VERSION}",Base64.getEncoder().encodeToString(HTTPHandler.getJSHash()).replaceAll("=","")).replace("
","
"+Main.class.getPackage().getImplementationVersion()+"
").getBytes(); ByteBuf responseContent = Unpooled.copiedBuffer(indexData); FullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(),HttpResponseStatus.valueOf(status),responseContent); response.headers().add("Content-Length",responseContent.capacity()); @@ -143,4 +146,14 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{ return HTTPHandler.class.getClassLoader().getResourceAsStream(name); } + private static byte[] getJSHash(){ + if(HTTPHandler.jsHash==null){ + try{ + MessageDigest md = MessageDigest.getInstance("SHA-1"); + HTTPHandler.jsHash = md.digest(HTTPHandler.readResource(HTTPHandler.getResource("globe.js"))); + }catch(Exception ignored){} + } + return HTTPHandler.jsHash; + } + } \ No newline at end of file diff --git a/src/main/resources/index.html b/src/main/resources/index.html index 4bec8f9..1f88927 100644 --- a/src/main/resources/index.html +++ b/src/main/resources/index.html @@ -10,7 +10,7 @@ - + LBRY Globe