import (
"testing"
+ "testing/quick"
"time"
)
peer *Peer
plaintext []byte
ciphertext []byte
- peerId *PeerId
+ peerId PeerId
conf *PeerConf
)
}
func init() {
- MTU = 1500
id := new([IDSize]byte)
- peerId := PeerId(*id)
+ peerId = PeerId(*id)
conf = &PeerConf{
Id: &peerId,
+ MTU: MTUDefault,
Timeout: time.Second * time.Duration(TimeoutDefault),
- Noise: false,
- CPR: 0,
}
peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
plaintext = make([]byte, 789)
}
+func TestTransportSymmetric(t *testing.T) {
+ peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
+ f := func(payload []byte) bool {
+ if len(payload) == 0 {
+ return true
+ }
+ peer.EthProcess(payload)
+ return peerd.PktProcess(ciphertext, Dummy{nil}, true)
+ }
+ if err := quick.Check(f, nil); err != nil {
+ t.Error(err)
+ }
+}
+
+func TestTransportSymmetricNoise(t *testing.T) {
+ peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
+ peer.NoiseEnable = true
+ peerd.NoiseEnable = true
+ f := func(payload []byte) bool {
+ if len(payload) == 0 {
+ return true
+ }
+ peer.EthProcess(payload)
+ return peerd.PktProcess(ciphertext, Dummy{nil}, true)
+ }
+ if err := quick.Check(f, nil); err != nil {
+ t.Error(err)
+ }
+ peer.NoiseEnable = true
+}
+
+func TestTransportSymmetricEncless(t *testing.T) {
+ peerd := newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
+ peer.Encless = true
+ peer.NoiseEnable = true
+ peerd.Encless = true
+ peerd.NoiseEnable = true
+ f := func(payload []byte) bool {
+ if len(payload) == 0 {
+ return true
+ }
+ peer.EthProcess(payload)
+ return peerd.PktProcess(ciphertext, Dummy{nil}, true)
+ }
+ if err := quick.Check(f, nil); err != nil {
+ t.Error(err)
+ }
+ peer.NoiseEnable = false
+ peer.Encless = false
+}
+
func BenchmarkEnc(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {