Changeset 231040d


Ignore:
Timestamp:
Nov 14, 2015 2:07:01 AM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
23cb4ca
Parents:
ded249d
Message:

Profiles: Don't allow creation of our own profile
TunnelCreatorConfig?:

  • locking
  • comment out unused code
  • don't set bandwidth stats in profile for ourselves

TunnelDispatcher?:

  • don't set tunnel stats in profile for ourselves

BuildHandler?, TunnelPool?: Minor optimizations

Location:
router/java/src/net/i2p/router
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    rded249d r231040d  
    157157     */
    158158    public PeerProfile getProfile(Hash peer) {
     159        if (peer.equals(_us)) {
     160            if (_log.shouldWarn())
     161                _log.warn("Who wanted our own profile?", new Exception("I did"));
     162            return null;
     163        }
    159164        getReadLock();
    160165        try {
     
    169174     */
    170175    public PeerProfile getProfileNonblocking(Hash peer) {
     176        if (peer.equals(_us)) {
     177            if (_log.shouldWarn())
     178                _log.warn("Who wanted our own profile?", new Exception("I did"));
     179            return null;
     180        }
    171181        if (tryReadLock()) {
    172182            try {
     
    185195
    186196        Hash peer = profile.getPeer();
     197        if (peer.equals(_us)) {
     198            if (_log.shouldWarn())
     199                _log.warn("Who added our own profile?", new Exception("I did"));
     200            return null;
     201        }
    187202
    188203        if (_log.shouldLog(Log.DEBUG))
  • router/java/src/net/i2p/router/tunnel/HopConfig.java

    rded249d r231040d  
    5151    public void setReceiveTunnelId(TunnelId id) { _receiveTunnelId = DataHelper.toLong(4, id.getTunnelId()); }
    5252   
    53     /** what is the previous peer in the tunnel (if any)? */
     53    /** what is the previous peer in the tunnel (null if gateway) */
    5454    public Hash getReceiveFrom() { return _receiveFrom; }
    5555    public void setReceiveFrom(Hash from) { _receiveFrom = from; }
    5656   
    57     /** what is the next tunnel ID we are sending to? */
     57    /** what is the next tunnel ID we are sending to? (null if endpoint) */
    5858    public byte[] getSendTunnelId() { return _sendTunnelId; }
     59
     60    /** what is the next tunnel we are sending to? (null if endpoint) */
    5961    public TunnelId getSendTunnel() {
    6062        if (_sendTunnel == null)
     
    7173    }
    7274   
    73     /** what is the next peer in the tunnel (if any)? */
     75    /** what is the next peer in the tunnel (null if endpoint) */
    7476    public Hash getSendTo() { return _sendTo; }
    7577    public void setSendTo(Hash to) { _sendTo = to; }
  • router/java/src/net/i2p/router/tunnel/TunnelCreatorConfig.java

    rded249d r231040d  
    3131    private final boolean _isInbound;
    3232    private int _messagesProcessed;
    33     private volatile long _verifiedBytesTransferred;
     33    private long _verifiedBytesTransferred;
    3434    private boolean _failed;
    3535    private int _failures;
    3636    private boolean _reused;
    3737    private int _priority;
    38    
     38    //private static final int THROUGHPUT_COUNT = 3;
     39    // Fastest 1 minute throughput, in bytes per minute, ordered with fastest first.
     40    //private final double _peakThroughput[] = new double[THROUGHPUT_COUNT];
     41    private long _peakThroughputCurrentTotal;
     42    private long _peakThroughputLastCoallesce = System.currentTimeMillis();
     43    // Make configurable? - but can't easily get to pool options from here
     44    private static final int MAX_CONSECUTIVE_TEST_FAILURES = 3;
     45    private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss", Locale.UK);
     46   
     47    /**
     48     * For exploratory only (null destination)
     49     * @param length 1 minimum (0 hop is length 1)
     50     */
    3951    public TunnelCreatorConfig(RouterContext ctx, int length, boolean isInbound) {
    4052        this(ctx, length, isInbound, null);
    4153    }
    4254
     55    /**
     56     * @param length 1 minimum (0 hop is length 1)
     57     * @param destination null for exploratory
     58     */
    4359    public TunnelCreatorConfig(RouterContext ctx, int length, boolean isInbound, Hash destination) {
    4460        _context = ctx;
     
    132148   
    133149    /** take note of a message being pumped through this tunnel */
    134     public void incrementProcessedMessages() { _messagesProcessed++; }
    135     public int getProcessedMessagesCount() { return _messagesProcessed; }
    136 
    137     public void incrementVerifiedBytesTransferred(int bytes) {
     150    public synchronized void incrementProcessedMessages() { _messagesProcessed++; }
     151    public synchronized int getProcessedMessagesCount() { return _messagesProcessed; }
     152
     153    /**
     154     *  This calls profile manager tunnelDataPushed1m() for each peer
     155     *  @return null for exploratory
     156     */
     157    public synchronized void incrementVerifiedBytesTransferred(int bytes) {
    138158        _verifiedBytesTransferred += bytes;
    139159        _peakThroughputCurrentTotal += bytes;
     
    145165            _peakThroughputLastCoallesce = now;
    146166            _peakThroughputCurrentTotal = 0;
    147             if (_context != null)
    148                 for (int i = 0; i < _peers.length; i++)
     167            if (_context != null) {
     168                // skip ourselves
     169                int start = _isInbound ? 0 : 1;
     170                int end = _isInbound ? _peers.length - 1 : _peers.length;
     171                for (int i = start; i < end; i++) {
    149172                    _context.profileManager().tunnelDataPushed1m(_peers[i], (int)normalized);
    150         }
    151     }
    152 
    153     public long getVerifiedBytesTransferred() { return _verifiedBytesTransferred; }
    154 
    155     private static final int THROUGHPUT_COUNT = 3;
    156     /**
    157      * fastest 1 minute throughput, in bytes per minute, ordered with fastest
    158      * first.
    159      */
    160     private final double _peakThroughput[] = new double[THROUGHPUT_COUNT];
    161     private volatile long _peakThroughputCurrentTotal;
    162     private volatile long _peakThroughputLastCoallesce = System.currentTimeMillis();
    163     public double getPeakThroughputKBps() {
     173                }
     174            }
     175        }
     176    }
     177
     178    public synchronized long getVerifiedBytesTransferred() { return _verifiedBytesTransferred; }
     179
     180/**** unused
     181    public synchronized double getPeakThroughputKBps() {
    164182        double rv = 0;
    165183        for (int i = 0; i < THROUGHPUT_COUNT; i++)
     
    168186        return rv;
    169187    }
    170     public void setPeakThroughputKBps(double kBps) {
     188
     189    public synchronized void setPeakThroughputKBps(double kBps) {
    171190        _peakThroughput[0] = kBps*60*1024;
    172191        //for (int i = 0; i < THROUGHPUT_COUNT; i++)
    173192        //    _peakThroughput[i] = kBps*60;
    174193    }
    175    
    176    
    177     // Make configurable? - but can't easily get to pool options from here
    178     private static final int MAX_CONSECUTIVE_TEST_FAILURES = 3;
     194****/
    179195   
    180196    /**
     
    265281    }
    266282   
    267     private static final SimpleDateFormat _fmt = new SimpleDateFormat("HH:mm:ss", Locale.UK);
    268 
    269283    private String getExpirationString() {
    270284        return format(_expiration);
    271285    }
     286
    272287    static String format(long date) {
    273288        Date d = new Date(date);
  • router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java

    rded249d r231040d  
    796796            cfg.setLayerKey(req.readLayerKey());
    797797            if (isInGW) {
    798                 cfg.setReceiveFrom(null);
     798                // default
     799                //cfg.setReceiveFrom(null);
    799800            } else {
    800801                if (state.fromHash != null) {
     
    809810            cfg.setReceiveTunnelId(DataHelper.toLong(4, ourId));
    810811            if (isOutEnd) {
    811                 cfg.setSendTo(null);
    812                 cfg.setSendTunnelId(null);
     812                // default
     813                //cfg.setSendTo(null);
     814                //cfg.setSendTunnelId(null);
    813815            } else {
    814816                cfg.setSendTo(nextPeer);
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    rded249d r231040d  
    11691169            cfg.setPeer(j, peers.get(i));
    11701170            HopConfig hop = cfg.getConfig(j);
    1171             hop.setCreation(_context.clock().now());
     1171            hop.setCreation(now);
    11721172            hop.setExpiration(expiration);
    11731173            hop.setIVKey(_context.keyGenerator().generateSessionKey());
Note: See TracChangeset for help on using the changeset viewer.