README.md
1# cjdnsadmin.py
2
3Using cjdnsadmin.py is trivially simple, you can connect to a router and
4issue it commands in 3 steps:
5
6## from cjdnsadmin.cjdnsadmin import connect;
7Make sure `cjdnsadmin/cjdnsadmin.py` and `cjdnsadmin/bencode.py` are in your
8path, the easiest thing to do is put `cjdnsadmin/` in the same directory
9as your script.
10
11## connect()
12This takes 3 parameters, the ip address of the listening router, it's port
13number, and the password to connect to it. These can be found in your
14cjdroute.conf here:
15
16 "admin":
17 {
18 // Port to bind the admin RPC server to.
19 "bind": "127.0.0.1:11234",
20
21 // Password for admin RPC server.
22 "password": "4s8mshm4hbb2lbdwz4bxfdn9w7"
23 },
24
25To connect to this node, you would use:
26
27 cjdns = connect('127.0.0.1', 11234, '4s8mshm4hbb2lbdwz4bxfdn9w7');
28
29The password will be checked when you connect and if it's incorrect you will get
30an exception.
31
32Or just use
33
34 from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
35 cjdns = connectWithAdminInfo();
36
37It gets data from `~/.cjdnsadmin`
38
39## Use it!
40
41The `cjdns` object returned from `connect()` and `connectWithAdminInfo()`
42contains functions corresponding to each of the RPC calls in the router.
43There is a field called `cjdns.functions` which contains a list of the
44functions and their parameters.
45
46
47## Example usage of cjdnsadmin/cjdnsadmin.py
48
49 user@debo8:~/wrk/play$ python
50 Python 2.7.2+ (default, Jan 20 2012, 17:51:10)
51 [GCC 4.6.2] on linux2
52 Type "help", "copyright", "credits" or "license" for more information.
53 >>> from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
54 >>> cjdns = connectWithAdminInfo();
55 >>> cjdns.functions();
56 RouterModule_pingNode(required String path)
57 UDPInterface_scrambleKeys(required String xorValue)
58 ping()
59 AuthorizedPasswords_add(Int authType, required String password)
60 AuthorizedPasswords_flush()
61 memory()
62 NodeStore_dumpTable()
63 UDPInterface_beginConnection(required String publicKey, String password, required String address)
64 >>> print cjdns.AuthorizedPasswords_add(1, 1);
65 {'error': 'Entry [password] is required and must be of type [String]'}
66 >>> print cjdns.AuthorizedPasswords_add(1, 'abcd');
67 {'error': 'none'}
68 >>> print cjdns.memory();
69 {'bytes': 750556}
70 >>> routes = cjdns.NodeStore_dumpTable();
71 >>> print routes;
72 {'routingTable': [{'ip': 'fc45:a51e:89eb:6d57:ad43:5723:e1d3:5d51', 'link': 4294967295, 'path': '0000.0000.0000.0001'}, {'ip': 'fcf1:a7a8:8ec0:589b:c64c:cc95:1ced:3679', 'link': 266287520, 'path': '0000.0000.0000.0006'}, {'ip': 'fce5:de17:cbde:c87b:5289:0556:8b83:c9c8', 'link': 0, 'path': '0000.0000.0000.0004'}]}
73 >>> for route in routes['routingTable']: print route['ip'] + "@" + route['path'] + "\n";
74 ...
75 fc45:a51e:89eb:6d57:ad43:5723:e1d3:5d51@0000.0000.0000.0001
76
77 fcf1:a7a8:8ec0:589b:c64c:cc95:1ced:3679@0000.0000.0000.0006
78
79 fce5:de17:cbde:c87b:5289:0556:8b83:c9c8@0000.0000.0000.0004
80
81 >>> cjdns.disconnect();
82 >>> exit(0)
83
84For convenience, you can directly start `./cjdnsa`
85
86
87#peerStats
88
89 ./peerStats --help
90 usage: peerStats [-h]
91
92 -h, --humanreadable human readable output of transmitted bytes
93 --help this list
94
95