Initial commit
[novacoin-seeder.git] / test.pl
1 #!/usr/bin/perl
2
3 use threads;
4 use threads::shared;
5 use bytes;
6 use IO::Socket;
7 use strict;
8
9 my @dom = ("seed","bitcoin","sipa","be");
10
11 my $run :shared = 1;
12
13 sub go {
14   my ($idx) = @_;
15
16   my $runs = 0;
17   
18   my $sock = IO::Socket::INET->new(
19     Proto    => 'udp',
20     PeerPort => 53,
21     PeerAddr => "vps.sipa.be",
22   ) or die "Could not create socket: $!\n";
23
24   while($run) {
25
26     my $id = int(rand(65536));
27     my $qr = 0;
28     my $opcode = 0;
29     my $aa = 0;
30     my $tc = 0;
31     my $rd = 0;
32     my $ra = 0;
33     my $z = 0;
34     my $rcode = 0;
35     my $qdcount = 1;
36     my $ancount = 0;
37     my $nscount = 0;
38     my $arcount = 0;
39     my $header = pack('nnnnnn',$id,1*$qr + 2*$opcode + 32*$aa + 64*$tc + 128*$rd + 256*$ra + 512*$z + 4096*$rcode, $qdcount, $ancount, $nscount, $arcount);
40     my $qtype = 1; # A record
41     my $qclass = 1; # IN class
42     my $query = (join("", map { chr(length($_)) . $_ } (@dom,""))) . pack('nn',$qtype,$qclass);
43     my $msg = $header . $query;
44     $sock->send($msg);
45     my $resp;
46     $runs++ if ($sock->recv($resp, 512, 0));
47     
48 #    $sock->close();
49   }
50   return $runs;
51 }
52
53 my @threads;
54
55 for my $i (0..500) {
56   $threads[$i] = threads->create(\&go, $i);
57 }
58
59 sleep 10;
60
61 $run=0;
62 my $runs = 0;
63 foreach my $thr (@threads) {
64   $runs += $thr->join();
65 }
66
67 print "$runs runs\n";