]> Cypherpunks.ru repositories - govpn.git/blob - src/govpn/transport_test.go
Replace -noncediff with the hash keeping up to 256 seen nonces
[govpn.git] / src / govpn / transport_test.go
1 package govpn
2
3 import (
4         "net"
5         "testing"
6         "time"
7 )
8
9 var (
10         peer       *Peer
11         plaintext  []byte
12         ready      chan struct{}
13         dummy      = &Dummy{}
14         ciphertext []byte
15         addr       *net.UDPAddr
16         peerId     *PeerId
17         conf       *PeerConf
18 )
19
20 func init() {
21         MTU = 1500
22         addr, _ = net.ResolveUDPAddr("udp", "[::1]:1")
23         peerId, _ = IDDecode("ffffffffffffffffffffffffffffffff")
24         conf = &PeerConf{
25                 Id:          peerId,
26                 Timeout:     time.Second * time.Duration(TimeoutDefault),
27                 NoiseEnable: false,
28                 CPR:         0,
29         }
30         peer = newPeer(addr, conf, 128, new([SSize]byte))
31         plaintext = make([]byte, 789)
32         ready = make(chan struct{})
33         go func() {
34                 for {
35                         <-ready
36                 }
37         }()
38 }
39
40 type Dummy struct{}
41
42 func (d *Dummy) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) {
43         ciphertext = b
44         return len(b), nil
45 }
46
47 func (d *Dummy) Write(p []byte) (n int, err error) {
48         return len(p), nil
49 }
50
51 func BenchmarkEnc(b *testing.B) {
52         b.ResetTimer()
53         for i := 0; i < b.N; i++ {
54                 peer.NonceOur = 128
55                 peer.EthProcess(plaintext, dummy, ready)
56         }
57 }
58
59 func BenchmarkDec(b *testing.B) {
60         peer.EthProcess(plaintext, dummy, ready)
61         peer = newPeer(addr, conf, 128, new([SSize]byte))
62         b.ResetTimer()
63         for i := 0; i < b.N; i++ {
64                 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
65                 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
66                 if !peer.UDPProcess(ciphertext, dummy, ready) {
67                         b.Fail()
68                 }
69         }
70 }