… | |
… | |
53 | Virtually every number in the FCP protocol is in hex. Be sure to use |
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 |
54 | "hex()" on all such numbers, as the module (currently) does nothing |
55 | to convert these for you. |
55 | to convert these for you. |
56 | |
56 | |
57 | THE Net::FCP CLASS |
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 | $string = Net::FCP::build_metadata $meta |
|
|
93 | Takes a hash reference as returned by "Net::FCP::parse_metadata" and |
|
|
94 | returns the corresponding string form. If a string is given, it's |
|
|
95 | returned as is. |
|
|
96 | |
|
|
97 | $fcp = new Net::FCP [host => $host][, port => $port][, progress => \&cb] |
58 | $fcp = new Net::FCP [host => $host][, port => $port][, progress => \&cb] |
98 | Create a new virtual FCP connection to the given host and port |
59 | Create a new virtual FCP connection to the given host and port |
99 | (default 127.0.0.1:8481, or the environment variables "FREDHOST" and |
60 | (default 127.0.0.1:8481, or the environment variables "FREDHOST" and |
100 | "FREDPORT"). |
61 | "FREDPORT"). |
101 | |
62 | |
… | |
… | |
110 | my ($self, $txn, $type, $attr) = @_; |
71 | my ($self, $txn, $type, $attr) = @_; |
111 | |
72 | |
112 | warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
73 | warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
113 | } |
74 | } |
114 | |
75 | |
115 | $txn = $fcp->txn(type => attr => val,...) |
76 | $txn = $fcp->txn (type => attr => val,...) |
116 | The low-level interface to transactions. Don't use it. |
77 | The low-level interface to transactions. Don't use it unless you |
117 | |
78 | have "special needs". Instead, use predefiend transactions like |
118 | Here are some examples of using transactions: |
79 | this: |
119 | |
80 | |
120 | The blocking case, no (visible) transactions involved: |
81 | The blocking case, no (visible) transactions involved: |
121 | |
82 | |
122 | my $nodehello = $fcp->client_hello; |
83 | my $nodehello = $fcp->client_hello; |
123 | |
84 | |
… | |
… | |
179 | $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
140 | $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
180 | Calculates a CHK, given the metadata and data. $cipher is either |
141 | Calculates a CHK, given the metadata and data. $cipher is either |
181 | "Rijndael" or "Twofish", with the latter being the default. |
142 | "Rijndael" or "Twofish", with the latter being the default. |
182 | |
143 | |
183 | $txn = $fcp->txn_generate_svk_pair |
144 | $txn = $fcp->txn_generate_svk_pair |
184 | ($public, $private) = @{ $fcp->generate_svk_pair } |
145 | ($public, $private, $crypto) = @{ $fcp->generate_svk_pair } |
185 | Creates a new SVK pair. Returns an arrayref with the public key, the |
146 | Creates a new SVK pair. Returns an arrayref with the public key, the |
186 | private key and a crypto key, which is just additional entropy. |
147 | private key and a crypto key, which is just additional entropy. |
187 | |
148 | |
188 | [ |
149 | [ |
189 | "acLx4dux9fvvABH15Gk6~d3I-yw", |
150 | "acLx4dux9fvvABH15Gk6~d3I-yw", |
… | |
… | |
216 | Finds and returns the size (rounded up to the nearest power of two) |
177 | Finds and returns the size (rounded up to the nearest power of two) |
217 | of the given document. |
178 | of the given document. |
218 | |
179 | |
219 | $txn = $fcp->txn_client_get ($uri [, $htl = 15 [, $removelocal = 0]]) |
180 | $txn = $fcp->txn_client_get ($uri [, $htl = 15 [, $removelocal = 0]]) |
220 | ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
181 | ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
221 | Fetches a (small, as it should fit into memory) file from freenet. |
182 | Fetches a (small, as it should fit into memory) key content block |
222 | $meta is the metadata (as returned by "parse_metadata" or "undef"). |
183 | from freenet. $meta is a "Net::FCP::Metadata" object or "undef"). |
223 | |
184 | |
224 | The $uri should begin with "freenet:", but the scheme is currently |
185 | The $uri should begin with "freenet:", but the scheme is currently |
225 | added, if missing. |
186 | added, if missing. |
226 | |
|
|
227 | Due to the overhead, a better method to download big files should be |
|
|
228 | used. |
|
|
229 | |
187 | |
230 | my ($meta, $data) = @{ |
188 | my ($meta, $data) = @{ |
231 | $fcp->client_get ( |
189 | $fcp->client_get ( |
232 | "freenet:CHK@hdXaxkwZ9rA8-SidT0AN-bniQlgPAwI,XdCDmBuGsd-ulqbLnZ8v~w" |
190 | "freenet:CHK@hdXaxkwZ9rA8-SidT0AN-bniQlgPAwI,XdCDmBuGsd-ulqbLnZ8v~w" |
233 | ) |
191 | ) |