Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCC 2: Electric Boogaloo #172

Closed
wants to merge 26 commits into from

Conversation

octylFractal
Copy link

@octylFractal octylFractal commented Jan 4, 2017

Back from the dead, it's DCC support!

This closes #93, and replaces #138.

Things to do:

  • Receive DCC requests
    • Fire event when request is received, regardless of potentially malformed content
    • Allow clients to accept/deny requests and actually do something if they call the methods
  • Fire DCCConnectionClosedEvent :P
  • Timeout if no response
    • Should it be configurable?
  • Refactor the Netty handling
  • Get input on all TODOs
  • Implement DCC Send?

@codecov-io
Copy link

codecov-io commented Jan 4, 2017

Current coverage is 32.61% (diff: 0.00%)

Merging #172 into master will decrease coverage by 2.32%

@@             master       #172   diff @@
==========================================
  Files           152        161     +9   
  Lines          3818       4093   +275   
  Methods           0          0          
  Messages          0          0          
  Branches        536        567    +31   
==========================================
+ Hits           1334       1335     +1   
- Misses         2431       2705   +274   
  Partials         53         53          

Powered by Codecov. Last update 8fc8af2...1b3150f

/**
* Represents an exchange using DCC.
*/
public interface DccExchange extends Actor, Closeable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DCCExchange.


import javax.annotation.Nonnull;

public interface DccChat extends DccExchange {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DCCChat.

* a {@link DccConnectedEvent} will be fired. If the connection fails, a
* {@link DccFailedEvent} will be fired.</p>
*/
void requestDccChat(@Nonnull User target);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be requestDCCChat.

*
* @see Client#requestDccChat(User)
*/
default void requestDccChat() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be requestDCCChat.

/**
* Fires when a DCC CHAT message is received.
*/
public class DccChatMessageEvent extends ActorMessageEventBase<DccChat> implements ReplyableEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DCCChatMessageEvent.

@lol768
Copy link
Member

lol768 commented Jan 4, 2017

Any objections if I write some tests?

@octylFractal
Copy link
Author

No, @lol768.

super(client, originalMessages, actor);
Sanity.nullCheck(type, "type cannot be null");
Sanity.nullCheck(ip, "ip cannot be null");
this.type = type;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.type = Sanity.nullCheck(type, "type cannot be null");

Copy link
Author

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually meant to migrate to that style for a while now. ^_^

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then change it on master first and I'll follow up :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/**
* @return the readable reason for the failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing full javadocs.

@octylFractal
Copy link
Author

@mbax @kashike @lol768 It's mostly done, I just need input on the TODOs and anything else you want cleaned up. DCC is happening!

return this.type;
}

public String getIp() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be convenient to have this return an InetAddress

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InetSocketAddress now, and dropped getPort.

/**
* Denies the request.
*/
public abstract void deny();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my mind, the opposite of accept is reject, and the opposite of deny is allow. It's something to consider, although not hugely relevant.

Copy link
Member

@lol768 lol768 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thoughts

import java.util.Optional;

/**
* Represents an exchange using DCC.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

immutable exchange snapshot?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other immutable snapshots are written this way. Is there anything special about this that sets it apart?

/**
* Returns the exception that caused the failure.
*
* @return the exception that caused the failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is he present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or she

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is they present?

/**
* Returns the human-readable reason for the failure.
*
* @return the human-readable reason for the failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is he present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or she

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is they present?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They is always present.

@@ -996,6 +1002,69 @@ public void ctcp(ClientReceiveCommandEvent event) {
}
}

private void handleDCCEvent(User user, List<ServerMessage> originalMessages, List<String> parameters) {
// TODO should unknown requests or improperly formatted requests get logged? just to clarify to the user that they are still noticed
Copy link
Member

@lol768 lol768 Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We throw server exceptions for invalid server messages.. could do the same here but not sure since it's a user originating message..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really user but client originating. Still could be maliciously crafted easily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on IRC.

return addressLong.toString();
}

private static final BigInteger X_FFFF = BigInteger.valueOf(0xFFFF);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better up top?

@@ -996,6 +1002,69 @@ public void ctcp(ClientReceiveCommandEvent event) {
}
}

private void handleDCCEvent(User user, List<ServerMessage> originalMessages, List<String> parameters) {
// TODO should unknown requests or improperly formatted requests get logged? just to clarify to the user that they are still noticed
Copy link
Member

@Zarthus Zarthus Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logged in the background? yes. Silently dropping things is bad. will also allow covering for possible exploit attempts


public final class IPUtil {
private static final BigInteger X_FFFF = BigInteger.valueOf(0xFFFF);
private static final int LENGTH_OF_LARGEST_IPV6_INTEGER = BigInteger.valueOf(2).pow(128).toString().length();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is missing a -1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow?

Copy link
Member

@mbax mbax Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff is
340282366920938463463374607431768211455
2^128 is
340282366920938463463374607431768211456

But that is, of course, not relevant. They're both the same length, which is 39.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I don't really think that matters too much. We could even just hardcode the 39 and add a comment 😛

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now just a 39.


import javax.annotation.Nonnull;

public interface DCCChat extends DCCExchange {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing javadocs.

* @param ipInteger the IP integer string
* @return the corresponding IP address as an InetAddress instance
*/
public static InetAddress getInetAdressFromIntString(String ipInteger) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a d in address.
getInetAdressFromIntString
getInetAddressFromIntString

@octylFractal octylFractal changed the title [WIP] DCC 2: Electric Boogaloo DCC 2: Electric Boogaloo Jan 9, 2017
@Zarthus
Copy link
Member

Zarthus commented Jan 9, 2017

2017 is off to a great start

@mbax mbax removed the proposal label Jan 14, 2017
@mbax
Copy link
Member

mbax commented Mar 1, 2017

Closing this PR to give the dcc branch's PR the spotlight. #181

@mbax mbax closed this Mar 1, 2017
@mbax mbax removed this from the 3.1.0 milestone May 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DCC Support
6 participants