Skip to content

Commit

Permalink
Merge pull request #134 from DeNA/fix/duplex_sync
Browse files Browse the repository at this point in the history
DuplexSyncでcallOnServerChunkSendが呼び出されてないバグを修正
  • Loading branch information
funa-tk authored Aug 10, 2022
2 parents 0769650 + dd151e4 commit 057e1a1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/java/core/packetproxy/DuplexSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@
import packetproxy.common.Endpoint;
import packetproxy.model.OneShotPacket;

public class DuplexSync extends Duplex
{
public class DuplexSync extends Duplex {
private Endpoint server;
private OutputStream out;
private InputStream in;

public DuplexSync(Endpoint endpoint) throws Exception {
this.server = endpoint;
this.out = this.server.getOutputStream();
this.in = this.server.getInputStream();
}

public static OneShotPacket encodePacket(OneShotPacket one_shot) {
return one_shot;
}
Expand All @@ -49,33 +48,35 @@ public boolean isListenPort(int listenPort) {
public Duplex createSameConnectionDuplex() throws Exception {
return new DuplexSync(this.server);
}

public byte[] prepareFastSend(byte[] data) throws Exception {
int accepted_length = callOnClientPacketReceived(data);
if (accepted_length <= 0){
if (accepted_length <= 0) {
return null;
}
byte[] accepted = ArrayUtils.subarray(data, 0, accepted_length);

byte[] pass = callOnClientChunkPassThrough();

byte[] decoded = super.callOnClientChunkReceived(accepted);
byte[] encoded = super.callOnClientChunkSend(decoded);

return ArrayUtils.addAll(pass, encoded);
}

public void execFastSend(byte[] data) throws Exception {
out.write(data);
out.flush();
}

@Override
public void send(byte[] data) throws Exception {
int accepted_length = callOnClientPacketReceived(data);
if (accepted_length <= 0){
if (accepted_length <= 0) {
return;
}
byte[] accepted = ArrayUtils.subarray(data, 0, accepted_length);

byte[] decoded = super.callOnClientChunkReceived(accepted);
byte[] encoded = super.callOnClientChunkSend(decoded);
out.write(encoded);
Expand All @@ -90,13 +91,13 @@ public byte[] receive() throws Exception {
ByteArrayOutputStream bout = new ByteArrayOutputStream();

int length = 0;
while((length = in.read(input_data, 0, input_data.length)) >= 0) {
while ((length = in.read(input_data, 0, input_data.length)) >= 0) {

bin.write(input_data, 0, length);

int packetLen = 0;
while ((packetLen = callOnServerPacketReceived(bin.toByteArray())) > 0) {

byte[] packetData = ArrayUtils.subarray(bin.toByteArray(), 0, packetLen);
byte[] restData = ArrayUtils.subarray(bin.toByteArray(), packetLen, bin.size());
bin.reset();
Expand All @@ -113,12 +114,13 @@ public byte[] receive() throws Exception {
bout.write(decoded);
available_data = callOnServerChunkAvailable();
} while (available_data != null && available_data.length > 0);
return bout.toByteArray();
byte[] encoded = callOnServerChunkSend(bout.toByteArray());
return encoded;
}
}
return null;
}

@Override
public void close() throws Exception {
in.close();
Expand Down

0 comments on commit 057e1a1

Please sign in to comment.