ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-FCP/README
Revision: 1.9
Committed: Sun Sep 28 08:58:07 2003 UTC (22 years, 11 months ago) by root
Branch: MAIN
Changes since 1.8: +9 -5 lines
Log Message:
*** empty log message ***

File Contents

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