diff --git a/modules/brother/README.md b/modules/brother/README.md index 50089e55..4183fa17 100644 --- a/modules/brother/README.md +++ b/modules/brother/README.md @@ -82,7 +82,7 @@ is not given, and the printer is not contacted. ### Documents in parts The bus refuses a message over 1 MiB, so a document crosses it in parts of at most 700 KiB (both the size this module -cuts and the most it accepts; ADR 0468 clause 3 says 768 KiB, which is 1 MiB of base64 before the message around it), +cuts and the most it accepts, as ADR 0468 clause 3 says), counted from 1, each carried base64-encoded in JSON. A caller joins the parts and checks the SHA-256. The bucket (`s3-bucket`, from `minio`) is spoken to by the device process alone, from `store.json` (owner `brother-device`, mode 0600), with the S3 client mesh-mail uses; a scan is kept once as `.pdf` and an upload as `uploads/.`. diff --git a/modules/brother/cmd/brother/admin_test.go b/modules/brother/cmd/brother/admin_test.go index c78a61e1..f51f3465 100644 --- a/modules/brother/cmd/brother/admin_test.go +++ b/modules/brother/cmd/brother/admin_test.go @@ -119,6 +119,12 @@ func (f *fakePrinter) host() string { return strings.TrimPrefix(f.URL, "https:// // print is the fingerprint of the certificate the server serves. func (f *fakePrinter) print() string { return Fingerprint(f.TLS.Certificates[0].Certificate[0]) } +func (f *fakePrinter) connsNow() int { + f.mu.Lock() + defer f.mu.Unlock() + return f.conns +} + func (f *fakePrinter) loggedInNow() int { f.mu.Lock() defer f.mu.Unlock() diff --git a/modules/brother/cmd/brother/parts.go b/modules/brother/cmd/brother/parts.go index 114e5df0..df357ded 100644 --- a/modules/brother/cmd/brother/parts.go +++ b/modules/brother/cmd/brother/parts.go @@ -11,8 +11,7 @@ import ( const ( // PartSize is how large the parts this module cuts are, and MaxPart the most raw bytes a part may hold; a part // of more is refused. They are one: 700 KiB, so that a part's base64 text (about 933 KB) and the message around - // it stay under the bus's 1 MiB. (ADR 0468 clause 3 says at most 768 KiB, which is 1 MiB of base64 before the - // message around it, and so over the bus's limit.) + // it stay under the bus's 1 MiB. (ADR 0468 clause 3.) PartSize = 700 << 10 MaxPart = PartSize // MostParts bounds how many parts one document has (a 100 MiB document is the most). diff --git a/modules/brother/cmd/brother/printer_test.go b/modules/brother/cmd/brother/printer_test.go index 45dad26c..fc73230d 100644 --- a/modules/brother/cmd/brother/printer_test.go +++ b/modules/brother/cmd/brother/printer_test.go @@ -119,8 +119,8 @@ func TestPrinterSettingsSaysWhichConfigIsUnsetAndQueuesNothing(t *testing.T) { t.Errorf("%s: an ask was queued", c.name) } } - if f.conns != 0 || len(f.requests) != 0 { - t.Errorf("the printer was contacted: %d connections, %v", f.conns, f.requests) + if f.connsNow() != 0 || len(f.requests) != 0 { + t.Errorf("the printer was contacted: %d connections, %v", f.connsNow(), f.requests) } } @@ -141,8 +141,8 @@ func TestPrinterSettingsSaysTheSecretIsNotGivenAndContactsNothing(t *testing.T) if _, err := r.run(nil); err == nil || !strings.Contains(err.Error(), "admin-password is not given") { t.Errorf("empty secret: error = %v", err) } - if f.conns != 0 || len(f.requests) != 0 { - t.Errorf("the printer was contacted: %d connections, %v", f.conns, f.requests) + if f.connsNow() != 0 || len(f.requests) != 0 { + t.Errorf("the printer was contacted: %d connections, %v", f.connsNow(), f.requests) } } @@ -162,8 +162,8 @@ func TestPrinterSettingsRefusesAPageOutsideTheSite(t *testing.T) { if _, err := r.run(map[string]any{"page": 5}); err == nil { t.Errorf("a page that is no string was accepted") } - if r.bus.asks() != 0 || f.conns != 0 { - t.Errorf("%d asks queued, the printer contacted %d times", r.bus.asks(), f.conns) + if r.bus.asks() != 0 || f.connsNow() != 0 { + t.Errorf("%d asks queued, the printer contacted %d times", r.bus.asks(), f.connsNow()) } } @@ -193,14 +193,14 @@ func TestTheAdminWorkerSettlesEachAsk(t *testing.T) { t.Errorf("an unreadable ask: action %v, want term", act) } old, _ := json.Marshal(Ask{ID: "old", Op: OpSettings, Page: DefaultPage, At: fixedNow.Add(-StaleAfter - time.Second)}) - if act, _ := w.Handle(old, nil); act != actionAck || r.answers.get("old") != nil || f.conns != 0 { - t.Errorf("a stale ask: action %v, answer %s, %d connections", act, r.answers.get("old"), f.conns) + if act, _ := w.Handle(old, nil); act != actionAck || r.answers.get("old") != nil || f.connsNow() != 0 { + t.Errorf("a stale ask: action %v, answer %s, %d connections", act, r.answers.get("old"), f.connsNow()) } fresh, _ := json.Marshal(Ask{ID: "a1", Op: OpSettings, Page: DefaultPage, At: fixedNow}) if act, _ := w.Handle(fresh, nil); act != actionAck || r.answers.get("a1") == nil { t.Errorf("a fresh ask: action %v", act) } - conns := f.conns + conns := f.connsNow() if act, _ := w.Handle(fresh, nil); act != actionAck { t.Errorf("an ask already answered: action %v, want ack", act) }