fcp
TOC »
Description
fcp is a very minimal and somewhat simplistic interface to the Freenet FCP library. Freenet documentation can be found here Freenet and FCP is documented hereFCPv2.
NOTE: Qwen3.8 + hermes-agent was used to make many of these changes. I understand this is controversial and I myself am on the fence on the use of LLMs. This used maybe as much as 2 kWHrs of electric power over a period of a few days.
IMPORTANT: This release is minimally tested. I'll remove this message once the validation is completed. Adjust expectations accordingly.
Author
Matt Welland is the author of the fcp chicken egg. Freenet and the Freenet client protocol (FCPv2) were written by Ian Clarke and others.
Repository
The fossil repository for the fcp source code is hosted by Kiatoa: https://www.kiatoa.com/fossils/freenet.
Requirements
You will need to install Freenet on the same machine where the fcp calls are made. If Freenet is running on another machine you'll need to configure it accordingly.
The egg builds and runs under both Chicken 5 (tested on 5.4) and Chicken 6. It avoids anything whose home moved between the two releases: the egg provides its own parameter accessor in place of make-parameter, and uses (handle-exceptions ex (void) ...) from (chicken condition) for port cleanup instead of checking input/output-port-open?, which is in (chicken base) on 5 but in (scheme base) on 6.
Parameters
verbosity
- verbosity numberprocedure
Turn up the noise. Default is 0 (minimal feedback but still some on std-out).
port
- port #!optional numberprocedure
FCP server port. Read with no argument, set with one. Default is 9481.
host
- host #!optional stringprocedure
FCP server host to connect to. Read with no argument, set with one. Default is "localhost".
debug-fake-hyphanet-path
- debug-fake-hyphanet-path #!optional path-or-#fprocedure
Offline test hook (module-internal, not exported). When set to a directory path, the network functions are replaced by fakes before any network I/O happens: retrieve-file only creates the target directory, and insert-file, gen-ssk and gen-usk return #f without touching a node. Default is #f (real Freenet). Intended for the test harness in tests/.
Procedures
gen-usk
- gen-usk name version-numberprocedure
Creates an SSK then publishes name at version number on it, returning the InsertURI / RequestURI in an alist (USK@... form). Used for USK-based content: insert with gen-usk / ssk->usk, then fetch with the RequestURI.
ssk->usk
- ssk->usk insert-uri request-uri name version-numberprocedure
Low-level helper: takes the SSK pair from gen-ssk and rewrites both URIs to USK@.../name/version form.
register-directory
- register-directory pathprocedure
Ask the Freenet node (via DDA) to keep the given directory synchronized with the Freenet cache: content inserted into that directory is published, and retrieved content is written into it. This is the "register as a directory" step for persistent storage / DDA clients.
retrieve-file
- retrieve-file URI dir fileprocedure
Download the content of URI into file in dir. See Freenet documentation for URI format and information. A keyword argument timeout (seconds, #f = no limit) is available. If the node reports the content is not fully available yet (RedirectURI), retrieve-file retries with the new URI. Returns #t on success, #f on failure.
insert-file
- insert-file dir file #!optional URIprocedure
Insert file residing in dir into Freenet. A URI will be returned. To insert SSK, USK and KSK (I believe KSK will work) provide the URI. The reply loop matches messages against the request Identifier, so interleaved traffic on the same connection no longer ends the wait early.
gen-ssk
- gen-sskprocedure
Create a URI to use in insert-file. Returns the private and publish URI strings along with other info in an alist.
Example
(insert-file "/tmp" "ten-habits.pdf") .................... "CHK@ugLEKvesBPC0c5bKbh86N9omjaMF4a-JUdzifYc9wPE,kj4d7bUEqmXFthm8rbG69UKqpLrxLM7e2n6LJMAVpPE,AAMC--8/ten-habits.pdf" (retrieve-file "CHK@ofHXEz3mHZpOeBVryuq0cSupwgxLxfbzNn9FwjQzRDs,VK54VUNcV7DfDKupp7ugDojwtJNV-iPXwwV6OWLvnmM,AAMC--8/quick-beef-noodle-pho.pdf" "/tmp" "quick-beef-noodle-pho.pdf") Progress: retrieved 0 out of 1 and 1 (false) Progress: retrieved 0 out of 1 and 1 (false) Progress: retrieved 1 out of 1 and 1 (false) Progress: retrieved 1 out of 800 and 1608 (true) #t
App
fcpapp
Usage: fcpapp [options] cmd [args]
Options (before the command):
--host HOST FCP host to connect to [default: localhost]
--port NUM FCP port to connect to [default: 9481]
--verbose LEVEL 0=quiet 1=normal 2=debug [default: 0]
-v bump verbosity one level (repeatable)
--help, -h show usage
Commands:
retrieve URI destpath/file : get a file
insert path/file : insert file
insert path/file SSK : insert file using SSK
genssk : create an SSK
genusk NAME VERNUM : create a USK
registerdir PATH : register a directory with the DDALicense
Copyright (c) 2022, Matt Welland
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Version history
Version 1.0
- Dual compatibility: builds and runs under both Chicken 5 (5.4) and Chicken 6. make-parameter replaced by an in-egg parameter accessor; with-connection cleanup uses (chicken condition)'s handle-exceptions instead of input/output-port-open? guards, so it no longer depends on where that predicate lives (chicken base on 5, scheme base on 6).
- New exported parameters: host, port (already used internally, now documented and settable from the app).
- New procedure: gen-usk NAME VERNUM (and ssk->usk helper) for USK-based publish; new command genusk NAME VERNUM in fcpapp.
- New procedure: register-directory, DDA directory registration; new command registerdir PATH in fcpapp.
- fcpapp rewrite: proper option parsing with --host / --port / --verbose / -v / --help before the command.
- retrieve-file-core: removed a stray extra close-paren in the reply loop (an old "paren mismatching" note marked this spot), fixing the tail of the COMPAT_UNKNOWN detection.
- insert-file: reply loop now matches incoming messages against the request Identifier, so interleaved traffic on the same connection no longer ends the wait early.
- Offline test support: debug-fake-hyphanet-path switches the network calls to fakes; tests/ contains a mock FCP node (fake-server.scm) and drivers for insert, retrieve (incl. redirect and error paths) and DDA register.
- freemail and imap companion modules included in the egg for IMAP/POP-like mail over Freenet (work in progress).
Version 0.4
- Basics working
Version 0.2
- Initial release