2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2019 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, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 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: time.Second * time.Duration(TimeoutDefault),
53 testPt = make([]byte, 789)
57 testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
60 func TestTransportSymmetric(t *testing.T) {
62 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
63 f := func(payload []byte) bool {
64 if len(payload) == 0 {
67 testPeer.EthProcess(payload)
68 return peerd.PktProcess(testCt, Dummy{nil}, true)
70 if err := quick.Check(f, nil); err != nil {
75 func TestTransportSymmetricNoise(t *testing.T) {
77 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
78 testPeer.NoiseEnable = true
79 peerd.NoiseEnable = true
80 f := func(payload []byte) bool {
81 if len(payload) == 0 {
84 testPeer.EthProcess(payload)
85 return peerd.PktProcess(testCt, Dummy{nil}, true)
87 if err := quick.Check(f, nil); err != nil {
90 testPeer.NoiseEnable = true
93 func TestTransportSymmetricEncless(t *testing.T) {
95 peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte))
96 testPeer.Encless = true
97 testPeer.NoiseEnable = true
99 peerd.NoiseEnable = true
100 f := func(payload []byte) bool {
101 if len(payload) == 0 {
104 testPeer.EthProcess(payload)
105 return peerd.PktProcess(testCt, Dummy{nil}, true)
107 if err := quick.Check(f, nil); err != nil {
110 testPeer.NoiseEnable = false
111 testPeer.Encless = false
114 func BenchmarkEnc(b *testing.B) {
115 for i := 0; i < b.N; i++ {
116 testPeer.EthProcess(testPt)
120 func BenchmarkDec(b *testing.B) {
121 testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte))
122 testPeer.EthProcess(testPt)
123 testPeer = newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte))
124 orig := make([]byte, len(testCt))
126 nonce := new([NonceSize]byte)
127 copy(nonce[:], testCt[len(testCt)-NonceSize:])
129 for i := 0; i < b.N; i++ {
130 testPeer.nonceBucketL = make(map[[NonceSize]byte]struct{}, 1)
131 testPeer.nonceBucketM = make(map[[NonceSize]byte]struct{}, 1)
132 testPeer.nonceBucketH = make(map[[NonceSize]byte]struct{}, 1)
133 testPeer.nonceBucketL[*nonce] = struct{}{}
135 if !testPeer.PktProcess(testCt, Dummy{nil}, true) {
141 func TestTransportBigger(t *testing.T) {
142 tmp := make([]byte, MTUMax*4)
144 testPeer.PktProcess(tmp, Dummy{nil}, true)