fuck your cum assholes
parent
2aea192c1a
commit
4f7be92b03
|
@ -2,16 +2,13 @@ package server;
|
||||||
|
|
||||||
import io.opentelemetry.api.trace.Span;
|
import io.opentelemetry.api.trace.Span;
|
||||||
import io.opentelemetry.api.trace.Tracer;
|
import io.opentelemetry.api.trace.Tracer;
|
||||||
import io.opentelemetry.context.Context;
|
|
||||||
import io.opentelemetry.context.Scope;
|
import io.opentelemetry.context.Scope;
|
||||||
import net.jpountz.xxhash.StreamingXXHash64;
|
import net.jpountz.xxhash.StreamingXXHash64;
|
||||||
import shared.ArrayData;
|
|
||||||
import shared.FileUtil;
|
import shared.FileUtil;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class ChunkedCompressedChecksumFileReader {
|
public class ChunkedCompressedChecksumFileReader {
|
||||||
|
|
||||||
|
@ -20,6 +17,14 @@ public class ChunkedCompressedChecksumFileReader {
|
||||||
private final DataOutputStream fileOutputWriter;
|
private final DataOutputStream fileOutputWriter;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
|
private Span currentSpan = null;
|
||||||
|
private Scope currentScope = null;
|
||||||
|
private long count = 0;
|
||||||
|
private static final long MAX_COUNT = 50;
|
||||||
|
|
||||||
|
private long uncompressed_bytes = 0;
|
||||||
|
private long compressed_bytes = 0;
|
||||||
|
|
||||||
public ChunkedCompressedChecksumFileReader(DataInputStream networkStreamReader, String fileOutputPath, long seed) throws IOException {
|
public ChunkedCompressedChecksumFileReader(DataInputStream networkStreamReader, String fileOutputPath, long seed) throws IOException {
|
||||||
this.networkStreamReader = networkStreamReader;
|
this.networkStreamReader = networkStreamReader;
|
||||||
this.streamHash = FileUtil.XX_HASH_FACTORY.newStreamingHash64(seed);
|
this.streamHash = FileUtil.XX_HASH_FACTORY.newStreamingHash64(seed);
|
||||||
|
@ -28,26 +33,36 @@ public class ChunkedCompressedChecksumFileReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileHeader readChunk(Tracer trace, Span sp) throws IOException {
|
public FileHeader readChunk(Tracer trace, Span sp) throws IOException {
|
||||||
Span gf = trace.spanBuilder("Chunk Read").startSpan();
|
if (++count >= MAX_COUNT) {
|
||||||
|
currentSpan.addEvent("--{End Read}--");
|
||||||
|
currentScope.close();
|
||||||
|
currentSpan.end();
|
||||||
|
currentSpan = null;
|
||||||
|
currentScope = null;
|
||||||
|
}
|
||||||
|
if (currentSpan == null) {
|
||||||
|
count = 0;
|
||||||
|
currentSpan = trace.spanBuilder("Chunk Read").startSpan();
|
||||||
|
currentScope = currentSpan.makeCurrent();
|
||||||
|
}
|
||||||
FileHeader header = readHeader();
|
FileHeader header = readHeader();
|
||||||
gf.setAttribute("Read Uncompressed", header.getUncompressed());
|
uncompressed_bytes += header.getUncompressed();
|
||||||
gf.setAttribute("Read Compressed", header.getCompressed());
|
compressed_bytes += header.getCompressed();
|
||||||
gf.setAttribute("Read Hash", header.getHash());
|
currentSpan.addEvent("--{Begin Read}--");
|
||||||
try (Scope scope = gf.makeCurrent()) {
|
currentSpan.addEvent("Attribute: Read Uncompressed = " + header.getUncompressed());
|
||||||
|
currentSpan.addEvent("Attribute: Read Compressed = " + header.getCompressed());
|
||||||
|
currentSpan.addEvent("Attribute: Compression Ratio = " + ((double)header.getUncompressed() / header.getCompressed()));
|
||||||
|
currentSpan.addEvent("Attribute: Read Hash = " + header.getHash());
|
||||||
if (header.getUncompressed() == 0)
|
if (header.getUncompressed() == 0)
|
||||||
return header;
|
return header;
|
||||||
gf.addEvent("Read Data");
|
currentSpan.addEvent("Read Data");
|
||||||
byte[] data = readSome(header);
|
byte[] data = readSome(header);
|
||||||
gf.addEvent("Decompress Data");
|
currentSpan.addEvent("Decompress Data");
|
||||||
byte[] decompressed = decompress(header, data);
|
byte[] decompressed = decompress(header, data);
|
||||||
gf.addEvent("Hash");
|
currentSpan.addEvent("Hash");
|
||||||
hash(header, decompressed);
|
hash(header, decompressed);
|
||||||
gf.addEvent("Write");
|
currentSpan.addEvent("Write");
|
||||||
fileOutputWriter.write(decompressed, 0, decompressed.length);
|
fileOutputWriter.write(decompressed, 0, decompressed.length);
|
||||||
gf.addEvent("End");
|
|
||||||
} finally {
|
|
||||||
gf.end();
|
|
||||||
}
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +72,21 @@ public class ChunkedCompressedChecksumFileReader {
|
||||||
throw new RuntimeException("Stream total hash doesn't match the client's sent hash!");
|
throw new RuntimeException("Stream total hash doesn't match the client's sent hash!");
|
||||||
fileOutputWriter.flush();
|
fileOutputWriter.flush();
|
||||||
fileOutputWriter.close();
|
fileOutputWriter.close();
|
||||||
|
currentSpan.addEvent("--{End Read}--");
|
||||||
|
currentScope.close();
|
||||||
|
currentSpan.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCompressedBytes(){
|
||||||
|
return compressed_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUncompressedBytes(){
|
||||||
|
return uncompressed_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRatio(){
|
||||||
|
return (double) uncompressed_bytes / (double) compressed_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileHeader readHeader() throws IOException {
|
private FileHeader readHeader() throws IOException {
|
||||||
|
|
|
@ -51,21 +51,22 @@ public class Connection implements Runnable {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (in.available() > 0) {
|
if (in.available() > 0) {
|
||||||
fileSend.addEvent("File Received");
|
|
||||||
Span fileIn = trace.spanBuilder("File Received").setAttribute("Files Received", filesReceived).startSpan();
|
|
||||||
try (Scope s = fileIn.makeCurrent()){
|
|
||||||
byte command = in.readByte();
|
byte command = in.readByte();
|
||||||
|
|
||||||
if (command == FileUtil.COMMAND.CLOSE.type) {
|
if (command == FileUtil.COMMAND.CLOSE.type) {
|
||||||
System.out.println("Client sent disconnect signal!");
|
System.out.println("Client sent disconnect signal!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (command == FileUtil.COMMAND.WRITE.type)
|
if (command == FileUtil.COMMAND.WRITE.type) {
|
||||||
|
fileSend.addEvent("File Received");
|
||||||
|
Span fileIn = trace.spanBuilder("File Received").setAttribute("Files Received", filesReceived).startSpan();
|
||||||
|
try (Scope s = fileIn.makeCurrent()) {
|
||||||
FileUtil.receive(in, trace, fileIn);
|
FileUtil.receive(in, trace, fileIn);
|
||||||
} finally {
|
} finally {
|
||||||
fileIn.end();
|
fileIn.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fileSend.recordException(e);
|
fileSend.recordException(e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class Server {
|
||||||
|
|
||||||
public static volatile boolean running = true;
|
public static volatile boolean running = true;
|
||||||
|
|
||||||
private static final OpenTelemetry ot = OTelUtils.create();
|
private static final OpenTelemetry ot = OTelUtils.create("CumServer");
|
||||||
|
|
||||||
public Server() {
|
public Server() {
|
||||||
Tracer main = ot.getTracer("Main Server", "0.69");
|
Tracer main = ot.getTracer("Main Server", "0.69");
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
// do not change it breaks stuff
|
// do not change it breaks stuff
|
||||||
protected static final int READER_SIZE = 131072;
|
protected static final int READER_SIZE = 65000;
|
||||||
public static final long SEED = 691;
|
public static final long SEED = 691;
|
||||||
|
|
||||||
private static final LZ4Factory LZ_FACTORY = LZ4Factory.fastestInstance();
|
private static final LZ4Factory LZ_FACTORY = LZ4Factory.fastestInstance();
|
||||||
|
@ -77,6 +77,9 @@ public class FileUtil {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sp.setAttribute("Data Read Uncompressed Bytes", reader.getUncompressedBytes());
|
||||||
|
sp.setAttribute("Data Read Compressed Bytes", reader.getCompressedBytes());
|
||||||
|
sp.setAttribute("Data Compression Ratio", reader.getRatio());
|
||||||
reader.close();
|
reader.close();
|
||||||
System.out.println("Writing " + path + " complete");
|
System.out.println("Writing " + path + " complete");
|
||||||
sp.addEvent("File Written");
|
sp.addEvent("File Written");
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class OTelUtils {
|
||||||
.buildAndRegisterGlobal();
|
.buildAndRegisterGlobal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OpenTelemetry create(){
|
public static OpenTelemetry create(String name){
|
||||||
Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME.getKey(), "cum").put(ResourceAttributes.SERVICE_VERSION.getKey(), "0.1.0").build();
|
Resource resource = Resource.getDefault().toBuilder().put(ResourceAttributes.SERVICE_NAME.getKey(), name).put(ResourceAttributes.SERVICE_VERSION.getKey(), "1.3.37").build();
|
||||||
|
|
||||||
SpanExporter otlpExporter = OtlpGrpcSpanExporter.builder()
|
SpanExporter otlpExporter = OtlpGrpcSpanExporter.builder()
|
||||||
.setEndpoint("http://sc.on.underlying.skynet.tpgc.me:4317")
|
.setEndpoint("http://sc.on.underlying.skynet.tpgc.me:4317")
|
||||||
|
@ -49,7 +49,7 @@ public class OTelUtils {
|
||||||
|
|
||||||
BatchSpanProcessor batchSpanProcessor = BatchSpanProcessor.builder(otlpExporter)
|
BatchSpanProcessor batchSpanProcessor = BatchSpanProcessor.builder(otlpExporter)
|
||||||
.setMaxQueueSize(2048)
|
.setMaxQueueSize(2048)
|
||||||
.setMaxExportBatchSize(512) // Example max export batch size
|
.setMaxExportBatchSize(512)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
|
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue