Commit 535b4245 authored by bernd's avatar bernd

do-keypad uses sec@ and sec\!, too

parent 03daae4b
......@@ -210,12 +210,14 @@ User b$
: bemit b$ c$+! ;
: bcr #lf bemit b$ $@ (type) b$ $off ;
' btype ' bemit ' bcr ' form output: b-out
\ ' btype ' bemit ' bcr ' form output: b-out
' noop alias b-out
\ misc
: etype ( addr u -- ) >stderr type ;
: $err ( xt -- ) $tmp stderr write-file throw ;
\ : $err ( xt -- ) $tmp stderr write-file throw ;
: $err ( xt -- ) execute ;
\ extra hints for last word executed
......
......@@ -45,6 +45,8 @@ $4000 Constant /kregion
: sec@ ( addr -- addr1 u1 )
@ dup IF $40 over $20 + $20 zero32 over str= IF 2/ THEN
ELSE 0 THEN ;
: sec+! ( addr1 u1 addr2 -- )
dup @ 0= IF sec! ELSE sec@ dup >r + swap $40 r> - umin move THEN ;
: sec-off ( addr -- ) >r r@ @ ?dup-IF kfree64 THEN r> off ;
: sec+[]! ( addr1 u1 addr2 -- ) >r
......
......@@ -359,14 +359,14 @@ previous
cmd( dest-addr 64@ $64. ." resend canned code reply " tag-addr hex. cr )
r> reply-dest 64@ send-cmd true
1 packets2 +!
ELSE dest-addr 64@ 64>n dup 0 r> 2! u>= THEN ;
ELSE dest-addr 64@ [ cell 4 = ] [IF] 0<> - [THEN] dup 0 r> 2! u>= THEN ;
Variable throwcount
: do-cmd-loop ( addr u -- )
cmd( dest-addr 64@ $64. 2dup n2o:see )
sp@ >r throwcount off
[: BEGIN cmd-dispatch dup 0<= UNTIL ;] catch
[: BEGIN cmd-dispatch dup 0<= UNTIL ;] catch
dup IF 1 throwcount +!
[: ." do-cmd-loop: " dup . .exe cr ;] $err
dup DoError nothrow
......@@ -379,7 +379,7 @@ Variable throwcount
o IF
maxdata code+
cmd0source off
tag-addr? IF
tag-addr? IF
2drop >flyburst 1 packetr2 +! EXIT THEN
ELSE
cmd0buf cmd0source !
......@@ -551,8 +551,8 @@ $20 net2o: emit ( xc -- ) \ emit character on server log
o 0= IF ." don't store key, o=0: " .nnb F cr un-cmd EXIT THEN
own-crypt? IF
key( ." store key: o=" o hex. 2dup .nnb F cr )
2dup do-keypad $!
crypto-key $!
2dup do-keypad sec!
crypto-key sec!
ELSE ." don't store key: o=" o hex. .nnb F cr THEN ;
+net2o: map-request ( addrs ucode udata -- ) \ request mapping
......
......@@ -169,7 +169,7 @@ Variable do-keypad
Sema regen-sema
: keypad$ ( -- addr u )
do-keypad $@ dup 0= IF 2drop crypto-key sec@ THEN ;
do-keypad sec@ dup 0= IF 2drop crypto-key sec@ THEN ;
: >crypt-key-ivs ( -- )
o 0= IF no-key state# ELSE keypad$ THEN
......@@ -277,21 +277,21 @@ Defer check-key \ check if we know that key
?keysize dup keysize [: check-key ;] $err
dup keysize pubkey $!
keypad$ keysize <> !!no-tmpkey!!
skc rot keypad ed-dhx do-keypad $+! ;
skc rot keypad ed-dhx do-keypad sec+! ;
: net2o:receive-tmpkey ( addr u -- ) ?keysize \ dup keysize .nnb cr
o 0= IF gen-stkeys stskc ELSE tskc THEN \ dup keysize .nnb cr
swap keypad ed-dh
o IF do-keypad $! ELSE 2drop THEN
o IF do-keypad sec! ELSE 2drop THEN
( keypad keysize .nnb cr ) ;
: tmpkey@ ( -- addr u )
do-keypad $@ dup ?EXIT 2drop
do-keypad sec@ dup ?EXIT 2drop
keypad keysize ;
: net2o:update-key ( -- )
do-keypad $@ dup IF
do-keypad sec@ dup IF
key( ." store key, o=" o hex. 2dup .nnb cr ) crypto-key sec!
"" do-keypad $!
do-keypad sec-off
EXIT
THEN
2drop ;
......
......@@ -224,20 +224,24 @@ Create ip6::0 here 16 dup allot erase
: .ip6::0 ( -- ) ip6::0 $10 type ;
: .ip4::0 ( -- ) ip6::0 4 type ;
: .sockaddr { addr alen -- }
Create sockaddr" 2 c, $16 allot
: .sockaddr
\ convert socket into net2o address token
[: { addr alen -- sockaddr u } '2' emit
case addr family w@
AF_INET of
'2' emit .ip6::0 addr sin_addr 4 type addr port 2 type
.ip6::0 addr sin_addr 4 move type
endof
AF_INET6 of
addr sin6_addr 12 fake-ip4 over str= IF
'2' emit .ip6::0 addr sin6_addr 12 + 4 type
.ip6::0 addr sin6_addr 12 + 4 type
ELSE
'2' emit addr sin6_addr $10 type .ip4::0
THEN addr sin6_port 2 type
addr sin6_addr $10 type .ip4::0
THEN
endof
endcase ;
endcase
addr port 2 type ;] $tmp ;
: .port ( addr len -- addr' len' )
." :" over be-uw@ 0 ['] .r #10 base-execute 2 /string ;
......@@ -542,8 +546,8 @@ Defer init-reply
alloc-buf to inbuf alloc-buf to outbuf
maxdata allocate throw to cmd0buf
maxdata 2/ mykey-salt# + $10 + allocate throw to init0buf
sockaddr_in6 %size alloz to sockaddr
sockaddr_in6 %size alloz to sockaddr1
sockaddr_in %size alloz to sockaddr
sockaddr_in %size alloz to sockaddr1
$400 allocate throw to aligned$
init-statbuf
init-ed25519 c:init ;
......@@ -552,8 +556,8 @@ Defer init-reply
free-ed25519 c:free
free-statbuf
aligned$ $400 freez
sockaddr sockaddr_in6 %size freez
sockaddr1 sockaddr_in6 %size freez
sockaddr sockaddr_in %size freez
sockaddr1 sockaddr_in %size freez
init0buf maxdata 2/ mykey-salt# + $10 + freez
cmd0buf maxdata freez
inbuf free-buf
......@@ -601,7 +605,7 @@ MSG_WAITALL Constant do-block
MSG_DONTWAIT Constant don't-block
: read-a-packet ( blockage -- addr u / 0 0 )
>r sockaddr_in6 %size alen !
>r [ sockaddr_in %size ]L alen !
net2o-sock inbuf maxpacket r> sockaddr alen recvfrom
dup 0< IF
errno dup 11 = IF 2drop 0. EXIT THEN
......@@ -1695,7 +1699,7 @@ User file-reg#
: -skip ( addr u char -- ) >r
BEGIN 1- dup 0>= WHILE 2dup + c@ r@ <> UNTIL THEN 1+ rdrop ;
: >sockaddr ( -- addr len )
return-address be@ routes #.key $@ ['] .sockaddr $tmp ;
return-address be@ routes #.key $@ .sockaddr ;
: n2oaddrs ( xt -- )
my-ip$ [: [: type return-address $10 0 -skip type ;] $tmp
rot dup >r execute r> ;] $[]map drop ;
......@@ -2097,7 +2101,7 @@ User try-reads
: read-a-packet4/6 ( -- addr u )
pollfds revents w@ POLLIN = IF try-reads off
do-block read-a-packet 0 pollfds revents w! +rec EXIT THEN
do-block read-a-packet 0 pollfds revents w! +rec EXIT THEN
try-read# try-reads ! 0 0 ;
: read-event ( -- )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment