Make Encryptor.AppendFrame more consistent with FrameConsumer
Also removes references to Peer type in crypto.go, to keep it agnostic of higher-level concerns.
This commit is contained in:
1 parent
a670272a37
commit
bc45a363dd
2 files changed
+12
-16
No files matched your search
+9
-10
@@ -107,7 +107,7 @@ type Encryptor interface {
|
|||||||
PacketOverhead() int
|
PacketOverhead() int
|
||||||
IsEmpty() bool
|
IsEmpty() bool
|
||||||
Bytes() []byte
|
Bytes() []byte
|
||||||
AppendFrame(*ForwardedFrame)
|
AppendFrame(src []byte, dst []byte, frame []byte)
|
||||||
TotalLen() int
|
TotalLen() int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,18 +159,17 @@ func (ne *NonEncryptor) Bytes() []byte {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ne *NonEncryptor) AppendFrame(frame *ForwardedFrame) {
|
func (ne *NonEncryptor) AppendFrame(src []byte, dst []byte, frame []byte) {
|
||||||
bufTail := ne.bufTail
|
bufTail := ne.bufTail
|
||||||
srcLen := copy(bufTail, frame.srcPeer.NameByte)
|
srcLen := copy(bufTail, src)
|
||||||
bufTail = bufTail[srcLen:]
|
bufTail = bufTail[srcLen:]
|
||||||
dstLen := copy(bufTail, frame.dstPeer.NameByte)
|
dstLen := copy(bufTail, dst)
|
||||||
bufTail = bufTail[dstLen:]
|
bufTail = bufTail[dstLen:]
|
||||||
frameLen := len(frame.frame)
|
binary.BigEndian.PutUint16(bufTail, uint16(len(frame)))
|
||||||
binary.BigEndian.PutUint16(bufTail, uint16(frameLen))
|
|
||||||
bufTail = bufTail[2:]
|
bufTail = bufTail[2:]
|
||||||
copy(bufTail, frame.frame)
|
copy(bufTail, frame)
|
||||||
ne.bufTail = bufTail[frameLen:]
|
ne.bufTail = bufTail[len(frame):]
|
||||||
ne.buffered += srcLen + dstLen + 2 + frameLen
|
ne.buffered += srcLen + dstLen + 2 + len(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ne *NonEncryptor) TotalLen() int {
|
func (ne *NonEncryptor) TotalLen() int {
|
||||||
@@ -245,7 +244,7 @@ func (ne *NaClEncryptor) TotalLen() int {
|
|||||||
|
|
||||||
// Frame Decryptors
|
// 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 {
|
type Decryptor interface {
|
||||||
IterateFrames(FrameConsumer, *UDPPacket) error
|
IterateFrames(FrameConsumer, *UDPPacket) error
|
||||||
|
|||||||
+3
-6
@@ -281,11 +281,8 @@ func (fwd *Forwarder) verifyEffectivePMTU(newUnverifiedPMTU int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *Forwarder) attemptVerifyEffectivePMTU() {
|
func (fwd *Forwarder) attemptVerifyEffectivePMTU() {
|
||||||
pmtuVerifyFrame := &ForwardedFrame{
|
fwd.enc.AppendFrame(fwd.conn.local.NameByte, fwd.conn.remote.NameByte,
|
||||||
srcPeer: fwd.conn.local,
|
make([]byte, fwd.unverifiedPMTU+EthernetOverhead))
|
||||||
dstPeer: fwd.conn.remote,
|
|
||||||
frame: make([]byte, fwd.unverifiedPMTU+EthernetOverhead)}
|
|
||||||
fwd.enc.AppendFrame(pmtuVerifyFrame)
|
|
||||||
fwd.flush()
|
fwd.flush()
|
||||||
if fwd.verifyPMTUTick == nil {
|
if fwd.verifyPMTUTick == nil {
|
||||||
fwd.verifyPMTUTick = time.After(PMTUVerifyTimeout << (PMTUVerifyAttempts - fwd.pmtuVerifyCount))
|
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 {
|
if fwd.enc.TotalLen()+fwd.enc.FrameOverhead()+frameLen > fwd.maxPayload {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fwd.enc.AppendFrame(frame)
|
fwd.enc.AppendFrame(frame.srcPeer.NameByte, frame.dstPeer.NameByte, frame.frame)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user