X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fgovpn%2Fpeer_test.go;h=6c16469f18c008298918d43f34e902fd965dacec;hb=f47fff1e42f75b736e7067ec06c2e81394833d46;hp=7fa8aab8438a7fd04eaccf53972064edd91b8792;hpb=a87ec543051d428aaa3888804d6c8451f6d537c9;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/peer_test.go b/src/cypherpunks.ru/govpn/peer_test.go index 7fa8aab..6c16469 100644 --- a/src/cypherpunks.ru/govpn/peer_test.go +++ b/src/cypherpunks.ru/govpn/peer_test.go @@ -1,6 +1,6 @@ /* GoVPN -- simple secure free software virtual private network daemon -Copyright (C) 2014-2016 Sergey Matveev +Copyright (C) 2014-2017 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ var ( testPeer *Peer testPt []byte testCt []byte - testPeerId PeerId + testPeerID PeerID testConf *PeerConf ) @@ -45,18 +45,22 @@ func (d Dummy) Write(b []byte) (int, error) { func init() { id := new([IDSize]byte) - testPeerId = PeerId(*id) + testPeerID = PeerID(*id) testConf = &PeerConf{ - Id: &testPeerId, + ID: &testPeerID, MTU: MTUDefault, Timeout: time.Second * time.Duration(TimeoutDefault), } - testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte)) testPt = make([]byte, 789) } +func testPeerNew() { + testPeer = newPeer(true, "foo", Dummy{&testCt}, testConf, new([SSize]byte)) +} + func TestTransportSymmetric(t *testing.T) { - peerd := newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte)) + testPeerNew() + peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte)) f := func(payload []byte) bool { if len(payload) == 0 { return true @@ -70,7 +74,8 @@ func TestTransportSymmetric(t *testing.T) { } func TestTransportSymmetricNoise(t *testing.T) { - peerd := newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte)) + testPeerNew() + peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte)) testPeer.NoiseEnable = true peerd.NoiseEnable = true f := func(payload []byte) bool { @@ -87,7 +92,8 @@ func TestTransportSymmetricNoise(t *testing.T) { } func TestTransportSymmetricEncless(t *testing.T) { - peerd := newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte)) + testPeerNew() + peerd := newPeer(false, "foo", Dummy{nil}, testConf, new([SSize]byte)) testPeer.Encless = true testPeer.NoiseEnable = true peerd.Encless = true @@ -107,7 +113,6 @@ func TestTransportSymmetricEncless(t *testing.T) { } func BenchmarkEnc(b *testing.B) { - b.ResetTimer() for i := 0; i < b.N; i++ { testPeer.EthProcess(testPt) } @@ -119,10 +124,14 @@ func BenchmarkDec(b *testing.B) { testPeer = newPeer(true, "foo", Dummy{nil}, testConf, new([SSize]byte)) orig := make([]byte, len(testCt)) copy(orig, testCt) + nonce := new([NonceSize]byte) + copy(nonce[:], testCt[len(testCt)-NonceSize:]) b.ResetTimer() for i := 0; i < b.N; i++ { - testPeer.nonceBucket0 = make(map[uint64]struct{}, 1) - testPeer.nonceBucket1 = make(map[uint64]struct{}, 1) + testPeer.nonceBucketL = make(map[[NonceSize]byte]struct{}, 1) + testPeer.nonceBucketM = make(map[[NonceSize]byte]struct{}, 1) + testPeer.nonceBucketH = make(map[[NonceSize]byte]struct{}, 1) + testPeer.nonceBucketL[*nonce] = struct{}{} copy(testCt, orig) if !testPeer.PktProcess(testCt, Dummy{nil}, true) { b.Fail()