]> Cypherpunks.ru repositories - govpn.git/blob - src/govpn/transport_test.go
Merge branch 'develop'
[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 init() {
29         MTU = 1500
30         peerId, _ = IDDecode("ffffffffffffffffffffffffffffffff")
31         conf = &PeerConf{
32                 Id:          peerId,
33                 Timeout:     time.Second * time.Duration(TimeoutDefault),
34                 NoiseEnable: false,
35                 CPR:         0,
36         }
37         peer = newPeer("foo", Dummy{&ciphertext}, conf, 128, new([SSize]byte))
38         plaintext = make([]byte, 789)
39         ready = make(chan struct{})
40         go func() {
41                 for {
42                         <-ready
43                 }
44         }()
45 }
46
47 func BenchmarkEnc(b *testing.B) {
48         b.ResetTimer()
49         for i := 0; i < b.N; i++ {
50                 peer.NonceOur = 128
51                 peer.EthProcess(plaintext, ready)
52         }
53 }
54
55 func BenchmarkDec(b *testing.B) {
56         peer.EthProcess(plaintext, ready)
57         peer = newPeer("foo", Dummy{nil}, conf, 128, new([SSize]byte))
58         b.ResetTimer()
59         for i := 0; i < b.N; i++ {
60                 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
61                 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
62                 if !peer.PktProcess(ciphertext, Dummy{nil}, ready) {
63                         b.Fail()
64                 }
65         }
66 }