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 wayEvery 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§
- Upload
Error - 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
responsesays, as far asMAX_ANSWER. - authorization 🔒
- What the
Authorizationheader says for the authorizationauth: the event as base64, for addresses and unpadded as the specification has it, or plain andpaddedas servers older than that read it. - counted 🔒
bytesas what a request sends, a piece at a time, withsentkept at how much of it was handed over.- endpoint 🔒
- The address of
pathonserver. - 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 tomedia, whose hash there ishash. Its kind, its hash, its size, and for a picture that was measured its width and height. - imeta_
url - The link that
tagsays something of, if it is animetatag. - mirror
- Ask
serverto fetch the file aturl, which the authorizationauthis for, and keep it as well (BUD-04). - names_
server 🔒 - Whether
tagnames a media server. - refusal 🔒
- Why
response, which is no success, says the request was refused: the reason the server gives in itsX-Reasonheader, or failing that in what it answers, or failing that what the status means. - send
- Send
media, whose hash ishashand whichauthauthorizes sending, to the first ofserversthat takes it, and have the others fetch it from there; withsentkept 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: withserversfor its servers, in that order, and whatever elseearlierhad 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
urlis the address of, or is an address on. - servers
- The media servers the server list
listnames, in its order, each once. None with no list. - typed_
server - The media server typed as
typed, with or withouthttps://.Noneif it is no address, or not anhttpsone: 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 ishashand which is amime, toserver(BUD-02), after asking whether it would take it (BUD-06), withsentkept 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 ishash, to media servers, fromnowforAUTH_SECONDS: for the account to sign. - why 🔒
- Why
errorcame 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.