Commit 0ac04d5e authored by bernd's avatar bernd
Browse files

Move to pubkey based connections, nick>pk is used for conversion

parent a1992480
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ i'm anonymous

init-client

"" connect-nick $!  strict-keys off
"test" connect-nick $!  strict-keys off

!time

+3 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ UValue test# 0 to test#

Variable connect-nick  "test" connect-nick $!

: c:dht ( n -- )  $8 $8 connect-nick $@ ins-ip c:connect 0 ?DO
: c:dht ( n -- )  $8 $8 connect-nick $@ nick>pk ins-ip pk:connect 0 ?DO
	c:add-tag "anonymous" c:fetch-tag \ c:fetch-tags
    LOOP  disconnect-me ;

@@ -148,7 +148,7 @@ Variable connect-nick "test" connect-nick $!

: c:test ( -- )
    init-cache'
    $a $e connect-nick $@ ins-ip c:connect c:test-rest ;
    $a $e connect-nick $@ nick>pk ins-ip pk:connect c:test-rest ;

event: ->throw dup DoError throw ;

@@ -187,7 +187,7 @@ event: ->throw dup DoError throw ;
\ terminal connection

: c:terminal ( -- )
    $a $e connect-nick $@ ins-ip c:connect
    $a $e connect-nick $@ nick>pk ins-ip pk:connect
    [: .time ." Terminal test: connect to server" cr ;] $err
    tc-permit# fs-class-permit or to fs-class-permit
    net2o-code
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ net2o-base

: time-offset! ( -- )  ticks 64dup lit, >time-offset ack@ .time-offset 64! ;
: reply-key, ( -- )
    nest[ pkc keysize $, pubkey @ keypad$ nip keysize u<= and IF
    nest[ pkc keysize $, pubkey $@len 0> keypad$ nip keysize u<= and IF
	pubkey $@ $, keypair
	pubkey $@ drop skc key-stage2
    ELSE  receive-key  THEN
+2 −38
Original line number Diff line number Diff line
@@ -2582,14 +2582,6 @@ require net2o-msg.fs
: ins-ip6 ( -- net2oaddr )
    net2o-host $@ net2o-port insert-ip6 ;

: c:connect ( code data nick u ret -- )
    [: .time ." Connect to: " dup hex. cr ;] $err
    n2o:new-context >o rdrop o to connection  setup!
    dest-key \ get our destination key
    n2o:connect
    +flow-control +resend
    [: .time ." Connected, o=" o hex. cr ;] $err ;

: pk:connect ( code data key u ret -- )
    [: .time ." Connect to: " dup hex. cr ;] $err
    n2o:new-context >o rdrop o to connection  setup!
@@ -2607,12 +2599,6 @@ require net2o-msg.fs
      cookie+request
    end-code| ;

: c:addme-fetch-host ( nick u -- ) +addme
    net2o-code
      expect-reply get-ip fetch-host, replace-me,
      cookie+request
    end-code| -setip n2o:send-replace ;

: pk:addme-fetch-host ( key u -- ) +addme
    net2o-code
      expect-reply get-ip fetch-id, replace-me,
@@ -2622,17 +2608,9 @@ require net2o-msg.fs
Variable dhtnick "net2o-dhtroot" dhtnick $!

: announce-me ( -- )
    $8 $8 dhtnick $@ ins-ip dup add-beacon c:connect replace-me disconnect-me ;
    $8 $8 dhtnick $@ nick>pk ins-ip
    dup add-beacon pk:connect replace-me disconnect-me ;

: nick-lookup ( addr u -- )
    $A $E dhtnick $@ ins-ip c:connect
    2dup c:addme-fetch-host
    nick-key >o ke-pk $@
    BEGIN  >d#id >o 0 dht-host $[]@ o> 2dup d0= !!host-notfound!!
	over c@ '!' =  WHILE
	    replace-key o> >o ke-pk $@ ." replace key: " 2dup 85type cr
	    o o> >r 2dup c:fetch-id r> >o
    REPEAT  o> 2drop disconnect-me ;
: pk-lookup ( addr u -- )
    $A $E dhtnick $@ nick>pk ins-ip pk:connect
    2dup pk:addme-fetch-host
@@ -2652,15 +2630,6 @@ Variable dhtnick "net2o-dhtroot" dhtnick $!
	    THEN ;] $>sock
    ELSE  2drop  THEN ;

: nick-id ( addr-nick u -- id )
    nick>pk >d#id ;

: n2o:lookup ( addr u -- )
    2dup nick-id { id }
    id .dht-host $[]# 0= IF  2dup nick-lookup  2dup nick-id to id  THEN
    0 n2o:new-context >o rdrop 2dup dest-key  return-addr $10 erase
    id dup .dht-host ['] insert-host $[]map drop 2drop ;

: n2o:pklookup ( addr u -- )
    2dup >d#id { id }
    id .dht-host $[]# 0= IF  2dup pk-lookup  2dup >d#id to id  THEN
@@ -2671,11 +2640,6 @@ Variable dhtnick "net2o-dhtroot" dhtnick $!
    0 [: drop 2dup pubkey $@ str= o and  dup 0= ;] search-context
    nip nip  dup to connection ;

: nickx-connect ( addr u cmdlen datalen -- )
    2>r n2o:lookup 2r>
    cmd0( ." trying to connect to: " return-addr $10 xtype cr )
    n2o:connect +flow-control +resend ;

:noname ( addr u cmdlen datalen -- )
    2>r n2o:pklookup 2r>
    cmd0( ." trying to connect to: " return-addr $10 xtype cr )