… | |
… | |
4 | SYNOPSIS |
4 | SYNOPSIS |
5 | use Net::FCP; |
5 | use Net::FCP; |
6 | |
6 | |
7 | my $fcp = new Net::FCP; |
7 | my $fcp = new Net::FCP; |
8 | |
8 | |
|
|
9 | my $ni = $fcp->txn_node_info->result; |
|
|
10 | my $ni = $fcp->node_info; |
|
|
11 | |
9 | DESCRIPTION |
12 | DESCRIPTION |
|
|
13 | See <http://freenet.sourceforge.net/index.php?page=fcp> for a |
|
|
14 | description of what the messages do. I am too lazy to document all this |
|
|
15 | here. |
|
|
16 | |
|
|
17 | WARNING |
|
|
18 | This module is alpha. While it probably won't destroy (much :) of your |
|
|
19 | data, it currently falls short of what it should provide (intelligent |
|
|
20 | uri following, splitfile downloads, healing...) |
|
|
21 | |
|
|
22 | IMPORT TAGS |
|
|
23 | Nothing much can be "imported" from this module right now. There are, |
|
|
24 | however, certain "import tags" that can be used to select the event |
|
|
25 | model to be used. |
|
|
26 | |
|
|
27 | Event models are implemented as modules under the "Net::FCP::Event::xyz" |
|
|
28 | class, where "xyz" is the event model to use. The default is "Event" (or |
|
|
29 | later "Auto"). |
|
|
30 | |
|
|
31 | The import tag to use is named "event=xyz", e.g. "event=Event", |
|
|
32 | "event=Glib" etc. |
|
|
33 | |
|
|
34 | You should specify the event module to use only in the main program. |
|
|
35 | |
|
|
36 | FREENET BASICS |
|
|
37 | Ok, this section will not explain any freenet basics to you, just some |
|
|
38 | problems I found that you might want to avoid: |
|
|
39 | |
|
|
40 | freenet URIs are _NOT_ URIs |
|
|
41 | Whenever a "uri" is required by the protocol, freenet expects a kind |
|
|
42 | of URI prefixed with the "freenet:" scheme, e.g. "freenet:CHK...". |
|
|
43 | However, these are not URIs, as freeent fails to parse them |
|
|
44 | correctly, that is, you must unescape an escaped characters ("%2c" |
|
|
45 | => ",") yourself. Maybe in the future this library will do it for |
|
|
46 | you, so watch out for this incompatible change. |
|
|
47 | |
|
|
48 | Numbers are in HEX |
|
|
49 | Virtually every number in the FCP protocol is in hex. Be sure to use |
|
|
50 | "hex()" on all such numbers, as the module (currently) does nothing |
|
|
51 | to convert these for you. |
|
|
52 | |
|
|
53 | THE Net::FCP CLASS |
|
|
54 | $meta = Net::FCP::parse_metadata $string |
|
|
55 | Parse a metadata string and return it. |
|
|
56 | |
|
|
57 | The metadata will be a hashref with key "version" (containing the |
|
|
58 | mandatory version header entries). |
|
|
59 | |
|
|
60 | All other headers are represented by arrayrefs (they can be |
|
|
61 | repeated). |
|
|
62 | |
|
|
63 | Since this is confusing, here is a rather verbose example of a |
|
|
64 | parsed manifest: |
|
|
65 | |
|
|
66 | ( |
|
|
67 | version => { revision => 1 }, |
|
|
68 | document => [ |
|
|
69 | { |
|
|
70 | info => { format" => "image/jpeg" }, |
|
|
71 | name => "background.jpg", |
|
|
72 | redirect => { target => "freenet:CHK\@ZcagI,ra726bSw" }, |
|
|
73 | }, |
|
|
74 | { |
|
|
75 | info => { format" => "text/html" }, |
|
|
76 | name => ".next", |
|
|
77 | redirect => { target => "freenet:SSK\@ilUPAgM/TFEE/3" }, |
|
|
78 | }, |
|
|
79 | { |
|
|
80 | info => { format" => "text/html" }, |
|
|
81 | redirect => { target => "freenet:CHK\@8M8Po8ucwI,8xA" }, |
|
|
82 | } |
|
|
83 | ] |
|
|
84 | ) |
|
|
85 | |
|
|
86 | $fcp = new Net::FCP [host => $host][, port => $port] |
|
|
87 | Create a new virtual FCP connection to the given host and port |
|
|
88 | (default 127.0.0.1:8481, or the environment variables "FREDHOST" and |
|
|
89 | "FREDPORT"). |
|
|
90 | |
|
|
91 | Connections are virtual because no persistent physical connection is |
|
|
92 | established. |
|
|
93 | |
|
|
94 | $txn = $fcp->txn(type => attr => val,...) |
|
|
95 | The low-level interface to transactions. Don't use it. |
|
|
96 | |
|
|
97 | Here are some examples of using transactions: |
|
|
98 | |
|
|
99 | The blocking case, no (visible) transactions involved: |
|
|
100 | |
|
|
101 | my $nodehello = $fcp->client_hello; |
|
|
102 | |
|
|
103 | A transaction used in a blocking fashion: |
|
|
104 | |
|
|
105 | my $txn = $fcp->txn_client_hello; |
|
|
106 | ... |
|
|
107 | my $nodehello = $txn->result; |
|
|
108 | |
|
|
109 | Or shorter: |
|
|
110 | |
|
|
111 | my $nodehello = $fcp->txn_client_hello->result; |
|
|
112 | |
|
|
113 | Setting callbacks: |
|
|
114 | |
|
|
115 | $fcp->txn_client_hello->cb( |
|
|
116 | sub { my $nodehello => $_[0]->result } |
|
|
117 | ); |
|
|
118 | |
|
|
119 | $txn = $fcp->txn_client_hello |
|
|
120 | $nodehello = $fcp->client_hello |
|
|
121 | Executes a ClientHello request and returns it's results. |
|
|
122 | |
|
|
123 | { |
|
|
124 | max_file_size => "5f5e100", |
|
|
125 | node => "Fred,0.6,1.46,7050" |
|
|
126 | protocol => "1.2", |
|
|
127 | } |
|
|
128 | |
|
|
129 | $txn = $fcp->txn_client_info |
|
|
130 | $nodeinfo = $fcp->client_info |
|
|
131 | Executes a ClientInfo request and returns it's results. |
|
|
132 | |
|
|
133 | { |
|
|
134 | active_jobs => "1f", |
|
|
135 | allocated_memory => "bde0000", |
|
|
136 | architecture => "i386", |
|
|
137 | available_threads => 17, |
|
|
138 | datastore_free => "5ce03400", |
|
|
139 | datastore_max => "2540be400", |
|
|
140 | datastore_used => "1f72bb000", |
|
|
141 | estimated_load => 52, |
|
|
142 | free_memory => "5cc0148", |
|
|
143 | is_transient => "false", |
|
|
144 | java_name => "Java HotSpot(_T_M) Server VM", |
|
|
145 | java_vendor => "http://www.blackdown.org/", |
|
|
146 | java_version => "Blackdown-1.4.1-01", |
|
|
147 | least_recent_timestamp => "f41538b878", |
|
|
148 | max_file_size => "5f5e100", |
|
|
149 | most_recent_timestamp => "f77e2cc520" |
|
|
150 | node_address => "1.2.3.4", |
|
|
151 | node_port => 369, |
|
|
152 | operating_system => "Linux", |
|
|
153 | operating_system_version => "2.4.20", |
|
|
154 | routing_time => "a5", |
|
|
155 | } |
|
|
156 | |
|
|
157 | $txn = $fcp->txn_generate_chk ($metadata, $data) |
|
|
158 | $uri = $fcp->generate_chk ($metadata, $data) |
|
|
159 | Creates a new CHK, given the metadata and data. UNTESTED. |
|
|
160 | |
|
|
161 | $txn = $fcp->txn_generate_svk_pair |
|
|
162 | ($public, $private) = @{ $fcp->generate_svk_pair } |
|
|
163 | Creates a new SVK pair. Returns an arrayref. |
|
|
164 | |
|
|
165 | [ |
|
|
166 | "hKs0-WDQA4pVZyMPKNFsK1zapWY", |
|
|
167 | "ZnmvMITaTXBMFGl4~jrjuyWxOWg" |
|
|
168 | ] |
|
|
169 | |
|
|
170 | $txn = $fcp->txn_insert_private_key ($private) |
|
|
171 | $public = $fcp->insert_private_key ($private) |
|
|
172 | Inserts a private key. $private can be either an insert URI (must |
|
|
173 | start with "freenet:SSK@") or a raw private key (i.e. the private |
|
|
174 | value you get back from "generate_svk_pair"). |
|
|
175 | |
|
|
176 | Returns the public key. |
|
|
177 | |
|
|
178 | UNTESTED. |
|
|
179 | |
|
|
180 | $txn = $fcp->txn_get_size ($uri) |
|
|
181 | $length = $fcp->get_size ($uri) |
|
|
182 | Finds and returns the size (rounded up to the nearest power of two) |
|
|
183 | of the given document. |
|
|
184 | |
|
|
185 | UNTESTED. |
|
|
186 | |
|
|
187 | $txn = $fcp->txn_client_get ($uri [, $htl = 15 [, $removelocal = 0]]) |
|
|
188 | ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
|
|
189 | Fetches a (small, as it should fit into memory) file from freenet. |
|
|
190 | $meta is the metadata (as returned by "parse_metadata" or "undef"). |
|
|
191 | |
|
|
192 | Due to the overhead, a better method to download big files should be |
|
|
193 | used. |
|
|
194 | |
|
|
195 | my ($meta, $data) = @{ |
|
|
196 | $fcp->client_get ( |
|
|
197 | "freenet:CHK@hdXaxkwZ9rA8-SidT0AN-bniQlgPAwI,XdCDmBuGsd-ulqbLnZ8v~w" |
|
|
198 | ) |
|
|
199 | }; |
|
|
200 | |
|
|
201 | $txn = $fcp->txn_client_put ($uri, $metadata, $data, $htl, $removelocal) |
|
|
202 | my $uri = $fcp->client_put ($uri, $metadata, $data, $htl, $removelocal); |
|
|
203 | Insert a new key. If the client is inserting a CHK, the URI may be |
|
|
204 | abbreviated as just CHK@. In this case, the node will calculate the |
|
|
205 | CHK. |
|
|
206 | |
|
|
207 | $meta can be a reference or a string (ONLY THE STRING CASE IS |
|
|
208 | IMPLEMENTED!). |
|
|
209 | |
|
|
210 | THIS INTERFACE IS UNTESTED AND SUBJECT TO CHANGE. |
|
|
211 | |
|
|
212 | MISSING: (ClientPut), InsretKey |
|
|
213 | |
|
|
214 | THE Net::FCP::Txn CLASS |
|
|
215 | All requests (or transactions) are executed in a asynchroneous way (LIE: |
|
|
216 | uploads are blocking). For each request, a "Net::FCP::Txn" object is |
|
|
217 | created (worse: a tcp connection is created, too). |
|
|
218 | |
|
|
219 | For each request there is actually a different subclass (and it's |
|
|
220 | possible to subclass these, although of course not documented). |
|
|
221 | |
|
|
222 | The most interesting method is "result". |
|
|
223 | |
|
|
224 | new arg => val,... |
|
|
225 | Creates a new "Net::FCP::Txn" object. Not normally used. |
|
|
226 | |
|
|
227 | $txn = $txn->cb ($coderef) |
|
|
228 | Sets a callback to be called when the request is finished. The |
|
|
229 | coderef will be called with the txn as it's sole argument, so it has |
|
|
230 | to call "result" itself. |
|
|
231 | |
|
|
232 | Returns the txn object, useful for chaining. |
|
|
233 | |
|
|
234 | Example: |
|
|
235 | |
|
|
236 | $fcp->txn_client_get ("freenet:CHK....") |
|
|
237 | ->userdata ("ehrm") |
|
|
238 | ->cb(sub { |
|
|
239 | my $data = shift->result; |
|
|
240 | }); |
|
|
241 | |
|
|
242 | $txn = $txn->userdata ([$userdata]) |
|
|
243 | Set user-specific data. This is useful in progress callbacks. The |
|
|
244 | data can be accessed using "$txn->{userdata}". |
|
|
245 | |
|
|
246 | Returns the txn object, useful for chaining. |
|
|
247 | |
|
|
248 | $txn->cancel (%attr) |
|
|
249 | Cancels the operation with a "cancel" exception anf the given |
|
|
250 | attributes (consider at least giving the attribute "reason"). |
|
|
251 | |
|
|
252 | UNTESTED. |
|
|
253 | |
|
|
254 | $result = $txn->result |
|
|
255 | Waits until a result is available and then returns it. |
|
|
256 | |
|
|
257 | This waiting is (depending on your event model) not very efficient, |
|
|
258 | as it is done outside the "mainloop". |
|
|
259 | |
|
|
260 | The Net::FCP::Exception CLASS |
|
|
261 | Any unexpected (non-standard) responses that make it impossible to |
|
|
262 | return the advertised result will result in an exception being thrown |
|
|
263 | when the "result" method is called. |
|
|
264 | |
|
|
265 | These exceptions are represented by objects of this class. |
|
|
266 | |
|
|
267 | $exc = new Net::FCP::Exception $type, \%attr |
|
|
268 | Create a new exception object of the given type (a string like |
|
|
269 | "route_not_found"), and a hashref containing additional attributes |
|
|
270 | (usually the attributes of the message causing the exception). |
|
|
271 | |
|
|
272 | $exc->type([$type]) |
|
|
273 | With no arguments, returns the exception type. Otherwise a boolean |
|
|
274 | indicating wether the exception is of the given type is returned. |
|
|
275 | |
|
|
276 | $exc->attr([$attr]) |
|
|
277 | With no arguments, returns the attributes. Otherwise the named |
|
|
278 | attribute value is returned. |
|
|
279 | |
10 | SEE ALSO |
280 | SEE ALSO |
11 | <http://freenet.sf.net>. |
281 | <http://freenet.sf.net>. |
12 | |
282 | |
13 | BUGS |
283 | BUGS |
14 | Should EXPORT or EXPORT_OK the MODE constants. |
|
|
15 | |
|
|
16 | There should be a way to access initial IV contents :( |
|
|
17 | |
|
|
18 | Although I tried to make the original twofish code portable, I can't say |
|
|
19 | how much I did succeed. The code tries to be portable itself, and I hope |
|
|
20 | I got the endianness issues right. The code is also copyright |
|
|
21 | Counterpane Systems, no license accompanied it, so using it might |
|
|
22 | actually be illegal ;) |
|
|
23 | |
|
|
24 | I also cannot guarantee for security, but the module is used quite a |
|
|
25 | bit, so there are no obvious bugs left. |
|
|
26 | |
|
|
27 | AUTHOR |
284 | AUTHOR |
28 | Marc Lehmann <pcg@goof.com> |
285 | Marc Lehmann <pcg@goof.com> |
29 | http://www.goof.com/pcg/marc/ |
286 | http://www.goof.com/pcg/marc/ |
30 | |
287 | |
31 | The actual twofish encryption is written in horribly microsoft'ish looking |
|
|
32 | almost ansi-c by Doug Whiting. |
|
|
33 | |
|
|