Skip to content

Latest commit

 

History

History
86 lines (60 loc) · 7.52 KB

NETWORK.md

File metadata and controls

86 lines (60 loc) · 7.52 KB

The network layer

FormCite works offline. From version 0.5.0 it can look a reference up by its identifier (DOI, arXiv id, ISBN, PubMed ID) through public services. Every outbound connection FormCite makes goes through one package, backend/app/net/. No other code in FormCite opens a connection.

The rules

  1. Nothing in the background. FormCite calls a service only when a person or an agent asked for exactly that lookup: a verb such as ./formcite cli add doi=..., a route such as POST /api/library/lookup, or identifying a PDF someone named (POST /api/library/identify, /identify/scan) or dropped on the window (POST /api/library/identify/upload). There is no timer, no start-up check, no update check and no prefetch: the engine's start-up only writes its own discovery file, and the window's only repeating calls go to the engine on this computer.
  2. Every host is declared. A service is registered with a name, one host, a purpose and the address of its own documentation. A fetch is refused unless the address is https and its host is exactly the registered host. A redirect is followed only to https on a host some registered service declares, at most three times, and never to a service you have switched off.
  3. You hold the switches. The whole network can be switched off, and so can each service. When a switch is off, the lookup fails with a plain sentence before any connection is opened, and nothing is added to the library.
  4. Every call is logged in a file in your data folder that you can read.

Other limits: a call waits at most 10 seconds by default; an answer larger than 5 MB is refused; answers may be gzip-compressed; each service gets a polite minimum gap between two calls (one second unless the service asks for more), kept inside one running FormCite process. Every request carries the same User-Agent: FormCite/VERSION (+https://github.com/nodemode-dev/formcite).

The contact address

Some services ask callers to name someone they can write to: Crossref (its mailto parameter), NCBI (its email parameter) and Open Library (a contact in the User-Agent). FormCite sends no address unless you set one. Set it with ./formcite cli network contact you@example.org, clear it with network contact --clear, or use PUT /api/network/contact {"contact": "you@example.org"}; it is kept in network.json. The environment variable FORMCITE_CONTACT_EMAIL is used when the file holds none. Once set, the address goes to Crossref's works route as mailto, to NCBI as email, and to every service inside the User-Agent as mailto:ADDRESS. That is the only personal detail FormCite ever sends.

The switches

They live in network.json in the data folder, beside libraries.json (the data folder is ~/FormCite unless FORMCITE_DATA_DIR names another). The file is written atomically. When it is missing, the network and every service are on.

How Command line Engine route (changes need the window key)
See every service and its switch ./formcite cli network list GET /api/network/services
Network off or on ./formcite cli network off, network on PUT /api/network/enabled {"enabled": false}
One service off or on ./formcite cli network disable NAME, network enable NAME PUT /api/network/services/NAME {"enabled": false}
Read the log ./formcite cli network log --limit 20 GET /api/network/log?limit=20

The window shows the same list in Preferences under Network: the master switch, one switch per service with its purpose, the contact address and the recent calls. Its list comes from GET /api/network/services.

Setting the environment variable FORMCITE_OFFLINE=1 forces the network off for that process, whatever network.json says. It is read on every call and never written to the file.

The log

network-log.jsonl in the data folder holds one JSON object per call:

{"time": "2026-11-26T23:59:01-05:00", "service": "crossref", "host": "api.crossref.org", "path": "/works/10.1038/nature12373", "status": 200, "error": null, "ms": 429}

time is US Eastern. path keeps the query string, and its values are kept on purpose: they are the identifier you asked about (a DOI, an ISBN, a PubMed ID), so the log shows what was sent. If you consider an identifier private, the log holds it. The file is append-only; when it reaches 1 MB it is renamed to network-log.jsonl.1 (replacing the previous one) and a new file starts. A call refused before a connection (a switch off, a host not declared, an address that is not https) writes no line, because nothing was sent.

The errors

Error When Engine answer
NetworkOff the network or that service is switched off, or FORMCITE_OFFLINE=1 422 with the sentence
NetworkError no answer, a time-out, a host name that cannot be found, a bad status, an answer too large or not readable 422 with a sentence naming the service
RemoteNotFound the service answered 404 404

Services the lookup modules register

Filled from what the lookup modules declared when this page was written. The DOI lookup relies on redirects: doi.org sends the request on to api.crossref.org or data.crosscite.org, which is allowed because both hosts are declared. The engine always answers the current list at GET /api/network/services, and ./formcite cli network list prints it.

Name Host Purpose Its documentation Gap
arxiv export.arxiv.org a preprint's title, authors, dates, abstract and categories by arXiv id https://info.arxiv.org/help/api/user-manual.html 3 s
crosscite data.crosscite.org CSL-JSON of a DataCite DOI, where doi.org redirects a content negotiation request https://citation.doi.org/docs.html 1 s
crossref api.crossref.org metadata of a Crossref DOI: the CSL-JSON doi.org redirects to, and the REST API works route https://www.crossref.org/documentation/retrieve-metadata/rest-api/ 1 s
datacite api.datacite.org metadata of a DataCite DOI through the DataCite REST API https://support.datacite.org/docs/api-get-doi 1 s
doi-org doi.org a DOI by content negotiation for CSL-JSON; doi.org redirects to the agency that registered it https://citation.doi.org/docs.html 1 s
openlibrary openlibrary.org book records by ISBN, through the Open Library Books API https://openlibrary.org/dev/docs/api/books 1 s
pubmed eutils.ncbi.nlm.nih.gov PubMed records by PubMed ID (NCBI E-utilities EFetch) https://www.ncbi.nlm.nih.gov/books/NBK25499/ 0.4 s

The net.register(...) calls at the top of backend/app/lookup/arxiv.py, doi.py, isbn.py and pubmed.py are the source of this table; read them, and docs/LOOKUP.md, for anything added later.

How to add a service

  1. Read the service's own documentation: its address, parameters, answer shape and usage rules (rate limits, contact parameters).
  2. At the top of your module in backend/app/lookup/, declare it once:
from app import net

net.register(
    "example",
    "api.example.org",
    "What FormCite asks this service for, in one sentence.",
    "https://api.example.org/docs",
    interval=1.0,
)
  1. Fetch only through net.fetch_json("example", "https://api.example.org/...", params={...}) or net.fetch_text(...). Never import urllib.request, http.client, socket, requests or httpx.
  2. Let RemoteNotFound mean "no such record" and let NetworkOff and NetworkError reach the person unchanged: their sentences already name the service.
  3. Add the service to the table above.