]> Cypherpunks.ru repositories - govpn.git/blob - src/govpn/transport_test.go
[DOC] Link to Git repository browser
[govpn.git] / src / govpn / transport_test.go
1 package govpn
2
3 import (
4         "testing"
5         "time"
6 )
7
8 var (
9         peer       *Peer
10         plaintext  []byte
11         ready      chan struct{}
12         ciphertext []byte
13         peerId     *PeerId
14         conf       *PeerConf
15 )
16
17 type Dummy struct {
18         dst *[]byte
19 }
20
21 func (d Dummy) Write(b []byte) (int, error) {
22         if d.dst != nil {
23                 *d.dst = b
24         }
25         return len(b), nil
26 }
27
28 func (d Dummy) Reorderable() bool {
29         return true
30 }
31
32 func init() {
33         MTU = 1500
34         peerId, _ = IDDecode("ffffffffffffffffffffffffffffffff")
35         conf = &PeerConf{
36                 Id:          peerId,
37                 Timeout:     time.Second * time.Duration(TimeoutDefault),
38                 NoiseEnable: false,
39                 CPR:         0,
40         }
41         peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
42         plaintext = make([]byte, 789)
43         ready = make(chan struct{})
44         go func() {
45                 for {
46                         <-ready
47                 }
48         }()
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, ready)
56         }
57 }
58
59 func BenchmarkDec(b *testing.B) {
60         peer.EthProcess(plaintext, ready)
61         peer = newPeer(true, "foo", Dummy{nil}, conf, 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.PktProcess(ciphertext, Dummy{nil}, ready) {
67                         b.Fail()
68                 }
69         }
70 }