]> Cypherpunks.ru repositories - govpn.git/blob - transport_test.go
Use A-EKE instead of EKE. Doc refactoring. Preparing for 3.0 release
[govpn.git] / 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                 Noncediff:   1,
28                 NoiseEnable: false,
29                 CPR:         0,
30         }
31         peer = newPeer(addr, conf, 128, new([SSize]byte))
32         plaintext = make([]byte, 789)
33         ready = make(chan struct{})
34         go func() {
35                 for {
36                         <-ready
37                 }
38         }()
39 }
40
41 type Dummy struct{}
42
43 func (d *Dummy) WriteTo(b []byte, addr net.Addr) (int, error) {
44         ciphertext = b
45         return len(b), nil
46 }
47
48 func (d *Dummy) Write(p []byte) (n int, err error) {
49         return len(p), nil
50 }
51
52 func BenchmarkEnc(b *testing.B) {
53         b.ResetTimer()
54         for i := 0; i < b.N; i++ {
55                 peer.NonceOur = 128
56                 peer.EthProcess(plaintext, dummy, ready)
57         }
58 }
59
60 func BenchmarkDec(b *testing.B) {
61         peer.EthProcess(plaintext, dummy, ready)
62         peer = newPeer(addr, conf, 128, new([SSize]byte))
63         b.ResetTimer()
64         for i := 0; i < b.N; i++ {
65                 if !peer.UDPProcess(ciphertext, dummy, ready) {
66                         b.Fail()
67                 }
68         }
69 }