Changeset 7e229cce


Ignore:
Timestamp:
Dec 26, 2010 1:17:33 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
bebd6b2
Parents:
12fae66 (diff), cd0d062 (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.test4' (head bf9ef6aabb549475a41e936e7074ef625ab194e0)

to branch 'i2p.i2p.zzz.dhtsnark' (head 0a6fe29cd1c9fc357ad2c973be4f1a2a752b52b7)

Files:
26 edited

Legend:

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

    r12fae66 r7e229cce  
    307307      return piece_length;
    308308    else if (piece == pieces -1)
    309       return (int)(length - piece * piece_length);
     309      return (int)(length - ((long)piece * piece_length));
    310310    else
    311311      throw new IndexOutOfBoundsException("no piece: " + piece);
  • apps/i2psnark/java/src/org/klomp/snark/Peer.java

    r12fae66 r7e229cce  
    9595    this.metainfo = metainfo;
    9696    _id = ++__id;
    97     //_log.debug("Creating a new peer with " + peerID.getAddress().calculateHash().toBase64(), new Exception("creating"));
     97    //_log.debug("Creating a new peer with " + peerID.toString(), new Exception("creating"));
    9898  }
    9999
     
    121121    _id = ++__id;
    122122    if (_log.shouldLog(Log.DEBUG))
    123         _log.debug("Creating a new peer with " + peerID.getAddress().calculateHash().toBase64(), new Exception("creating " + _id));
     123        _log.debug("Creating a new peer with " + peerID.toString(), new Exception("creating " + _id));
    124124  }
    125125
     
    217217
    218218    if (_log.shouldLog(Log.DEBUG))
    219         _log.debug("Running connection to " + peerID.getAddress().calculateHash().toBase64(), new Exception("connecting"));   
     219        _log.debug("Running connection to " + peerID.toString(), new Exception("connecting"));   
    220220    try
    221221      {
  • apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java

    r12fae66 r7e229cce  
    302302                          if(coordinator.addPeer(cur)) {
    303303                            int delay = DELAY_MUL;
    304                             delay *= ((int)cur.getPeerID().getAddress().calculateHash().toBase64().charAt(0)) % 10;
     304                            delay *= r.nextInt(10);
    305305                            delay += DELAY_MIN;
    306306                            sleptTime += delay;
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHandler.java

    r12fae66 r7e229cce  
    1010import java.util.Set;
    1111
     12import net.i2p.router.client.ClientManagerFacadeImpl;
    1213import net.i2p.router.startup.ClientAppConfig;
    1314import net.i2p.router.startup.LoadClientAppsJob;
     
    3435        if (_action.equals(_("Save Client Configuration"))) {
    3536            saveClientChanges();
     37            return;
     38        }
     39        if (_action.equals(_("Save Interface Configuration"))) {
     40            saveInterfaceChanges();
    3641            return;
    3742        }
     
    194199        if (arr == null)
    195200            return null;
    196         return arr[0];
     201        return arr[0].trim();
    197202    }
    198203
     
    338343        }
    339344    }
     345
     346    /**
     347     *  Handle interface form
     348     *  @since 0.8.3
     349     */
     350    private void saveInterfaceChanges() {
     351        String port = getJettyString("port");
     352        if (port != null)
     353            _context.router().setConfigSetting(ClientManagerFacadeImpl.PROP_CLIENT_PORT, port);
     354        String intfc = getJettyString("interface");
     355        if (intfc != null)
     356            _context.router().setConfigSetting(ClientManagerFacadeImpl.PROP_CLIENT_HOST, intfc);
     357        String user = getJettyString("user");
     358        if (user != null)
     359            _context.router().setConfigSetting(ConfigClientsHelper.PROP_USER, user);
     360        String pw = getJettyString("pw");
     361        if (pw != null)
     362            _context.router().setConfigSetting(ConfigClientsHelper.PROP_PW, pw);
     363        String mode = getJettyString("mode");
     364        boolean disabled = "0".equals(mode);
     365        boolean ssl = "2".equals(mode);
     366        _context.router().setConfigSetting(ConfigClientsHelper.PROP_DISABLE_EXTERNAL,
     367                                           Boolean.toString(disabled));
     368        _context.router().setConfigSetting(ConfigClientsHelper.PROP_ENABLE_SSL,
     369                                           Boolean.toString(ssl));
     370        _context.router().setConfigSetting(ConfigClientsHelper.PROP_AUTH,
     371                                           Boolean.toString((_settings.get("auth") != null)));
     372        boolean all = "0.0.0.0".equals(intfc) || "0:0:0:0:0:0:0:0".equals(intfc) ||
     373                      "::".equals(intfc);
     374        _context.router().setConfigSetting(ConfigClientsHelper.BIND_ALL_INTERFACES, Boolean.toString(all));
     375        _context.router().saveConfig();
     376        addFormNotice(_("Interface configuration saved successfully - restart required to take effect."));
     377    }
    340378}
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigClientsHelper.java

    r12fae66 r7e229cce  
    22
    33import java.text.SimpleDateFormat;
     4import java.util.ArrayList;
     5import java.util.Arrays;
     6import java.util.Collections;
    47import java.util.Date;
    58import java.util.Iterator;
     
    912import java.util.TreeSet;
    1013
     14import net.i2p.router.client.ClientManagerFacadeImpl;
    1115import net.i2p.router.startup.ClientAppConfig;
     16import net.i2p.router.transport.Addresses;
    1217
    1318public class ConfigClientsHelper extends HelperBase {
    1419    private String _edit;
    1520
     21    /** from ClientListenerRunner */
     22    public static final String BIND_ALL_INTERFACES = "i2cp.tcp.bindAllInterfaces";
     23    /** from ClientManager */
     24    public static final String PROP_DISABLE_EXTERNAL = "i2cp.disableInterface";
     25    public static final String PROP_ENABLE_SSL = "i2cp.SSL";
     26    /** from ClientMessageEventListener */
     27    public static final String PROP_AUTH = "i2cp.auth";
     28    public static final String PROP_USER = "i2cp.username";
     29    public static final String PROP_PW = "i2cp.password";
     30
    1631    public ConfigClientsHelper() {}
    17    
     32
     33    /** @since 0.8.3 */
     34    public String getPort() {
     35        return _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_PORT,
     36                                    Integer.toString(ClientManagerFacadeImpl.DEFAULT_PORT));
     37    }
     38
     39    /** @since 0.8.3 */
     40    public String getUser() {
     41        return _context.getProperty(PROP_USER, "");
     42    }
     43
     44    /** @since 0.8.3 */
     45    public String getPw() {
     46        return _context.getProperty(PROP_PW, "");
     47    }
     48
     49    /** @since 0.8.3 */
     50    public String i2cpModeChecked(int mode) {
     51        boolean disabled =  _context.getBooleanProperty(PROP_DISABLE_EXTERNAL);
     52        boolean ssl =  _context.getBooleanProperty(PROP_ENABLE_SSL);
     53        if ((mode == 0 && disabled) ||
     54            (mode == 1 && (!disabled) && (!ssl)) ||
     55            (mode == 2 && (!disabled) && ssl))
     56            return "checked=\"true\"";
     57        return "";
     58    }
     59
     60    /** @since 0.8.3 */
     61    public String getAuth() {
     62        boolean enabled =  _context.getBooleanProperty(PROP_AUTH);
     63        if (enabled)
     64            return "checked=\"true\"";
     65        return "";
     66    }
     67
     68    /** @since 0.8.3 */
     69    public String[] intfcAddresses() {
     70        String[] addrs = Addresses.getAllAddresses();
     71        List<String> aList = new ArrayList();
     72        aList.addAll(Arrays.asList(addrs));
     73        boolean ipv6 = false;
     74        for (String a : aList) {
     75            if (a.indexOf(':') >= 0) {
     76                ipv6 = true;
     77                break;
     78            }
     79        }
     80        if (!aList.contains("0.0.0.0"))
     81            aList.add("0.0.0.0");
     82        if (ipv6 && !aList.contains("0:0:0:0:0:0:0:0"))
     83            aList.add("0:0:0:0:0:0:0:0");  // we could do "::" but all the other ones are probably in long form
     84        Collections.sort(aList);
     85        return aList.toArray(addrs);
     86    }
     87
     88    /** @since 0.8.3 */
     89    public boolean isIFSelected(String addr) {
     90        boolean bindAll = _context.getBooleanProperty(BIND_ALL_INTERFACES);
     91        if (bindAll && addr.equals("0.0.0.0") || addr.equals("::"))
     92            return true;
     93        String host = _context.getProperty(ClientManagerFacadeImpl.PROP_CLIENT_HOST,
     94                                           ClientManagerFacadeImpl.DEFAULT_HOST);
     95        return (host.equals(addr));
     96    }
     97
    1898    public void setEdit(String edit) {
    1999         if (edit == null)
     
    93173                StringBuilder desc = new StringBuilder(256);
    94174                desc.append("<table border=\"0\">")
    95                     .append("<tr><td><b>").append(_("Version")).append("<td>").append(stripHTML(appProps, "version"))
     175                    .append("<tr><td><b>").append(_("Version")).append("</b></td><td>").append(stripHTML(appProps, "version"))
    96176                    .append("<tr><td><b>")
    97                     .append(_("Signed by")).append("<td>");
     177                    .append(_("Signed by")).append("</b></td><td>");
    98178                String s = stripHTML(appProps, "signer");
    99179                if (s != null) {
     
    112192                        String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(ms));
    113193                        desc.append("<tr><td><b>")
    114                             .append(_("Date")).append("<td>").append(date);
     194                            .append(_("Date")).append("</b></td><td>").append(date);
    115195                    }
    116196                }
     
    118198                if (s != null) {
    119199                    desc.append("<tr><td><b>")
    120                         .append(_("Author")).append("<td>");
     200                        .append(_("Author")).append("</b></td><td>");
    121201                    if (s.indexOf("@") > 0)
    122202                        desc.append("<a href=\"mailto:").append(s).append("\">").append(s).append("</a>");
     
    129209                if (s != null) {
    130210                    desc.append("<tr><td><b>")
    131                         .append(_("Description")).append("<td>").append(s);
     211                        .append(_("Description")).append("</b></td><td>").append(s);
    132212                }
    133213                s = stripHTML(appProps, "license");
    134214                if (s != null) {
    135215                    desc.append("<tr><td><b>")
    136                         .append(_("License")).append("<td>").append(s);
     216                        .append(_("License")).append("</b></td><td>").append(s);
    137217                }
    138218                s = stripHTML(appProps, "websiteURL");
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigStatsHelper.java

    r12fae66 r7e229cce  
    140140    public String getExplicitFilter() { return _filter; }
    141141    public boolean getIsFull() {
    142         return _context.getBooleanPropertyDefaultTrue(StatManager.PROP_STAT_FULL);
     142        return _context.getBooleanProperty(StatManager.PROP_STAT_FULL);
    143143    }
    144144}
  • apps/routerconsole/java/src/net/i2p/router/web/UpdateHandler.java

    r12fae66 r7e229cce  
    11package net.i2p.router.web;
    22
     3import java.io.ByteArrayInputStream;
     4import java.io.ByteArrayOutputStream;
    35import java.io.File;
    46import java.text.DecimalFormat;
    57import java.util.ArrayList;
     8import java.util.Collections;
    69import java.util.List;
    710import java.util.StringTokenizer;
     
    1619import net.i2p.util.I2PAppThread;
    1720import net.i2p.util.Log;
     21import net.i2p.util.PartialEepGet;
     22import net.i2p.util.VersionComparator;
    1823
    1924/**
    20  * <p>Handles the request to update the router by firing off an
    21  * {@link net.i2p.util.EepGet} call to download the latest signed update file
     25 * <p>Handles the request to update the router by firing one or more
     26 * {@link net.i2p.util.EepGet} calls to download the latest signed update file
    2227 * and displaying the status to anyone who asks.
    2328 * </p>
     
    126131        protected EepGet _get;
    127132        protected final DecimalFormat _pct = new DecimalFormat("0.0%");
     133        /** tells the listeners what mode we are in */
     134        private boolean _isPartial;
     135        /** set by the listeners on completion */
     136        private boolean _isNewer;
     137        private ByteArrayOutputStream _baos;
    128138
    129139        public UpdateRunner() {
     
    142152            _isRunning = false;
    143153        }
     154
     155        /**
     156         *  Loop through the entire list of update URLs.
     157         *  For each one, first get the version from the first 56 bytes and see if
     158         *  it is newer than what we are running now.
     159         *  If it is, get the whole thing.
     160         */
    144161        protected void update() {
    145             updateStatus("<b>" + _("Updating") + "</b>");
    146162            // TODO:
    147163            // Do a PartialEepGet on the selected URL, check for version we expect,
     
    150166            // Alternative: In bytesTransferred(), Check the data in the output file after
    151167            // we've received at least 56 bytes. Need a cancel() method in EepGet ?
    152             String updateURL = selectUpdateURL();
    153             if (_log.shouldLog(Log.DEBUG))
    154                 _log.debug("Selected update URL: " + updateURL);
     168
    155169            boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
    156170            String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    157171            int proxyPort = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);
    158             try {
    159                 if (shouldProxy)
    160                     // 40 retries!!
    161                     _get = new EepGet(_context, proxyHost, proxyPort, 40, _updateFile, updateURL, false);
    162                 else
    163                     _get = new EepGet(_context, 1, _updateFile, updateURL, false);
    164                 _get.addStatusListener(UpdateRunner.this);
    165                 _get.fetch();
    166             } catch (Throwable t) {
    167                 _log.error("Error updating", t);
     172
     173            List<String> urls = getUpdateURLs();
     174            if (urls.isEmpty()) {
     175                // not likely, don't bother translating
     176                updateStatus("<b>Update source list is empty, cannot download update</b>");
     177                _log.log(Log.CRIT, "Update source list is empty - cannot download update");
     178                return;
     179            }
     180
     181            if (shouldProxy)
     182                _baos = new ByteArrayOutputStream(TrustedUpdate.HEADER_BYTES);
     183            for (String updateURL : urls) {
     184                updateStatus("<b>" + _("Updating from {0}", linkify(updateURL)) + "</b>");
     185                if (_log.shouldLog(Log.DEBUG))
     186                    _log.debug("Selected update URL: " + updateURL);
     187
     188                // Check the first 56 bytes for the version
     189                if (shouldProxy) {
     190                    _isPartial = true;
     191                    _isNewer = false;
     192                    _baos.reset();
     193                    try {
     194                        // no retries
     195                        _get = new PartialEepGet(_context, proxyHost, proxyPort, _baos, updateURL, TrustedUpdate.HEADER_BYTES);
     196                        _get.addStatusListener(UpdateRunner.this);
     197                        _get.fetch();
     198                    } catch (Throwable t) {
     199                        _isNewer = false;
     200                    }
     201                    _isPartial = false;
     202                    if (!_isNewer)
     203                        continue;
     204                }
     205
     206                // Now get the whole thing
     207                try {
     208                    if (shouldProxy)
     209                        // 40 retries!!
     210                        _get = new EepGet(_context, proxyHost, proxyPort, 40, _updateFile, updateURL, false);
     211                    else
     212                        _get = new EepGet(_context, 1, _updateFile, updateURL, false);
     213                    _get.addStatusListener(UpdateRunner.this);
     214                    _get.fetch();
     215                } catch (Throwable t) {
     216                    _log.error("Error updating", t);
     217                }
     218                if (this.done)
     219                    break;
    168220            }
    169221        }
    170222       
     223        // EepGet Listeners below.
     224        // We use the same for both the partial and the full EepGet,
     225        // with a couple of adjustments depending on which mode.
     226
    171227        public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) {
     228            _isNewer = false;
    172229            if (_log.shouldLog(Log.DEBUG))
    173230                _log.debug("Attempt failed on " + url, cause);
     
    175232        }
    176233        public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) {
     234            if (_isPartial)
     235                return;
    177236            StringBuilder buf = new StringBuilder(64);
    178237            buf.append("<b>").append(_("Updating")).append("</b> ");
     
    187246        }
    188247        public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
     248            if (_isPartial) {
     249                // Compare version with what we have now
     250                String newVersion = TrustedUpdate.getVersionString(new ByteArrayInputStream(_baos.toByteArray()));
     251                boolean newer = (new VersionComparator()).compare(newVersion, RouterVersion.VERSION) > 0;
     252                if (!newer) {
     253                    updateStatus("<b>" + _("No new version found at {0}", linkify(url)) + "</b>");
     254                    if (_log.shouldLog(Log.WARN))
     255                        _log.warn("Found old version \"" + newVersion + "\" at " + url);
     256                }
     257                _isNewer = newer;
     258                return;
     259            }
     260            // Process the .sud/.su2 file
    189261            updateStatus("<b>" + _("Update downloaded") + "</b>");
    190262            TrustedUpdate up = new TrustedUpdate(_context);
     
    224296            } else {
    225297                _log.log(Log.CRIT, err + " from " + url);
    226                 updateStatus("<b>" + err + ' ' + _("from {0}", url) + " </b>");
     298                updateStatus("<b>" + err + ' ' + _("from {0}", linkify(url)) + " </b>");
    227299            }
    228300        }
    229301        public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
     302            _isNewer = false;
    230303            // don't display bytesTransferred as it is meaningless
    231             _log.log(Log.CRIT, "Update from " + url + " did not download completely (" +
     304            _log.error("Update from " + url + " did not download completely (" +
    232305                               bytesRemaining + " remaining after " + currentAttempt + " tries)");
    233306
    234             updateStatus("<b>" + _("Transfer failed") + "</b>");
     307            updateStatus("<b>" + _("Transfer failed from {0}", linkify(url)) + "</b>");
    235308        }
    236309        public void headerReceived(String url, int attemptNum, String key, String val) {}
     
    243316    }
    244317
    245     private String selectUpdateURL() {
     318    private List<String> getUpdateURLs() {
    246319        String URLs = _context.getProperty(ConfigUpdateHandler.PROP_UPDATE_URL, ConfigUpdateHandler.DEFAULT_UPDATE_URL);
    247320        StringTokenizer tok = new StringTokenizer(URLs, " ,\r\n");
    248         List URLList = new ArrayList();
     321        List<String> URLList = new ArrayList();
    249322        while (tok.hasMoreTokens())
    250323            URLList.add(tok.nextToken().trim());
    251         int size = URLList.size();
    252         //_log.log(Log.DEBUG, "Picking update source from " + size + " candidates.");
    253         if (size <= 0) {
    254             _log.log(Log.CRIT, "Update source list is empty - cannot download update");
    255             return null;
    256         }
    257         int index = I2PAppContext.getGlobalContext().random().nextInt(size);
    258         _log.log(Log.DEBUG, "Picked update source " + index + ".");
    259         return (String) URLList.get(index);
     324        Collections.shuffle(URLList, _context.random());
     325        return URLList;
    260326    }
    261327   
    262328    protected void updateStatus(String s) {
    263329        _status = s;
     330    }
     331
     332    protected static String linkify(String url) {
     333        return "<a target=\"_blank\" href=\"" + url + "\"/>" + url + "</a>";
    264334    }
    265335
  • apps/routerconsole/jsp/configclients.jsp

    r12fae66 r7e229cce  
    4848<% } %>
    4949 <input type="submit" name="action" value="<%=intl._("Save Client Configuration")%>" />
    50 </div></div><h3><a name="webapp"></a><%=intl._("WebApp Configuration")%></h3><p>
     50</div></div>
     51
     52<h3><a name="i2cp"></a><%=intl._("Advanced Client Interface Configuration")%></h3><p>
     53<b><%=intl._("External I2CP (I2P Client Protocol) Interface Configuration")%></b><br>
     54<input type="radio" class="optbox" name="mode" value="1" <%=clientshelper.i2cpModeChecked(1) %> >
     55<%=intl._("Enabled without SSL")%><br>
     56<input type="radio" class="optbox" name="mode" value="2" <%=clientshelper.i2cpModeChecked(2) %> >
     57<%=intl._("Enabled with SSL required")%><br>
     58<input type="radio" class="optbox" name="mode" value="0" <%=clientshelper.i2cpModeChecked(0) %> >
     59<%=intl._("Disabled - Clients outside this Java process may not connect")%><br>
     60<%=intl._("I2CP Port")%>:
     61<input name="port" type="text" size="5" maxlength="5" value="<jsp:getProperty name="clientshelper" property="port" />" ><br>
     62<%=intl._("I2CP Interface")%>:
     63<select name="interface">
     64<%
     65       String[] ips = clientshelper.intfcAddresses();
     66       for (int i = 0; i < ips.length; i++) {
     67           out.print("<option value=\"");
     68           out.print(ips[i]);
     69           out.print('\"');
     70           if (clientshelper.isIFSelected(ips[i]))
     71               out.print(" selected=\"selected\"");
     72           out.print('>');
     73           out.print(ips[i]);
     74           out.print("</option>\n");
     75       }
     76%>
     77</select><br>
     78<b><%=intl._("Authorization")%></b><br>
     79<input type="checkbox" class="optbox" name="auth" value="true" <jsp:getProperty name="clientshelper" property="auth" /> >
     80<%=intl._("Requre username and password")%><br>
     81<%=intl._("Username")%>:
     82<input name="user" type="text" value="<jsp:getProperty name="clientshelper" property="user" />" ><br>
     83<%=intl._("Password")%>:
     84<input name="pw" type="password" value="<jsp:getProperty name="clientshelper" property="pw" />" ><br>
     85</p><p><b><%=intl._("The default settings will work for most people.")%></b>
     86<%=intl._("Any changes made here must also be configured in the external client.")%>
     87<%=intl._("Many clients do not support SSL or authorization.")%>
     88<i><%=intl._("All changes require restart to take effect.")%></i>
     89</p><hr><div class="formaction">
     90<input type="submit" name="foo" value="<%=intl._("Cancel")%>" />
     91<input type="submit" name="action" value="<%=intl._("Save Interface Configuration")%>" />
     92</div>
     93
     94<h3><a name="webapp"></a><%=intl._("WebApp Configuration")%></h3><p>
    5195 <%=intl._("The Java web applications listed below are started by the webConsole client and run in the same JVM as the router. They are usually web applications accessible through the router console. They may be complete applications (e.g. i2psnark),front-ends to another client or application which must be separately enabled (e.g. susidns, i2ptunnel), or have no web interface at all (e.g. addressbook).")%>
    5296 </p><p>
  • core/java/src/net/i2p/data/Certificate.java

    r12fae66 r7e229cce  
    2727 */
    2828public class Certificate extends DataStructureImpl {
    29     private int _type;
    30     private byte[] _payload;
     29    public final static Certificate NULL_CERT = new NullCert();
     30
     31    protected int _type;
     32    protected byte[] _payload;
    3133
    3234    /** Specifies a null certificate type with no payload */
     
    4244    public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
    4345
     46    /**
     47     * If null cert, return immutable static instance, else create new
     48     * @since 0.8.3
     49     */
     50    public static Certificate create(InputStream in) throws DataFormatException, IOException {
     51        int type = (int) DataHelper.readLong(in, 1);
     52        int length = (int) DataHelper.readLong(in, 2);
     53        if (type == 0 && length == 0)
     54            return NULL_CERT;
     55        // from here down roughly the same as readBytes() below
     56        if (length == 0)
     57            return new Certificate(type, null);
     58        byte[] payload = new byte[length];
     59        int read = DataHelper.read(in, payload);
     60        if (read != length)
     61            throw new DataFormatException("Not enough bytes for the payload (read: " + read + " length: " + length + ')');
     62        return new Certificate(type, payload);
     63    }
     64
    4465    public Certificate() {
    4566    }
     
    91112        }
    92113    }
    93    
    94    
     114
     115    /**
     116     *  @return the written length (NOT the new offset)   
     117     */   
    95118    public int writeBytes(byte target[], int offset) {
    96119        int cur = offset;
     
    141164        return _type == cert.getCertificateType() && DataHelper.eq(_payload, cert.getPayload());
    142165    }
     166
    143167    @Override
    144168    public int hashCode() {
    145169        return _type + DataHelper.hashCode(_payload);
    146170    }
     171
    147172    @Override
    148173    public String toString() {
     
    178203        return buf.toString();
    179204    }
     205
     206    /**
     207     *  An immutable null certificate.
     208     *  @since 0.8.3
     209     */
     210    private static final class NullCert extends Certificate {
     211        private static final int NULL_LENGTH = 1 + 2;
     212        private static final byte[] NULL_DATA = new byte[NULL_LENGTH];
     213
     214        public NullCert() {
     215            // zero already
     216            //_type = CERTIFICATE_TYPE_NULL;
     217        }
     218
     219        /** @throws RuntimeException always */
     220        @Override
     221        public void setCertificateType(int type) {
     222            throw new RuntimeException("Data already set");
     223        }
     224
     225        /** @throws RuntimeException always */
     226        @Override
     227        public void setPayload(byte[] payload) {
     228            throw new RuntimeException("Data already set");
     229        }
     230   
     231        /** @throws RuntimeException always */
     232        @Override
     233        public void readBytes(InputStream in) throws DataFormatException, IOException {
     234            throw new RuntimeException("Data already set");
     235        }
     236   
     237        /** Overridden for efficiency */
     238        @Override
     239        public void writeBytes(OutputStream out) throws IOException {
     240            out.write(NULL_DATA);
     241        }
     242   
     243        /** Overridden for efficiency */
     244        @Override
     245        public int writeBytes(byte target[], int offset) {
     246            System.arraycopy(NULL_DATA, 0, target, offset, NULL_LENGTH);
     247            return NULL_LENGTH;
     248        }
     249   
     250        /** @throws RuntimeException always */
     251        @Override
     252        public int readBytes(byte source[], int offset) throws DataFormatException {
     253            throw new RuntimeException("Data already set");
     254        }
     255   
     256        /** Overridden for efficiency */
     257        @Override
     258        public int size() {
     259            return NULL_LENGTH;
     260        }
     261   
     262        /** Overridden for efficiency */
     263        @Override
     264        public int hashCode() {
     265            return 99999;
     266        }
     267    }
    180268}
  • core/java/src/net/i2p/data/DataHelper.java

    r12fae66 r7e229cce  
    915915    }
    916916
     917    /**
     918     *  This is different than InputStream.read(target), in that it
     919     *  does repeated reads until the full data is received.
     920     */
    917921    public static int read(InputStream in, byte target[]) throws IOException {
    918922        return read(in, target, 0, target.length);
    919923    }
     924
     925    /**
     926     *  This is different than InputStream.read(target, offset, length), in that it
     927     *  returns the new offset (== old offset + bytes read).
     928     *  It also does repeated reads until the full data is received.
     929     *  @return the new offset (== old offset + bytes read)
     930     */
    920931    public static int read(InputStream in, byte target[], int offset, int length) throws IOException {
    921932        int cur = offset;
  • core/java/src/net/i2p/data/Destination.java

    r12fae66 r7e229cce  
    2929    }
    3030
    31     /** deprecated, used only by Packet.java in streaming */
     31    /**
     32     *  deprecated, used only by Packet.java in streaming
     33     *  @return the written length (NOT the new offset)   
     34     */   
    3235    public int writeBytes(byte target[], int offset) {
    3336        int cur = offset;
  • core/java/src/net/i2p/data/KeysAndCert.java

    r12fae66 r7e229cce  
    6666        _signingKey = new SigningPublicKey();
    6767        _signingKey.readBytes(in);
    68         _certificate = new Certificate();
    69         _certificate.readBytes(in);
     68        //_certificate = new Certificate();
     69        //_certificate.readBytes(in);
     70        _certificate = Certificate.create(in);
    7071        __calculatedHash = null;
    7172    }
  • core/java/src/net/i2p/data/Payload.java

    r12fae66 r7e229cce  
    9494            _log.debug("wrote payload: " + _encryptedData.length);
    9595    }
     96
     97    /**
     98     *  @return the written length (NOT the new offset)   
     99     */   
    96100    public int writeBytes(byte target[], int offset) {
    97101        if (_encryptedData == null) throw new IllegalStateException("Not yet encrypted.  Please set the encrypted data");
  • core/java/src/net/i2p/data/SimpleDataStructure.java

    r12fae66 r7e229cce  
    2020 *
    2121 * Implemented in 0.8.2 and retrofitted over several of the classes in this package.
     22 *
     23 * As of 0.8.3, SDS objects may be cached. An SDS may be instantiated with null data,
     24 * and setData(null) is also OK. However,
     25 * once non-null data is set, the data reference is immutable;
     26 * subsequent attempts to set the data via setData(), readBytes(),
     27 * or fromBase64() will throw a RuntimeException.
    2228 *
    2329 * @since 0.8.2
     
    5864     * @param data of correct length, or null
    5965     * @throws IllegalArgumentException if data is not the legal number of bytes (but null is ok)
     66     * @throws RuntimeException if data already set.
    6067     */
    6168    public void setData(byte[] data) {
     69        if (_data != null)
     70            throw new RuntimeException("Data already set");
    6271        if (data != null && data.length != _length)
    6372            throw new IllegalArgumentException("Bad data length");
     
    6574    }
    6675
     76    /**
     77     * Sets the data.
     78     * @param data of correct length, or null
     79     * @throws RuntimeException if data already set.
     80     */
    6781    public void readBytes(InputStream in) throws DataFormatException, IOException {
     82        if (_data != null)
     83            throw new RuntimeException("Data already set");
    6884        _data = new byte[_length];
    6985        int read = read(in, _data);
     
    86102     * Sets the data.
    87103     * @throws DataFormatException if decoded data is not the legal number of bytes or on decoding error
     104     * @throws RuntimeException if data already set.
    88105     */
    89106    @Override
     
    163180        return DataHelper.eq(_data, ((SimpleDataStructure) obj)._data);
    164181    }
    165    
    166182}
  • core/java/src/net/i2p/stat/StatManager.java

    r12fae66 r7e229cce  
    207207     */
    208208    public boolean ignoreStat(String statName) {
    209         if (_context.getBooleanPropertyDefaultTrue(PROP_STAT_FULL))
     209        if (_context.getBooleanProperty(PROP_STAT_FULL))
    210210            return false;
    211211        String required = _context.getProperty(PROP_STAT_REQUIRED, DEFAULT_STAT_REQUIRED);
  • core/java/src/net/i2p/util/FortunaRandomSource.java

    r12fae66 r7e229cce  
    2424 */
    2525public class FortunaRandomSource extends RandomSource implements EntropyHarvester {
    26     private AsyncFortunaStandalone _fortuna;
     26    private final AsyncFortunaStandalone _fortuna;
    2727    private double _nextGaussian;
    2828    private boolean _haveNextGaussian;
     
    211211    }
    212212   
     213/*****
    213214    public static void main(String args[]) {
    214215        try {
     
    232233        } catch (Exception e) { e.printStackTrace(); }
    233234    }
     235*****/
    234236}
  • core/java/src/net/i2p/util/RandomSource.java

    r12fae66 r7e229cce  
    2626 */
    2727public class RandomSource extends SecureRandom implements EntropyHarvester {
    28     private Log _log;
    29     private EntropyHarvester _entropyHarvester;
    30     protected I2PAppContext _context;
     28    private final EntropyHarvester _entropyHarvester;
     29    protected final I2PAppContext _context;
    3130
    3231    public RandomSource(I2PAppContext context) {
    3332        super();
    3433        _context = context;
    35         _log = context.logManager().getLog(RandomSource.class);
    3634        // when we replace to have hooks for fortuna (etc), replace with
    3735        // a factory (or just a factory method)
    3836        _entropyHarvester = this;
    3937    }
     38
     39    /**
     40     * Singleton for whatever PRNG i2p uses. 
     41     * Same as I2PAppContext.getGlobalContext().random();
     42     * use context.random() if you have a context already.
     43     * @return I2PAppContext.getGlobalContext().random()
     44     */
    4045    public static RandomSource getInstance() {
    4146        return I2PAppContext.getGlobalContext().random();
  • installer/resources/themes/console/classic/console.css

    r12fae66 r7e229cce  
    715715}
    716716
    717 input[type=text] {
     717input[type=text], input[type=password] {
    718718     margin: 3px 5px 3px 5px;
    719719     vertical-align: middle;
  • installer/resources/themes/console/dark/console.css

    r12fae66 r7e229cce  
    844844}
    845845
    846 input[type=text] {
     846input[type=text], input[type=password] {
    847847     background: #000;
    848848     color: #EE9;
     
    860860}
    861861
    862 input[type=text]:active, input[type=text]:hover {
     862input[type=text]:active, input[type=text]:hover, input[type=password]:active, input[type=password]:hover {
    863863     background: #000;
    864864}
  • installer/resources/themes/console/light/console.css

    r12fae66 r7e229cce  
    912912}
    913913
    914 input[type=text] {
     914input[type=text], input[type=password] {
    915915     background: #ffe;
    916916     color: #001;
  • installer/resources/themes/console/midnight/console.css

    r12fae66 r7e229cce  
    751751}
    752752
    753 input[type=text] {
     753input[type=text], input[type=password] {
    754754     margin: 3px 5px 3px 5px;
    755755     vertical-align: middle;
     
    761761}
    762762
    763 input[type=text], select {
     763input[type=text], input[type=password] select {
    764764     background: #001;
    765765     color: #eef;
  • router/java/src/net/i2p/data/i2np/GarlicClove.java

    r12fae66 r7e229cce  
    6969        if (_log.shouldLog(Log.DEBUG))
    7070            _log.debug("CloveID read: " + _cloveId + " expiration read: " + _expiration);
    71         _certificate = new Certificate();
    72         _certificate.readBytes(in);
     71        //_certificate = new Certificate();
     72        //_certificate.readBytes(in);
     73        _certificate = Certificate.create(in);
    7374        if (_log.shouldLog(Log.DEBUG))
    7475            _log.debug("Read cert: " + _certificate);
  • router/java/src/net/i2p/router/message/OutboundClientMessageJobHelper.java

    r12fae66 r7e229cce  
    116116        instructions.setTunnelId(null);
    117117       
    118         config.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     118        config.setCertificate(Certificate.NULL_CERT);
    119119        config.setDeliveryInstructions(instructions);
    120120        config.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
     
    166166            log.debug("Delivery status message key: " + replyToken + " arrival: " + msg.getArrival());
    167167       
    168         ackClove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     168        ackClove.setCertificate(Certificate.NULL_CERT);
    169169        ackClove.setDeliveryInstructions(ackInstructions);
    170170        ackClove.setExpiration(expiration);
     
    197197        instructions.setEncrypted(false);
    198198       
    199         clove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     199        clove.setCertificate(Certificate.NULL_CERT);
    200200        clove.setDeliveryInstructions(instructions);
    201201        clove.setExpiration(expiration);
     
    223223        instructions.setEncrypted(false);
    224224       
    225         clove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     225        clove.setCertificate(Certificate.NULL_CERT);
    226226        clove.setDeliveryInstructions(instructions);
    227227        clove.setExpiration(expiration);
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    r12fae66 r7e229cce  
    873873        instructions.setEncrypted(false);
    874874       
    875         clove.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     875        clove.setCertificate(Certificate.NULL_CERT);
    876876        clove.setDeliveryInstructions(instructions);
    877877        clove.setExpiration(OVERALL_TIMEOUT_MS_DEFAULT+getContext().clock().now());
  • router/java/src/net/i2p/router/networkdb/kademlia/MessageWrapper.java

    r12fae66 r7e229cce  
    4747
    4848        PayloadGarlicConfig payload = new PayloadGarlicConfig();
    49         payload.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
     49        payload.setCertificate(Certificate.NULL_CERT);
    5050        payload.setId(ctx.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    5151        payload.setPayload(m);
  • router/java/src/net/i2p/router/transport/Addresses.java

    r12fae66 r7e229cce  
    3232
    3333    /**
    34      *  @return an array of all addresses, excluding
     34     *  @return a sorted array of all addresses, excluding
    3535     *  IPv6, local, broadcast, multicast, etc.
    3636     */
    3737    public static String[] getAddresses() {
     38        return getAddresses(false);
     39    }
     40
     41    /**
     42     *  @return a sorted array of all addresses, excluding
     43     *  only link local and multicast
     44     *  @since 0.8.3
     45     */
     46    public static String[] getAllAddresses() {
     47        return getAddresses(true);
     48    }
     49
     50    /**
     51     *  @return a sorted array of all addresses
     52     *  @param whether to exclude IPV6 and local
     53     *  @return an array of all addresses
     54     *  @since 0.8.3
     55     */
     56    public static String[] getAddresses(boolean all) {
    3857        Set<String> rv = new HashSet(4);
    3958        try {
     
    4160            InetAddress[] allMyIps = InetAddress.getAllByName(localhost.getCanonicalHostName());
    4261            if (allMyIps != null) {
    43                 for (int i = 0; i < allMyIps.length; i++)
    44                      add(rv, allMyIps[i]);
     62                for (int i = 0; i < allMyIps.length; i++) {
     63                    if (all)
     64                        addAll(rv, allMyIps[i]);
     65                    else
     66                        add(rv, allMyIps[i]);
     67                }
    4568            }
    4669        } catch (UnknownHostException e) {}
     
    5174                for(Enumeration<InetAddress> addrs =  ifc.getInetAddresses(); addrs.hasMoreElements();) {
    5275                    InetAddress addr = addrs.nextElement();
    53                     add(rv, addr);
     76                    if (all)
     77                        addAll(rv, addr);
     78                    else
     79                        add(rv, addr);
    5480                }
    5581            }
     
    80106    }
    81107
     108    private static void addAll(Set<String> set, InetAddress ia) {
     109        if (ia.isLinkLocalAddress() ||
     110            ia.isMulticastAddress())
     111            return;
     112        String ip = ia.getHostAddress();
     113        set.add(ip);
     114    }
     115
    82116    public static void main(String[] args) {
    83         String[] a = getAddresses();
     117        String[] a = getAddresses(true);
    84118        for (String s : a)
    85119            System.err.println("Address: " + s);
Note: See TracChangeset for help on using the changeset viewer.