Changeset 4322cb3


Ignore:
Timestamp:
Dec 17, 2011 6:52:23 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a2454e8e
Parents:
a7311a57 (diff), b18e7c7 (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:

merge of '0035c4f64c2b0f23c9e007363b634f360e2f10cb'

and '0c2d5fea1f036773ef51ce22d9d8c4e9203ee5f3'

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Storage.java

    ra7311a57 r4322cb3  
    2424import java.io.IOException;
    2525import java.io.RandomAccessFile;
     26import java.nio.charset.Charset;
     27import java.nio.charset.CharsetEncoder;
    2628import java.security.MessageDigest;
    2729import java.util.ArrayList;
    2830import java.util.Iterator;
    2931import java.util.List;
     32import java.util.Map;
    3033import java.util.StringTokenizer;
     34import java.util.concurrent.ConcurrentHashMap;
    3135
    3236import net.i2p.crypto.SHA1;
     
    6771  public static final int MAX_PIECES = 10*1024;
    6872  public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;
     73
     74  private static final Map<String, String> _filterNameCache = new ConcurrentHashMap();
    6975
    7076  /**
     
    569575   * Removes 'suspicious' characters from the given file name.
    570576   * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
     577   * Then replace chars not supported in the charset.
     578   *
     579   * This is called frequently and it can be pretty slow so cache the result.
     580   *
     581   * TODO: If multiple files in the same torrent map to the same filter name,
     582   * the whole torrent will blow up. Check at torrent creation?
    571583   */
    572584  public static String filterName(String name)
    573585  {
    574     if (name.equals(".") || name.equals(" "))
    575         return "_";
    576     String rv = name;
    577     if (rv.startsWith("."))
    578         rv = '_' + rv.substring(1);
    579     if (rv.endsWith(".") || rv.endsWith(" "))
    580         rv = rv.substring(0, rv.length() - 1) + '_';
    581     for (int i = 0; i < ILLEGAL.length; i++) {
    582         if (rv.indexOf(ILLEGAL[i]) >= 0)
    583             rv = rv.replace(ILLEGAL[i], '_');
    584     }
     586    String rv = _filterNameCache.get(name);
     587    if (rv != null)
     588        return rv;
     589    if (name.equals(".") || name.equals(" ")) {
     590        rv = "_";
     591    } else {
     592        rv = name;
     593        if (rv.startsWith("."))
     594            rv = '_' + rv.substring(1);
     595        if (rv.endsWith(".") || rv.endsWith(" "))
     596            rv = rv.substring(0, rv.length() - 1) + '_';
     597        for (int i = 0; i < ILLEGAL.length; i++) {
     598            if (rv.indexOf(ILLEGAL[i]) >= 0)
     599                rv = rv.replace(ILLEGAL[i], '_');
     600        }
     601        // Replace characters not supported in the charset
     602        if (!Charset.defaultCharset().name().equals("UTF-8")) {
     603            try {
     604                CharsetEncoder enc = Charset.defaultCharset().newEncoder();
     605                if (!enc.canEncode(rv)) {
     606                    String repl = rv;
     607                    for (int i = 0; i < rv.length(); i++) {
     608                        char c = rv.charAt(i);
     609                        if (!enc.canEncode(c))
     610                            repl = repl.replace(c, '_');
     611                    }
     612                    rv = repl;
     613                }
     614            } catch (Exception ex) {
     615                ex.printStackTrace();
     616            }
     617    }   }
     618    _filterNameCache.put(name, rv);
    585619    return rv;
    586620  }
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    ra7311a57 r4322cb3  
    17601760            //buf.append("<br>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">")
    17611761            //   .append(MAGGOT).append(hex).append(':').append(hex).append("</a>");
     1762            buf.append("<br>").append(_("Torrent file")).append(": ").append(snark.getName());
    17621763            buf.append("</div></th></tr>");
    17631764        }
  • build.xml

    ra7311a57 r4322cb3  
    889889        </exec>
    890890        <exec executable="echo" osfamily="unix" failifexecutionfails="true" output="pkg-temp/history.txt" append="true">
    891             <arg value="EARLIER HISTORY IS AVAILABLE IN THE SOURCE PACKAGE" />
     891            <arg value="&#10;&#10;----------------&#10;&#10;EARLIER HISTORY IS AVAILABLE IN THE SOURCE PACKAGE" />
    892892        </exec>
    893893        <copy file="installer/resources/deletelist.txt" todir="pkg-temp/" />
  • core/java/src/net/i2p/util/SimpleTimer2.java

    ra7311a57 r4322cb3  
    236236                _log.warn(_pool + " wtf, early execution " + delay + ": " + this);
    237237            else if (_log.shouldLog(Log.WARN) && delay < -1000)
    238                 _log.warn(" wtf, late execution " + delay + ": " + this + _pool.debug());
     238                _log.warn(" wtf, late execution " + (0 - delay) + ": " + this + _pool.debug());
    239239            try {
    240240                timeReached();
  • history.txt

    ra7311a57 r4322cb3  
     12011-12-17 zzz
     2  * i2psnark:
     3    - Replace file name characters not supported in default charset
     4    - Add torrent file name to local details page
     5  * GeoIP: Reduce thread priority during lookup
     6  * ProfileManager: Make some methods non-blocking to reduce
     7                    lock contention in transports
     8
    192011-12-15 kytv
    210  * Swedish translation updates from Transifex
  • router/java/src/net/i2p/router/InNetMessagePool.java

    ra7311a57 r4322cb3  
    147147            //    level = Log.INFO;
    148148            if (_log.shouldLog(level))
    149                 _log.log(level, "Duplicate message received [" + messageBody.getUniqueId()
    150                           + " expiring on " + exp + "]: " + messageBody.getClass().getName() + ": " + invalidReason
     149                _log.log(level, "Dropping message [" + messageBody.getUniqueId()
     150                          + " expiring on " + exp + "]: " + messageBody.getClass().getSimpleName() + ": " + invalidReason
    151151                          + ": " + messageBody);
    152152            _context.statManager().addRateData("inNetPool.dropped", 1, 0);
     153            // FIXME not necessarily a duplicate, could be expired too long ago / too far in future
    153154            _context.statManager().addRateData("inNetPool.duplicate", 1, 0);
    154155            _context.messageHistory().droppedOtherMessage(messageBody, (fromRouter != null ? fromRouter.calculateHash() : fromRouterHash));
    155156            _context.messageHistory().messageProcessingError(messageBody.getUniqueId(),
    156                                                                 messageBody.getClass().getName(),
     157                                                                messageBody.getClass().getSimpleName(),
    157158                                                                "Duplicate/expired");
    158159            return -1;
  • router/java/src/net/i2p/router/RouterVersion.java

    ra7311a57 r4322cb3  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 21;
     21    public final static long BUILD = 22;
    2222
    2323    /** for example "-test" */
    24     public final static String EXTRA = "";
     24    public final static String EXTRA = "-rc";
    2525    public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
    2626    public static void main(String args[]) {
  • router/java/src/net/i2p/router/message/GarlicMessageReceiver.java

    ra7311a57 r4322cb3  
    113113                           + " expiration " + howLongAgo + " ago: " + invalidReason + ": " + clove);
    114114            _context.messageHistory().messageProcessingError(clove.getCloveId(),
    115                                                              clove.getData().getClass().getName(),
     115                                                             clove.getData().getClass().getSimpleName(),
    116116                                                             "Clove is not valid (expiration " + howLongAgo + " ago)");
    117117        }
  • router/java/src/net/i2p/router/peermanager/ProfileManagerImpl.java

    ra7311a57 r4322cb3  
    2222import net.i2p.util.Log;
    2323
     24/**
     25 *  Methods to update profiles.
     26 *  Unless otherwise noted, methods are blocking on the reorganize lock.
     27 */
    2428public class ProfileManagerImpl implements ProfileManager {
    2529    private final Log _log;
     
    3438     * Note that it took msToSend to send a message of size bytesSent to the peer over the transport.
    3539     * This should only be called if the transport considered the send successful.
    36      *
     40     * Non-blocking. Will not update the profile if we can't get the lock.
    3741     */
    3842    public void messageSent(Hash peer, String transport, long msToSend, long bytesSent) {
    39         PeerProfile data = getProfile(peer);
     43        PeerProfile data = getProfileNonblocking(peer);
    4044        if (data == null) return;
    4145        data.setLastSendSuccessful(_context.clock().now());
     
    4448   
    4549    /**
    46      * Note that the router failed to send a message to the peer over the transport specified
    47      *
     50     * Note that the router failed to send a message to the peer over the transport specified.
     51     * Non-blocking. Will not update the profile if we can't get the lock.
    4852     */
    4953    public void messageFailed(Hash peer, String transport) {
    50         PeerProfile data = getProfile(peer);
     54        PeerProfile data = getProfileNonblocking(peer);
    5155        if (data == null) return;
    5256        data.setLastSendFailed(_context.clock().now());
     
    5458   
    5559    /**
    56      * Note that the router failed to send a message to the peer over any transport
    57      *
     60     * Note that the router failed to send a message to the peer over any transport.
     61     * Non-blocking. Will not update the profile if we can't get the lock.
    5862     */
    5963    public void messageFailed(Hash peer) {
    60         PeerProfile data = getProfile(peer);
     64        PeerProfile data = getProfileNonblocking(peer);
    6165        if (data == null) return;
    6266        data.setLastSendFailed(_context.clock().now());
     
    7175            _log.info("Comm error occurred for peer " + peer.toBase64(), new Exception("Comm error"));
    7276        PeerProfile data = getProfile(peer);
    73         if (data == null) return;
     77        //if (data == null) return;
    7478        data.setLastSendFailed(_context.clock().now());
    7579    }
     
    8185    public void tunnelJoined(Hash peer, long responseTimeMs) {
    8286        PeerProfile data = getProfile(peer);
    83         if (data == null) return;
     87        //if (data == null) return;
    8488        data.getTunnelCreateResponseTime().addData(responseTimeMs, responseTimeMs);
    8589        data.setLastHeardFrom(_context.clock().now());
     
    96100    public void tunnelRejected(Hash peer, long responseTimeMs, int severity) {
    97101        PeerProfile data = getProfile(peer);
    98         if (data == null) return;
     102        //if (data == null) return;
    99103        data.setLastHeardFrom(_context.clock().now());
    100104        data.getTunnelHistory().incrementRejected(severity);
     
    109113    public void tunnelTimedOut(Hash peer) {
    110114        PeerProfile data = getProfile(peer);
    111         if (data == null) return;
     115        //if (data == null) return;
    112116        data.getTunnelHistory().incrementRejected(TunnelHistory.TUNNEL_REJECT_BANDWIDTH);
    113117    }
     
    120124    public void tunnelTestSucceeded(Hash peer, long responseTimeMs) {
    121125        PeerProfile data = getProfile(peer);
    122         if (data == null) return;
     126        //if (data == null) return;
    123127        data.updateTunnelTestTimeAverage(responseTimeMs);
    124128        data.getTunnelTestResponseTime().addData(responseTimeMs, responseTimeMs);
     
    129133            return;
    130134        PeerProfile data = getProfile(peer);
    131         if (data != null)
     135        //if (data != null)
    132136            data.dataPushed(size); // ignore rtt, as we are averaging over a minute
    133137    }
     138
    134139    public void tunnelDataPushed1m(Hash peer, int size) {
    135140        if (_context.routerHash().equals(peer))
    136141            return;
    137142        PeerProfile data = getProfile(peer);
    138         if (data != null)
     143        //if (data != null)
    139144            data.dataPushed1m(size);
    140145    }
     
    145150            return;
    146151        PeerProfile data = getProfile(peer);
    147         if (data != null)
     152        //if (data != null)
    148153            data.tunnelDataTransferred(size);
    149154    }
     
    163168    public void tunnelFailed(Hash peer, int pct) {
    164169        PeerProfile data = getProfile(peer);
    165         if (data == null) return;
     170        //if (data == null) return;
    166171        data.setLastHeardFrom(_context.clock().now());
    167172        data.getTunnelHistory().incrementFailed(pct);
     
    175180    public void dbLookupSuccessful(Hash peer, long responseTimeMs) {
    176181        PeerProfile data = getProfile(peer);
    177         if (data == null) return;
     182        //if (data == null) return;
    178183        data.setLastHeardFrom(_context.clock().now());
    179184        if (!data.getIsExpandedDB())
     
    192197    public void dbLookupFailed(Hash peer) {
    193198        PeerProfile data = getProfile(peer);
    194         if (data == null) return;
     199        //if (data == null) return;
    195200        if (!data.getIsExpandedDB())
    196201            data.expandDBProfile();
     
    209214    public void dbLookupReply(Hash peer, int newPeers, int oldPeers, int invalid, int duplicate, long responseTimeMs) {
    210215        PeerProfile data = getProfile(peer);
    211         if (data == null) return;
     216        //if (data == null) return;
    212217        data.setLastHeardFrom(_context.clock().now());
    213218        if (!data.getIsExpandedDB())
     
    225230    public void dbLookupReceived(Hash peer) {
    226231        PeerProfile data = getProfile(peer);
    227         if (data == null) return;
     232        //if (data == null) return;
    228233        data.setLastHeardFrom(_context.clock().now());
    229234        if (!data.getIsExpandedDB())
     
    239244    public void dbStoreReceived(Hash peer, boolean wasNewKey) {
    240245        PeerProfile data = getProfile(peer);
    241         if (data == null) return;
     246        //if (data == null) return;
    242247        data.setLastHeardFrom(_context.clock().now());
    243248        if (!data.getIsExpandedDB())
     
    258263    public void dbStoreSent(Hash peer, long responseTimeMs) {
    259264        PeerProfile data = getProfile(peer);
    260         if (data == null) return;
     265        //if (data == null) return;
    261266        long now = _context.clock().now();
    262267        data.setLastHeardFrom(now);
     
    276281    public void dbStoreSuccessful(Hash peer) {
    277282        PeerProfile data = getProfile(peer);
    278         if (data == null) return;
     283        //if (data == null) return;
    279284        long now = _context.clock().now();
    280285        data.setLastHeardFrom(now);
     
    294299    public void dbStoreFailed(Hash peer) {
    295300        PeerProfile data = getProfile(peer);
    296         if (data == null) return;
     301        //if (data == null) return;
    297302        if (!data.getIsExpandedDB())
    298303            data.expandDBProfile();
     
    309314    public void heardAbout(Hash peer) {
    310315        PeerProfile data = getProfile(peer);
    311         if (data == null) return;
     316        //if (data == null) return;
    312317        data.setLastHeardAbout(_context.clock().now());
    313318    }
     
    319324    public void heardAbout(Hash peer, long when) {
    320325        PeerProfile data = getProfile(peer);
    321         if (data == null) return;
     326        //if (data == null) return;
    322327        if (when > data.getLastHeardAbout())
    323328            data.setLastHeardAbout(when);
     
    328333     * transport.  Messages received without any "from" information aren't recorded
    329334     * through this metric.  If msToReceive is negative, there was no timing information
    330      * available
    331      *
     335     * available.
     336     * Non-blocking. Will not update the profile if we can't get the lock.
    332337     */
    333338    public void messageReceived(Hash peer, String style, long msToReceive, int bytesRead) {
    334         PeerProfile data = getProfile(peer);
     339        PeerProfile data = getProfileNonblocking(peer);
    335340        if (data == null) return;
    336341        data.setLastHeardFrom(_context.clock().now());
     
    338343    }
    339344   
     345    /**
     346     *   Blocking.
     347     *   Creates a new profile if it didn't exist.
     348     *   @return non-null
     349     */
    340350    private PeerProfile getProfile(Hash peer) {
    341351        PeerProfile prof = _context.profileOrganizer().getProfile(peer);
     
    348358    }
    349359   
    350    
    351     /** provide a simple summary of a number of peers, suitable for publication in the netDb */
     360    /**
     361     *  Non-blocking.
     362     *  @return null if the profile doesn't exist, or the fetch would have blocked
     363     *  @since 0.8.12
     364     */
     365    private PeerProfile getProfileNonblocking(Hash peer) {
     366        return _context.profileOrganizer().getProfileNonblocking(peer);
     367    }
     368   
     369    /**
     370     *  provide a simple summary of a number of peers, suitable for publication in the netDb
     371     *  @deprecated unused
     372     */
    352373    public Properties summarizePeers(int numPeers) {
     374/****
    353375        Set peers = new HashSet(numPeers);
    354376        // lets get the fastest ones we've got (this fails over to include just plain reliable,
    355377        // or even notFailing peers if there aren't enough fast ones)
    356378        _context.profileOrganizer().selectFastPeers(numPeers, null, peers);
     379****/
    357380        Properties props = new Properties();
     381/****
    358382        for (Iterator iter  = peers.iterator(); iter.hasNext(); ) {
    359383            Hash peer = (Hash)iter.next();
     
    385409            props.setProperty("profile." + peer.toBase64().replace('=', '_'), buf.toString());
    386410        }
     411****/
    387412        return props;
    388413    }
    389414   
     415/****
    390416    private final static DecimalFormat _fmt = new DecimalFormat("##0.00", new DecimalFormatSymbols(Locale.UK));
    391417    private final static String num(double val) {
    392418        synchronized (_fmt) { return _fmt.format(val); }
    393419    }
     420****/
    394421}
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    ra7311a57 r4322cb3  
    5353    /** H(routerIdnetity), containing elements in _notFailingPeers */
    5454    private final List<Hash> _notFailingPeersList;
    55     /** H(routerIdentity) to PeerProfile for all peers that ARE failing horribly (but that we haven't dropped reference to yet) */
     55    /** TO BE REMOVED H(routerIdentity) to PeerProfile for all peers that ARE failing horribly (but that we haven't dropped reference to yet) */
    5656    private final Map<Hash, PeerProfile> _failingPeers;
    5757    /** who are we? */
     
    121121    }
    122122
     123    /**
     124     *  Get the lock if we can. Non-blocking.
     125     *  @return true if the lock was acquired
     126     *  @since 0.8.12
     127     */
     128    private boolean tryReadLock() {
     129        return _reorganizeLock.readLock().tryLock();
     130    }
     131
    123132    private void releaseReadLock() {
    124133        _reorganizeLock.readLock().unlock();
     
    148157   
    149158    /**
    150      * Retrieve the profile for the given peer, if one exists (else null)
    151      *
     159     * Retrieve the profile for the given peer, if one exists (else null).
     160     * Blocking if a reorganize is happening.
    152161     */
    153162    public PeerProfile getProfile(Hash peer) {
     
    156165            return locked_getProfile(peer);
    157166        } finally { releaseReadLock(); }
     167    }
     168   
     169    /**
     170     * Retrieve the profile for the given peer, if one exists (else null).
     171     * Non-blocking. Returns null if a reorganize is happening.
     172     * @since 0.8.12
     173     */
     174    public PeerProfile getProfileNonblocking(Hash peer) {
     175        if (tryReadLock()) {
     176            try {
     177                return locked_getProfile(peer);
     178            } finally { releaseReadLock(); }
     179        }
     180        return null;
    158181    }
    159182   
     
    244267    public boolean isHighCapacity(Hash peer) { return isX(_highCapacityPeers, peer); }
    245268    public boolean isWellIntegrated(Hash peer) { return isX(_wellIntegratedPeers, peer); }
    246     public boolean isFailing(Hash peer) { return isX(_failingPeers, peer); }
     269
     270    /**
     271     *  Deprecated for now, always false
     272     */
     273    public boolean isFailing(Hash peer) {
     274        // Always false so skip the lock
     275        //return isX(_failingPeers, peer);
     276        return false;
     277    }
    247278       
    248279    /** @since 0.8.8 */
  • router/java/src/net/i2p/router/transport/GeoIP.java

    ra7311a57 r4322cb3  
    9999            return;
    100100        }
    101         LookupJob j = new LookupJob();
    102         j.run();
    103         updateOurCountry();
     101        int pri = Thread.currentThread().getPriority();
     102        if (pri > Thread.MIN_PRIORITY)
     103            Thread.currentThread().setPriority(pri - 1);
     104        try {
     105            LookupJob j = new LookupJob();
     106            j.run();
     107            updateOurCountry();
     108        } finally {
     109            if (pri > Thread.MIN_PRIORITY)
     110                Thread.currentThread().setPriority(pri);
     111        }
    104112    }
    105113
  • router/java/src/net/i2p/router/transport/udp/IntroductionManager.java

    ra7311a57 r4322cb3  
    127127                continue;
    128128            }
    129             if (_context.profileOrganizer().isFailing(cur.getRemotePeer()) ||
     129            if ( /* _context.profileOrganizer().isFailing(cur.getRemotePeer()) || */
    130130                _context.shitlist().isShitlisted(cur.getRemotePeer()) ||
    131131                _transport.wasUnreachable(cur.getRemotePeer())) {
  • router/java/src/net/i2p/router/tunnel/HopProcessor.java

    ra7311a57 r4322cb3  
    1313 * inbound and outbound participants, outbound endpoints,
    1414 * and inbound gateways (with a small modification per
    15  * InbuondGatewayProcessor). 
     15 * InboundGatewayProcessor). 
    1616 *
    1717 */
     
    7878        if (!okIV) {
    7979            if (_log.shouldLog(Log.WARN))
    80                 _log.warn("Invalid IV received on tunnel " + _config.getReceiveTunnel());
     80                _log.warn("Invalid IV, dropping at hop " + _config);
    8181            return false;
    8282        }
     
    112112        _context.aes().encryptBlock(orig, offset, _config.getIVKey(), orig, offset);
    113113    }
     114
     115    /**
     116     *  @since 0.8.12
     117     */
     118    @Override
     119    public String toString() {
     120        return getClass().getSimpleName() + " for " + _config;
     121    }
    114122}
  • router/java/src/net/i2p/router/tunnel/InboundEndpointProcessor.java

    ra7311a57 r4322cb3  
    6464        if (!ok) {
    6565            if (_log.shouldLog(Log.WARN))
    66                 _log.warn("Invalid IV received");
     66                _log.warn("Invalid IV, dropping at IBEP " + _config);
    6767            _cache.release(ba);
    6868            return false;
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    ra7311a57 r4322cb3  
    8181            _inProgress.clear();
    8282        }
    83         if (_log.shouldLog(Log.WARN))
    84             _log.warn(toString() + ": Startup() called, was already alive? " + _alive, new Exception());
     83        if (_log.shouldLog(Log.INFO))
     84            _log.info(toString() + ": Startup() called, was already alive? " + _alive, new Exception());
    8585        _alive = true;
    8686        _started = System.currentTimeMillis();
Note: See TracChangeset for help on using the changeset viewer.