Skip to content

Commit

Permalink
Extra code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericBregier committed Sep 4, 2020
1 parent 2ce86e0 commit 4d5f0a0
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public void channelInactive(final ChannelHandlerContext ctx)
throws Exception {
logger.debug("Data Channel closed with a session ? " + (session != null));
if (session != null) {
if (!session.getDataConn().checkCorrectChannel(ctx.channel())) {
for (int i = 0; i < FtpInternalConfiguration.RETRYNB; i++) {
Thread.sleep(FtpInternalConfiguration.RETRYINMS);
if (session.getDataConn().checkCorrectChannel(ctx.channel())) {
break;
}
}
}
if (session.getDataConn().checkCorrectChannel(ctx.channel())) {
session.getDataConn().getFtpTransferControl().setPreEndOfTransfer();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageCodec;
import org.waarp.common.exception.InvalidArgumentException;
Expand Down Expand Up @@ -239,7 +238,7 @@ protected void decode(final ChannelHandlerContext ctx, final ByteBuf buf,
if (mode == TransferMode.STREAM) {
dataBlock = new DataBlock();
if (structure != TransferStructure.RECORD) {
final ByteBuf newbuf = Unpooled.wrappedBuffer(buf);
final ByteBuf newbuf = buf.slice();
buf.readerIndex(buf.readableBytes());
newbuf.retain();
dataBlock.setBlock(newbuf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,30 @@ public abstract void createAllBuffers(LocalChannelReference lcr,
*
* @throws OpenR66ProtocolPacketException
*/
public abstract void createHeader(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException;
public void createHeader(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
throw new IllegalStateException("Should not be called");
}

/**
* Prepare the Middle buffer
*
* @throws OpenR66ProtocolPacketException
*/
public abstract void createMiddle(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException;
public void createMiddle(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
throw new IllegalStateException("Should not be called");
}

/**
* Prepare the End buffer
*
* @throws OpenR66ProtocolPacketException
*/
public abstract void createEnd(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException;
public void createEnd(LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
throw new IllegalStateException("Should not be called");
}

/**
* @return the type of Packet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,37 +171,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
}
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
final byte[] bversion = version != null? version.getBytes() : null;
final int size = 5 + (version != null? bversion.length : 0);
end = ByteBufAllocator.DEFAULT.buffer(size, size);
end.writeInt(localId);
end.writeByte(way);
if (version != null) {
end.writeBytes(bversion);
}
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (hostId == null) {
throw new OpenR66ProtocolPacketException(NOT_ENOUGH_DATA);
}
header = Unpooled.wrappedBuffer(hostId.getBytes());
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (key == null) {
throw new OpenR66ProtocolPacketException(NOT_ENOUGH_DATA);
}
middle = Unpooled.wrappedBuffer(key);
}

@Override
public byte getType() {
return LocalPacketFactory.AUTHENTPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
header.writeBytes(key);
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
end = Unpooled.EMPTY_BUFFER;
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
header = ByteBufAllocator.DEFAULT.buffer(1 + key.length, 1 + key.length);
header.writeByte(block? 1 : 0);
header.writeBytes(key);
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
middle = Unpooled.EMPTY_BUFFER;
}

@Override
public String toString() {
return "BlockRequestPacket: " + block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
global.retain();
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
end = ByteBufAllocator.DEFAULT.buffer(1, 1);
end.writeByte(way);
end.retain();
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
header = Unpooled.wrappedBuffer(sheader.getBytes());
header.retain();
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
middle = ByteBufAllocator.DEFAULT.buffer(4, 4);
middle.writeInt(delay);
middle.retain();
}

@Override
public byte getType() {
return LocalPacketFactory.BUSINESSREQUESTPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
}
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
end = Unpooled.EMPTY_BUFFER;
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (sheader != null) {
header = Unpooled.wrappedBuffer(sheader.getBytes());
}
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (smiddle != null) {
middle = Unpooled.wrappedBuffer(smiddle.getBytes());
}
}

@Override
public String toString() {
return "ConnectionErrorPacket: " + sheader + ':' + smiddle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
}
}

@Override
public void createEnd(final LocalChannelReference lcr) {
if (optional == null) {
end = Unpooled.EMPTY_BUFFER;
} else {
end = Unpooled.copiedBuffer(optional, Charset.defaultCharset());
}
}

@Override
public void createHeader(final LocalChannelReference lcr) {
header = ByteBufAllocator.DEFAULT.buffer(4, 4);
header.writeInt(code);
}

@Override
public void createMiddle(final LocalChannelReference lcr) {
final byte[] newbytes = { way };
middle = Unpooled.wrappedBuffer(newbytes);
}

@Override
public byte getType() {
return LocalPacketFactory.ENDREQUESTPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import org.waarp.common.utility.WaarpNettyUtil;
import org.waarp.common.utility.WaarpStringUtils;
import org.waarp.openr66.protocol.exception.OpenR66ProtocolPacketException;
Expand Down Expand Up @@ -148,27 +147,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
}
}

@Override
public void createEnd(final LocalChannelReference lcr) {
if (hashOptional == null) {
end = Unpooled.EMPTY_BUFFER;
} else {
end = Unpooled.copiedBuffer(hashOptional, Charset.defaultCharset());
}
}

@Override
public void createHeader(final LocalChannelReference lcr) {
final byte[] newbytes = { request };
header = Unpooled.wrappedBuffer(newbytes);
}

@Override
public void createMiddle(final LocalChannelReference lcr) {
final byte[] newbytes = { way };
middle = Unpooled.wrappedBuffer(newbytes);
}

@Override
public byte getType() {
return LocalPacketFactory.ENDTRANSFERPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
end.writeInt(code);
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
end = ByteBufAllocator.DEFAULT.buffer(4, 4);
end.writeInt(code);
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (sheader != null) {
header = Unpooled.wrappedBuffer(sheader.getBytes());
}
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (smiddle != null) {
middle = Unpooled.wrappedBuffer(smiddle.getBytes());
}
}

@Override
public String toString() {
return "ErrorPacket:(" + code + ':' + smiddle + ") " + sheader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
}
}

@Override
public void createEnd(final LocalChannelReference lcr) {
if (filename != null) {
end = Unpooled.wrappedBuffer(filename.getBytes());
}
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (rulename == null) {
throw new OpenR66ProtocolPacketException(NOT_ENOUGH_DATA);
}
header = Unpooled.wrappedBuffer(rulename.getBytes());
}

@Override
public void createMiddle(final LocalChannelReference lcr) {
final byte[] newbytes = { requestedInfo };
middle = Unpooled.wrappedBuffer(newbytes);
}

@Override
public byte getType() {
return LocalPacketFactory.INFORMATIONPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
end.writeByte(send);
}

@Override
public void createEnd(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
end = ByteBufAllocator.DEFAULT.buffer(1, 1);
end.writeByte(send);
}

@Override
public void createHeader(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (request != null) {
header = Unpooled.wrappedBuffer(request.getBytes());
}
}

@Override
public void createMiddle(final LocalChannelReference lcr)
throws OpenR66ProtocolPacketException {
if (result != null) {
middle = Unpooled.wrappedBuffer(result.getBytes());
}
}

@Override
public String toString() {
return "JsonCommandPacket: " + request + ':' + result + ':' + send;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
header = Unpooled.EMPTY_BUFFER;
}

@Override
public void createEnd(final LocalChannelReference lcr) {
end = Unpooled.EMPTY_BUFFER;
}

@Override
public void createHeader(final LocalChannelReference lcr) {
header = Unpooled.EMPTY_BUFFER;
}

@Override
public void createMiddle(final LocalChannelReference lcr) {
final byte[] newbytes = { way };
middle = Unpooled.wrappedBuffer(newbytes);
}

@Override
public byte getType() {
return LocalPacketFactory.KEEPALIVEPACKET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,6 @@ public void createAllBuffers(final LocalChannelReference lcr,
middle = Unpooled.EMPTY_BUFFER;
}

@Override
public void createEnd(final LocalChannelReference lcr) {
end = Unpooled.EMPTY_BUFFER;
}

@Override
public void createHeader(final LocalChannelReference lcr) {
header = Unpooled.EMPTY_BUFFER;
}

@Override
public void createMiddle(final LocalChannelReference lcr) {
middle = Unpooled.EMPTY_BUFFER;
}

@Override
public byte getType() {
return LocalPacketFactory.NOOPPACKET;
Expand Down
Loading

0 comments on commit 4d5f0a0

Please sign in to comment.