Commit d3d9583d authored by bernd's avatar bernd

Removed old IP format

parent 170e8fbd
......@@ -69,10 +69,8 @@ debug: recvfrom(
debug: sendto(
debug: avalanche( \ distribution tree
debug: adjust-timer( \ adjust timer
debug: new-addr( \ new address to try out
debug: reply( \ test replies
+db new-addr( \ )
-db profile( \ )
0 [IF]
......
......@@ -174,7 +174,7 @@ previous
\ sockaddr conversion
also net2o-base
: new.sockaddr ( addr alen -- sockaddr u )
: .sockaddr ( addr alen -- sockaddr u )
\ convert socket into net2o address token
[: { addr alen }
case addr family w@
......@@ -196,7 +196,7 @@ also net2o-base
is sockaddr+return
previous
:noname ( -- addr len )
return-address be@ routes #.key $@ new.sockaddr ; is new>sockaddr
return-address be@ routes #.key $@ .sockaddr ; is >sockaddr
0 [IF]
Local Variables:
......
......@@ -117,9 +117,7 @@ net2o-base
: request, ( -- ) next-request #request, ;
: gen-punch ( -- )
new-addr( my-addr$ [: -sig nat( ." punch: " 2dup .addr$ forth:cr ) $, punch ;]
)else( my-ip$ [: nat( ." punch: " 2dup .ipaddr forth:cr )
$, punch ;] ) $[]map ;
my-addr$ [: -sig nat( ." punch: " 2dup .addr$ forth:cr ) $, punch ;] $[]map ;
: cookie+request ( -- ) request( ." gen cookie" forth:cr )
nest[ cookie, request, ]nest ;
......
......@@ -30,8 +30,7 @@ $20 net2o: disconnect ( -- ) \g close connection
+net2o: set-ip ( $:string -- ) \g set address information
$> setip-xt perform ;
+net2o: get-ip ( -- ) \g request address information
new-addr( new>sockaddr )else( >sockaddr ) $, set-ip
[: $, set-ip ;] new-addr( new-n2oaddrs )else( n2oaddrs ) ;
>sockaddr $, set-ip [: $, set-ip ;] n2oaddrs ;
+net2o: set-blocksize ( n -- ) \g set blocksize to 2^n
64>n 1 swap max-block# umin lshift blocksizes! ;
......
......@@ -150,7 +150,7 @@ Variable dht-table
: .tag ( addr u -- ) 2dup 2>r
>tag verify-tag >r sigpksize# - type r> 2r> .sigdates .check ;
: .host ( addr u -- ) over c@ '!' = IF .revoke EXIT THEN
2dup sigsize# - new-addr( .addr$ )else( .ipaddr )
2dup sigsize# - .addr$
2dup .sigdates >host verify-host .check 2drop ;
: host>$ ( addr u -- addr u' flag )
>host verify-host >r sigsize# - r> ;
......@@ -282,43 +282,16 @@ gen-table $freeze
also net2o-base
: pub? ( addr u -- addr u flag ) skip-symname
over c@ '2' = IF dup $17 u<= ELSE false THEN ;
false Value add-myip
Variable $addme
: +name ( addr u -- addr' u' )
\ add my name to host
$addme $off
[: .myname type ;] $addme $exec
$addme $@ ;
: addme-end ( -- ) request( ." addme" forth:cr )
add-myip IF
my-ip$ [: gen-host $, dht-host+ ;] $[]map
THEN
endwith do-expect-reply ( request, end-cmd ) ;
: addme ( addr u -- ) nat( ." addme: " 2dup .ipaddr forth:cr )
pub? IF
my-ip-merge IF 2drop EXIT THEN
my-ip$ $ins[] EXIT THEN
2dup my-ip? 0= IF 2dup my-ip$ $ins[] THEN
now>never
what's expect-reply? ['] addme-end <> IF
expect-reply pkc keysize2 $, dht-id
THEN
gen-host $, dht-host+
['] addme-end IS expect-reply? ;
\ new address formats
: new-addme-end ( -- ) request( ." addme" forth:cr )
: addme-end ( -- ) request( ." addme" forth:cr )
add-myip IF
my-addr$ [: $, dht-host+ ;] $[]map
THEN
endwith do-expect-reply ;
: new-addme ( addr u -- ) new-addr { addr } now>never
: addme ( addr u -- ) new-addr { addr } now>never
addr >o +my-id o>
nat( ." addme: " addr .addr )
addr .host-route $@len 0= IF
......@@ -331,15 +304,15 @@ Variable $addme
addr o>addr gen-host my-addr$ $ins[]
nat( ." routed" ) THEN
nat( forth:cr )
what's expect-reply? ['] new-addme-end <> IF
what's expect-reply? ['] addme-end <> IF
expect-reply pkc keysize2 $, dht-id
THEN
addr o>addr gen-host $, dht-host+
addr >o n2o:dispose-addr o>
['] new-addme-end IS expect-reply? ;
['] addme-end IS expect-reply? ;
previous
: +addme new-addr( ['] new-addme )else( ['] addme ) setip-xt ! ;
: +addme ['] addme setip-xt ! ;
: -setip ['] .iperr setip-xt ! ;
\ replace me stuff
......
......@@ -63,23 +63,6 @@ Create ip6::0 here 16 dup allot erase
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
.ip6::0 addr sin_addr 4 type
endof
AF_INET6 of
addr sin6_addr 12 fake-ip4 over str= IF
.ip6::0 addr sin6_addr 12 + 4 type
ELSE
addr sin6_addr $10 type .ip4::0
THEN
endof
endcase
addr port 2 type ;] $tmp ;
: .port ( addr len -- addr' len' )
." :" over be-uw@ 0 ['] .r #10 base-execute 2 /string ;
: .net2o ( addr u -- ) dup IF ." |" xtype ELSE 2drop THEN ;
......@@ -118,22 +101,11 @@ User ip6:#
: skip-symname ( addr u -- addr' u' )
over c@ '0' = IF 2 safe/string THEN
over c@ '?' - 0 max safe/string ;
: .symname ( addr u -- addr' u' )
over c@ '0' = IF over 1+ c@ 0 .r '#' emit 2 safe/string THEN
over c@ '?' - 0 max >r r@ IF '"' emit over r@ 1 /string type '"' emit THEN
r> safe/string ;
: .ipaddr ( addr len -- ) .symname
case over c@ >r 1 /string r>
'1' of ." |" xtype endof
'2' of .ip64 endof
dup emit -rot dump endcase ;
Defer .addr$
: .iperr ( addr len -- ) [: <info>
.time ." connected from: "
new-addr( .addr$ )else( .ipaddr ) <default> cr ;] $err ;
: .iperr ( addr len -- )
[: <info> .time ." connected from: " .addr$ <default> cr ;] $err ;
: ipv4! ( ipv4 sockaddr -- )
>r r@ sin6_addr 12 + be-l!
......@@ -264,20 +236,6 @@ $FD c, $00 c, $0000 w, $0000 w, $0000 w, $0000 w, $0000 w, $0000 w, $0100 w,
Variable myname
: +my-ip ( addr u -- ) dup 0= IF 2drop EXIT THEN
[: .myname '2' emit
dup 4 = IF ip6::0 $10 type ELSE dup $10 = IF type ip6::0 4 THEN THEN type
my-port# 8 rshift emit my-port# $FF and emit ;] $tmp
nat( ." myip: " 2dup .ipaddr cr )
my-ip$ $ins[] ;
Variable $tmp2
: !my-ips ( -- ) $tmp2 $off nat( ." start storing myips" cr )
global-ip6 tuck [: type global-ip4 type ;] $tmp2 $exec
$tmp2 $@ +my-ip
0= IF local-ip6 +my-ip THEN ;
\ new address handling is in net2o-addr.fs, loaded later
Defer !my-addr
......@@ -292,52 +250,14 @@ Defer !my-addr
2dup ip6::0 over str= >r
2over ip6::0 over str= >r str= r> r> or or ;
: my-ip= skip-symname 2swap skip-symname { addr1 u1 addr2 u2 -- flag }
addr1 c@ '2' = addr2 c@ '2' = and &&
addr1 u1 $15 safe/string addr2 u2 $15 safe/string str= &&
addr1 1+ $10 addr2 1+ over str=?0 &&
addr1 $11 + 4 addr2 $11 + over str=?0 ;
: str>merge ( addr1 u1 addr2 u2 -- )
2dup ip6::0 over str= IF rot umin move ELSE 2drop 2drop THEN ;
: my-ip>merge ( addr1 u1 addr2 u2 -- )
skip-symname 2swap skip-symname 2swap
{ addr1 u1 addr2 u2 -- }
addr1 1+ $10 addr2 1+ over str>merge
addr1 $11 + 4 addr2 $11 + over str>merge ;
: my-ip? ( addr u -- addr u flag )
0 my-ip$ [: rot >r 2over my-ip= r> or ;] $[]map ;
: my-ip-merge ( addr u -- addr u flag )
0 my-ip$ [: rot >r 2over 2over my-ip= IF
2over 2swap my-ip>merge rdrop true ELSE 2drop r> THEN ;] $[]map ;
\ insert address for punching
: !temp-addr ( addr u -- ) dup 0<> ind-addr !
temp-addr dup $10 erase swap $10 umin move ;
: 6>sock ( addr u -- )
over $10 + w@ sockaddr1 port w!
over $10 sockaddr1 sin6_addr swap move
$12 /string !temp-addr ;
: 4>sock ( addr u -- )
over $4 + w@ sockaddr1 port w!
over be-ul@ sockaddr1 ipv4!
6 /string !temp-addr ;
: 64>6sock ( addr u -- )
over $14 + w@ sockaddr1 port w!
over $10 sockaddr1 sin6_addr swap move
$16 /string !temp-addr ;
: 64>4sock ( addr u -- )
over $14 + w@ sockaddr1 port w!
over $10 + be-ul@ sockaddr1 ipv4!
$16 /string !temp-addr ;
: check-addr1 ( -- addr u flag )
sockaddr1 sock-rest 2dup try-ip
nat( ." check: " >r 2dup .address
......@@ -348,19 +268,6 @@ Defer !my-addr
nat( ." ping: " 2dup .address cr )
2>r net2o-sock "" 0 2r> sendto drop ;
: 64-6? ( addr u -- ) $10 umin ip6::0 over str= 0= ;
: 64-4? ( addr u -- ) $10 /string 4 umin 64-6? ;
: $>sock ( addr u xt -- ) { xt }
skip-symname
case over c@ >r 1 /string r>
'2' of
2dup 64-4? IF 2dup 64>4sock xt execute THEN
2dup 64-6? IF 2dup 64>6sock xt execute THEN
2drop
endof
!!no-addr!! endcase ;
0 [IF]
Local Variables:
forth-local-words:
......
......@@ -132,7 +132,7 @@ Variable net2o-host "net2o.de" net2o-host $!
[IFDEF] no-hybrid
net2o-sock drop my-port# create-udp-server to net2o-sock
[THEN]
!my-ips !my-addr ;
!my-addr ;
begin-structure reply
field: reply-len
......@@ -1079,18 +1079,13 @@ require net2o-file.fs
\ helpers for addresses
Defer new>sockaddr
Defer >sockaddr
Defer sockaddr+return
: -skip ( addr u char -- ) >r
BEGIN 1- dup 0>= WHILE 2dup + c@ r@ <> UNTIL THEN 1+ rdrop ;
: -sig ( addr u -- addr u' ) 2dup + 1- c@ 2* $11 + - ;
: >sockaddr ( -- addr len )
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 ;
: new-n2oaddrs ( xt -- )
my-addr$ [: -sig sockaddr+return rot dup >r execute r> ;] $[]map drop ;
\ load crypto here
......@@ -1193,9 +1188,9 @@ Defer new-addr
: net2o:punch ( addr u -- )
o IF
new-addr( new-addr )
new-addr
punch-load @ IF ['] send-punch ELSE ['] ping-addr1 THEN
new-addr( addr>sock )else( $>sock )
addr>sock
ELSE 2drop THEN ;
\ send chunk
......@@ -1999,20 +1994,10 @@ Variable dhtnick "net2o-dhtroot" dhtnick $!
replace-key o> >o ke-pk $@ ." replace key: " 2dup 85type cr
o o> >r 2dup c:fetch-id r> >o
REPEAT 2drop disconnect-me ;
: insert-host ( o addr u -- o )
2 pick >o \ ." check host: " 2dup .host cr
host>$ o> IF
[: check-addr1 0= IF 2drop EXIT THEN
insert-address temp-addr ins-dest
." insert host: " temp-addr $10 xtype cr
return-addr $10 0 skip nip 0= IF
temp-addr return-addr $10 move
THEN ;] $>sock
ELSE 2drop THEN ;
User host$ \ check for this hostname
: new-insert-host ( o addr u -- o )
: insert-host ( o addr u -- o )
2 pick >o host>$ o> IF
new-addr dup .host-id $@
host$ $@ str= host$ $@len 0= or IF
......@@ -2032,8 +2017,7 @@ User host$ \ check for this hostname
2dup >d#id { id }
id .dht-host $[]# 0= IF 2dup pk-lookup 2dup >d#id to id THEN
0 n2o:new-context >o rdrop 2dup dest-pk return-addr $10 erase
id dup .dht-host
new-addr( ['] new-insert-host )else( ['] insert-host ) $[]map drop 2drop ;
id dup .dht-host ['] insert-host $[]map drop 2drop ;
: search-connect ( key u -- o/0 )
0 [: drop 2dup pubkey $@ str= o and dup 0= ;] search-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