Commit 0bd693bf authored by bernd's avatar bernd

Use error-id to pass on errors to the waiting task on connection-less tasks

parent 7b6cec4c
......@@ -150,8 +150,6 @@ Variable connect-nick "test" connect-nick $!
init-cache'
$a $e connect-nick $@ nick>pk ins-ip pk:connect c:test-rest ;
event: ->throw dup DoError throw ;
: c:test& ( n -- ) \ in background
up@ 2 stacksize4 NewTask4 pass >r
alloc-io ['] c:test catch ?dup-IF
......
......@@ -58,7 +58,7 @@ gen-table $freeze
host-revoke $off ;
:noname ( -- )
punch-addrs $@ bounds ?DO I @ .n2o:dispose-addr cell +LOOP
punch-addrs $off ; is punch-dispose
punch-addrs $off defers extra-dispose ; is extra-dispose
:noname ( addr u -- o ) \G create a new address object from string
n2o:new-addr n:>o nest-cmd-loop o n:o> ; is new-addr
......
......@@ -136,6 +136,7 @@ cmd-class class
field: mpubkey \ our side official pubkey
field: punch-addrs
field: rqd-xts \ callbacks for request done (array)
field: my-error-id
0 +field end-strings
field: request-gen \ pre-generated request number
field: perm-mask
......
......@@ -222,9 +222,9 @@ drop
.net2o-name
0 endcase ]hex ;
Variable show-offset show-offset on
User show-offset show-offset on
sema see-sema
Sema see-sema
: cmd-see ( addr u -- addr' u' )
dup show-offset @ = IF ." <<< " THEN
......@@ -292,7 +292,7 @@ code-buf
:noname ( n -- ) cmdbuf# +! ; to -cmdbuf
:noname ( -- 64dest ) code-vdest 64dup 64-0= !!no-dest!! ; to cmddest
sema cmd0lock
Sema cmd0lock
cmd-buf-c class
maxdata uvar cmd0buf
......
......@@ -44,7 +44,7 @@ $20 net2o: request-done ( ureq -- ) 64>n \g signal request is completed
+net2o: punch-load, ( $:string -- ) \g use for punch payload: nest it
$> $, nest o IF
['] punchs code-reply send-xt !
punch-dispose o-beacon THEN ;
extra-dispose THEN ;
+net2o: punch ( $:string -- ) \g punch NAT traversal hole
$> net2o:punch ;
+net2o: punch-done ( -- ) \g punch received
......@@ -172,13 +172,33 @@ net2o-base
connect( ." establish a context!" forth:cr ) ;
: time-offset! ( -- ) ticks 64dup lit, >time-offset ack@ .time-offset 64! ;
\ error ID handling
Variable id-hash
: gen-id ( -- addr u )
$10 rng$ o { w^ idcon } idcon cell 2over id-hash #! ;
Sema id-sema
: new-error-id ( -- addr u )
$10 rng$ o { w^ idcon } idcon cell 2over
[: id-hash #! ;] id-sema c-section
2dup my-error-id $! ;
: error-id>o ( addr u -- o/0 )
$error-id $@ ?dup-IF
id-hash #@ cell = IF
@ EXIT THEN THEN
drop 0 ;
: error-id$off ( -- )
[: my-error-id $@ ?dup-IF id-hash #off ELSE drop THEN
my-error-id $off ;] id-sema c-section ;
:noname error-id$off defers extra-dispose ; IS extra-dispose
\ compile a reply key
: reply-key, ( -- )
key-setup? @ !!doublekey!!
nest[
gen-id $, error-id
new-error-id $, error-id
pkc keysize $, pubkey $@len 0> keypad$ nip keysize u<= and IF
pubkey $@ key| $, keypair
pubkey $@ drop skc key-stage2
......
......@@ -158,7 +158,9 @@ gen-table $freeze
$error-id $@ dup IF $, error-id ELSE 2drop THEN
nlit, ko THEN
ELSE
throw
error-id>o ?dup-IF
>o <event elit, ->throw wait-task @ event> o>
ELSE throw THEN
THEN ; IS >throw
set-current
......
......@@ -304,11 +304,12 @@ blue >fg yellow bg| , cyan >fg red >bg or bold or ,
: .rsk ( nick u -- )
skrev $20 .stripe85 space type ." (keep offline copy!)" cr ;
: .key ( addr u -- ) drop cell+ >o
." nick: " .nick cr
." nick: " .nick cr
." pubkey: " ke-pk $@ 85type cr
ke-sk @ IF ." seckey: " ke-sk sec@ .black85 ." (keep secret!)" cr THEN
ke-sk @ IF
." seckey: " ke-sk sec@ .black85 ." (keep secret!)" cr THEN
." valid: " ke-selfsig $@ .sigdates cr
." perm: " ke-mask @ .perm cr
." perm: " ke-mask @ .perm cr
o> ;
: .key-rest ( o:key -- o:key )
ke-pk $@ key| .import85
......@@ -389,7 +390,9 @@ event: ->search-key key| over >r dht-nick? r> free throw ;
ELSE
.ke-mask @ tmp-perm !
connect( .key# )else( 2drop )
THEN ; IS check-key
THEN
tmp-perm @ perm%blocked and 0<> !!unknown-key!!
; IS check-key
:noname ( pkc -- skc )
keysize key-table #@ 0= !!unknown-key!!
......
......@@ -35,7 +35,7 @@ Variable otr-mode
User replay-mode
User skip-sig?
sema msglog-sema
Sema msglog-sema
: ?msg-context ( -- o )
msg-context @ dup 0= IF
......
......@@ -561,7 +561,7 @@ comp: loadfilename 2@ postpone sliteral :, ;
Variable 0keys
sema 0key-sema
Sema 0key-sema
: ins-0key [: { w^ addr -- }
addr cell 0keys $+! ;] 0key-sema c-section ;
......@@ -586,7 +586,7 @@ sema 0key-sema
\ unique list of cells
sema resize-sema
Sema resize-sema
: unique$cell? ( x addr -- flag )
$@ bounds ?DO dup I @ = IF drop false unloop EXIT THEN
......
......@@ -243,6 +243,7 @@ $080 Constant newcode-val
$100 Constant keypair-val
$200 Constant receive-val
$400 Constant ivs-val
$800 Constant connection-val
: crypt? ( -- flag ) validated @ crypt-val and ;
: own-crypt? ( -- flag ) validated @ own-crypt-val and ;
......@@ -606,7 +607,7 @@ reply buffer: dummy-reply
\ timing records
sema timing-sema
Sema timing-sema
: net2o:track-timing ( -- ) \ initialize timing records
s" " timing-stat $! ;
......@@ -1377,7 +1378,8 @@ User remote?
: handle-cmd ( addr -- ) parent @ >o
msg( ." Handle command to addr: " dup hex. cr )
outflag off remote? on
outflag off remote? on connection-val validated !
$error-id $off \ no error id so far
maxdata negate and >r inbuf packet-data r@ swap dup >r move
r> r> swap cmd-exec o IF ( 0timeout ) o> ELSE rdrop THEN
remote? off ;
......@@ -1424,8 +1426,7 @@ User remote?
: ungroup-ctx ( -- )
msg-groups [: >r o r> cell+ del$cell ;] #map ;
Defer punch-dispose
Defer o-beacon
Defer extra-dispose
: n2o:dispose-context ( o:addr -- o:addr )
[: cmd( ." Disposing context... " o hex. cr )
......@@ -1446,7 +1447,6 @@ Defer o-beacon
unlink-ctx ungroup-ctx
end-semas start-semas DO I pthread_mutex_destroy drop
1 pthread-mutexes +LOOP
punch-dispose o-beacon
dispose 0 to connection
cmd( ." disposed" cr ) ;] file-sema c-section ;
......@@ -1484,6 +1484,7 @@ event: ->request ( n o -- ) >o maxrequest# and
event: ->timeout ( o -- )
>o 0 reqmask !@ >r -timeout r> o> msg( ." Request timed out" cr )
r> 0<> !!timeout!! ;
event: ->throw ( error -- ) throw ;
: timeout-expired? ( -- flag )
ack@ .timeouts @ timeouts# >= ;
......@@ -1535,7 +1536,7 @@ Variable beacons \ destinations to send beacons to
obj 2 cells last# cell+ $+! 2drop
THEN ;
:noname ( -- )
: o-beacon ( -- )
beacon( ." remove beacons: " o hex. cr )
beacons [: { bucket } bucket cell+ $@ 1 64s /string bounds ?DO
I @ o = IF
......@@ -1544,7 +1545,9 @@ Variable beacons \ destinations to send beacons to
bucket cell+ $@len 8 = IF
bucket $off bucket cell+ $off
THEN
;] #map ; is o-beacon
;] #map ;
:noname o-beacon defers extra-dispose ; is extra-dispose
: add-beacon ( net2oaddr xt -- )
>r route>address IF sockaddr alen @ r@ +beacon THEN rdrop ;
......@@ -1645,7 +1648,9 @@ Variable cookies
cookies $@ bounds ?DO
I .cc-timeout 64@ timeout 64u< IF
cookies I cookie-size# del$one
unloop cookies next$ ?DO NOPE 0
cookies next$
unloop ?DO NOPE \ this replaces the loop variables
0
ELSE
64dup I .cc-timeout 64@ 64= IF
64drop I .cc-context @
......
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