upmgr wtf
[brdnet.git] / upmgr.pas
blobe5b21b8da6cacff379a869c93d460b61e336403e
1 UNIT UPMGR;
2 {Upload Manager for brodnetd}
3 {mission:
4 multiplex uploads thru TC connection
5 - read files
6 - add demux info
7 - add sequence/offset
8 - handle retransmit requests
9 - handle all requests
10 - deprioritize/cancel uploads
11 keep one TC connection per peer (+expire-delete)
12 => need 'chat' protocol
15 {to download a file:
16 - send file request (chat)
17 (GET channel CHK hash ofset length)
18 - channel, client choose, reuse
19 - prepare recv channel
20 - wait reply (positive/negative)
23 INTERFACE
24 USES TC;
26 type tUH = procedure(var tcs:tTCS): of object;
27 procedure AddUpload(rcpt:tNetAddr; channel:byte; handler:tUH);
28 {delete with handler=nil}
30 IMPLEMENTATION
32 type tPeer_ptr=^tPeer; tPeer=object
33 tcs: tTCS;
34 prv: ^tUH; {dynamic array}
35 prvc: word; {number of allocated items unused are nil}
36 next:tPeer_ptr;
37 procedure OnCont;
38 function AllocChannel:word;
39 end;
40 var Peers:^tPeer;
42 function FindPeer(const addr:tNetAddr): tPeer_ptr;
43 begin
44 result:=Peers;
45 while assigned(result) do begin
46 if result^.tcs.remote=addr then exit;
47 result:=result^.next;
48 end;
49 end;
51 procedure AddUpload(rcpt:tNetAddr; channel:byte; handler:tUH);
52 var peer:^tPeer;
53 begin
54 peer:=FindPeer(rcpt);
55 if not assigned(peer) then begin
56 New(peer);
57 peer^.next:=Peers;
58 peer^.prvc:=channel+1;
59 peer^.prv:=GetMem(sizeof(peer^.prv)*peer^.prvc);
60 Peers:=peer;
61 peer^.tcs.Init(rcpt);
62 peer^.tcs.CanSend:=@OnCont;
63 end else begin
65 end;
66 if peer^.tcs.txLastSize=0 then peer^.tcs.Start;