use of com.google.privacy.dlp.v2.Error in project dodo by devhawala.
the class NetMachine method handlePacket.
public void handlePacket(IDP idp) {
if (idp.getPacketType() == PacketType.SPP) {
SPP spp = new SPP(idp);
Log.L1.printf(idp, "handlePacket( %s )\n", spp.toString());
} else {
Log.L1.printf(idp, "handlePacket( %s )\n", idp.toString());
}
// temp: verify the checksum to test the algorithm
int packetChecksum = idp.getChecksum();
if (packetChecksum != IDP.NO_CHECKSUM) {
int tmpCkSum = idp.computeChecksum();
if (tmpCkSum != packetChecksum) {
Log.E.printf(idp, "** checksums: orig = 0x%04X - recomputed = 0x%04X\n%s\n", packetChecksum, tmpCkSum, idp.packet.payloadToString());
// } else {
// Log.I.printf(idp, "++ checksum OK (orig == recomputed = 0x%04X)\n", packetChecksum);
}
}
// end temp
int targetSocket = idp.getDstSocket();
Error err = (idp.getPacketType() == PacketType.ERROR) ? new Error(idp) : null;
if (err != null) {
IDP errPacket = err.getOffendingIdpPaket();
String errData = (errPacket.getPacketType() == PacketType.SPP) ? (new SPP(errPacket)).toString() : errPacket.toString();
Log.E.printf(idp, "handlePacket(): packet type is ERROR(%s), offending packet: %s\n", err.getErrorCode(), errData);
targetSocket = err.getOffendingIdpPaket().getSrcSocket();
}
iIDPReceiver listener = this.getListener(targetSocket);
if (listener == null) {
Log.L1.printf(idp, "** handlePacket(): no listener registered for target socket\n");
// avoid error ping-pong or replying errors to broadcasts
if (err == null && idp.getDstHost() != IDP.BROADCAST_ADDR) {
Log.L1.printf(idp, "** handlePacket(): sending back error packet\n");
this.sender.send(new Error(ErrorCode.NO_SOCKET, idp.getDstSocket(), idp).idp);
}
return;
}
int ckSum = idp.getChecksum();
if (this.enforceChecksums && ckSum != IDP.NO_CHECKSUM) {
int localCkSum = idp.computeChecksum();
if (localCkSum != ckSum) {
Log.L1.printf(idp, "** handlePacket(): checkum error (packet-checksum: 0x%04X, locally-recomputed: 0x%04X\n", ckSum, localCkSum);
this.sender.send(new Error(ErrorCode.BAD_CHECKSUM, idp.getDstSocket(), idp).idp);
}
}
if (err != null) {
Log.L1.printf(idp, "handlePacket(): invoking listener.acceptError()\n");
listener.acceptError(err);
} else {
Log.L1.printf(idp, "handlePacket(): invoking listener.accept()\n");
listener.accept(idp);
}
}
use of com.google.privacy.dlp.v2.Error in project dodo by devhawala.
the class PexServerListener method accept.
@Override
public void accept(IDP idp) {
if (idp.getPacketType() != PacketType.PEX) {
Error err = new Error(ErrorCode.INVALID_PACKET_TYPE, 0, idp);
this.sender.send(err.idp);
return;
}
PEX request = new PEX(idp);
long clientIdentification = request.getIdentification();
int clientType = request.getClientType();
byte[] buffer = new byte[request.getPayloadLength()];
request.rdBytes(0, buffer.length, buffer, 0, buffer.length);
responder.handlePacket(idp.getSrcHost(), clientType, buffer, (b, o, l) -> {
PEX response = new PEX();
response.idp.asReplyTo(request.idp);
response.idp.setSrcHost(localEndpoint.host);
response.idp.setSrcNetwork(localEndpoint.network);
response.setIdentification(clientIdentification);
response.setClientType(clientType);
response.wrBytes(0, l, b, o, l);
response.idp.resetChecksum();
sender.send(response.idp);
}, (c, p) -> {
Error err = new Error(c, p, request.idp);
sender.send(err.idp);
});
}
use of com.google.privacy.dlp.v2.Error in project dodo by devhawala.
the class TestPayloads method testErrorReadData.
@Test
public void testErrorReadData() {
NetPacket packet = this.mkNetPacket();
IDP idp = new IDP(packet);
Error err = new Error(idp);
assertEquals("err.errorCode", ErrorCode.UNSPECIFIED, err.getErrorCode());
assertEquals("err.errorParam", 0x2021, err.getErrorParam());
assertEquals("err.payloadLen", TESTCONTENT.length - 34, err.getPayloadLength());
IDP offending = err.getOffendingIdpPaket();
assertEquals("offending.payloadLength", 0, offending.getPayloadLength());
assertEquals("offending.checksum", 0x2223, offending.getChecksum());
assertEquals("offending.length", 0x2425, offending.getLength());
assertEquals("offending.transportControl", 0x26, offending.getTransportControl());
assertEquals("offending.packetTypeCode", 0x27, offending.getPacketTypeCode());
assertEquals("offending.dstNetwork", 0x28292A2B, offending.getDstNetwork());
assertEquals("offending.dstHost", 0x2C2D2E2F3031L, offending.getDstHost());
assertEquals("offending.dstSocket", 0x3233, offending.getDstSocket());
assertEquals("offending.srcNetwork", 0x34353637, offending.getSrcNetwork());
assertEquals("offending.srcHost", 0x38393A3B3C3DL, offending.getSrcHost());
assertEquals("offending.srcSocket", 0x3E3F, offending.getSrcSocket());
}
use of com.google.privacy.dlp.v2.Error in project dodo by devhawala.
the class TestPayloads method testErrorWriteData.
@Test
public void testErrorWriteData() {
NetPacket offendingPacket = this.mkNetPacket();
IDP offendingIdp = new IDP(offendingPacket);
Error err = new Error(ErrorCode.PROTOCOL_VIOLATION, 0x1234, offendingIdp);
assertEquals("err.payloadLength", 64, err.getPayloadLength());
assertEquals("idp.payloadLength", 68, err.idp.getPayloadLength());
assertEquals("idp.length", 98, err.idp.getLength());
byte[] refData = { // IDP automatically resets the checksum => 0xFFFF
(byte) 0xFF, // IDP automatically resets the checksum => 0xFFFF
(byte) 0xFF, 0x00, (byte) 98, 0x00, IDP.PacketType.ERROR.getPacketTypeCode(), // dest network (== src network of offending packet)
0x12, // dest network (== src network of offending packet)
0x13, // dest network (== src network of offending packet)
0x14, // dest network (== src network of offending packet)
0x15, // dest host (==src host of offending packet)
0x16, // dest host (==src host of offending packet)
0x17, // dest host (==src host of offending packet)
0x18, // dest host (==src host of offending packet)
0x19, // dest host (==src host of offending packet)
0x1A, // dest host (==src host of offending packet)
0x1B, // dest socket == error
0x00, // dest socket == error
0x03, // src network (== dest network of offending packet)
0x06, // src network (== dest network of offending packet)
0x07, // src network (== dest network of offending packet)
0x08, // src network (== dest network of offending packet)
0x09, // src host (== dest host of offending packet)
0x0A, // src host (== dest host of offending packet)
0x0B, // src host (== dest host of offending packet)
0x0C, // src host (== dest host of offending packet)
0x0D, // src host (== dest host of offending packet)
0x0E, // src host (== dest host of offending packet)
0x0F, // src socket (== dest socket of offending packet)
0x10, // src socket (== dest socket of offending packet)
0x11, // ErrorCode.PROTOCOL_VIOLATION
0x00, // ErrorCode.PROTOCOL_VIOLATION
0x06, // error param
0x12, // error param
0x34, // offending packet (first <n> bytes)
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F };
assertEquals("refData.length", 98, refData.length);
byte[] actualData = new byte[refData.length];
int copiedLength = err.idp.packet.rdBytes(0, NetPacket.MAX_PACKET_SIZE, actualData, 0, NetPacket.MAX_PACKET_SIZE);
assertEquals("copiedLength", actualData.length, copiedLength);
this.checkByteArrayContents(refData, actualData);
}
use of com.google.privacy.dlp.v2.Error in project dodo by devhawala.
the class DodoTest method testTimeService.
// time PEX service test (time service)
private static void testTimeService() throws XnsException {
localSite.pexListen(IDP.KnownSocket.TIME.getSocket(), new TimeServiceResponder(0, 0));
byte[] requestData = { 0x00, 0x02, 0x00, 0x01 };
Payload response = localSite.pexRequest(IDP.BROADCAST_ADDR, IDP.KnownSocket.TIME.getSocket(), PEX.ClientType.TIME.getTypeValue(), requestData, 0, requestData.length);
if (response == null) {
System.out.println("time response: null (timeout)\n");
} else if (response instanceof PEX) {
System.out.println("time response is of type: PEX\n");
PEX pex = (PEX) response;
System.out.printf("=> PEX: %s\n", pex.toString());
System.out.printf("=> PEX.payload: %s\n", pex.payloadToString());
} else if (response instanceof Error) {
System.out.println("time response is of type: Error\n");
} else {
System.out.printf("time response is of unexpected type: %s\n", response.getClass().getName());
}
}
Aggregations