- Add news button, news page, initialNews.xml

- Add clients.config, i2ptunnel.config, hosts.txt, i2ptunnel.jar,
  streaiming.jar, ministreaming.jar
  Clients won't load yet, have to fight the class loader.
- More BroadcastReceiver work (still not hooked in)
- enums
This commit is contained in:
zzz
2011-06-10 18:12:24 +00:00
parent 7cc1e37cc2
commit 8fb166b61b
13 changed files with 221 additions and 28 deletions

View File

@ -26,5 +26,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.NewsActivity"
android:label="@string/app_name"
android.theme="@android:style/Theme.NoTitleBar" >
</activity>
</application>
</manifest>

View File

@ -90,7 +90,10 @@
<target name="buildrouter" depends="-dirs" >
<!-- build router and core -->
<ant dir="${i2pbase}" target="buildrouter" />
<ant dir="${i2pbase}" >
<target name="buildRouter" />
<target name="buildI2PTunnel" />
</ant>
<!-- router -->
<copy file="${i2pbase}/build/router.jar" todir="${jar.libs.dir}" />
@ -122,12 +125,19 @@
<exclude name="org/bouncycastle/crypto/digests/MD5Digest.class" />
</zipfileset >
</jar>
<!-- i2ptunnel -->
<copy file="${i2pbase}/apps/ministreaming/java/build/mstreaming.jar" todir="${jar.libs.dir}" />
<copy file="${i2pbase}/apps/streaming/java/build/streaming.jar" todir="${jar.libs.dir}" />
<copy file="${i2pbase}/apps/i2ptunnel/java/build/i2ptunnel.jar" todir="${jar.libs.dir}" />
</target>
<!-- some resources -->
<target name="copy-i2p-resources" depends="-dirs" >
<copy file="${i2pbase}/installer/resources/themes/console/images/i2plogo.png" todir="res/drawable/" />
<copy file="${i2pbase}/installer/resources/blocklist.txt" tofile="res/raw/blocklist_txt" />
<copy file="${i2pbase}/installer/resources/hosts.txt" tofile="res/raw/hosts_txt" />
</target>
<target name="hackcleanup">
@ -159,6 +169,7 @@
<delete dir="${jar.libs.dir}" verbose="${verbose}" />
<delete file="res/drawable/i2plogo.png" verbose="${verbose}"/>
<delete file="res/raw/blocklist_txt" verbose="${verbose}" />
<delete file="res/raw/hosts_txt" verbose="${verbose}" />
<delete dir="jni/build/" verbose="${verbose}" />
<delete file="jni/libjbigi.so" verbose="${verbose}" />
<delete file="scripts/build.number" verbose="${verbose}" />

View File

@ -7,12 +7,18 @@
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, I2PAndroid"
android:text="I2P News Page"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/i2plogo"
/>
<Button
android:id="@+id/news_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to news"
/>
</LinearLayout>

23
res/layout/news.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, I2PAndroid"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/i2plogo"
/>
<WebView
android:id="@+id/news_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

5
res/raw/clients_config Normal file
View File

@ -0,0 +1,5 @@
# poke the i2ptunnels defined in i2ptunnel.config
clientApp.0.main=net.i2p.i2ptunnel.TunnelControllerGroup
clientApp.0.name=Application tunnels
clientApp.0.args=i2ptunnel.config
clientApp.0.startOnLoad=true

45
res/raw/i2ptunnel_config Normal file
View File

