code wiki / _hdl_build / nx_adnet_advreport.nx
nx_adnet_advreport.nx source
↩ module page · 82 lines · 4521 B
1// nx_adnet_advreport.nx -- RUNNER: the per-advertiser delivery report, made REACHABLE.
2// THE GAP: `ainv_report_for_advertiser` is gated (tenant isolation proven: own campaigns included, a
3// rival's EXCLUDED, unknown advertiser gets an EMPTY report rather than everyone's) but nothing could
4// CALL it. The public /advertise page promises "you see the delivery ratio -- served and viewable side
5// by side", and a claim on a public page with no surface behind it is a promise you will be asked to
6// honour. A gated function with no caller is, by this ecosystem's own law, still the baseline.
7//
8// Shipped as a REGISTERED ORGAN, not a mgmt route, for two reasons:
9// 1. every new route widens the control plane, and this needs no authority beyond reading four files;
10// 2. the mgmt API currently cannot be modified at all -- /api/srcwrite truncates source at the ampersand character and
11// nx_mgmt_api.nx has 25 of them, so the route path is physically blocked until that is fixed.
12// Choosing the reachable door is not a workaround; it is the door that exists.
13//
14// ★ AUTH IS THE CALLER'S JOB, STILL. This takes an advertiser_bk on argv and does NOT authenticate it.
15// organ_run is operator-gated, so today that IS the boundary. Do NOT expose this to an advertiser
16// without establishing identity first -- baking a token check in here is how the check gets skipped by
17// the second caller.
18//
19// nx_adnet_advreport <advertiser_bk> (live confs)
20// nx_adnet_advreport <advertiser_bk> <camps> <rates> <served> <view> <clicks> (fixtures; read-only)
21// expect_exit: 0 license_tier: ORIGINAL
22import "nx_syscalls.nx"
23import "_hdl_build/nx_adnet_invoice.nx"
24
25const ADR_CAMPS: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/status/adnet_campaigns.conf" as *u8
26const ADR_RATES: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/status/adnet_rates.conf" as *u8
27const ADR_SERVED: *u8 = "/volume1/homes/elderwesto/nishihost/adnet_impressions.log" as *u8
28const ADR_CLICKS: *u8 = "/volume1/homes/elderwesto/nishihost/adnet_clicks.log" as *u8
29const ADR_VIEW: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/status/adnet_viewable.log" as *u8
30const ADR_CAP: i64 = 262144
31
32func adr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
33
34func adr_run(adv: *u8, pc: *u8, pr: *u8, ps: *u8, pv: *u8, pk: *u8) -> i64 {
35 if aslot_id_ok(adv) == 0 {
36 adr_puts("ADNET-ADVREPORT: refused -- advertiser id must be [A-Za-z0-9_-], 1..64\n" as *u8)
37 return 1
38 }
39 let b1: *i64 = sys_mmap(16) as *i64
40 var camps: *u8 = sys_read_file(pc, b1)
41 var cl: i64 = b1[0]
42 if (camps as i64) == 0 { camps = "" as *u8; cl = 0 }
43 let b2: *i64 = sys_mmap(16) as *i64
44 var rates: *u8 = sys_read_file(pr, b2)
45 var rl: i64 = b2[0]
46 if (rates as i64) == 0 { rates = "" as *u8; rl = 0 }
47 let b3: *i64 = sys_mmap(16) as *i64
48 var slog: *u8 = sys_read_file(ps, b3)
49 var sl: i64 = b3[0]
50 if (slog as i64) == 0 { slog = "" as *u8; sl = 0 }
51 let b4: *i64 = sys_mmap(16) as *i64
52 var vlog: *u8 = sys_read_file(pv, b4)
53 var vl: i64 = b4[0]
54 if (vlog as i64) == 0 { vlog = "" as *u8; vl = 0 }
55 let b5: *i64 = sys_mmap(16) as *i64
56 var clog: *u8 = sys_read_file(pk, b5)
57 var kl: i64 = b5[0]
58 if (clog as i64) == 0 { clog = "" as *u8; kl = 0 }
59
60 let out: *u8 = sys_mmap(ADR_CAP)
61 let n: i64 = ainv_report_for_advertiser(camps, cl, adv, rates, rl, slog, sl, vlog, vl, clog, kl, out, ADR_CAP)
62 if n == 0 {
63 // An advertiser with no campaigns is a legitimate state, NOT an error, and must not look like a
64 // failure to the operator reading this. It is also what an unknown id returns -- deliberately
65 // indistinguishable, so this can never be used to enumerate who our advertisers are.
66 adr_puts("ADNET-ADVREPORT: no campaigns for that advertiser\n" as *u8)
67 return 0
68 }
69 sys_write(1, out, n)
70 return 0
71}
72
73func main(argc: i64, argv: *i64) -> i64 {
74 if argc < 2 {
75 adr_puts("usage: nx_adnet_advreport <advertiser_bk> [camps rates served view clicks]\n" as *u8)
76 return 1
77 }
78 let adv: *u8 = argv[1] as *u8
79 if argc > 6 {
80 return adr_run(adv, argv[2] as *u8, argv[3] as *u8, argv[4] as *u8, argv[5] as *u8, argv[6] as *u8)
81 }
82 return adr_run(adv, ADR_CAMPS, ADR_RATES, ADR_SERVED, ADR_VIEW, ADR_CLICKS)
83}