2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2017 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/>.
38 func (d Dummy) Write(b []byte) (int, error) {
46 id := new([IDSize]byte)
47 testPeerID = PeerID(*id)
51 Timeout: TimeoutDefault,
53 testPt = make([]byte, 789)
56 func testPeerNew(t *testing.T) {
58 testPeer, err = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
64 func TestTransportSymmetric(t *testing.T) {
66 peerd, err := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
70 f := func(payload []byte) bool {
71 if len(payload) == 0 {
74 if err := testPeer.EthProcess(payload); err != nil {
77 return peerd.PktProcess(testCt, Dummy{nil}, true)
79 if err := quick.Check(f, nil); err != nil {
84 func TestTransportSymmetricNoise(t *testing.T) {
86 peerd, err := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
90 testPeer.NoiseEnable = true
91 peerd.NoiseEnable = true
92 f := func(payload []byte) bool {
93 if len(payload) == 0 {
96 if err := testPeer.EthProcess(payload); err != nil {
99 return peerd.PktProcess(testCt, Dummy{nil}, true)
101 if err := quick.Check(f, nil); err != nil {
104 testPeer.NoiseEnable = true
107 func TestTransportSymmetricEncless(t *testing.T) {
109 peerd, err := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
113 testPeer.Encless = true
114 testPeer.NoiseEnable = true
116 peerd.NoiseEnable = true
117 f := func(payload []byte) bool {
118 if len(payload) == 0 {
121 if err := testPeer.EthProcess(payload); err != nil {
124 return peerd.PktProcess(testCt, Dummy{nil}, true)
126 if err := quick.Check(f, nil); err != nil {
129 testPeer.NoiseEnable = false
130 testPeer.Encless = false
133 func BenchmarkEnc(b *testing.B) {
135 for i := 0; i < b.N; i++ {
136 if err = testPeer.EthProcess(testPt); err != nil {
142 func BenchmarkDec(b *testing.B) {
144 testPeer, err = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
148 if err := testPeer.EthProcess(testPt); err != nil {
151 testPeer, err = newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte))
155 orig := make([]byte, len(testCt))
157 nonce := new([NonceSize]byte)
158 copy(nonce[:], testCt[len(testCt)-NonceSize:])
160 for i := 0; i < b.N; i++ {
161 testPeer.nonceBucketL = make(map[[NonceSize]byte]struct{}, 1)
162 testPeer.nonceBucketM = make(map[[NonceSize]byte]struct{}, 1)
163 testPeer.nonceBucketH = make(map[[NonceSize]byte]struct{}, 1)
164 testPeer.nonceBucketL[*nonce] = struct{}{}
166 if !testPeer.PktProcess(testCt, Dummy{nil}, true) {
172 func TestTransportBigger(t *testing.T) {
173 tmp := make([]byte, MTUMax*4)
175 testPeer.PktProcess(tmp, Dummy{nil}, true)