Skip to main content

Module blossom

Module blossom 

Source
Expand description

Media servers (Blossom): the account’s list of them, and sending a file to them so that a note can link to it.

A media server keeps files by what they are: each is known by the SHA-256 of its bytes, and is at that address on every server that has it. So a file that is on several servers is still to be found when one of them is gone, by anyone who knows where else its owner keeps files: which is what the account’s server list says (BUD-03, kind 10063), one server tag for each, the one to try first at the top.

A file is sent to the first server of the list that takes it (BUD-02), and the others are then asked to fetch it from there (BUD-04), so that it is on all of them:

sequenceDiagram
    participant A as Avestruz
    participant F as The first server
    participant O as Each other server
    Note over A: The file is hashed, and an authorization signed for that hash
    A->>F: HEAD /upload: would you take this? Its hash, size and type
    F-->>A: Yes. Or no, and why: the next server is tried
    A->>F: PUT /upload: the file
    F-->>A: Where it is now: its address, hash, size and type
    A->>O: PUT /mirror: fetch it from that address
    O-->>A: Done, or not: the file is attached either way

Every request carries the same authorization (BUD-11): an event of kind 24242 that the account signs, which says what may be done (t: upload), to which file (x: its hash) and until when (expiration). It goes in the Authorization header, as base64. The specification says base64 for addresses, without padding; servers written before it said so read only the plain kind, padded, and answer the other with 400 or 401. Such an answer has the request made once more, the other way.

The server is asked first whether it would take the file (BUD-06), which costs nothing; a server that says no is not sent the file to say no again, and one that doesn’t know the question is sent it.

What the note then carries is the file’s address, in its text, and an imeta tag (NIP-92) that says of that address what whoever shows the note would otherwise have to fetch the file to know: what kind of file it is, how large, its hash, and for a picture its width and height.

No server is built in, and no list is written that the account did not ask for: where its files go is for the account to say.

Structs§

Asking 🔒
Requests to one server, each with the authorization: written as the specification has it until the server doesn’t read it, and the other way from then on.
Attachment
A file that is on a media server, for a note to link to.
Blob
A file as a server says it has it (BUD-02).
Descriptor 🔒
What a server answers when it has taken a file: a blob descriptor.

Enums§

UploadError
Why a server did not take a file, or did not fetch it.

Constants§

AUTH_SECONDS 🔒
How long an authorization holds: long enough for a large file on a slow line, and not much use to whoever comes by it later.
IMETA_TAG 🔒
The name of the tag that says of a link in a note what is at it (NIP-92).
MAX_ANSWER 🔒
How much is read of what a server answers: where the file is, or why it was not taken.
MAX_REASON 🔒
How much of a server’s reason is shown, in characters.
MIRROR_TIMEOUT 🔒
NOT_ASKED_THAT 🔒
What a server answers a question it doesn’t know with, where the question is whether it would take a file (BUD-06): the file is sent without asking.
NOT_READ 🔒
What a server that doesn’t read the authorization as it was written answers with: it is written the other way and sent once more.
PIECE 🔒
How much of a file is handed over at a time: how finely it is known how much of it has gone.
SERVER_TAG 🔒
The name of the tag that names a media server in a server list (BUD-03).
UPLOAD_TIMEOUT 🔒
How long a server gets to take a file, and how long to fetch one from another server.

Functions§

answer 🔒
What response says, as far as MAX_ANSWER.
authorization 🔒
What the Authorization header says for the authorization auth: the event as base64, for addresses and unpadded as the specification has it, or plain and padded as servers older than that read it.
counted 🔒
bytes as what a request sends, a piece at a time, with sent kept at how much of it was handed over.
endpoint 🔒
The address of path on server.
hash_of
What a file is known by on a media server: the SHA-256 of bytes, in lowercase hex.
imeta
What a note says of the link url (NIP-92): that it is to media, whose hash there is hash. Its kind, its hash, its size, and for a picture that was measured its width and height.
imeta_url
The link that tag says something of, if it is an imeta tag.
mirror
Ask server to fetch the file at url, which the authorization auth is for, and keep it as well (BUD-04).
names_server 🔒
Whether tag names a media server.
refusal 🔒
Why response, which is no success, says the request was refused: the reason the server gives in its X-Reason header, or failing that in what it answers, or failing that what the status means.
send
Send media, whose hash is hash and which auth authorizes sending, to the first of servers that takes it, and have the others fetch it from there; with sent kept at how much of it has gone. Returns where it is, or why each server did not take it.
server_list
The server list (BUD-03) that replaces earlier, if there is one to replace: with servers for its servers, in that order, and whatever else earlier had in it as it was.
server_name
What a server is called on a page: its address without the scheme.
server_of 🔒
The server that url is the address of, or is an address on.
servers
The media servers the server list list names, in its order, each once. None with no list.
typed_server
The media server typed as typed, with or without https://. None if it is no address, or not an https one: nothing else is sent to. A server is where its endpoints are, which is at the root of its domain (BUD-01), so whatever path was typed after it is not part of it.
upload
Send the file bytes, whose hash is hash and which is a mime, to server (BUD-02), after asking whether it would take it (BUD-06), with sent kept at how much of it has gone. Returns the file as the server has it.
upload_auth
The authorization (BUD-11) to send the file called name, whose hash is hash, to media servers, from now for AUTH_SECONDS: for the account to sign.
why 🔒
Why error came about, down to what was behind it: a request that failed says no more of itself than that it did.

Type Aliases§

Sent
How much of a file has been handed over to be sent, in bytes: counted by what sends it, and read by what shows how far it has got.