Changeset 79e3223


Ignore:
Timestamp:
Aug 24, 2009 12:06:48 AM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
47c8389
Parents:
0cc72a4 (diff), 80f9f85 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

propagate from branch 'i2p.i2p.zzz.test' (head b1e81b14fbaafdc188ae4d312f843c38b65cc310)

to branch 'i2p.i2p' (head 010351f9470b0e699e17447c87daf6c67e5e5dcc)

Files:
1 added
19 edited
2 moved

Legend:

Unmodified
Added
Removed
  • apps/ministreaming/java/src/net/i2p/client/streaming/package.html

    r0cc72a4 r79e3223  
    1717appropriate {@link net.i2p.client.streaming.I2PSocketManager#connect} call.</p>
    1818
    19 <p>There is a simple pair of demo applications available as well - {@link
    20 net.i2p.client.streaming.StreamSinkServer} listens to a destination and dumps
    21 the data from all sockets it accepts to individual files, while {@link
    22 net.i2p.client.streaming.StreamSinkClient} connects to a particular destination
     19<p>There is a simple pair of demo applications available as well -
     20net.i2p.client.streaming.StreamSinkServer listens to a destination and dumps
     21the data from all sockets it accepts to individual files, while
     22net.i2p.client.streaming.StreamSinkClient connects to a particular destination
    2323and sends a specific amount of random data then disconnects.</p>
    2424</body></html>
  • apps/streaming/java/src/net/i2p/client/streaming/Connection.java

    r0cc72a4 r79e3223  
    355355    }
    356356   
     357/*********
    357358    private class PingNotifier implements ConnectionManager.PingNotifier {
    358359        private long _startedPingOn;
     
    368369        }
    369370    }
     371*********/
    370372   
    371373    List ackPackets(long ackThrough, long nacks[]) {
     
    549551    }
    550552   
     553    /** ignore tag issues */
    551554    private void killOutstandingPackets() {
    552         boolean tagsCancelled = false;
     555        //boolean tagsCancelled = false;
    553556        synchronized (_outboundPackets) {
    554557            for (Iterator iter = _outboundPackets.values().iterator(); iter.hasNext(); ) {
    555558                PacketLocal pl = (PacketLocal)iter.next();
    556                 if ( (pl.getTagsSent() != null) && (pl.getTagsSent().size() > 0) )
    557                     tagsCancelled = true;
     559                //if ( (pl.getTagsSent() != null) && (pl.getTagsSent().size() > 0) )
     560                //    tagsCancelled = true;
    558561                pl.cancelled();
    559562            }
     
    561564            _outboundPackets.notifyAll();
    562565        }           
    563         if (tagsCancelled)
    564             _context.sessionKeyManager().failTags(_remotePeer.getPublicKey());
     566        //if (tagsCancelled)
     567        //    _context.sessionKeyManager().failTags(_remotePeer.getPublicKey());
    565568    }
    566569   
     
    11411144                // in case things really suck, the other side may have lost thier
    11421145                // session tags (e.g. they restarted), so jump back to ElGamal.
    1143                 int failTagsAt = _options.getMaxResends() - 2;
    1144                 if ( (newWindowSize == 1) && (numSends == failTagsAt) ) {
    1145                     if (_log.shouldLog(Log.WARN))
    1146                         _log.warn("Optimistically failing tags at resend " + numSends);
    1147                     _context.sessionKeyManager().failTags(_remotePeer.getPublicKey());
    1148                 }
     1146                //int failTagsAt = _options.getMaxResends() - 2;
     1147                //if ( (newWindowSize == 1) && (numSends == failTagsAt) ) {
     1148                //    if (_log.shouldLog(Log.WARN))
     1149                //        _log.warn("Optimistically failing tags at resend " + numSends);
     1150                //    _context.sessionKeyManager().failTags(_remotePeer.getPublicKey());
     1151                //}
    11491152               
    11501153                if (numSends - 1 > _options.getMaxResends()) {
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    r0cc72a4 r79e3223  
    350350        }
    351351    }
     352
     353    /** blocking */
    352354    public boolean ping(Destination peer, long timeoutMs) {
    353         return ping(peer, timeoutMs, true);
     355        return ping(peer, timeoutMs, true, null);
    354356    }
    355357    public boolean ping(Destination peer, long timeoutMs, boolean blocking) {
    356         return ping(peer, timeoutMs, blocking, null, null, null);
    357     }
    358 
     358        return ping(peer, timeoutMs, blocking, null);
     359    }
     360
     361    /**
     362     * @deprecated I2PSession ignores tags, use non-tag variant
     363     * @param keyToUse ignored
     364     * @param tagsToSend ignored
     365     */
    359366    public boolean ping(Destination peer, long timeoutMs, boolean blocking, SessionKey keyToUse, Set tagsToSend, PingNotifier notifier) {
     367        return ping(peer, timeoutMs, blocking, notifier);
     368    }
     369
     370    public boolean ping(Destination peer, long timeoutMs, boolean blocking, PingNotifier notifier) {
    360371        Long id = new Long(_context.random().nextLong(Packet.MAX_STREAM_ID-1)+1);
    361372        PacketLocal packet = new PacketLocal(_context, peer);
     
    364375        packet.setFlag(Packet.FLAG_SIGNATURE_INCLUDED);
    365376        packet.setOptionalFrom(_session.getMyDestination());
    366         if ( (keyToUse != null) && (tagsToSend != null) ) {
    367             packet.setKeyUsed(keyToUse);
    368             packet.setTagsSent(tagsToSend);
    369         }
     377        //if ( (keyToUse != null) && (tagsToSend != null) ) {
     378        //    packet.setKeyUsed(keyToUse);
     379        //    packet.setTagsSent(tagsToSend);
     380        //}
    370381       
    371382        PingRequest req = new PingRequest(peer, packet, notifier);
     
    436447        public void pong() {
    437448            _log.debug("Ping successful");
    438             _context.sessionKeyManager().tagsDelivered(_peer.getPublicKey(), _packet.getKeyUsed(), _packet.getTagsSent());
     449            //_context.sessionKeyManager().tagsDelivered(_peer.getPublicKey(), _packet.getKeyUsed(), _packet.getTagsSent());
    439450            synchronized (ConnectionManager.PingRequest.this) {
    440451                _ponged = true;
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionPacketHandler.java

    r0cc72a4 r79e3223  
    264264               
    265265                // ACK the tags we delivered so we can use them
    266                 if ( (p.getKeyUsed() != null) && (p.getTagsSent() != null)
    267                       && (p.getTagsSent().size() > 0) ) {
    268                     _context.sessionKeyManager().tagsDelivered(p.getTo().getPublicKey(),
    269                                                                p.getKeyUsed(),
    270                                                                p.getTagsSent());
    271                 }
     266                //if ( (p.getKeyUsed() != null) && (p.getTagsSent() != null)
     267                //      && (p.getTagsSent().size() > 0) ) {
     268                //    _context.sessionKeyManager().tagsDelivered(p.getTo().getPublicKey(),
     269                //                                               p.getKeyUsed(),
     270                //                                               p.getTagsSent());
     271                //}
    272272                if (_log.shouldLog(Log.DEBUG))
    273273                    _log.debug("Packet acked after " + p.getAckTime() + "ms: " + p);
  • apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java

    r0cc72a4 r79e3223  
    4848    public void setTo(Destination to) { _to = to; }
    4949   
     50    /**
     51     * @deprecated should always return null
     52     */
    5053    public SessionKey getKeyUsed() { return _keyUsed; }
    51     public void setKeyUsed(SessionKey key) { _keyUsed = key; }
    52    
     54
     55    /**
     56     * @deprecated I2PSession throws out the tags
     57     */
     58    public void setKeyUsed(SessionKey key) {
     59        if (key != null)
     60            _log.error("Who is sending tags thru the streaming lib?");
     61        _keyUsed = key;
     62    }
     63   
     64    /**
     65     * @deprecated should always return null or an empty set
     66     */
    5367    public Set getTagsSent() { return _tagsSent; }
     68
     69    /**
     70     * @deprecated I2PSession throws out the tags
     71     */
    5472    public void setTagsSent(Set tags) {
     73        if (tags != null && tags.size() > 0)
     74            _log.error("Who is sending tags thru the streaming lib? " + tags.size());
    5575        if ( (_tagsSent != null) && (_tagsSent.size() > 0) && (tags.size() > 0) ) {
    5676            //int old = _tagsSent.size();
  • apps/streaming/java/src/net/i2p/client/streaming/PacketQueue.java

    r0cc72a4 r79e3223  
    3737    /**
    3838     * Add a new packet to be sent out ASAP
     39     *
     40     * keys and tags disabled since dropped in I2PSession
    3941     */
    4042    public void enqueue(PacketLocal packet) {
    4143        packet.prepare();
    4244       
    43         SessionKey keyUsed = packet.getKeyUsed();
    44         if (keyUsed == null)
    45             keyUsed = new SessionKey();
    46         Set tagsSent = packet.getTagsSent();
    47         if (tagsSent == null)
    48             tagsSent = new HashSet(0);
     45        //SessionKey keyUsed = packet.getKeyUsed();
     46        //if (keyUsed == null)
     47        //    keyUsed = new SessionKey();
     48        //Set tagsSent = packet.getTagsSent();
     49        //if (tagsSent == null)
     50        //    tagsSent = new HashSet(0);
    4951
    5052        // cache this from before sendMessage
     
    9395                //sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent, expires);
    9496                // I2PSessionMuxedImpl
    95                 sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent, expires,
     97                //sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent, expires,
     98                //                 I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
     99                // I2PSessionMuxedImpl no tags
     100                sent = _session.sendMessage(packet.getTo(), buf, 0, size, null, null, expires,
    96101                                 I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
    97102            else
     
    99104                //sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent, 0);
    100105                // I2PSessionMuxedImpl
    101                 sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent,
     106                //sent = _session.sendMessage(packet.getTo(), buf, 0, size, keyUsed, tagsSent,
     107                //                 I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
     108                // I2PSessionMuxedImpl no tags
     109                sent = _session.sendMessage(packet.getTo(), buf, 0, size, null, null,
    102110                                 I2PSession.PROTO_STREAMING, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED);
    103111            end = _context.clock().now();
     
    130138                c.disconnect(false);
    131139        } else {
    132             packet.setKeyUsed(keyUsed);
    133             packet.setTagsSent(tagsSent);
     140            //packet.setKeyUsed(keyUsed);
     141            //packet.setTagsSent(tagsSent);
    134142            packet.incrementSends();
    135143            if (_log.shouldLog(Log.DEBUG)) {
    136                 String msg = "SEND " + packet + (tagsSent.size() > 0
    137                              ? " with " + tagsSent.size() + " tags"
    138                              : "")
     144                String msg = "SEND " + packet
    139145                             + " send # " + packet.getNumSends()
    140146                             + " sendTime: " + (end-begin)
  • core/java/src/net/i2p/client/I2CPMessageProducer.java

    r0cc72a4 r79e3223  
    9494     * Package up and send the payload to the router for delivery
    9595     *
     96     * @param tag unused - no end-to-end crypto
     97     * @param tags unused - no end-to-end crypto
     98     * @param key unused - no end-to-end crypto
     99     * @param newKey unused - no end-to-end crypto
    96100     */
    97101    public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload, SessionTag tag,
     
    136140     * Create a new signed payload and send it off to the destination
    137141     *
     142     * @param tag unused - no end-to-end crypto
     143     * @param tags unused - no end-to-end crypto
     144     * @param key unused - no end-to-end crypto
     145     * @param newKey unused - no end-to-end crypto
    138146     */
    139147    private Payload createPayload(Destination dest, byte[] payload, SessionTag tag, SessionKey key, Set tags,
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    r0cc72a4 r79e3223  
    356356    public abstract boolean sendMessage(Destination dest, byte[] payload) throws I2PSessionException;
    357357   
     358    /**
     359     * @param keyUsed unused - no end-to-end crypto
     360     * @param tagsSent unused - no end-to-end crypto
     361     */
    358362    public abstract boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed,
    359363                                        Set tagsSent) throws I2PSessionException;
     
    361365    public abstract void receiveStatus(int msgId, long nonce, int status);
    362366
     367/****** no end-to-end crypto
    363368    protected static final Set createNewTags(int num) {
    364369        Set tags = new HashSet();
     
    367372        return tags;
    368373    }
     374*******/
    369375
    370376    /**
  • core/java/src/net/i2p/client/I2PSessionImpl2.java

    r0cc72a4 r79e3223  
    134134    }
    135135   
     136    /**
     137     * @param keyUsed unused - no end-to-end crypto
     138     * @param tagsSent unused - no end-to-end crypto
     139     */
    136140    @Override
    137141    public boolean sendMessage(Destination dest, byte[] payload, SessionKey keyUsed, Set tagsSent) throws I2PSessionException {
    138142        return sendMessage(dest, payload, 0, payload.length, keyUsed, tagsSent, 0);
    139143    }
     144
     145    /**
     146     * @param keyUsed unused - no end-to-end crypto
     147     * @param tagsSent unused - no end-to-end crypto
     148     */
    140149    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent)
    141150                   throws I2PSessionException {
    142151        return sendMessage(dest, payload, offset, size, keyUsed, tagsSent, 0);
    143152    }
     153
     154    /**
     155     * @param keyUsed unused - no end-to-end crypto
     156     * @param tagsSent unused - no end-to-end crypto
     157     */
    144158    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expires)
    145159                   throws I2PSessionException {
     
    197211    private static final int NUM_TAGS = 50;
    198212
     213    /**
     214     * @param keyUsed unused - no end-to-end crypto
     215     * @param tagsSent unused - no end-to-end crypto
     216     */
    199217    protected boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent, long expires)
    200218                    throws I2PSessionException {
    201         SessionKey key = null;
    202         SessionKey newKey = null;
    203         SessionTag tag = null;
    204         Set sentTags = null;
    205         int oldTags = 0;
     219        //SessionKey key = null;
     220        //SessionKey newKey = null;
     221        //SessionTag tag = null;
     222        //Set sentTags = null;
     223        //int oldTags = 0;
    206224        long begin = _context.clock().now();
    207225        /***********
     
    257275        if (_log.shouldLog(Log.DEBUG)) _log.debug("before sync state");
    258276        MessageState state = new MessageState(_context, nonce, getPrefix());
    259         state.setKey(key);
    260         state.setTags(sentTags);
    261         state.setNewKey(newKey);
     277        //state.setKey(key);
     278        //state.setTags(sentTags);
     279        //state.setNewKey(newKey);
    262280        state.setTo(dest);
    263         if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "Setting key = " + key);
    264 
    265         if (keyUsed != null) {
     281        //if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "Setting key = " + key);
     282
     283        //if (keyUsed != null) {
    266284            //if (I2CPMessageProducer.END_TO_END_CRYPTO) {
    267285            //    if (newKey != null)
     
    270288            //        keyUsed.setData(key.getData());
    271289            //} else {
    272                 keyUsed.setData(SessionKey.INVALID_KEY.getData());
     290            //    keyUsed.setData(SessionKey.INVALID_KEY.getData());
    273291            //}
    274         }
    275         if (tagsSent != null) {
    276             if (sentTags != null) {
    277                 tagsSent.addAll(sentTags);
    278             }
    279         }
     292        //}
     293        //if (tagsSent != null) {
     294        //    if (sentTags != null) {
     295        //        tagsSent.addAll(sentTags);
     296        //    }
     297        //}
    280298
    281299        if (_log.shouldLog(Log.DEBUG)) _log.debug("before sync state");
     
    292310                       + " sync took " + (inSendingSync-beforeSendingSync)
    293311                       + " add took " + (afterSendingSync-inSendingSync));
    294         _producer.sendMessage(this, dest, nonce, payload, tag, key, sentTags, newKey, expires);
     312        //_producer.sendMessage(this, dest, nonce, payload, tag, key, sentTags, newKey, expires);
     313        _producer.sendMessage(this, dest, nonce, payload, null, null, null, null, expires);
    295314       
    296315        // since this is 'best effort', all we're waiting for is a status update
  • core/java/src/net/i2p/client/I2PSessionMuxedImpl.java

    r0cc72a4 r79e3223  
    129129    }
    130130
     131    /**
     132     * @param keyUsed unused - no end-to-end crypto
     133     * @param tagsSent unused - no end-to-end crypto
     134     */
    131135    @Override
    132136    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size,
     
    136140    }
    137141
     142    /**
     143     * @param keyUsed unused - no end-to-end crypto
     144     * @param tagsSent unused - no end-to-end crypto
     145     */
    138146    @Override
    139147    public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent,
     
    143151
    144152    /**
     153     *  @param keyUsed unused - no end-to-end crypto
     154     *  @param tagsSent unused - no end-to-end crypto
    145155     *  @param proto 1-254 or 0 for unset; recommended:
    146156     *         I2PSession.PROTO_UNSPECIFIED
  • core/java/src/net/i2p/client/MessagePayloadMessageHandler.java

    r0cc72a4 r79e3223  
    2222 * of a message by accepting it, decrypting the payload, adding it to the set of
    2323 * recieved messages, and telling the router that it has been recieved correctly.
     24 *
     25 * We don't really decrypt (no more end-to-end crypto)
    2426 *
    2527 * @author jrandom
     
    5254    /**
    5355     * Decrypt the payload
     56     *
     57     * We don't really decrypt (no more end-to-end crypto)
     58     * If we do, we need to use the correct key manager in the decrypt() call below
    5459     */
    5560    private Payload decryptPayload(MessagePayloadMessage msg, I2PSessionImpl session) throws DataFormatException {
    5661        Payload payload = msg.getPayload();
    57         if (!I2CPMessageProducer.END_TO_END_CRYPTO) {
     62        //if (!I2CPMessageProducer.END_TO_END_CRYPTO) {
    5863            payload.setUnencryptedData(payload.getEncryptedData());
    5964            return payload;
    60         }
     65        //}
    6166           
    62         byte[] data = _context.elGamalAESEngine().decrypt(payload.getEncryptedData(), session.getDecryptionKey());
    63         if (data == null) {
    64             if (_log.shouldLog(Log.WARN))
    65                 _log.warn("Error decrypting the payload");
    66             throw new DataFormatException("Unable to decrypt the payload");
    67         }
    68         payload.setUnencryptedData(data);
    69         return payload;
     67        //byte[] data = _context.elGamalAESEngine().decrypt(payload.getEncryptedData(), session.getDecryptionKey());
     68        //if (data == null) {
     69        //    if (_log.shouldLog(Log.WARN))
     70        //        _log.warn("Error decrypting the payload");
     71        //    throw new DataFormatException("Unable to decrypt the payload");
     72        //}
     73        //payload.setUnencryptedData(data);
     74        //return payload;
    7075    }
    7176}
  • core/java/src/net/i2p/crypto/HMAC256Generator.java

    r0cc72a4 r79e3223  
    1313/**
    1414 * Calculate the HMAC-SHA256 of a key+message.  All the good stuff occurs
    15  * in {@link org.bouncycastle.crypto.macs.HMac} and
     15 * in {@link org.bouncycastle.crypto.macs.I2PHMac} and
    1616 * {@link org.bouncycastle.crypto.digests.MD5Digest}.
    1717 *
  • core/java/src/net/i2p/crypto/HMACGenerator.java

    r0cc72a4 r79e3223  
    1616/**
    1717 * Calculate the HMAC-MD5 of a key+message.  All the good stuff occurs
    18  * in {@link org.bouncycastle.crypto.macs.HMac} and
     18 * in {@link org.bouncycastle.crypto.macs.I2PHMac} and
    1919 * {@link org.bouncycastle.crypto.digests.MD5Digest}.
    2020 *
  • core/java/src/net/i2p/crypto/SessionKeyManager.java

    r0cc72a4 r79e3223  
    1010 */
    1111
     12import java.io.IOException;
     13import java.io.Writer;
    1214import java.util.Set;
    1315
     
    131133    public void shutdown() { // nop
    132134    }
     135
     136    public void renderStatusHTML(Writer out) throws IOException {}
    133137}
  • core/java/src/net/i2p/crypto/TransientSessionKeyManager.java

    r0cc72a4 r79e3223  
    1010 */
    1111
     12import java.io.IOException;
     13import java.io.Writer;
    1214import java.util.ArrayList;
     15import java.util.Comparator;
    1316import java.util.Date;
    1417import java.util.HashMap;
     
    1821import java.util.Map;
    1922import java.util.Set;
     23import java.util.TreeSet;
    2024
    2125import net.i2p.I2PAppContext;
     
    504508    }
    505509
    506     public String renderStatusHTML() {
     510    @Override
     511    public void renderStatusHTML(Writer out) throws IOException {
    507512        StringBuilder buf = new StringBuilder(1024);
    508         buf.append("<h2>Inbound sessions</h2>");
    509         buf.append("<table>");
     513        buf.append("<h2>Inbound sessions</h2>" +
     514                   "<table>");
    510515        Set<TagSet> inbound = getInboundTagSets();
    511516        Map<SessionKey, Set<TagSet>> inboundSets = new HashMap(inbound.size());
     517        // Build a map of the inbound tag sets, grouped by SessionKey
    512518        for (Iterator<TagSet> iter = inbound.iterator(); iter.hasNext();) {
    513519            TagSet ts = iter.next();
     
    516522            sets.add(ts);
    517523        }
     524        int total = 0;
     525        long now = _context.clock().now();
    518526        for (Iterator<SessionKey> iter = inboundSets.keySet().iterator(); iter.hasNext();) {
    519527            SessionKey skey = iter.next();
    520             Set<TagSet> sets = inboundSets.get(skey);
    521             buf.append("<tr><td><b>Session key</b>: ").append(skey.toBase64()).append("</td>");
    522             buf.append("<td><b># Sets:</b> ").append(sets.size()).append("</td></tr>");
    523             buf.append("<tr><td colspan=\"2\"><ul>");
     528            Set<TagSet> sets = new TreeSet(new TagSetComparator());
     529            sets.addAll(inboundSets.get(skey));
     530            buf.append("<tr><td><b>Session key</b>: ").append(skey.toBase64()).append("</td>" +
     531                       "<td><b># Sets:</b> ").append(sets.size()).append("</td></tr>" +
     532                       "<tr><td colspan=\"2\"><ul>");
    524533            for (Iterator<TagSet> siter = sets.iterator(); siter.hasNext();) {
    525534                TagSet ts = siter.next();
    526                 buf.append("<li><b>Received on:</b> ").append(new Date(ts.getDate())).append(" with ")
    527                    .append(ts.getTags().size()).append(" tags remaining</li>");
    528             }
    529             buf.append("</ul></td></tr>");
    530         }
    531         buf.append("</table>");
    532 
    533         buf.append("<h2><b>Outbound sessions</b></h2>");
    534 
    535         buf.append("<table>");
     535                int size = ts.getTags().size();
     536                total += size;
     537                buf.append("<li><b>Received:</b> ").append(DataHelper.formatDuration(now - ts.getDate())).append(" ago with ");
     538                buf.append(size).append(" tags remaining</li>");
     539            }
     540            buf.append("</ul></td></tr>\n");
     541            out.write(buf.toString());
     542            buf.setLength(0);
     543        }
     544        buf.append("<tr><th colspan=\"2\">Total tags: ").append(total).append(" (");
     545        buf.append(DataHelper.formatSize(32*total)).append("B)</th></tr>\n" +
     546                   "</table>" +
     547                   "<h2><b>Outbound sessions</b></h2>" +
     548                   "<table>");
     549        total = 0;
    536550        Set<OutboundSession> outbound = getOutboundSessions();
    537551        for (Iterator<OutboundSession> iter = outbound.iterator(); iter.hasNext();) {
    538552            OutboundSession sess = iter.next();
    539             buf.append("<tr><td><b>Target key:</b> ").append(sess.getTarget().toString()).append("<br>");
    540             buf.append("<b>Established:</b> ").append(new Date(sess.getEstablishedDate())).append("<br>");
    541             buf.append("<b>Last Used:</b> ").append(new Date(sess.getLastUsedDate())).append("<br>");
    542             buf.append("<b># Sets:</b> ").append(sess.getTagSets().size()).append("</td></tr>");
    543             buf.append("<tr><td><b>Session key:</b> ").append(sess.getCurrentKey().toBase64()).append("</td></tr>");
    544             buf.append("<tr><td><ul>");
    545             for (Iterator<TagSet> siter = sess.getTagSets().iterator(); siter.hasNext();) {
     553            Set<TagSet> sets = new TreeSet(new TagSetComparator());
     554            sets.addAll(sess.getTagSets());
     555            buf.append("<tr><td><b>Target key:</b> ").append(sess.getTarget().toBase64().substring(0, 64)).append("<br>" +
     556                       "<b>Established:</b> ").append(DataHelper.formatDuration(now - sess.getEstablishedDate())).append(" ago<br>" +
     557                       "<b>Last Used:</b> ").append(DataHelper.formatDuration(now - sess.getLastUsedDate())).append(" ago<br>" +
     558                       "<b>Session key:</b> ").append(sess.getCurrentKey().toBase64()).append("</td>" +
     559                       "<td><b># Sets:</b> ").append(sess.getTagSets().size()).append("</td></tr>" +
     560                       "<tr><td colspan=\"2\"><ul>");
     561            for (Iterator<TagSet> siter = sets.iterator(); siter.hasNext();) {
    546562                TagSet ts = siter.next();
    547                 buf.append("<li><b>Sent on:</b> ").append(new Date(ts.getDate())).append(" with ").append(
    548                                                                                                           ts.getTags()
    549                                                                                                             .size())
    550                    .append(" tags remaining</li>");
    551             }
    552             buf.append("</ul></td></tr>");
    553         }
    554         buf.append("</table>");
    555 
    556         return buf.toString();
     563                int size = ts.getTags().size();
     564                total += size;
     565                buf.append("<li><b>Sent:</b> ").append(DataHelper.formatDuration(now - ts.getDate())).append(" ago with ");
     566                buf.append(size).append(" tags remaining</li>");
     567            }
     568            buf.append("</ul></td></tr>\n");
     569            out.write(buf.toString());
     570            buf.setLength(0);
     571        }
     572        buf.append("<tr><th colspan=\"2\">Total tags: ").append(total).append(" (");
     573        buf.append(DataHelper.formatSize(32*total)).append("B)</th></tr>\n" +
     574                   "</table>");
     575
     576        out.write(buf.toString());
     577    }
     578
     579    /**
     580     *  Just for the HTML method above so we can see what's going on easier
     581     *  Earliest first
     582     */
     583    private class TagSetComparator implements Comparator {
     584         public int compare(Object l, Object r) {
     585             return (int) (((TagSet)l).getDate() - ((TagSet)r).getDate());
     586        }
    557587    }
    558588
     
    761791        public int hashCode() {
    762792            long rv = 0;
    763             if (_key != null) rv = rv * 7 + _key.hashCode();
     793            if (_key != null) rv = _key.hashCode();
    764794            rv = rv * 7 + _date;
    765795            // no need to hashCode the tags, key + date should be enough
  • router/java/src/net/i2p/router/ClientManagerFacade.java

    r0cc72a4 r79e3223  
    8686     * @return set of Destination objects
    8787     */
    88     public Set listClients() { return Collections.EMPTY_SET; }
     88    public Set<Destination> listClients() { return Collections.EMPTY_SET; }
    8989   
    9090    /**
     
    9393     */
    9494    public abstract SessionConfig getClientSessionConfig(Destination dest);
    95     public abstract SessionKeyManager getClientSessionKeyManager(Destination dest);
     95    public abstract SessionKeyManager getClientSessionKeyManager(Hash dest);
    9696    public void renderStatusHTML(Writer out) throws IOException { }
    9797}
  • router/java/src/net/i2p/router/DummyClientManagerFacade.java

    r0cc72a4 r79e3223  
    4242   
    4343    public SessionConfig getClientSessionConfig(Destination _dest) { return null; }
    44     public SessionKeyManager getClientSessionKeyManager(Destination _dest) { return null; }
     44    public SessionKeyManager getClientSessionKeyManager(Hash _dest) { return null; }
    4545   
    4646    public void requestLeaseSet(Hash dest, LeaseSet set) {}
  • router/java/src/net/i2p/router/client/ClientManager.java

    r0cc72a4 r79e3223  
    4343    private Log _log;
    4444    private ClientListenerRunner _listener;
    45     private final HashMap _runners;        // Destination --> ClientConnectionRunner
    46     private final Set _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
     45    private final HashMap<Destination, ClientConnectionRunner> _runners;        // Destination --> ClientConnectionRunner
     46    private final Set<ClientConnectionRunner> _pendingRunners; // ClientConnectionRunner for clients w/out a Dest yet
    4747    private RouterContext _ctx;
    4848
     
    9191        _log.info("Shutting down the ClientManager");
    9292        _listener.stopListening();
    93         Set runners = new HashSet();
    94         synchronized (_runners) {
    95             for (Iterator iter = _runners.values().iterator(); iter.hasNext();) {
    96                 ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     93        Set<ClientConnectionRunner> runners = new HashSet();
     94        synchronized (_runners) {
     95            for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext();) {
     96                ClientConnectionRunner runner = iter.next();
    9797                runners.add(runner);
    9898            }
    9999        }
    100100        synchronized (_pendingRunners) {
    101             for (Iterator iter = _pendingRunners.iterator(); iter.hasNext();) {
    102                 ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     101            for (Iterator<ClientConnectionRunner> iter = _pendingRunners.iterator(); iter.hasNext();) {
     102                ClientConnectionRunner runner = iter.next();
    103103                runners.add(runner);
    104104            }
    105105        }
    106         for (Iterator iter = runners.iterator(); iter.hasNext(); ) {
    107             ClientConnectionRunner runner = (ClientConnectionRunner)iter.next();
     106        for (Iterator<ClientConnectionRunner> iter = runners.iterator(); iter.hasNext(); ) {
     107            ClientConnectionRunner runner = iter.next();
    108108            runner.stopRunning();
    109109        }
     
    132132    }
    133133   
     134    /**
     135     * Add to the clients list. Check for a dup destination.
     136     */
    134137    public void destinationEstablished(ClientConnectionRunner runner) {
     138        Destination dest = runner.getConfig().getDestination();
    135139        if (_log.shouldLog(Log.DEBUG))
    136             _log.debug("DestinationEstablished called for destination " + runner.getConfig().getDestination().calculateHash().toBase64());
     140            _log.debug("DestinationEstablished called for destination " + dest.calculateHash().toBase64());
    137141
    138142        synchronized (_pendingRunners) {
    139143            _pendingRunners.remove(runner);
    140144        }
    141         synchronized (_runners) {
    142             _runners.put(runner.getConfig().getDestination(), runner);
     145        boolean fail = false;
     146        synchronized (_runners) {
     147            fail = _runners.containsKey(dest);
     148            if (!fail)
     149                _runners.put(dest, runner);
     150        }
     151        if (fail) {
     152            _log.log(Log.CRIT, "Client attempted to register duplicate destination " + dest.calculateHash().toBase64());
     153            runner.disconnectClient("Duplicate destination");
    143154        }
    144155    }
     
    279290    }
    280291
    281     public Set listClients() {
    282         Set rv = new HashSet();
     292    public Set<Destination> listClients() {
     293        Set<Destination> rv = new HashSet();
    283294        synchronized (_runners) {
    284295            rv.addAll(_runners.keySet());
     
    294305        synchronized (_runners) {
    295306            inLock = _ctx.clock().now();
    296             rv = (ClientConnectionRunner)_runners.get(dest);
     307            rv = _runners.get(dest);
    297308        }
    298309        long afterLock = _ctx.clock().now();
     
    318329    /**
    319330     * Return the client's SessionKeyManager
    320      *
     331     * Use this instead of the RouterContext.sessionKeyManager()
     332     * to prevent correlation attacks across destinations
    321333     */
    322     public SessionKeyManager getClientSessionKeyManager(Destination dest) {
     334    public SessionKeyManager getClientSessionKeyManager(Hash dest) {
    323335        ClientConnectionRunner runner = getRunner(dest);
    324336        if (runner != null)
     
    332344            return null;
    333345        synchronized (_runners) {
    334             for (Iterator iter = _runners.values().iterator(); iter.hasNext(); ) {
    335                 ClientConnectionRunner cur = (ClientConnectionRunner)iter.next();
     346            for (Iterator<ClientConnectionRunner> iter = _runners.values().iterator(); iter.hasNext(); ) {
     347                ClientConnectionRunner cur = iter.next();
    336348                if (cur.getDestHash().equals(destHash))
    337349                    return cur;
     
    355367    }
    356368   
    357     Set getRunnerDestinations() {
    358         Set dests = new HashSet();
     369    Set<Destination> getRunnerDestinations() {
     370        Set<Destination> dests = new HashSet();
    359371        long beforeLock = _ctx.clock().now();
    360372        long inLock = 0;
     
    391403        buf.append("<u><b>Local destinations</b></u><br>");
    392404       
    393         Map runners = null;
     405        Map<Destination, ClientConnectionRunner> runners = null;
    394406        synchronized (_runners) {
    395407            runners = (Map)_runners.clone();
    396408        }
    397         for (Iterator iter = runners.keySet().iterator(); iter.hasNext(); ) {
    398             Destination dest = (Destination)iter.next();
    399             ClientConnectionRunner runner = (ClientConnectionRunner)runners.get(dest);
     409        for (Iterator<Destination> iter = runners.keySet().iterator(); iter.hasNext(); ) {
     410            Destination dest = iter.next();
     411            ClientConnectionRunner runner = runners.get(dest);
    400412            buf.append("<b>*</b> ").append(dest.calculateHash().toBase64().substring(0,6)).append("<br>\n");
    401413            LeaseSet ls = runner.getLeaseSet();
  • router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java

    r0cc72a4 r79e3223  
    195195     *
    196196     */
    197     public SessionKeyManager getClientSessionKeyManager(Destination dest) {
     197    public SessionKeyManager getClientSessionKeyManager(Hash dest) {
    198198        if (_manager != null)
    199199            return _manager.getClientSessionKeyManager(dest);
     
    216216     */
    217217    @Override
    218     public Set listClients() {
     218    public Set<Destination> listClients() {
    219219        if (_manager != null)
    220220            return _manager.listClients();
Note: See TracChangeset for help on using the changeset viewer.