3 Commits

3 changed files with 65 additions and 164 deletions

65
BUILD.txt Normal file
View File

@ -0,0 +1,65 @@
Setting up a build environment for I2PSnark-RPC
===============================================
These build instructions seem to work with both git and mtn.
1. You can build I2PSnark-RPC using either the packages that come with
an I2P installation or with packages from the I2P code.
If you have an existing I2P installation and want to use it, you should set
the I2P environment variable to point to your I2P Installation. If you
installed I2P via the .jar, this will be $HOME/i2p. On Apple, the I2P
libraries are found at `/Applications/i2p`. If you have installed I2P using
a Debian package(i.e. `sudo apt-get install i2p i2p-router`) then you have
libraries available at /usr/lib/i2p.
If you have the I2P source code in ../i2p relative to the parent directory,
and have run `ant pkg`, then the libraries will automatically be detected.
./i2p/pkg-tmp
./i2p.plugins.i2psnark-rpc
2. Copy plugin.config from the scripts directory into the plugin directory.
cp scripts/plugin.config plugin/plugin.config
3. If you don't have plugin signing keys yet, the build script will generate them.
However, if you prefer to do this in advance, you can.
To do this with I2P installed in the $HOME directory, you can run the following
script:
java -cp "~/i2p/lib/i2p.jar:/usr/share/java/gnu-getopt.jar" \
net.i2p.crypto.SU3File keygen -t RSA_SHA512_4096 \
"~/.i2p-plugin-keys/user-su3-public-signing.crt" \
"~/.i2p-plugin-keys/user-su3-keystore.ks" \
"user@mail.i2p"
There is a helper script to make this process easier at
[i2pgit.org](https://i2pgit.org/idk/generate-plugin-signing-keys)
[git.idk.i2p](https://i2pgit.org/idk/generate-plugin-signing-keys). If you
have never generated plugin signing keys before, you can run the command:
./i2pk -p $HOME/.i2p-plugin-keys -n 'user' -s 'user@mail.i2p' generate_keys
4. Edit the plugin/plugin.config file. You will need to change the signer field to
match your keys, and add a version line to the file.
name=i2psnark-rpc
-signer=zzz-plugin@mail.i2p
+signer=user@mail.i2p
consoleLinkName=I2PSnark-Remote
consoleLinkURL=/transmission/web/
description=RPC and Web UI for i2psnark
min-java-version=1.7
min-jetty-version=9
min-i2p-version=0.9.47
+version=0.1.2-test
5. You should be ready to build the plugin. Run the script scripts/makeplugin.sh
from the project root.
./scripts/makeplugin.sh
You will be prompted to generate your keystore password. Once entered, the
i2psnark-rpc plugin packages will be generated.

View File

@ -1,157 +0,0 @@
**** LICENSING NOTE FROM PARG ****
The version included within Vuze in LGPL version 2.1 and is an old version of the software available here:
https://code.google.com/p/json-simple/downloads/detail?name=json_simple.zip&can=2&q=
(archived here: https://web.archive.org/web/20140328054522/https://json-simple.googlecode.com/files/json_simple.zip )
The license was subsequently updated to Apache but the Vuze copy remains LGPL.
***********************************
Simple Java toolkit for JSON (JSON.simple)
==========================================
1.Why the Simple Java toolkit (also named as JSON.simple) for JSON?
When I use JSON as the data exchange format between the AJAX client and JSP
for the first time, what worry me mostly is how to encode Java strings and
numbers correctly in the server side so the AJAX client will receive a well
formed JSON data. When I looked into the 'JSON in Java' directory in JSON
website,I found that wrappers to JSONObject and JSONArray can be simpler,
due to the simplicity of JSON itself. So I wrote the JSON.simple package.
2.Is it simple,really?
I think so. Take an example:
import org.json.simple.JSONObject;
JSONObject obj=new JSONObject();
obj.put("name","foo");
obj.put("num",new Integer(100));
obj.put("balance",new Double(1000.21));
obj.put("is_vip",new Boolean(true));
obj.put("nickname",null);
System.out.print(obj);
Result:
{"nickname":null,"num":100,"balance":1000.21,"is_vip":true,"name":"foo"}
The JSONObject.toString() will escape controls and specials correctly.
3.How to use JSON.simple in JSP?
Take an example in JSP:
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%
JSONObject obj=new JSONObject();
obj.put("name","foo");
obj.put("num",new Integer(100));
obj.put("balance",new Double(1000.21));
obj.put("is_vip",new Boolean(true));
obj.put("nickname",null);
out.print(obj);
out.flush();
%>
So the AJAX client will get the responseText.
4.Some details about JSONObject?
JSONObject inherits java.util.HashMap,so it don't have to worry about the
mapping things between keys and values. Feel free to use the Map methods
like get(), put(), and remove() and others. JSONObject.toString() will
combine key value pairs to get the JSON data string. Values will be escaped
into JSON quote string format if it's an instance of java.lang.String. Other
type of instance like java.lang.Number,java.lang.Boolean,null,JSONObject and
JSONArray will NOT escape, just take their java.lang.String.valueOf() result.
null value will be the JSON 'null' in the result.
It's still correct if you put an instance of JSONObject or JSONArray into an
instance of JSONObject or JSONArray. Take the example about:
JSONObject obj2=new JSONObject();
obj2.put("phone","123456");
obj2.put("zip","7890");
obj.put("contact",obj2);
System.out.print(obj);
Result:
{"nickname":null,"num":100,"contact":{"phone":"123456","zip":"7890"},"balance":1000.21,"is_vip":true,"name":"foo"}
The method JSONObject.escape() is used to escape Java string into JSON quote
string. Controls and specials will be escaped correctly into \b,\f,\r,\n,\t,
\",\\,\/,\uhhhh.
5.Some detail about JSONArray?
org.json.simple.JSONArray inherits java.util.ArrayList. Feel free to use the
List methods like get(),add(),remove(),iterator() and so on. The rules of
JSONArray.toString() is similar to JSONObject.toString(). Here's the example:
import org.json.simple.JSONArray;
JSONArray array=new JSONArray();
array.add("hello");
array.add(new Integer(123));
array.add(new Boolean(false));
array.add(null);
array.add(new Double(123.45));
array.add(obj2);//see above
System.out.print(array);
Result:
["hello",123,false,null,123.45,{"phone":"123456","zip":"7890"}]
6.What is JSONValue for?
org.json.simple.JSONValue is use to parse JSON data into Java Object.
In JSON, the topmost entity is JSON value, not the JSON object. But
it's not necessary to wrap JSON string,boolean,number and null again,
for the Java has already had the according classes: java.lang.String,
java.lang.Boolean,java.lang.Number and null. The mapping is:
JSON Java
------------------------------------------------
string <=> java.lang.String
number <=> java.lang.Number
true|false <=> java.lang.Boolean
null <=> null
array <=> org.json.simple.JSONArray
object <=> org.json.simple.JSONObject
------------------------------------------------
JSONValue has only one kind of method, JSONValue.parse(), which receives
a java.io.Reader or java.lang.String. Return type of JSONValue.parse()
is according to the mapping above. If the input is incorrect in syntax or
there's exceptions during the parsing, I choose to return null, ignoring
the exception: I have no idea if it's a serious implementaion, but I think
it's convenient to the user.
Here's the example:
String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
Object obj=JSONValue.parse(s);
JSONArray array=(JSONArray)obj;
System.out.println(array.get(1));
JSONObject obj2=(JSONObject)array.get(1);
System.out.println(obj2.get("1"));
Result:
{"1":{"2":{"3":{"4":[5,{"6":7}]}}}}
{"2":{"3":{"4":[5,{"6":7}]}}}
7.About the author.
I'm a Java EE developer on Linux.
I'm working on web systems and information retrieval systems.
I also develop 3D games and Flash games.
You can contact me through:
Fang Yidong<fangyidong@yahoo.com.cn>
Fang Yidong<fangyidng@gmail.com>

View File

@ -35,13 +35,6 @@ Copyright (c) Transmission authors and contributors
<br>
See <a href="licenses/Transmission.txt">Transmission.txt</a>
<p>
JSON:
<br>
LGPLv2.1
<br>
See <a href="licenses/JSON.txt">JSON.txt</a>
<p>
Transmission/Vuze web UI:
<br>