interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / agora / test / fake-peer.om

112 lines · 2734 bytes Raw Blame History
1note fake-peer.om: a test-only Agora peer on loopback for net.sh. It serves GET /.well-known/agora naming
2note node feedfacefeedface at http://127.0.0.1:<its port> ("wrongbase" mode names http://127.0.0.1:1
3note instead, so a verifying node must refuse to list it) and answers every other GET (the since pulls)
4note with one malformed post record, so a syncing node must count it bad and drop the peer.
5note Usage: fake-peer good|wrongbase; prints "PORT <n>", serves 100 accepts and exits.
6note Compose: { printf 'om2\n'; cat sha256.om http.om client.om test/fake-peer.om; } | omc
7
8global gfp ulong 2
9
10note gfp: 0 the listening port, 1 set in wrongbase mode
11
12text fp_ctype "Content-Type"
13text fp_text "text/plain; charset=utf-8"
14text fp_well "/.well-known/agora"
15text fp_get "GET"
16text fp_port "PORT "
17text fp_wrong "wrongbase"
18text fp_wk1 "agora 1\nnode\tfeedfacefeedface\thttp://127.0.0.1:"
19text fp_wk2 "\tfake peer\napi\thttp://127.0.0.1:"
20text fp_wk3 "/agora/api/\n"
21text fp_wkbad "agora 1\nnode\tfeedfacefeedface\thttp://127.0.0.1:1\tfake peer\napi\thttp://127.0.0.1:1/agora/api/\n"
22text fp_bad "agora 1\nok\nrec\t1\tfeedfacefeedface\tpost\t1\nthread\tnot-a-number\tbad\tbad\nbody 3\nbad\n"
23
24fn fp_send cs edit ulong 320 io edit uchar 131072 s view uchar * to long
25r = hrspst cs io 200
26r = hfe r hhname cs io fp_ctype
27r = hfe r hhval cs io fp_text
28blen = len s
29r = hfe r hhend cs io 0 blen
30r = hfe r hput cs io s
31ret hfe r hwfin cs io
32end
33
34fn fp_wk cs edit ulong 320 io edit uchar 131072 to long
35b = new uchar 512 0
36if eq get gfp 1 1
37ret fp_send cs io fp_wkbad
38end
39q = ac_cat b 0 fp_wk1
40q = ac_catu b q get gfp 0
41q = ac_cat b q fp_wk2
42q = ac_catu b q get gfp 0
43q = ac_cat b q fp_wk3
44ret fp_send cs io view part b 0 q
45end
46
47fn route cs edit ulong 320 io edit uchar 131072 to long
48if not hismeth cs io fp_get
49ret hrspempty cs io 405
50end
51if hispath cs io fp_well
52ret fp_wk cs io
53end
54ret fp_send cs io fp_bad
55end
56
57fn serve1 lf int cs edit ulong 320 io edit uchar 131072 to long
58c = haccept lf 30000000000
59if lt c 0
60ret 0
61end
62r = hinit cs io int c 1
63if lt r 0
64x = hclose cs
65ret 0
66end
67hsettmo cs 10000000000 10000000000
68for k ulong 10
69r = hreqrd cs io
70if le r 0
71if lt r 0
72x = hreject cs io r
73end
74break
75end
76r = route cs io
77if lt r 0
78break
79end
80if eq hnext cs io 0
81break
82end
83end
84r = hclose cs
85ret 0
86end
87
88fn main to int
89cs = new ulong 320 0
90io = new uchar 131072 0
91a = new uchar 16 0
92ab = new uchar 32 0
93k = argread 1 ab 0 16
94if and gt k 0 ac_peq view ab 0 ulong k fp_wrong
95put gfp 1 1
96end
97r = haddr4 a 2130706433 0
98lf = hlisten a 16
99if lt lf 0
100ret 2
101end
102put gfp 0 hport a
103q = ac_cat ab 0 fp_port
104q = ac_catu ab q get gfp 0
105q = ac_catc ab q 10
106ac_say view part ab 0 q
107for j ulong 100
108r = serve1 int lf cs io
109end
110c = fclose int lf
111ret 0
112end