Changeset e9e550fb


Ignore:
Timestamp:
Jul 7, 2013 7:15:08 PM (7 years ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
aab4a3a
Parents:
f80ea38
Message:

cleanup, sync, more logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/PacketLocal.java

    rf80ea38 re9e550fb  
    22
    33import java.io.IOException;
     4import java.util.Collections;
    45import java.util.Set;
     6import java.util.concurrent.atomic.AtomicInteger;
    57
    68import net.i2p.I2PAppContext;
     
    2224    private final Destination _to;
    2325    private SessionKey _keyUsed;
    24     private Set _tagsSent;
    2526    private final long _createdOn;
    2627    private volatile int _numSends;
    27     private long _lastSend;
     28    private volatile long _lastSend;
    2829    private long _acceptedOn;
    29     private long _ackOn;
     30    /** LOCKING: this */
     31    private long _ackOn;
    3032    private long _cancelledOn;
    31     private volatile int _nackCount;
     33    private final AtomicInteger _nackCount = new AtomicInteger(0);
    3234    private volatile boolean _retransmitted;
    3335    private SimpleTimer2.TimedEvent _resendEvent;
     
    6769     * @deprecated should always return null or an empty set
    6870     */
    69     public Set getTagsSent() { return _tagsSent; }
     71    public Set getTagsSent() { return Collections.EMPTY_SET; }
    7072
    7173    /**
     
    112114    }
    113115    public void ackReceived() {
     116        final long now = _context.clock().now();
    114117        synchronized (this) {
    115118            if (_ackOn <= 0)
    116                 _ackOn = _context.clock().now();
     119                _ackOn = now;
    117120            releasePayload();
    118121            notifyAll();
     
    135138     * @return how long after packet creation the packet was ACKed in ms
    136139     */
    137     public int getAckTime() {
     140    public synchronized int getAckTime() {
    138141        if (_ackOn <= 0)
    139142            return -1;
     
    152155     */
    153156    public void incrementNACKs() {
    154         int cnt = ++_nackCount;
     157        final int cnt = _nackCount.incrementAndGet();
    155158        SimpleTimer2.TimedEvent evt = _resendEvent;
    156159        if (cnt >= Connection.FAST_RETRANSMIT_THRESHOLD && evt != null && (!_retransmitted) &&
     
    158161            _retransmitted = true;
    159162            evt.reschedule(0);
    160         }
    161     }
    162     public int getNACKs() { return _nackCount; }
     163            // shouldn't ^^^ be clock.now() - 4000 ??? --zab
     164           
     165            if (_log.shouldLog(Log.DEBUG)) {
     166                final String log = String.format("%s nacks and retransmits. Criteria: nacks=%d, retransmitted=%b,"+
     167                    " numSends=%d, lastSend=%d, now=%d",
     168                    toString(), cnt, _retransmitted, _numSends, _lastSend, _context.clock().now());
     169                    _log.debug(log);
     170            }
     171        } else if (_log.shouldLog(Log.DEBUG)) {
     172            final String log = String.format("%s nack but no retransmit.  Criteria: nacks=%d, retransmitted=%b,"+
     173                    " numSends=%d, lastSend=%d, now=%d",
     174                    toString(), cnt, _retransmitted, _numSends, _lastSend, _context.clock().now());
     175                    _log.debug(log);
     176        }
     177    }
     178    public int getNACKs() { return _nackCount.get(); }
    163179   
    164180    public void setResendPacketEvent(SimpleTimer2.TimedEvent evt) { _resendEvent = evt; }
     
    174190        //if ( (_tagsSent != null) && (!_tagsSent.isEmpty()) )
    175191        //    buf.append(" with tags");
    176 
    177         if (_nackCount > 0)
    178             buf.append(" nacked ").append(_nackCount).append(" times");
    179 
    180         if (_ackOn > 0)
    181             buf.append(" ack after ").append(getAckTime());
     192        final int nackCount = _nackCount.get();
     193        if (nackCount > 0)
     194            buf.append(" nacked ").append(nackCount).append(" times");
     195
     196        synchronized(this) {
     197            if (_ackOn > 0)
     198                buf.append(" ack after ").append(getAckTime());
     199        }
    182200       
    183201        if (_numSends > 1)
     
    257275    }
    258276   
    259     public boolean writeAccepted() { return _acceptedOn > 0 && _cancelledOn <= 0; }
    260     public boolean writeFailed() { return _cancelledOn > 0; }
    261     public boolean writeSuccessful() { return _ackOn > 0 && _cancelledOn <= 0; }
     277    public synchronized boolean writeAccepted() { return _acceptedOn > 0 && _cancelledOn <= 0; }
     278    public synchronized boolean writeFailed() { return _cancelledOn > 0; }
     279    public synchronized boolean writeSuccessful() { return _ackOn > 0 && _cancelledOn <= 0; }
    262280
    263281    /** Generate a pcap/tcpdump-compatible format,
Note: See TracChangeset for help on using the changeset viewer.