(secret)) {
            final URI uri;
            try {
                uri = new URI(chat.getParticipant());
            } catch (final URISyntaxException e) {
                log.error("Could not create URI from: {}", 
                    chat.getParticipant());
                return;
            }
            synchronized (peerProxySet) {
                if (!peerProxySet.contains(uri)) {
                    peerProxies.add(uri);
                    peerProxySet.add(uri);
                }
            }
        }
        
        /*
        if (StringUtils.isNotBlank(base64Cert)) {
            log.info("Got certificate:\n"+
                new String(Base64.decodeBase64(base64Cert)));
            // First we need to add this certificate to the trusted 
            // certificates on the proxy. Then we can add it to our list of
            // peers.
            final URI uri;
            try {
                uri = new URI(chat.getParticipant());
            } catch (final URISyntaxException e) {
                log.error("Could not create URI from: {}", 
                    chat.getParticipant());
                return;
            }
            try {
                // Add the peer if we're able to add the cert.
                this.keyStoreManager.addBase64Cert(mac, base64Cert);
                synchronized (peerProxySet) {
                    if (!peerProxySet.contains(uri)) {
                        peerProxies.add(uri);
                        peerProxySet.add(uri);
                    }
                }
            } catch (final IOException e) {
                log.error("Could not add cert??", e);
            }
        }
        */
    }

    private void addProxy(final String cur, final Chat chat) {
        log.info("Considering proxy: {}", cur);
        final String user = this.client.getXmppConnection().getUser().trim();
        if (user.equals(cur.trim())) {
            log.info("Not adding ourselves as a proxy!!");
            return;
        }
        if (cur.contains("appspot")) {
            addLaeProxy(cur, chat);
        } else if (cur.contains("@")) {
            try {
                addAnonymousProxy(new URI(cur));
            } catch (final URISyntaxException e) {
                log.info("Error with proxy URI", e);
            }
        } else {
            addGeneralProxy(cur, chat);
        }
    }

    private void addAnonymousProxy(final URI cur) {
        log.info("Considering Lantern proxy");
        addPeerProxy(cur, this.anonymousProxySet, this.anonymousProxies);
    }
    
    private void addPeerProxy(final URI cur) {
        log.info("Considering Lantern peer proxy");
        addPeerProxy(cur, this.peerProxySet, this.peerProxies);
    }
    <commit_msg>Cleanups to online handling<commit_after>package org.lantern;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;

import org.apache.commons.lang.StringUtils;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.lastbamboo.common.p2p.P2PConstants;
import org.lastbamboo.jni.JLibTorrent;
import org.littleshoot.commom.xmpp.XmppP2PClient;
import org.littleshoot.commom.xmpp.XmppUtils;
import org.littleshoot.p2p.P2P;
import org.littleshoot.util.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Handles logging in to the XMPP server and processing trusted users through
 * the roster.
 */
public class XmppHandler implements ProxyStatusListener, ProxyProvider {
    
    //private static final String LANTERN_JID = "<EMAIL>";
    private static final String LANTERN_JID = "<EMAIL>";

    private final Logger log = LoggerFactory.getLogger(getClass());
    
    private final String email;

    private final String pwd;
    
    private final Set<ProxyHolder> proxySet =
        new HashSet<ProxyHolder>();
    private final Queue<ProxyHolder> proxies = 
        new ConcurrentLinkedQueue<ProxyHolder>();
    
    private final Set<URI> peerProxySet = new HashSet<URI>();
    private final Queue<URI> peerProxies = 
        new ConcurrentLinkedQueue<URI>();
    
    private final Set<URI> anonymousProxySet = new HashSet<URI>();
    private final Queue<URI> anonymousProxies = 
        new ConcurrentLinkedQueue<URI>();
    
    private final Set<ProxyHolder> laeProxySet =
        new HashSet<ProxyHolder>();
    private final Queue<ProxyHolder> laeProxies = 
        new ConcurrentLinkedQueue<ProxyHolder>();

    static {
        SmackConfiguration.setPacketReplyTimeout(30 * 1000);
    }
    
    private final XmppP2PClient client;
    
    protected long updateTime = 10 * 60 * 1000;
    

    private final MessageListener typedListener = new MessageListener() {
        @Override
        public void processMessage(final Chat ch, final Message msg) {
            final String part = ch.getParticipant();
            log.info("Got chat participant: {}", part);
            if (part.startsWith(LANTERN_JID)) {
                log.info("Lantern controlling agent response");
                final String body = msg.getBody();
                log.info("Body: {}", body);
                final Object obj = JSONValue.parse(body);
                final JSONObject json = (JSONObject) obj;
                final JSONArray servers = 
                    (JSONArray) json.get(LanternConstants.SERVERS);
                final Long ut = (Long) json.get(LanternConstants.UPDATE_TIME);
                updateTime = ut;
                log.info("Update time is: {}", ut);
                if (servers == null) {
                    log.info("XMPP: "+XmppUtils.toString(msg));
                } else {
                    final Iterator<String> iter = servers.iterator();
                    if (!servers.isEmpty() &&! Configurator.configured()) {
                        Configurator.configure();
                    }
                    while (iter.hasNext()) {
                        final String server = iter.next();
                        addProxy(server, ch);
                    }
                }
            }
            final Integer type = 
                (Integer) msg.getProperty(P2PConstants.MESSAGE_TYPE);
            if (type!= null) {
                log.info("Not processing typed message");
                //processTypedMessage(msg, type