@ -0,0 +1,45 @@
# eepproxy
tunnel.0.name=I2P HTTP Proxy
tunnel.0.description=HTTP proxy for browsing eepsites and the web
tunnel.0.type=httpclient
tunnel.0.sharedClient=true
tunnel.0.interface=127.0.0.1
tunnel.0.listenPort=4444
tunnel.0.proxyList=false.i2p
tunnel.0.i2cpHost=127.0.0.1
tunnel.0.i2cpPort=7654
tunnel.0.option.inbound.nickname=shared clients
tunnel.0.option.outbound.nickname=shared clients
#tunnel.0.option.i2cp.delayOpen=true
tunnel.0.option.i2cp.reduceIdleTime=600000
tunnel.0.option.i2cp.reduceOnIdle=true
tunnel.0.option.i2cp.reduceQuantity=1
tunnel.0.option.i2p.streaming.connectDelay=1000
tunnel.0.option.inbound.length=2
tunnel.0.option.inbound.lengthVariance=0
tunnel.0.option.outbound.length=2
tunnel.0.option.outbound.lengthVariance=0
tunnel.0.startOnLoad=true
# irc
tunnel.1.name=IRC Proxy
tunnel.1.description=IRC proxy to access anonymous IRC servers
tunnel.1.type=ircclient
tunnel.1.sharedClient=true
tunnel.1.interface=127.0.0.1
tunnel.1.listenPort=6668
tunnel.1.targetDestination=irc.postman.i2p,irc.freshcoffee.i2p
tunnel.1.i2cpHost=127.0.0.1
tunnel.1.i2cpPort=7654
tunnel.1.option.inbound.nickname=IRC Proxy
tunnel.1.option.outbound.nickname=IRC Proxy
#tunnel.1.option.i2cp.delayOpen=true
tunnel.1.option.i2cp.reduceIdleTime=600000
tunnel.1.option.i2cp.reduceOnIdle=true
tunnel.1.option.i2cp.reduceQuantity=1
tunnel.1.option.i2p.streaming.connectDelay=1000
tunnel.1.option.inbound.length=2
tunnel.1.option.inbound.lengthVariance=0
tunnel.1.option.outbound.length=2
tunnel.1.option.outbound.lengthVariance=0
tunnel.1.startOnLoad=true

25
res/raw/initialnews_html Normal file
View File

@ -0,0 +1,25 @@
<html>
<head></head>
<body>
<div lang="en">
<h3>Congratulations on getting I2P installed!</h3>
<p>
<b>Welcome to I2P!</b>
Please <b>have patience</b> as I2P boots up and finds peers.
</p>
<p>
While you are waiting, please <b>adjust your bandwidth settings</b> on the
<a href="config.jsp">configuration page</a>.
</p>
<p>
Once you have a "shared clients" destination listed on the left,
please <b>check out</b> our
<a href="http://www.i2p2.i2p/faq.html">FAQ</a>.
</p>
<p>
Point your IRC client to <b>localhost:6668</b> and say hi to us on
<a href="irc://127.0.0.1:6668/i2p-help">#i2p-help</a> or <a href="irc://127.0.0.1:6668/i2p">#i2p</a>.
</p>
</div>
</body>
</html>

View File

@ -4,6 +4,7 @@ i2p.dir.temp=/data/data/net.i2p.router/files/tmp
i2p.dir.pid=/data/data/net.i2p.router/files/tmp
# save memory
prng.buffers=2
prng.bufferSize=32768
router.decayingBloomFilterM=20
stat.full=false
#
@ -11,9 +12,8 @@ stat.full=false
#
time.disabled=true
#
# no I2CP
# no external I2CP (7654)
#
i2p.dummyClientFacade=true
i2cp.disableInterface=true
#
##### Tunnels

View File

@ -1,6 +1,9 @@
package net.i2p.android.router.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import net.i2p.android.router.R;
@ -12,5 +15,17 @@ public class MainActivity extends I2PActivityBase {
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button news = (Button) findViewById(R.id.news_button);
if (news == null) {
System.err.println("No button resource!");
return;
}
news.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), NewsActivity.class);
startActivityForResult(intent, 0);
}
});
}
}

View File

@ -0,0 +1,48 @@
package net.i2p.android.router.activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.webkit.WebView;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import net.i2p.android.router.R;
public class NewsActivity extends I2PActivityBase {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
WebView wv = (WebView) findViewById(R.id.news_webview);
if (wv == null) {
System.err.println("No webview resource!");
return;
}
InputStream in = null;
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte buf[] = new byte[1024];
try {
in = getResources().openRawResource(R.raw.initialnews_html);
int read = 0;
while ( (read = in.read(buf)) != -1)
out.write(buf, 0, read);
} catch (IOException ioe) {
} catch (Resources.NotFoundException nfe) {
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
}
try {
String news = out.toString("UTF-8");
wv.loadData(news, "text/html", "UTF-8");
} catch (UnsupportedEncodingException uee) {
}
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import net.i2p.android.router.R;
@ -24,8 +25,18 @@ public class I2PReceiver extends BroadcastReceiver {
}
public void onReceive(Context context, Intent intent) {
System.out.println("Got broadcast: " + intent);
String action = intent.getAction();
System.out.println("Got broadcast: " + action);
ConnectivityManager cm = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
boolean failover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
boolean noConn = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
NetworkInfo other = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
System.out.println("No conn? " + noConn + " failover? " + failover +
" info: " + info + " other: " + other);
//ConnectivityManager cm = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
}
}

