3 Initialize DHT local node ID from file.
4 Restore DHT routing table from file.
5 Save DHT routing table on exit and periodically.
11 uses NetAddr
,ServerLoop
,DHT
,SysUtils
,Store1
;
13 const ndfn
='nodes.dat';
14 const idfn
='idhash.txt';
17 var nd
: FILE of tPeerPub
;
26 dht
.GetNextNode(nnp
,nni
,node
);
27 if node
.addr
.isNil
then break
;
28 //writeln('dhtPersist: save ',string(node.addr));
38 var nd
: FILE of tPeerPub
;
46 writeln('dhtPersist: can not open state file ',ndfn
);
48 {need to read the file backwards}
51 for pos
:=pos
-1 downto 0 do begin
54 //writeln('dhtPersist: load ',string(node.addr));
68 writeln('dhtPersist: can not open id file ',idfn
);
71 writeln('dhtPersist: set ID to ',line
);
76 procedure LoadIDFromArgs
;
82 assert(OptParamCount(oi
)=1,opt
+'(pid:sha1)');
83 writeln('dhtPersist: set ID to '+paramstr(oi
+1));
84 MyID
:=tPID(paramstr(oi
+1));
87 procedure LoadIDRandom
;
94 assert(OptParamCount(oi
)=0,opt
+'()');
95 for b
:=0 to 19 do MyID
[b
]:=Random(256);
96 writeln('dhtPersist: set ID to ',string(MyID
));
103 procedure doPeriodic
;
117 procedure t
.doPeriodic
;
120 Shedule(61273,@doPeriodic
);
128 Shedule(2000,@doSoon
);
129 Shedule(25000,@doPeriodic
);
131 pot:=ServerLoop.OnTerminate;
132 ServerLoop.OnTerminate:=@doLast;