-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBTCPeerDiscoveryUnit.pas
More file actions
74 lines (57 loc) · 1.58 KB
/
BTCPeerDiscoveryUnit.pas
File metadata and controls
74 lines (57 loc) · 1.58 KB
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
67
68
69
70
71
72
73
74
unit BTCPeerDiscoveryUnit;
interface
uses
System.SysUtils, System.Classes, ipwcore, ipwtypes,
ipwdns;
type
TSeedsNotifyEvent = procedure(Sender: TObject; Peer: string) of object;
TBTCPeerDiscovery = class(TComponent)
strict private
fDNS: TipwDNS;
fMaxPeers : cardinal;
FOnResponse: TSeedsNotifyEvent;
procedure DoResponse(Sender: TObject; RequestId: Integer;
const Domain: String; StatusCode: Integer; const Description: String;
Authoritative: Boolean);
public
constructor Create(Owner: TComponent); override;
procedure Discover;
published
property MaxPeers : cardinal read fMaxPeers write fMaxPeers;
property OnResponse: TSeedsNotifyEvent read FOnResponse write FOnResponse;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('CryptoCurrency', [TBTCPeerDiscovery]);
end;
{ TPeerDiscoveryBTC }
constructor TBTCPeerDiscovery.Create(Owner: TComponent);
begin
inherited;
fDNS := TipwDNS.Create(self);
fDNS.OnResponse := DoResponse;
end;
procedure TBTCPeerDiscovery.Discover;
begin
fDNS.Query('seed.bitcoin.sipa.be');
end;
procedure TBTCPeerDiscovery.DoResponse(Sender: TObject; RequestId: Integer;
const Domain: String; StatusCode: Integer; const Description: String;
Authoritative: Boolean);
var
k: Integer;
amaxpeers : integer;
begin
if fMaxPeers =0 then
amaxpeers := high(integer)
else
amaxpeers := fMaxPeers;
for k := 0 to fDNS.RecordCount - 1 do
begin
if Assigned(FOnResponse) and (k<amaxpeers) then
FOnResponse(self, fDNS.RecordFieldValue[k]);
end;
end;
end.