Commit bdcd7882 authored by Bernd Paysan's avatar Bernd Paysan

Limit time of host record&ekey

parent 46267fba
\ distributed hash table 16oct2013py
\ Copyright © 2013-2015 Bernd Paysan
\ Copyright © 2013-2019 Bernd Paysan
\ This program is free software: you can redistribute it and/or modify
\ it under the terms of the GNU Affero General Public License as published by
......@@ -20,16 +20,25 @@
\ might not be saved too frequently... robustness comes from distribution
\ This is actually a PHT, a prefix hash tree; base 256 (bytes)
$200 cells Constant dht-size# \ $100 entris + $100 chains
$200 cells Constant dht-size# \ $100 entries + $100 chains
Sema dht-sema
Variable d#public
Variable d#public \ root of public dht
: dht@ ( bucket -- addr ) >r
r@ @ 0= IF dht-size# allocate throw dup r> ! dup dht-size# erase
ELSE r> @ THEN ;
: dht-map { dht xt: xt -- }
dht @ 0= ?EXIT
dht @ dht-size# 2/ bounds DO
I @ ?dup-IF .xt THEN
cell +LOOP
dht @ dht-size# 2/ + dht-size# 2/ bounds DO
I @ ?dup-IF action-of xt recurse THEN
cell +LOOP ;
\ keys are enumerated small integers
0
......@@ -168,6 +177,8 @@ dht-class ' new static-a with-allocater constant dummy-dht
k#owner of [: cr .owner ." , " ;] $[]map endof
nip endcase cr
cell +LOOP ;
: d#.s ( -- )
d#public ['] d#. dht-map ;
: d#owner+ ( addr u -- ) \ with sanity checks
[: check-owner dht-owner $rep[]sig dht( d#. ) ;] dht-sema c-section ;
......@@ -190,6 +201,25 @@ dht-class ' new static-a with-allocater constant dummy-dht
[: delete-have? 0= IF dht-have $del[]sig dht( d#. )
ELSE 2drop THEN ;] dht-sema c-section ;
: d#cleanup ( o:dht -- )
k#size cell DO
dht-hash I + $@ bounds DO
I $@ check-date IF I $free THEN 2drop
cell +LOOP 0 I del$cell
cell +LOOP ;
: d#cleanups ( -- )
d#public [: ['] d#cleanup dht-sema c-section ;] dht-map ;
64Variable last-d#cleanup
: d#cleanups? ( -- )
last-d#cleanup 64@ ticks 64u< IF
d#cleanups
ticks config:dht-cleaninterval& 2@ d>64 64+ last-d#cleanup 64!
THEN ;
\ commands for DHT
scope{ net2o-base
......@@ -259,7 +289,8 @@ end-class dht-file-class
k#size cell/ 1 DO
mask 1 and IF
I dup cells dht-hash dht( ." access dht: " dup hex. over . forth:cr ) +
[: { k# a# u# } k# d#c, a# u# d#$, k# ;] $[]map drop
[: check-date 0= IF { k# a# u# } k# d#c, a# u# d#$, k#
ELSE 2drop THEN ;] $[]map drop
THEN mask 2/ to mask
LOOP ;
......
......@@ -2,7 +2,7 @@
echo "This script builds net2o from scratch"
GFORTH=gforth-0.7.9_20191115
GFORTH=gforth-0.7.9_20191121
if [ "$(uname -o)" = "Cygwin" ]
then
......
......@@ -105,7 +105,7 @@ event: :>disconnect ( addr -- ) .disconnect-me ;
64Variable announced \ time for next announcement
: announced! ( -- )
ticks config:ekey-timeout& 2@ d>64 64+ announced 64! ;
ticks config:ekey-timeout& 2@ d>64 dup 5 64rshift 64- 64+ announced 64! ;
: announced? ( -- flag ) announced 64@ ticks 64u>= ;
: subme ( -- ) announced? IF dht-connect sub-me THEN ;
......
......@@ -742,7 +742,7 @@ warnings !
: bye ( -- )
\U bye
\G bye: quit command mode and terminate program
subme dht-disconnect bye ;
bye ;
: -bw ( -- )
\O -bw
......
......@@ -175,12 +175,6 @@ kill-seconds# 1+ #1000000000 um* 2constant kill-timeout# \ 3s
REPEAT
r> kill-seconds# <> IF cr THEN 2drop ;
forward !save-all-msgs
0 warnings !@
: bye !save-all-msgs net2o-kills bye ;
warnings !
\ packet&header size
\ The first byte is organized in a way that works on wired-or busses,
......@@ -1858,6 +1852,7 @@ Variable need-beacon# need-beacon# on \ true if needs a hash for the ? beacon
Forward save-msgs?
Forward announce?
Forward d#cleanups?
Forward next-saved-msg
: >next-ticks ( -- )
......@@ -1875,6 +1870,7 @@ Forward next-saved-msg
beacon? !!0depth!!
save-msgs? !!0depth!!
announce? !!0depth!!
d#cleanups? !!0depth!!
request-timeout !!0depth!!
event-send !!0depth!!
last-packet-tos !!0depth!!
......@@ -2008,6 +2004,12 @@ require dhtroot.fs \ configuration for DHT root
context-table $save
\ modify bye
0 warnings !@
: bye !save-all-msgs subme dht-disconnect net2o-kills bye ;
warnings !
\ show problems
.unresolved
......
......@@ -394,6 +394,7 @@ $10 stack: dirstack
scope{ config
2Variable dht-cleaninterval&
2Variable ekey-timeout&
Variable timeouts#
Variable passmode#
......@@ -448,7 +449,8 @@ pad $400 get-dir rootdirs$ $!
$1000.0000. patchlimit& 2! \ 256MB patch limit size
#10.000.000.000. savedelta& 2! \ 10 seconds deltat
#3600.000.000.000. ekey-timeout& 2!
#3600.000.000.000. ekey-timeout& 2! \ one hour ekey timeout
#60.000.000.000. dht-cleaninterval& 2! \ one minute dht clean interval
: .net2o-config/ ( addr u -- addr' u' ) [: .net2o-config$ $. '/' emit type ;] $tmp ;
: .net2o-cache/ ( addr u -- addr' u' ) [: .net2o-cache$ $. '/' emit type ;] $tmp ;
......
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