2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
39 func (d Dummy) Write(b []byte) (int, error) {
47 id := new([IDSize]byte)
48 testPeerId = PeerId(*id)
52 Timeout: time.Second * time.Duration(TimeoutDefault),
54 testPt = make([]byte, 789)
58 testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
61 func TestTransportSymmetric(t *testing.T) {
63 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
64 f := func(payload []byte) bool {
65 if len(payload) == 0 {
68 testPeer.EthProcess(payload)
69 return peerd.PktProcess(testCt, Dummy{nil}, true)
71 if err := quick.Check(f, nil); err != nil {
76 func TestTransportSymmetricNoise(t *testing.T) {
78 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
79 testPeer.NoiseEnable = true
80 peerd.NoiseEnable = true
81 f := func(payload []byte) bool {
82 if len(payload) == 0 {
85 testPeer.EthProcess(payload)
86 return peerd.PktProcess(testCt, Dummy{nil}, true)
88 if err := quick.Check(f, nil); err != nil {
91 testPeer.NoiseEnable = true
94 func TestTransportSymmetricEncless(t *testing.T) {
96 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
97 testPeer.Encless = true
98 testPeer.NoiseEnable = true
100 peerd.NoiseEnable = true
101 f := func(payload []byte) bool {
102 if len(payload) == 0 {
105 testPeer.EthProcess(payload)
106 return peerd.PktProcess(testCt, Dummy{nil}, true)
108 if err := quick.Check(f, nil); err != nil {
111 testPeer.NoiseEnable = false
112 testPeer.Encless = false
115 func BenchmarkEnc(b *testing.B) {
116 for i := 0; i < b.N; i++ {
117 testPeer.EthProcess(testPt)
121 func BenchmarkDec(b *testing.B) {
122 testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
123 testPeer.EthProcess(testPt)
124 testPeer = newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte))
125 orig := make([]byte, len(testCt))
127 nonce := new([NonceSize]byte)
128 copy(nonce[:], testCt[len(testCt)-NonceSize:])
130 for i := 0; i < b.N; i++ {
131 testPeer.nonceBucketL = make(map[[NonceSize]byte]struct{}, 1)
132 testPeer.nonceBucketM = make(map[[NonceSize]byte]struct{}, 1)
133 testPeer.nonceBucketH = make(map[[NonceSize]byte]struct{}, 1)
134 testPeer.nonceBucketL[*nonce] = struct{}{}
136 if !testPeer.PktProcess(testCt, Dummy{nil}, true) {
142 func TestTransportBigger(t *testing.T) {
143 tmp := make([]byte, MTUMax*4)
145 testPeer.PktProcess(tmp, Dummy{nil}, true)