Skip to content

Commit

Permalink
Changing dependency structure to no longer use common
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Feb 18, 2011
1 parent c7e7d3e commit 8cc7267
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.swp
*.settings
*.classpath
*.project
**/target
2 changes: 2 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.lantern</groupId>
<artifactId>lantern-common</artifactId>
</dependency>
-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.mg.common.XmppMessageConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.littleshoot.commom.xmpp.XmppP2PClient;
import org.littleshoot.p2p.P2P;
import org.littleshoot.proxy.KeyStoreManager;
import org.mg.common.XmppMessageConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
21 changes: 21 additions & 0 deletions client/src/main/java/org/lantern/client/LanternUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
import java.util.Random;

import org.apache.commons.codec.binary.Base64;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFutureListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility methods for use with Lantern.
*/
public class LanternUtils {

private static final Logger LOG =
Expand All @@ -22,6 +28,21 @@ public class LanternUtils {
private static final File CONFIG_DIR =
new File(System.getProperty("user.home"), ".lantern");

/**
* Closes the specified channel after all queued write requests are flushed.
*/
public static void closeOnFlush(final Channel ch) {
LOG.info("Closing channel on flush: {}", ch);
if (ch == null) {
LOG.warn("Channel is NULL!!");
return;
}
if (ch.isConnected()) {
ch.write(ChannelBuffers.EMPTY_BUFFER).addListener(
ChannelFutureListener.CLOSE);
}
}

public static String getMacAddress() {
if (MAC_ADDRESS != null) {
return MAC_ADDRESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.lastbamboo.common.offer.answer.NoAnswerException;
import org.lastbamboo.common.util.ByteBufferUtils;
import org.littleshoot.commom.xmpp.XmppP2PClient;
import org.mg.common.MgUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -155,7 +154,7 @@ public void channelClosed(final ChannelHandlerContext ctx,
public void exceptionCaught(final ChannelHandlerContext ctx,
final ExceptionEvent e) {
log.error("Caught exception on INBOUND channel", e.getCause());
MgUtils.closeOnFlush(this.inboundChannel);
LanternUtils.closeOnFlush(this.inboundChannel);
closeOutgoing();
}

Expand Down Expand Up @@ -191,11 +190,11 @@ public void run() {
log.info("In while");
}
log.info("Out of while");
MgUtils.closeOnFlush(inboundChannel);
LanternUtils.closeOnFlush(inboundChannel);

} catch (final IOException e) {
log.info("Exception relaying peer data back to browser",e);
MgUtils.closeOnFlush(inboundChannel);
LanternUtils.closeOnFlush(inboundChannel);

// The other side probably just closed the connection!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jboss.netty.handler.ssl.SslHandler;
import org.littleshoot.proxy.KeyStoreManager;
import org.littleshoot.proxy.SslContextFactory;
import org.mg.common.MgUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -126,14 +125,14 @@ public void operationComplete(final ChannelFuture future)
public void channelClosed(final ChannelHandlerContext ctx,
final ChannelStateEvent e) {
log.info("Got inbound channel closed. Closing outbound.");
MgUtils.closeOnFlush(this.outboundChannel);
LanternUtils.closeOnFlush(this.outboundChannel);
}

@Override
public void exceptionCaught(final ChannelHandlerContext ctx,
final ExceptionEvent e) throws Exception {
log.error("Caught exception on INBOUND channel", e.getCause());
MgUtils.closeOnFlush(this.inboundChannel);
LanternUtils.closeOnFlush(this.inboundChannel);
}

private static class OutboundHandler extends SimpleChannelUpstreamHandler {
Expand All @@ -156,14 +155,14 @@ public void messageReceived(final ChannelHandlerContext ctx,
@Override
public void channelClosed(final ChannelHandlerContext ctx,
final ChannelStateEvent e) throws Exception {
MgUtils.closeOnFlush(inboundChannel);
LanternUtils.closeOnFlush(inboundChannel);
}

@Override
public void exceptionCaught(final ChannelHandlerContext ctx,
final ExceptionEvent e) throws Exception {
log.error("Caught exception on OUTBOUND channel", e.getCause());
MgUtils.closeOnFlush(e.getChannel());
LanternUtils.closeOnFlush(e.getChannel());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.lastbamboo.common.util.ByteBufferUtils;
import org.mg.common.MgUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -101,7 +100,7 @@ public void channelClosed(final ChannelHandlerContext ctx,
public void exceptionCaught(final ChannelHandlerContext ctx,
final ExceptionEvent e) {
log.error("Caught exception on INBOUND channel", e.getCause());
MgUtils.closeOnFlush(this.inboundChannel);
LanternUtils.closeOnFlush(this.inboundChannel);
closeOutgoing();
}

Expand Down Expand Up @@ -137,11 +136,11 @@ public void run() {
log.info("In while");
}
log.info("Out of while");
MgUtils.closeOnFlush(inboundChannel);
LanternUtils.closeOnFlush(inboundChannel);

} catch (final IOException e) {
log.info("Exception relaying peer data back to browser",e);
MgUtils.closeOnFlush(inboundChannel);
LanternUtils.closeOnFlush(inboundChannel);
//inboundChannel.close();
//proxyStatusListener.onError(peerUri);
}
Expand Down
36 changes: 36 additions & 0 deletions client/src/main/java/org/lantern/client/XmppMessageConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.lantern.client;

/**
* Class containing constants for message property keys.
*/
public class XmppMessageConstants {

private XmppMessageConstants() {}

public static final String MAC = "M";

public static final String HASHCODE = "H";

public static final String SEQ = "S";

public static final String MD5 = "M5";

public static final String HTTP = "HT";

public static final String SERVER_MAC = "SM";

public static final String CLOSE = "CL";

//public static final String TYPE = "T";

public static final int INFO_REQUEST_TYPE = 0x1111;

public static final int INFO_RESPONSE_TYPE = 0x1112;

public static final int ERROR_TYPE = 0x1113;

public static final String PROXIES = "P";

public static final String MESSAGE = "ME";

}

0 comments on commit 8cc7267

Please sign in to comment.