Initial proof-of-concept for crash report server
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
project.ext.mainClassName = "io.anuke.mindustry.reporter.Launcher"
|
||||
|
||||
task run(dependsOn: classes, type: JavaExec) {
|
||||
main = project.mainClassName
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
ignoreExitValue = true
|
||||
}
|
||||
|
||||
task dist(type: Jar) {
|
||||
dependsOn classes
|
||||
from files(sourceSets.main.output.classesDirs)
|
||||
from files(sourceSets.main.output.resourcesDir)
|
||||
from {configurations.compile.collect {zipTree(it)}}
|
||||
|
||||
writeVersion()
|
||||
|
||||
manifest {
|
||||
attributes 'Main-Class': project.mainClassName
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.anuke.mindustry.reporter;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static java.lang.System.out;
|
||||
|
||||
public class Launcher{
|
||||
private static final long REQUEST_TIME = 1000 * 6;
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
ReportHandler handler = new ReportHandler();
|
||||
HashMap<String, Long> rateLimit = new HashMap<>();
|
||||
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
|
||||
server.createContext("/report", t -> {
|
||||
String key = t.getRemoteAddress().getAddress().getHostName();
|
||||
if(rateLimit.get(key) != null && (currentTimeMillis() - rateLimit.get(key)) < REQUEST_TIME){
|
||||
rateLimit.put(key, currentTimeMillis());
|
||||
out.println("connection " + key + " is being rate limited");
|
||||
return;
|
||||
}
|
||||
|
||||
rateLimit.put(key, currentTimeMillis());
|
||||
byte[] bytes = new byte[t.getRequestBody().available()];
|
||||
new DataInputStream(t.getRequestBody()).readFully(bytes);
|
||||
handler.handle(new String(bytes));
|
||||
|
||||
t.sendResponseHeaders(200, 0);
|
||||
});
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
out.println("server up");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.anuke.mindustry.reporter;
|
||||
|
||||
import static java.lang.System.out;
|
||||
|
||||
public class ReportHandler{
|
||||
|
||||
public void handle(String text){
|
||||
out.println("recieved text: " + text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user