Commit 350dec25 authored by bernd's avatar bernd

power of two things transmitted by shift count

parent dcf34f57
......@@ -51,17 +51,19 @@ UValue test# 0 to test#
\ n2o:done
\ end-code| ;
: c:dht ( n -- ) $2000 $10000 "test" ins-ip c:connect 0 ?DO
: c:dht ( n -- ) $8 $8 "test" ins-ip c:connect 0 ?DO
c:add-tag "anonymous" c:fetch-tag \ c:fetch-tags
LOOP do-disconnect ;
: std-block ( -- ) $10 blocksize! $A blockalign! ;
: c:download1 ( -- )
[: .time ." Download test: 1 text file and 2 photos" cr ;] $err
net2o-code
expect-reply
log !time .time s" Download test " $, type 1 ulit, . pi float, f. cr endwith
get-ip
$400 blocksize! $400 blockalign! stat( request-stats )
std-block stat( request-stats )
"net2o.fs" "net2o.fs" >cache n2o:copy
"data/2011-05-13_11-26-57-small.jpg" "photo000s.jpg" >cache n2o:copy
"data/2011-05-20_17-01-12-small.jpg" "photo001s.jpg" >cache n2o:copy
......@@ -73,7 +75,7 @@ UValue test# 0 to test#
net2o-code
expect-reply close-all \ rewind-total
log .time s" Download test 2" $, type cr endwith
$10000 blocksize! $400 blockalign! stat( request-stats )
std-block stat( request-stats )
"data/2011-06-02_15-02-38-small.jpg" "photo002s.jpg" >cache n2o:copy
"data/2011-06-03_10-26-49-small.jpg" "photo003s.jpg" >cache n2o:copy
"data/2011-06-15_12-27-03-small.jpg" "photo004s.jpg" >cache n2o:copy
......@@ -89,7 +91,7 @@ UValue test# 0 to test#
net2o-code
expect-reply close-all \ rewind-total
log .time s" Download test 3" $, type cr endwith
$10000 blocksize! $400 blockalign! stat( request-stats )
std-block stat( request-stats )
"data/2011-05-13_11-26-57.jpg" "photo000.jpg" >cache n2o:copy
"data/2011-05-20_17-01-12.jpg" "photo001.jpg" >cache n2o:copy
n2o:done 0 ulit, file-id
......@@ -101,7 +103,7 @@ UValue test# 0 to test#
net2o-code
expect-reply close-all \ rewind-total
log .time s" Download test 4" $, type cr endwith
$10000 blocksize! $400 blockalign! stat( request-stats )
std-block stat( request-stats )
"data/2011-06-02_15-02-38.jpg" "photo002.jpg" >cache n2o:copy
"data/2011-06-03_10-26-49.jpg" "photo003.jpg" >cache n2o:copy
"data/2011-06-15_12-27-03.jpg" "photo004.jpg" >cache n2o:copy
......@@ -147,7 +149,7 @@ UValue test# 0 to test#
: c:test ( -- )
init-cache'
$10000 $100000 "test" ins-ip c:connect c:test-rest ;
$a $e "test" ins-ip c:connect c:test-rest ;
event: ->throw dup DoError throw ;
......@@ -165,7 +167,7 @@ event: ->throw dup DoError throw ;
\ lookup for other users
: nat:connect ( addr u -- ) $10000 $100000 2swap nick-connect
: nat:connect ( addr u -- ) $A $E 2swap nick-connect
." Connected!" cr ;
\ some more helpers
......@@ -188,13 +190,13 @@ event: ->throw dup DoError throw ;
\ terminal connection
: c:terminal ( -- )
$10000 $100000 "test" ins-ip c:connect
$a $e "test" ins-ip c:connect
[: .time ." Terminal test: connect to server" cr ;] $err
tc-permit# fs-class-permit or to fs-class-permit
net2o-code
expect-reply
log .time "Terminal test" $, type cr endwith
$10000 blocksize! $400 blockalign! stat( request-stats )
std-block stat( request-stats )
[: 3 ulit, file-type "" $, 0 ulit, open-file
state-addr >o 2 fs-class! o> ;] n2o>file
end-code| ['] .time $err ;
\ No newline at end of file
......@@ -44,7 +44,8 @@ $20 net2o: tmpnest ( $:string -- ) \ nested (temporary encrypted) command
: n2o:create-map
{ 64: addrs ucode udata 64: addrd -- addrd ucode udata addrs }
addrs lit, addrd lit, ucode ulit, new-code
addrs ucode n>64 64+ lit, addrd ucode n>64 64+ lit, udata ulit, new-data
addrs min-size ucode lshift n>64 64+ lit,
addrd min-size ucode lshift n>64 64+ lit, udata ulit, new-data
addrd ucode udata addrs ;
+net2o: store-key ( $:string -- ) $> \ store key
......
......@@ -28,10 +28,10 @@ $20 net2o: disconnect ( -- ) \ close connection
+net2o: get-ip ( -- ) \ request address information
>sockaddr $, set-ip [: $, set-ip ;] n2oaddrs ;
+net2o: set-blocksize ( n -- ) \ set blocksize
64>n blocksize! ;
+net2o: set-blockalign ( n -- ) \ set block alignment
64>n pow2? blockalign ! ;
+net2o: set-blocksize ( n -- ) \ set blocksize to 2^n
64>n 1 swap max-block# umin lshift blocksizes! ;
+net2o: set-blockalign ( n -- ) \ set block alignment to 2^n
64>n 1 swap max-block# umin lshift blockalign ! ;
+net2o: close-all ( -- ) \ close all files
n2o:close-all ;
\ better slurping
......@@ -79,9 +79,6 @@ $20 net2o: open-file ( $:string mode -- ) \ open file with mode
gen-table $freeze
' context-table is gen-table
: blocksize! ( n -- ) dup ulit, set-blocksize blocksize! ;
: blockalign! ( n -- ) pow2? dup ulit, set-blockalign blockalign ! ;
:noname ( uid useek -- ) 64>r ulit, file-id
64r> lit, set-seek endwith ; is do-track-seek
......@@ -153,6 +150,11 @@ gen-table $freeze
set-current
: blocksize! ( n -- ) max-block# umin dup ulit, set-blocksize
1 swap lshift blocksizes! ;
: blockalign! ( n -- ) max-block# umin dup ulit, set-blockalign
1 swap lshift blockalign ! ;
: open-tracked-file ( addr u mode --)
open-file get-size get-stat ;
......
......@@ -23,7 +23,7 @@ s" gap in file handles" throwcode !!gap!!
s" invalid file id" throwcode !!fileid!!
s" could not send" throwcode !!send!!
s" wrong packet size" throwcode !!size!!
s" no power of two" throwcode !!pow2!!
s" map size too big" throwcode !!mapsize!!
s" unimplemented net2o function" throwcode !!function!!
s" too many commands" throwcode !!commands!!
s" float does not fit" throwcode !!floatfit!!
......
......@@ -270,7 +270,7 @@ User file-reg#
: n2o:close-file ( id -- )
id>addr? .fs-close ;
: blocksize! ( n -- )
: blocksizes! ( n -- )
dup blocksize !
file( ." file read: ======= " cr ." file write: ======= " cr )
dup residualread ! residualwrite ! ;
......@@ -279,7 +279,7 @@ User file-reg#
[: fstates 0 ?DO
I n2o:close-file
LOOP file-reg# off fstate-off
blocksize @ blocksize!
blocksize @ blocksizes!
read-file# off write-file# off ;] file-sema c-section ;
: n2o:open-file ( addr u mode id -- )
......
......@@ -420,11 +420,17 @@ Variable net2o-host "net2o.de" net2o-host $!
r> ?dup-0=-IF my-port THEN to my-port#
!my-ips ;
$2A Constant overhead \ constant overhead
\ values, configurable
$4 Value max-size^2 \ 1k, don't fragment by default
$12 Value max-data# \ 16MB data space
$0C Value max-code# \ 256k code space
$10 Value max-block# \ 64k maximum block size+alignment
\ constants, and depending values
$2A Constant overhead \ constant overhead
$40 Constant min-size
$400000 Value max-data#
$10000 Value max-code#
1 Value buffers#
min-size max-size^2 lshift Value maxdata ( -- n )
maxdata overhead + Value maxpacket
......@@ -1214,12 +1220,13 @@ Variable mapstart $1 mapstart !
: server! ( -- ) 1 >is-server c! ;
: setup! ( -- ) setup-table @ token-table ! dest-0key @ ins-0key ;
: context! ( -- ) context-table @ token-table ! dest-0key @ del-0key ;
: pow2? ( n -- n ) dup dup 1- and 0<> !!pow2!! ;
: n2o:new-map ( u -- addr )
drop mapstart @ 1 mapstart +! reverse
[ cell 4 = ] [IF] 0 swap [ELSE] $FFFFFFFF00000000 and [THEN] ;
: n2o:new-data pow2? { 64: addrs 64: addrd u -- }
: n2o:new-data ( addrs addrd u -- )
dup max-data# u> !!mapsize!! min-size swap lshift
{ 64: addrs 64: addrd u -- }
o 0= IF
addrd >dest-map @ ?EXIT
return-addr be@ n2o:new-context >o rdrop server! setup! THEN
......@@ -1227,7 +1234,9 @@ Variable mapstart $1 mapstart !
>code-flag off
addrd u data-rmap map-data-dest
addrs u map-source data-map ! ;
: n2o:new-code pow2? { 64: addrs 64: addrd u -- }
: n2o:new-code ( addrs addrd u -- )
dup max-code# u> !!mapsize!! min-size swap lshift
{ 64: addrs 64: addrd u -- }
o 0= IF
addrd >dest-map @ ?EXIT
return-addr be@ n2o:new-context >o rdrop server! setup! THEN
......
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