Changeset 239fe51


Ignore:
Timestamp:
Oct 21, 2014 6:35:06 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
bcbda3cd
Parents:
86c43f4
Message:

Update: Partial implementation of su3 news with atom feed.
No spec yet, just followed str4d's testnews.atom.xml proposal.
Atom parsing is tested, su3 part is incomplete and untested.
Todo: add spec to http://i2p-projekt.i2p/en/docs/spec/updates,
finish su3 and test.

Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/build.xml

    r86c43f4 r239fe51  
    8282    </target>
    8383
     84    <!-- newsxml.jar only (subset of routerconsole, no war) for Android -->
     85    <target name="compileNewsOnly" depends="prepare, depend, dependVersion">
     86        <mkdir dir="./build" />
     87        <mkdir dir="./build/obj" />
     88        <javac
     89            srcdir="./src"
     90            includes="net/i2p/router/news/*.java"
     91            debug="true" deprecation="on" source="${javac.version}" target="${javac.version}"
     92            includeAntRuntime="false"
     93            destdir="./build/obj">
     94            <compilerarg line="${javac.compilerargs}" />
     95            <classpath>
     96                <pathelement location="../../../core/java/build/i2p.jar" />
     97                <pathelement location="../../../router/java/build/router.jar" />
     98            </classpath>
     99        </javac>
     100    </target>
     101
    84102    <!-- the jar with the latest message classes from the jsps, and the war too -->
    85103    <target name="jar" depends="jar1, war, bundle" />
     
    117135                <attribute name="Workspace-Changes" value="${workspace.changes.j.tr}" />
    118136            </manifest>
     137        </jar>
     138    </target>
     139
     140    <!-- newsxml.jar only (subset of routerconsole, no war) for Android -->
     141    <target name="newsxmljar" depends="compileNewsOnly" >
     142        <jar destfile="./build/newsxml.jar" basedir="./build/obj" includes="**/*.class">
    119143        </jar>
    120144    </target>
  • apps/routerconsole/java/src/net/i2p/router/update/ConsoleUpdateManager.java

    r86c43f4 r239fe51  
    159159        Checker c = new NewsHandler(_context, this);
    160160        register(c, NEWS, HTTP, 0);
    161         // TODO
    162         //register(c, NEWS_SU3, HTTP, 0);
     161        register(c, NEWS_SU3, HTTP, 0);
    163162        register(c, ROUTER_SIGNED, HTTP, 0);  // news is an update checker for the router
    164163        Updater u = new UpdateHandler(_context, this);
  • apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java

    r86c43f4 r239fe51  
    11package net.i2p.router.update;
    22
     3import java.io.BufferedWriter;
     4import java.io.ByteArrayInputStream;
    35import java.io.File;
    46import java.io.FileInputStream;
     7import java.io.FilterInputStream;
     8import java.io.FileOutputStream;
     9import java.io.InputStream;
    510import java.io.IOException;
     11import java.io.OutputStream;
     12import java.io.OutputStreamWriter;
     13import java.io.Writer;
    614import java.net.URI;
    715import java.net.URISyntaxException;
    816import java.util.ArrayList;
     17import java.util.Arrays;
    918import java.util.Collections;
    1019import java.util.HashMap;
     20import java.util.HashSet;
    1121import java.util.List;
    1222import java.util.Locale;
    1323import java.util.Map;
     24import java.util.Set;
    1425import java.util.StringTokenizer;
    1526
     27import net.i2p.crypto.SU3File;
    1628import net.i2p.crypto.TrustedUpdate;
    1729import net.i2p.data.DataHelper;
    1830import net.i2p.router.RouterContext;
    1931import net.i2p.router.RouterVersion;
     32import net.i2p.router.news.NewsEntry;
     33import net.i2p.router.news.NewsMetadata;
     34import net.i2p.router.news.NewsXMLParser;
    2035import net.i2p.router.util.RFC822Date;
    2136import net.i2p.router.web.ConfigUpdateHandler;
     
    2742import net.i2p.util.FileUtil;
    2843import net.i2p.util.Log;
     44import net.i2p.util.ReusableGZIPInputStream;
     45import net.i2p.util.SecureFileOutputStream;
    2946import net.i2p.util.SSLEepGet;
    3047import net.i2p.util.VersionComparator;
     
    329346        long now = _context.clock().now();
    330347        if (_tempFile.exists()) {
     348            if (url.endsWith(".su3")) {
     349                processSU3();
     350                return;
     351            }
    331352            boolean copied = FileUtil.copy(_tempFile, _newsFile, true, false);
    332353            _tempFile.delete();
     
    352373    @Override
    353374    public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {}
     375
     376    /**
     377     *  Process the fetched su3 news file _tempFile
     378     *
     379     *  @since 0.9.17
     380     */
     381    private void processSU3() {
     382        SU3File su3 = new SU3File(_context, _tempFile);
     383        File to1 = new File(_context.getTempDir(), "tmp-" + _context.random().nextInt() + ".xml");
     384        File to2 = new File(_context.getTempDir(), "tmp2-" + _context.random().nextInt() + ".xml");
     385        String sudVersion;
     386        String signingKeyName;
     387        try {
     388            su3.verifyAndMigrate(to1);
     389            int type = su3.getFileType();
     390            if (type != SU3File.TYPE_XML && type != SU3File.TYPE_XML_GZ)
     391                throw new IOException("bad file type");
     392            if (su3.getContentType() != SU3File.CONTENT_NEWS)
     393                throw new IOException("bad content type");
     394            File xml;
     395            if (type == SU3File.TYPE_XML_GZ) {
     396                gunzip(to1, to2);
     397                xml = to2;
     398            } else {
     399                xml = to1;
     400            }
     401            sudVersion = su3.getVersionString();
     402            signingKeyName = su3.getSignerString();
     403            NewsXMLParser parser = new NewsXMLParser(_context);
     404            parser.parse(xml);
     405            NewsMetadata data = parser.getMetadata();
     406            List<NewsEntry> entries = parser.getEntries();
     407            outputOldNewsXML(data, entries);
     408        } catch (IOException ioe) {
     409            // FIXME
     410            //statusDone("<b>" + ioe + ' ' + _("from {0}", _currentURI.toString()) + " </b>");
     411            _tempFile.delete();
     412            to1.delete();
     413            to2.delete();
     414            return;
     415        }
     416    }
     417
     418    /**
     419     *  Gunzip the file
     420     *
     421     *  @since 0.9.17
     422     */
     423    private static void gunzip(File from, File to) throws IOException {
     424        ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
     425        OutputStream out = null;
     426        try {
     427            in.initialize(new FileInputStream(from));
     428            out = new SecureFileOutputStream(to);
     429            byte buf[] = new byte[4096];
     430            int read;
     431            while ((read = in.read(buf)) != -1) {
     432                out.write(buf, 0, read);
     433            }
     434        } finally {
     435            if (out != null) try {
     436                out.close();
     437            } catch (IOException ioe) {}
     438            ReusableGZIPInputStream.release(in);
     439        }
     440    }
     441
     442    /**
     443     *  Output in the old format.
     444     *  Yes there is a better way.
     445     *
     446     *  @since 0.9.17
     447     */
     448    private void outputOldNewsXML(NewsMetadata data, List<NewsEntry> entries) throws IOException {
     449        Writer out = null;
     450        try {
     451            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(_newsFile), "UTF-8"));
     452            out.write("<!--\n");
     453            out.write("<i2p.news date=\"$Date: 2014-09-20 00:00:00 $\">\n");
     454            out.write("<i2p.release ");
     455            if (data.i2pVersion != null)
     456                out.write(" version=\"" + data.i2pVersion + '"');
     457            if (data.minVersion != null)
     458                out.write(" minVersion=\"" + data.minVersion + '"');
     459            if (data.minJavaVersion != null)
     460                out.write(" minJavaVersion=\"" + data.minJavaVersion + '"');
     461            if (data.su2Torrent != null)
     462                out.write(" su2Torrent=\"" + data.su2Torrent + '"');
     463            if (data.su3Torrent != null)
     464                out.write(" su3Torrent=\"" + data.su3Torrent + '"');
     465            out.write("/>\n");
     466            out.write("-->\n");
     467            for (NewsEntry e : entries) {
     468                if (e.title == null || e.content == null)
     469                    continue;
     470                out.write("<h3>");
     471                out.write(e.title);
     472                out.write("</h3>\n");
     473                out.write(e.content);
     474                out.write("\n\n");
     475            }
     476        } finally {
     477            if (out != null) try {
     478                out.close();
     479            } catch (IOException ioe) {}
     480        }
     481    }
    354482}
  • apps/routerconsole/java/src/net/i2p/router/update/NewsHandler.java

    r86c43f4 r239fe51  
    4848        List<URI> updateSources = new ArrayList<URI>(2);
    4949        try {
    50             // TODO SU3
     50            // This may be su3 or xml
    5151            updateSources.add(new URI(ConfigUpdateHelper.getNewsURL(_context)));
    5252        } catch (URISyntaxException use) {}
    5353        try {
    54             // TODO
    55             //updateSources.add(new URI(BACKUP_NEWS_URL_SU3));
    56             updateSources.add(new URI(BACKUP_NEWS_URL));
     54            //updateSources.add(new URI(BACKUP_NEWS_URL));
     55            updateSources.add(new URI(BACKUP_NEWS_URL_SU3));
    5756        } catch (URISyntaxException use) {}
    5857        UpdateRunner update = new NewsFetcher(_context, _mgr, updateSources);
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHandler.java

    r86c43f4 r239fe51  
    3131    public static final String PROP_NEWS_URL = "router.newsURL";
    3232//  public static final String DEFAULT_NEWS_URL = "http://dev.i2p.net/cgi-bin/cvsweb.cgi/i2p/news.xml?rev=HEAD";
     33    /** very old default */
    3334    public static final String OLD_DEFAULT_NEWS_URL = "http://complication.i2p/news.xml";
     35    /** old default */
    3436    public static final String DEFAULT_NEWS_URL = "http://echelon.i2p/i2p/news.xml";
     37    /** current default */
    3538    public static final String DEFAULT_NEWS_URL_SU3 = "http://echelon.i2p/i2p/news.su3";
    3639    public static final String PROP_REFRESH_FREQUENCY = "router.newsRefreshFrequency";
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigUpdateHelper.java

    r86c43f4 r239fe51  
    3333        the update page at some point */
    3434    public static String getNewsURL(I2PAppContext ctx) {
    35         // TODO SU3
    3635        String url = ctx.getProperty(ConfigUpdateHandler.PROP_NEWS_URL);
    37         if (url != null && !url.equals(ConfigUpdateHandler.OLD_DEFAULT_NEWS_URL))
     36        if (url != null && !url.equals(ConfigUpdateHandler.OLD_DEFAULT_NEWS_URL) &&
     37            !url.equals(ConfigUpdateHandler.DEFAULT_NEWS_URL))
    3838            return url;
    3939        else
    40             return ConfigUpdateHandler.DEFAULT_NEWS_URL;
     40            return ConfigUpdateHandler.DEFAULT_NEWS_URL_SU3;
    4141    }
    4242
  • build.xml

    r86c43f4 r239fe51  
    198198    </target>
    199199
     200    <!-- newsxml.jar only (subset of routerconsole, no war) for Android -->
     201    <target name="buildNewsXMLJar" depends="buildRouter" >
     202        <ant dir="apps/routerconsole/java/" target="newsxmljar" />
     203    </target>
     204
    200205    <target name="buildJetty" depends="buildCore" >
    201206        <ant dir="apps/jetty" target="build" />
     
    555560            <group title="Streaming Library" packages="net.i2p.client.streaming:net.i2p.client.streaming.impl" />
    556561            <group title="Router" packages="net.i2p.router:net.i2p.router.*:net.i2p.data.i2np:net.i2p.data.router:org.cybergarage.*:org.freenetproject:org.xlattice.crypto.filters" />
    557             <group title="Router Console" packages="net.i2p.router.web:net.i2p.router.update" />
     562            <group title="Router Console" packages="net.i2p.router.web:net.i2p.router.update:net.i2p.router.news" />
    558563            <!-- apps and bridges starting here, alphabetical please -->
    559564            <group title="Addressbook Application" packages="net.i2p.addressbook" />
  • core/java/src/net/i2p/crypto/SU3File.java

    r86c43f4 r239fe51  
    7272    /** @since 0.9.15 */
    7373    public static final int TYPE_HTML = 2;
     74    /** @since 0.9.17 */
     75    public static final int TYPE_XML_GZ = 3;
    7476
    7577    public static final int CONTENT_UNKNOWN = 0;
  • core/java/src/net/i2p/update/UpdateType.java

    r86c43f4 r239fe51  
    2626    ROUTER_SIGNED_SU3,
    2727    /** @since 0.9.15 */
    28     NEWS_SU3
     28    NEWS_SU3,
     29    /** @since 0.9.17 */
     30    ROUTER_DEV_SU3
    2931}
Note: See TracChangeset for help on using the changeset viewer.