[NET-727] Enable accessing options map for TFTP request packet and allow using blksize option#331
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
Hello @vimukthiD
Thank you for your PR!
Please rebase on git master to pick up the latest and address the comments I've scattered throughout.
TY!
| private int packetSize = TFTPPacket.SEGMENT_SIZE + 4; | ||
|
|
||
| /** Internal state to track if the send/receive buffers are initialized */ | ||
| private boolean buffersInityialized = false; |
There was a problem hiding this comment.
Fix spelling of buffersInityialized.
| public final void resetBuffersToSize(int packetSize) { | ||
| // the packet size should be between 8 - 65464 (inclusively) then we add 4 for the header | ||
| this.packetSize = (Math.min(Math.max(packetSize, 8), 65464) + 4); | ||
|
|
There was a problem hiding this comment.
Remove extra vertical whitespace.
| } | ||
|
|
||
| /** | ||
| * Returns the buffer size of the buffered used by {@link #bufferedSend bufferedSend() } and {@link #bufferedReceive bufferedReceive() }. |
There was a problem hiding this comment.
Javadoc: A getter "Gets..."
| /** The no such user error code according to RFC 783, value 7. */ | ||
| public static final int NO_SUCH_USER = 7; | ||
|
|
||
| /** The invalid options error code according to RFC 2347, value 8. */ |
There was a problem hiding this comment.
New public and protected elements should have a Javadoc @SInCE tag. In this case, for 3.12.0.
src/main/java/org/apache/commons/net/tftp/TFTPOptionsAckPacket.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/net/tftp/TFTPOptionsAckPacket.java
Outdated
Show resolved
Hide resolved
| byte[] key = entry.getKey().getBytes(StandardCharsets.US_ASCII); | ||
| System.arraycopy(key, 0, data, offset, key.length); | ||
| offset += key.length; | ||
|
|
There was a problem hiding this comment.
No need for blank lines, if there is something to call out, then write an inline // comment.
| public static final int ERROR = 5; | ||
|
|
||
| /** | ||
| * This is the actual TFTP spec identifier and is equal to 6. |
There was a problem hiding this comment.
No need to "This is", just say what it is 'TFTP spec identifier {@value}.'
| } | ||
|
|
||
| /** | ||
| * Returns the options extensions of the request as a map. |
6a8940a to
7022564
Compare
|
Hello @garydgregory , |
garydgregory
left a comment
There was a problem hiding this comment.
Thank you for updating your pull-request. You'll more comments to address in this round.
To verify your code coverage, run:
mvn clean site -Dcommons.jacoco.haltOnFailure=false -Pjacoco
and inspect the page:
target/site/jacoco/org.apache.commons.net.tftp/index.html#dn-b
Try to get the new code the highest possible coverage if you can.
TY!
| private DatagramPacket sendDatagram; | ||
|
|
||
| /** Internal packet size, which is the data octet size plus 4 (for TFTP header octets) */ | ||
| private int packetSize = TFTPPacket.SEGMENT_SIZE + 4; |
There was a problem hiding this comment.
Don't duplicate the expression that defines PACKET_SIZE, reuse that constant.
| /** | ||
| * The invalid options error code according to RFC 2347, value 8. | ||
| * @since 3.12.0 | ||
| * */ |
| for (Map.Entry<String, String> entry : options.entrySet()) { | ||
| optionsLength += entry.getKey().length() + 1 + entry.getValue().length() + 1; | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove extra vertical whitespace.
| int offset = 0; | ||
| data[offset++] = 0; | ||
| data[offset++] = (byte) type; | ||
|
|
There was a problem hiding this comment.
Remove extra vertical whitespace.
| } | ||
|
|
||
| private int writeOptionsData(byte[] data, int offset) { | ||
| // all the options would get written to the data byte array in following format |
There was a problem hiding this comment.
Put this inline comment in a Javadoc comment using <pre> tags, keep it simple, you don't need "~~"s...
| } | ||
|
|
||
| /** | ||
| * Gets the buffer size of the buffered used by {@link #bufferedSend bufferedSend() } and {@link #bufferedReceive bufferedReceive() }. |
There was a problem hiding this comment.
Simplify clutter: {@link #bufferedSend bufferedSend() } -> {@link #bufferedSend(TFTPPacket)} and so on.
| * @return current buffer size | ||
| * @since 3.12.0 | ||
| */ | ||
| public int getBufferSize() { |
There was a problem hiding this comment.
- This method is not tested or called, remove it or add a unit test for it.
- Rename to match the instance variable.
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** |
There was a problem hiding this comment.
This class is not tested. Remove it or create a unit test.
| for (Map.Entry<String, String> entry : options.entrySet()) { | ||
| optionsLength += entry.getKey().length() + 1 + entry.getValue().length() + 1; | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove extra vertical whitespace.
| throw new TFTPPacketException("Invalid option format"); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove extra vertical whitespace.
|
Hello @vimukthiD |
…w using `blksize` option (RFC-2348) to increase data size.
fb3b0f9 to
f45b494
Compare
|
Hello @garydgregory |
garydgregory
left a comment
There was a problem hiding this comment.
Hello @vimukthiD
Thank you for your updates.
The class TFTPOptionsAckPacket is not used in main. Why is it needed?
TY!
|
Hello @garydgregory, Oh yeah, sorry about that. At the moment it's not used, but was planning on implementing RFC-2347 which would require the Thank you! |
|
Hello @vimukthiD |
|
Hello @garydgregory , Sorry for the trouble. I've removed the Thank you ! |
blksize optionblksize option
relates to existing https://issues.apache.org/jira/browse/NET-727
This changes includes the mapping of options map in TFTPRequestPacket (according to RFC-2347) and allowing to use
blksize(according to the RFC-2348) when doing a TFTP buffered send/receive.