PROPHET/OS
NAME
copyv: carries one file from one machine to another, over TCP
SYNOPSIS
copyv serve [port] | send <address> <from> <to> [port] | get <address> <name> <here> [port]
DESCRIPTION
Carries one file from one machine to another, over TCP. Port 7421 by default.
copyv serve [port]
takes calls for one round of two seconds and stores what comes
under /data/copy, then returns, so a service starter gets its
thread back and the port stays open
copyv send <address> <from> <to> [port]
reads <from> on this machine and asks the other side for the
name <to>
copyv get <address> <name> <here> [port]
fetches <name> from the other side into the file <here>
copyv selbsttest
drives the decisions that read what comes from outside
The form on the wire
It stands in lib/include/os/copyform.h, once for both programs that speak it: copyv and, since the second stage of R9-DRAHT-02, rsync.
A fixed header, then what the kind says. The header carries the magic word PCP3, the kind, the length of the name and the size, so a stream that is not this protocol is turned away at the first four bytes instead of being read as a length. PCP2 had no sum, PCP1 no kind.
store header, the bytes, the sender's SHA-256 of them; back one
byte (0 stored, 2 the sums differ, else refused) and the
receiver's own SHA-256
ask header, then back: one byte (0 = there), the size as eight
bytes, that many bytes, their SHA-256
Every transfer is summed on both sides: the receiver stores a file only when its sum is the sender's, the sender checks the receiver's sum once more. A fetched file is written beside its name as <here>.copyv and its name moved onto <here> only once both sums are the same: until then nobody reads half a file, and a transfer that breaks off or differs leaves the old file as it was. Both sides print the first sixteen digits of the sum, ... the same on both sides.
Asking is what rsync needs: it writes a file only when it is missing or differs, so it has to see what lies over there. The comparison is then the same one it makes locally, byte for byte.
<to> and <name> are bare names, not paths: letters, digits, dot, underscore and hyphen, and never . or ... The file lands under /data/copy. It is written beside its name and hung over in one step at the end, so a transfer that breaks off leaves the old, whole file standing.
Why it is its own program
rsync compares two trees and writes only what is missing or differs. The way outwards belongs here and not in there: whoever builds the transport into the one program that compares trees has it in exactly one place instead of for all.
EXAMPLE
$ copyv --help copyv serve [port] | send <address> <from> <to> [port] | get <address> <name> <here> [port] carries one file over TCP, port 7421 by default serve takes calls for one round of two seconds and stores what comes under /data/copy send reads <from> here and asks for the name <to> get fetches <name> from there into <here>