From bc45a363ddb6cdfc1ded1091c6247a8bad783a55 Mon Sep 17 00:00:00 2001 From: David Wragg Date: Wed, 18 Mar 2015 15:31:36 +0000 Subject: [PATCH] Make Encryptor.AppendFrame more consistent with FrameConsumer Also removes references to Peer type in crypto.go, to keep it agnostic of higher-level concerns. --- router/crypto.go | 19 +++++++++---------- router/forwarder.go | 9 +++------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/router/crypto.go b/router/crypto.go index c4f29d26..f1f8ae51 100644 --- a/router/crypto.go +++ b/router/crypto.go @@ -107,7 +107,7 @@ type Encryptor interface { PacketOverhead() int IsEmpty() bool Bytes() []byte - AppendFrame(*ForwardedFrame) + AppendFrame(src []byte, dst []byte, frame []byte) TotalLen() int } @@ -159,18 +159,17 @@ func (ne *NonEncryptor) Bytes() []byte { return buf } -func (ne *NonEncryptor) AppendFrame(frame *ForwardedFrame) { +func (ne *NonEncryptor) AppendFrame(src []byte, dst []byte, frame []byte) { bufTail := ne.bufTail - srcLen := copy(bufTail, frame.srcPeer.NameByte) + srcLen := copy(bufTail, src) bufTail = bufTail[srcLen:] - dstLen := copy(bufTail, frame.dstPeer.NameByte) + dstLen := copy(bufTail, dst) bufTail = bufTail[dstLen:] - frameLen := len(frame.frame) - binary.BigEndian.PutUint16(bufTail, uint16(frameLen)) + binary.BigEndian.PutUint16(bufTail, uint16(len(frame))) bufTail = bufTail[2:] - copy(bufTail, frame.frame) - ne.bufTail = bufTail[frameLen:] - ne.buffered += srcLen + dstLen + 2 + frameLen + copy(bufTail, frame) + ne.bufTail = bufTail[len(frame):] + ne.buffered += srcLen + dstLen + 2 + len(frame) } func (ne *NonEncryptor) TotalLen() int { @@ -245,7 +244,7 @@ func (ne *NaClEncryptor) TotalLen() int { // Frame Decryptors -type FrameConsumer func(*LocalConnection, *net.UDPAddr, []byte, []byte, uint16, []byte) +type FrameConsumer func(conn *LocalConnection, sender *net.UDPAddr, src []byte, dst []byte, len uint16, frame []byte) type Decryptor interface { IterateFrames(FrameConsumer, *UDPPacket) error diff --git a/router/forwarder.go b/router/forwarder.go index 28f410e8..f1aeae3a 100644 --- a/router/forwarder.go +++ b/router/forwarder.go @@ -281,11 +281,8 @@ func (fwd *Forwarder) verifyEffectivePMTU(newUnverifiedPMTU int) { } func (fwd *Forwarder) attemptVerifyEffectivePMTU() { - pmtuVerifyFrame := &ForwardedFrame{ - srcPeer: fwd.conn.local, - dstPeer: fwd.conn.remote, - frame: make([]byte, fwd.unverifiedPMTU+EthernetOverhead)} - fwd.enc.AppendFrame(pmtuVerifyFrame) + fwd.enc.AppendFrame(fwd.conn.local.NameByte, fwd.conn.remote.NameByte, + make([]byte, fwd.unverifiedPMTU+EthernetOverhead)) fwd.flush() if fwd.verifyPMTUTick == nil { fwd.verifyPMTUTick = time.After(PMTUVerifyTimeout << (PMTUVerifyAttempts - fwd.pmtuVerifyCount)) @@ -337,7 +334,7 @@ func (fwd *Forwarder) appendFrame(frame *ForwardedFrame) bool { if fwd.enc.TotalLen()+fwd.enc.FrameOverhead()+frameLen > fwd.maxPayload { return false } - fwd.enc.AppendFrame(frame) + fwd.enc.AppendFrame(frame.srcPeer.NameByte, frame.dstPeer.NameByte, frame.frame) return true }