-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTCMonitorUnit.pas
66 lines (46 loc) · 1.3 KB
/
BTCMonitorUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
unit BTCMonitorUnit;
interface
uses
classes, generics.Collections, BTCPeerUnit, BTCThreadMonitorUnit;
type
TBTCMonitorComponent = class(TComponent)
private
fBTCPeerComponent: TBTCPeerComponent;
fMaxConnections: integer;
fConnectionsPool: TObjectList<TBTCThreadMonitor>;
procedure Response(Sender: TObject; Peer: String);
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
property MaxConnections: integer read fMaxConnections write fMaxConnections;
end;
implementation
uses
dialogs;
constructor TBTCMonitorComponent.Create(Owner: TComponent);
begin
inherited;
fMaxConnections := 1;
fConnectionsPool := TObjectList<TBTCThreadMonitor>.Create;
fConnectionsPool.OwnsObjects := true;
fBTCPeerComponent := TBTCPeerComponent.Create(self);
fBTCPeerComponent.OnResponse := Response;
fBTCPeerComponent.GetSeeds();
end;
destructor TBTCMonitorComponent.Destroy;
begin
// Destroy ConnectionsPool
fConnectionsPool.free;
// Destroy BTCPeer
fBTCPeerComponent.free;
inherited;
end;
procedure TBTCMonitorComponent.Response(Sender: TObject; Peer: String);
begin
// Create just MaxConnections
if fConnectionsPool.Count < MaxConnections then
begin
fConnectionsPool.Add(TBTCThreadMonitor.Create(Peer,self));
end;
end;
end.