Commit 64a4e82d authored by bernd's avatar bernd
Browse files

Prepare beacon signature (incomplete)

parent aa13dd2d
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -151,7 +151,9 @@ User dest-0key< \ pointer to obtained dest-0key
    \G dispose all addresses
    my-addr[] [: .n2o:dispose-addr ;] $[]o-map
    my-addr[] $off
    my-addr$ $[]off ;
    my-addr$ $[]off
    pub-addr$ $[]off
    priv-addr$ $[]off ;

: !my-addr$ ( -- )
    now>never  my-addr[] [:
@@ -160,6 +162,12 @@ User dest-0key< \ pointer to obtained dest-0key

: .my-addrs ( -- )
    my-addr[] [: .addr cr ;] $[]o-map ;
: .my-addr$s ( -- )
    my-addr$ [: sigsize# - .addr$ cr ;] $[]map ;
: .pub-addr$s ( -- )
    pub-addr$ [: sigsize# - .addr$ cr ;] $[]map ;
: .priv-addr$s ( -- )
    priv-addr$ [: sigsize# - .addr$ cr ;] $[]map ;

: !my-addr ( -- ) addrs-off !my-addrs !my-addr$ ;

@@ -182,7 +190,7 @@ User dest-0key< \ pointer to obtained dest-0key
: my-addr-merge ( o -- flag )
    false swap
    my-addr[] [: >o dup my-addr= IF dup my-addr-merge1
	nip 0 swap THEN o> ;] $[]o-map
	nip true swap THEN o> ;] $[]o-map
    drop ;

\ sockaddr conversion
+17 −3
Original line number Diff line number Diff line
@@ -288,6 +288,18 @@ gen-table $freeze
: gen-tag-del ( addr u hash-addr uh -- addr' u' )
    gen>tag "tag" >delete tag$ ;

\ Generate view for beacons

Variable beacon-tuple$

: beacon-tuple ( o:addr -- )
    beacon-tuple$ $off
    [: host-ipv4 be-ul@ 0=
      IF    host-ipv6 $10 type  host-portv6
      ELSE  host-ipv4   4 type  host-portv4  THEN
      w@ dup 8 rshift emit $FF and emit ;]
    beacon-tuple$ $exec ;

\ addme stuff

also net2o-base
@@ -308,9 +320,11 @@ false Value add-myip
    addr .+my-id
    nat( ." addme: " addr .addr )
    addr .host-route $@len 0= IF
	addr my-addr-merge IF  addr .n2o:dispose-addr
	    nat( ."  merged" forth:cr ) EXIT  THEN
	addr o>addr gen-host my-addr$ $ins[]sig drop
	addr my-addr-merge drop
	addr o>addr gen-host
	2dup my-addr$ $ins[]sig drop
	priv-addr$ $ins[]sig drop
	addr .beacon-tuple
	addr .n2o:dispose-addr
	nat( ."  public" forth:cr ) EXIT  THEN
    addr my-addr? 0= IF
+20 −6
Original line number Diff line number Diff line
@@ -176,22 +176,36 @@ event: ->do-beacon ( addr -- )
	'>' of  >-beacon  endof
    endcase ;

: my-beacon-hash ( sockaddr u -- hash u )
: >beacon-addr ( sockaddr u1 -- addr u2 )
    case
	sockaddr_in4 of  [: sin_addr 4 type port 2 type ;] $tmp
	sockaddr_in4 of  [: dup sin_addr 4 type port 2 type ;] $tmp
	endof
	sockaddr_in6 of  [: sin6_addr $10 sin6_port 2 type ;] $tmp
	sockaddr_in6 of  [: dup sin6_addr $10
		2dup fake-ip4 12 string-prefix?  IF  12 /string  THEN
		type  sin6_port 2 type ;] $tmp
	endof
	true !!unknown-protocol!!
    endcase
    my-0key sec@ keyed-hash#128 2/ ;
    endcase ;

: my-beacon-hash ( sockaddr u -- hash u )
    >beacon-addr my-0key sec@
    beacon( ." my-hash: " 2over 85type space 2dup 85type )
    keyed-hash#128 2/
    beacon( ."  -> " 2dup 85type forth:cr ) ;

: gen-beacon-hash ( -- hash u )
    beacon-tuple$ $@ dest-0key sec@
    beacon( ." gen-hash: " 2over 85type space 2dup 85type )
    keyed-hash#128 2/
    beacon( ."  -> " 2dup 85type forth:cr )
;
    
: check-beacon-hash ( addr u -- flag )
    sockaddr alen @ my-beacon-hash str= ;

: handle-beacon+hash ( addr u -- )
    over c@ >r 1 /string check-beacon-hash
    IF    r>  handle-beacon
    IF    r>    beacon( ." hashed " ) handle-beacon
    ELSE  rdrop beacon( ticks .ticks ."  wrong beacon hash" cr )
    THEN ;

+4 −0
Original line number Diff line number Diff line
@@ -26,12 +26,16 @@ UValue query-sock
Variable my-addr[] \ object based hosts
Variable my-addr$ \ string based hosts (with sigs)
Variable pub-addr$ \ publicated addresses (with sigs)
Variable priv-addr$ \ unpublished addresses (with sigs)

Create fake-ip4  $0000 w, $0000 w, $0000 w, $0000 w, $0000 w, $FFFF w,
\ prefix for IPv4 addresses encoded as IPv6
Create nat64-ip4 $0064 w, $ff9b w, $0000 w, $0000 w, $0000 w, $0000 w,
\ prefix for IPv4 addresses via NAT64

: >alen ( addr u -- alen )
    sockaddr_in6 sockaddr_in4 rot family w@ AF_INET6 = select ;

\ convention:
\ '!' is a key revocation, it contains the new key
\ Tags are kept sorted, so you'll get revocations first, then net2o and IPv6+4
+4 −1
Original line number Diff line number Diff line
@@ -961,7 +961,10 @@ also net2o-base scope: /chat
: myaddrs ( addr u -- )
    \U myaddrs              list my addresses
    \G myaddrs: list my own local addresses (debugging)
    2drop .my-addrs ;
    2drop
    ." ===== all =====" forth:cr    .my-addr$s
    ." ===== public =====" forth:cr .pub-addr$s
    ." ===== private =====" forth:cr .priv-addr$s ;
: !myaddrs ( addr u -- )
    \U !myaddrs             re-obtain my addresses
    \G !myaddrs: if automatic detection of address changes fail,
Loading