]> Cypherpunks.ru repositories - govpn.git/blob - src/govpn/peer_test.go
Fixed test passing
[govpn.git] / src / govpn / peer_test.go
1 package govpn
2
3 import (
4         "testing"
5         "time"
6 )
7
8 var (
9         peer       *Peer
10         plaintext  []byte
11         ciphertext []byte
12         peerId     *PeerId
13         conf       *PeerConf
14 )
15
16 type Dummy struct {
17         dst *[]byte
18 }
19
20 func (d Dummy) Write(b []byte) (int, error) {
21         if d.dst != nil {
22                 *d.dst = b
23         }
24         return len(b), nil
25 }
26
27 func init() {
28         MTU = 1500
29         peerId, _ = IDDecode("ffffffffffffffffffffffffffffffff")
30         conf = &PeerConf{
31                 Id:      peerId,
32                 Timeout: time.Second * time.Duration(TimeoutDefault),
33                 Noise:   false,
34                 CPR:     0,
35         }
36         peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
37         plaintext = make([]byte, 789)
38 }
39
40 func BenchmarkEnc(b *testing.B) {
41         b.ResetTimer()
42         for i := 0; i < b.N; i++ {
43                 peer.EthProcess(plaintext)
44         }
45 }
46
47 func BenchmarkDec(b *testing.B) {
48         peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
49         peer.EthProcess(plaintext)
50         peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
51         orig := make([]byte, len(ciphertext))
52         copy(orig, ciphertext)
53         b.ResetTimer()
54         for i := 0; i < b.N; i++ {
55                 peer.nonceBucket0 = make(map[uint64]struct{}, 1)
56                 peer.nonceBucket1 = make(map[uint64]struct{}, 1)
57                 copy(ciphertext, orig)
58                 if !peer.PktProcess(ciphertext, Dummy{nil}, true) {
59                         b.Fail()
60                 }
61         }
62 }