View File

@ -67,6 +67,10 @@ class Init {
void initialize() {
mergeResourceToFile(R.raw.router_config, "router.config");
mergeResourceToFile(R.raw.logger_config, "logger.config");
mergeResourceToFile(R.raw.clients_config, "clients.config");
mergeResourceToFile(R.raw.i2ptunnel_config, "i2ptunnel.config");
// FIXME this is a memory hog to merge this way
mergeResourceToFile(R.raw.hosts_txt, "hosts.txt");
copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt");
// Set up the locations so Router and WorkingDir can find them

View File

@ -20,20 +20,16 @@ import net.i2p.util.NativeBigInteger;
* Runs the router
*/
public class RouterService extends Service {
private enum State {INIT, STARTING, RUNNING, STOPPING, STOPPED}
private RouterContext _context;
private String _myDir;
private int _state;
private State _state = State.INIT;
private Thread _starterThread;
private Thread _statusThread;
private StatusBar _statusBar;
private final Object _stateLock = new Object();
private static final int STATE_INIT = 0;
private static final int STATE_STARTING = 1;
private static final int STATE_RUNNING = 2;
private static final int STATE_STOPPING = 3;
private static final int STATE_STOPPED = 4;
private static final String MARKER = "************************************** ";
@Override
@ -53,10 +49,10 @@ public class RouterService extends Service {
System.err.println(this + " onStart called" +
"Current state is: " + _state);
synchronized (_stateLock) {
if (_state != STATE_INIT)
if (_state != State.INIT)
return START_STICKY;
_statusBar.update("I2P is starting up");
_state = STATE_STARTING;
_state = State.STARTING;
_starterThread = new Thread(new Starter());
_starterThread.start();
}
@ -67,14 +63,14 @@ public class RouterService extends Service {
public void run() {
System.err.println(MARKER + this + " starter thread" +
"Current state is: " + _state);
System.err.println(MARKER + this + " JBigI speed test started");
NativeBigInteger.main(null);
System.err.println(MARKER + this + " JBigI speed test finished, launching router");
//System.err.println(MARKER + this + " JBigI speed test started");
//NativeBigInteger.main(null);
//System.err.println(MARKER + this + " JBigI speed test finished, launching router");
RouterLaunch.main(null);
synchronized (_stateLock) {
if (_state != STATE_STARTING)
if (_state != State.STARTING)
return;
_state = STATE_RUNNING;
_state = State.RUNNING;
List contexts = RouterContext.listContexts();
if ( (contexts == null) || (contexts.isEmpty()) )
throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
@ -95,7 +91,7 @@ public class RouterService extends Service {
System.err.println(MARKER + this + " status thread started" +
"Current state is: " + _state);
Router router = _context.router();
while (_state == STATE_RUNNING && router.isAlive()) {
while (_state == State.RUNNING && router.isAlive()) {
try {
Thread.sleep(5000);
} catch (InterruptedException ie) {
@ -156,15 +152,15 @@ public class RouterService extends Service {
System.err.println("onDestroy called" +
"Current state is: " + _state);
synchronized (_stateLock) {
if (_state == STATE_STARTING)
if (_state == State.STARTING)
_starterThread.interrupt();
if (_state == STATE_STARTING || _state == STATE_RUNNING) {
_state = STATE_STOPPING;
if (_state == State.STARTING || _state == State.RUNNING) {
_state = State.STOPPING;
// should this be in a thread?
_statusBar.update("I2P is stopping");
Thread stopperThread = new Thread(new Stopper());
stopperThread.start();
} else if (_state != STATE_STOPPING) {
} else if (_state != State.STOPPING) {
_statusBar.off(this);
}
}
@ -178,7 +174,7 @@ public class RouterService extends Service {
_statusBar.off(RouterService.this);
System.err.println("shutdown complete");
synchronized (_stateLock) {
_state = STATE_STOPPED;
_state = State.STOPPED;
}
}
}
@ -188,8 +184,8 @@ public class RouterService extends Service {
System.err.println(this + " shutdown hook" +
"Current state is: " + _state);
synchronized (_stateLock) {
if (_state == STATE_STARTING || _state == STATE_RUNNING) {
_state = STATE_STOPPED;
if (_state == State.STARTING || _state == State.RUNNING) {
_state = State.STOPPED;
if (_statusThread != null)
_statusThread.interrupt();
_statusBar.off(RouterService.this);