6 ServerLoop
,opcode
,MemStream
;
8 Same idea here as upmgr. Have an tAggr for each peer reporting speed and
9 tJob for each file request saving to file and reqesting missed segments.
10 The aggr should have limit of paralele jobs. Jobs will first be linked in
11 tAggr queue and then started as slots become available.
13 After node restart, notify requester with a No-Source error. But should
14 not be forgotten. More advanced DM could consult CHK or Category the file
18 tJob_ptr
=pointer;//^tJob;
25 Jobs
: array [0..15] of tJob_ptr
;
30 procedure Init(const src
:tNetAddr
);
31 procedure MsgDATA(sz
:Word;mark
:byte);
32 procedure MsgIMME(sz
:Word;mark
:byte);
33 procedure Recv(msg
:tSMsg
);
39 procedure tAggr
.Init(const src
:tNetAddr
);
44 CurMark
:=0;PrvMark
:=0;
46 refs
:=high(Jobs
); while refs
>0 do begin Jobs
[refs
]:=nil; dec(refs
) end;
47 ChanOfs
:=Random(255-high(Jobs
));
49 Shedule(5000,@Periodic
);
51 SetMsgHandler(opcode
.tcdata
,src
,@Recv
);
52 SetMsgHandler(opcode
.tcdataimm
,src
,@Recv
);
55 procedure tAggr
.Recv(msg
:tSMsg
);
60 op
:=msg
.stream
.readbyte
;
61 mark
:=msg
.stream
.readbyte
;
62 if op
=opcode
.tcdataimm
then MsgIMME(msg
.length
,mark
);
63 MsgDATA(msg
.length
,mark
);
64 chan
:=msg
.stream
.readbyte
;
65 //delegate to others todo
68 procedure tAggr
.MsgIMME(sz
:Word; mark
:byte);
70 var buf
:array [1..4] of byte;
72 r
.Init(@buf
,0,sizeof(buf
));
73 r
.WriteByte(opcode
.tceack
);
76 SendMessage(r
.base
^,r
.length
,remote
);
79 procedure tAggr
.MsgDATA(sz
:Word; mark
:byte);
81 var rateb
: DWord
; {BytesPerSecond shr 6 (=64)}
82 var buf
:array [1..6] of byte;
85 if mark
<>PrvMark
then begin
86 if mark
<>CurMark
then begin
92 end else begin Inc(ByteCnt
,sz
); Inc(DgrCnt
) end;
95 if DgrCnt
<8 then exit
;
96 delta
:=(mNow
-StartT
){*MSecsPerDay};
97 if delta
<400 then exit
;
98 rate
:=(ByteCnt
/delta
)*1000;
99 writeln('Rate: ',(rate
/1024):7:1, '(',ByteCnt
,')');
100 rateb
:=round((rate
)/64);
103 r
.Init(@buf
,0,sizeof(buf
));
104 r
.WriteByte(opcode
.tccont
);
106 r
.WriteWord(rateb
,4);
107 SendMessage(r
.base
^,r
.length
,remote
);
110 procedure tAggr
.Periodic
;
112 if DgrCntCheck
>1 then begin
114 Shedule(5000,@Periodic
);
116 writeln('Periodic check failed');
120 procedure tAggr
.Done
;
122 UnShedule(@Periodic
);