Merge pull request #1451 from dpw/sleeve-compat
Restore sleeve compatibility with 1.1
This commit is contained in:
commit
b5e7e9fc5c
4 files changed
+51
-51
No files matched your search
@@ -376,8 +376,8 @@ func (conn *LocalConnection) forwarderCrypto() *OverlayCrypto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *LocalConnection) sendOverlayControlMessage(msg []byte) error {
|
func (conn *LocalConnection) sendOverlayControlMessage(tag ProtocolTag, msg []byte) error {
|
||||||
return conn.sendProtocolMsg(ProtocolMsg{ProtocolOverlayControlMsg, msg})
|
return conn.sendProtocolMsg(ProtocolMsg{tag, msg})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnectionAsForwarderListener struct{ conn *LocalConnection }
|
type ConnectionAsForwarderListener struct{ conn *LocalConnection }
|
||||||
@@ -432,8 +432,8 @@ func (conn *LocalConnection) receiveTCP(receiver TCPReceiver) {
|
|||||||
func (conn *LocalConnection) handleProtocolMsg(tag ProtocolTag, payload []byte) error {
|
func (conn *LocalConnection) handleProtocolMsg(tag ProtocolTag, payload []byte) error {
|
||||||
switch tag {
|
switch tag {
|
||||||
case ProtocolHeartbeat:
|
case ProtocolHeartbeat:
|
||||||
case ProtocolOverlayControlMsg:
|
case ProtocolConnectionEstablished, ProtocolFragmentationReceived, ProtocolPMTUVerified, ProtocolOverlayControlMsg:
|
||||||
conn.forwarder.ControlMessage(payload)
|
conn.forwarder.ControlMessage(tag, payload)
|
||||||
case ProtocolGossipUnicast, ProtocolGossipBroadcast, ProtocolGossip:
|
case ProtocolGossipUnicast, ProtocolGossipBroadcast, ProtocolGossip:
|
||||||
return conn.Router.handleGossip(tag, payload)
|
return conn.Router.handleGossip(tag, payload)
|
||||||
default:
|
default:
|
||||||
|
|||||||
+6
-4
@@ -38,7 +38,7 @@ type ForwarderParams struct {
|
|||||||
|
|
||||||
// Function to send a control message to the counterpart
|
// Function to send a control message to the counterpart
|
||||||
// forwarder.
|
// forwarder.
|
||||||
SendControlMessage func([]byte) error
|
SendControlMessage func(tag ProtocolTag, msg []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a consumer is called, the decoder will already have been used
|
// When a consumer is called, the decoder will already have been used
|
||||||
@@ -66,8 +66,10 @@ type OverlayForwarder interface {
|
|||||||
|
|
||||||
Stop()
|
Stop()
|
||||||
|
|
||||||
// Handle a message from the peer
|
// Handle a message from the peer. 'tag' exists for
|
||||||
ControlMessage([]byte)
|
// compatibility, and should always be
|
||||||
|
// ProtocolOverlayControlMessage for non-sleeve overlays.
|
||||||
|
ControlMessage(tag ProtocolTag, msg []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OverlayForwarderListener interface {
|
type OverlayForwarderListener interface {
|
||||||
@@ -98,5 +100,5 @@ func (NullOverlay) Forward(ForwardPacketKey) FlowOp {
|
|||||||
func (NullOverlay) Stop() {
|
func (NullOverlay) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NullOverlay) ControlMessage([]byte) {
|
func (NullOverlay) ControlMessage(ProtocolTag, []byte) {
|
||||||
}
|
}
|
||||||
+4
-1
@@ -329,10 +329,13 @@ type ProtocolTag byte
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
ProtocolHeartbeat ProtocolTag = iota
|
ProtocolHeartbeat ProtocolTag = iota
|
||||||
ProtocolOverlayControlMsg
|
ProtocolConnectionEstablished
|
||||||
|
ProtocolFragmentationReceived
|
||||||
|
ProtocolPMTUVerified
|
||||||
ProtocolGossip
|
ProtocolGossip
|
||||||
ProtocolGossipUnicast
|
ProtocolGossipUnicast
|
||||||
ProtocolGossipBroadcast
|
ProtocolGossipBroadcast
|
||||||
|
ProtocolOverlayControlMsg
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtocolMsg struct {
|
type ProtocolMsg struct {
|
||||||
|
|||||||
+37
-42
@@ -277,13 +277,14 @@ type sleeveForwarder struct {
|
|||||||
sleeve *SleeveOverlay
|
sleeve *SleeveOverlay
|
||||||
remotePeer *Peer
|
remotePeer *Peer
|
||||||
remotePeerBin []byte
|
remotePeerBin []byte
|
||||||
sendControlMsg func([]byte) error
|
sendControlMsg func(ProtocolTag, []byte) error
|
||||||
connUID uint64
|
connUID uint64
|
||||||
|
|
||||||
// Channels to communicate with the aggregator goroutine
|
// Channels to communicate with the aggregator goroutine
|
||||||
aggregatorChan chan<- aggregatorFrame
|
aggregatorChan chan<- aggregatorFrame
|
||||||
aggregatorDFChan chan<- aggregatorFrame
|
aggregatorDFChan chan<- aggregatorFrame
|
||||||
specialChan chan<- specialFrame
|
specialChan chan<- specialFrame
|
||||||
|
controlMsgChan chan<- controlMessage
|
||||||
confirmedChan chan<- struct{}
|
confirmedChan chan<- struct{}
|
||||||
finishedChan <-chan struct{}
|
finishedChan <-chan struct{}
|
||||||
|
|
||||||
@@ -326,13 +327,18 @@ type aggregatorFrame struct {
|
|||||||
frame []byte
|
frame []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// A "special" message over UDP, or a control message. The sender is
|
// A "special" frame over UDP
|
||||||
// nil for control messages.
|
|
||||||
type specialFrame struct {
|
type specialFrame struct {
|
||||||
sender *net.UDPAddr
|
sender *net.UDPAddr
|
||||||
frame []byte
|
frame []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A control message
|
||||||
|
type controlMessage struct {
|
||||||
|
tag ProtocolTag
|
||||||
|
msg []byte
|
||||||
|
}
|
||||||
|
|
||||||
func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwarder, error) {
|
||||||
var crypto OverlayCrypto
|
var crypto OverlayCrypto
|
||||||
if params.Crypto != nil {
|
if params.Crypto != nil {
|
||||||
@@ -349,6 +355,7 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
aggChan := make(chan aggregatorFrame, ChannelSize)
|
aggChan := make(chan aggregatorFrame, ChannelSize)
|
||||||
aggDFChan := make(chan aggregatorFrame, ChannelSize)
|
aggDFChan := make(chan aggregatorFrame, ChannelSize)
|
||||||
specialChan := make(chan specialFrame, 1)
|
specialChan := make(chan specialFrame, 1)
|
||||||
|
controlMsgChan := make(chan controlMessage, 1)
|
||||||
confirmedChan := make(chan struct{})
|
confirmedChan := make(chan struct{})
|
||||||
finishedChan := make(chan struct{})
|
finishedChan := make(chan struct{})
|
||||||
|
|
||||||
@@ -361,6 +368,7 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
aggregatorChan: aggChan,
|
aggregatorChan: aggChan,
|
||||||
aggregatorDFChan: aggDFChan,
|
aggregatorDFChan: aggDFChan,
|
||||||
specialChan: specialChan,
|
specialChan: specialChan,
|
||||||
|
controlMsgChan: controlMsgChan,
|
||||||
confirmedChan: confirmedChan,
|
confirmedChan: confirmedChan,
|
||||||
finishedChan: finishedChan,
|
finishedChan: finishedChan,
|
||||||
remoteAddr: params.RemoteAddr,
|
remoteAddr: params.RemoteAddr,
|
||||||
@@ -372,8 +380,8 @@ func (sleeve *SleeveOverlay) MakeForwarder(params ForwarderParams) (OverlayForwa
|
|||||||
senderDF: newUDPSenderDF(params.LocalIP, sleeve.localPort),
|
senderDF: newUDPSenderDF(params.LocalIP, sleeve.localPort),
|
||||||
}
|
}
|
||||||
|
|
||||||
go fwd.run(aggChan, aggDFChan, specialChan, confirmedChan,
|
go fwd.run(aggChan, aggDFChan, specialChan, controlMsgChan,
|
||||||
finishedChan)
|
confirmedChan, finishedChan)
|
||||||
return fwd, nil
|
return fwd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,9 +577,9 @@ func frameTooBig(frame []byte, mtu int) bool {
|
|||||||
return len(frame) > mtu+EthernetOverhead
|
return len(frame) > mtu+EthernetOverhead
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) ControlMessage(msg []byte) {
|
func (fwd *sleeveForwarder) ControlMessage(tag ProtocolTag, msg []byte) {
|
||||||
select {
|
select {
|
||||||
case fwd.specialChan <- specialFrame{nil, msg}:
|
case fwd.controlMsgChan <- controlMessage{tag, msg}:
|
||||||
case <-fwd.finishedChan:
|
case <-fwd.finishedChan:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -588,6 +596,7 @@ func (fwd *sleeveForwarder) Stop() {
|
|||||||
func (fwd *sleeveForwarder) run(aggChan <-chan aggregatorFrame,
|
func (fwd *sleeveForwarder) run(aggChan <-chan aggregatorFrame,
|
||||||
aggDFChan <-chan aggregatorFrame,
|
aggDFChan <-chan aggregatorFrame,
|
||||||
specialChan <-chan specialFrame,
|
specialChan <-chan specialFrame,
|
||||||
|
controlMsgChan <-chan controlMessage,
|
||||||
confirmedChan <-chan struct{},
|
confirmedChan <-chan struct{},
|
||||||
finishedChan chan<- struct{}) {
|
finishedChan chan<- struct{}) {
|
||||||
defer close(finishedChan)
|
defer close(finishedChan)
|
||||||
@@ -605,14 +614,11 @@ loop:
|
|||||||
err = fwd.aggregateAndSend(frame, aggDFChan,
|
err = fwd.aggregateAndSend(frame, aggDFChan,
|
||||||
fwd.crypto.EncDF, fwd.senderDF, fwd.maxPayload)
|
fwd.crypto.EncDF, fwd.senderDF, fwd.maxPayload)
|
||||||
|
|
||||||
case special := <-specialChan:
|
case sf := <-specialChan:
|
||||||
if special.sender == nil {
|
err = fwd.handleSpecialFrame(sf)
|
||||||
// Control messages are sent on specialChan,
|
|
||||||
// with a nil sender
|
case cm := <-controlMsgChan:
|
||||||
err = fwd.handleControlMsg(special.frame)
|
err = fwd.handleControlMessage(cm)
|
||||||
} else {
|
|
||||||
err = fwd.handleSpecialFrame(special)
|
|
||||||
}
|
|
||||||
|
|
||||||
case _, ok := <-confirmedChan:
|
case _, ok := <-confirmedChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -741,32 +747,20 @@ func (fwd *sleeveForwarder) handleSpecialFrame(special specialFrame) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
func (fwd *sleeveForwarder) handleControlMessage(cm controlMessage) error {
|
||||||
HeartbeatAck = iota
|
switch cm.tag {
|
||||||
FragTestAck
|
case ProtocolConnectionEstablished:
|
||||||
MTUTestAck
|
|
||||||
)
|
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) handleControlMsg(msg []byte) error {
|
|
||||||
if len(msg) == 0 {
|
|
||||||
log.Print(fwd.logPrefix(),
|
|
||||||
"Received zero-length control message")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch msg[0] {
|
|
||||||
case HeartbeatAck:
|
|
||||||
return fwd.handleHeartbeatAck()
|
return fwd.handleHeartbeatAck()
|
||||||
|
|
||||||
case FragTestAck:
|
case ProtocolFragmentationReceived:
|
||||||
return fwd.handleFragTestAck()
|
return fwd.handleFragTestAck()
|
||||||
|
|
||||||
case MTUTestAck:
|
case ProtocolPMTUVerified:
|
||||||
return fwd.handleMTUTestAck(msg)
|
return fwd.handleMTUTestAck(cm.msg)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Print(fwd.logPrefix(),
|
log.Print(fwd.logPrefix(),
|
||||||
"Ignoring unknown control message: ", msg[0])
|
"Ignoring unknown control message tag: ", cm.tag)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -832,7 +826,7 @@ func (fwd *sleeveForwarder) handleHeartbeat(special specialFrame) error {
|
|||||||
|
|
||||||
if !fwd.ackedHeartbeat {
|
if !fwd.ackedHeartbeat {
|
||||||
fwd.ackedHeartbeat = true
|
fwd.ackedHeartbeat = true
|
||||||
if err := fwd.sendControlMsg([]byte{HeartbeatAck}); err != nil {
|
if err := fwd.sendControlMsg(ProtocolConnectionEstablished, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -857,6 +851,8 @@ func (fwd *sleeveForwarder) setRemoteAddr(addr *net.UDPAddr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) handleHeartbeatAck() error {
|
func (fwd *sleeveForwarder) handleHeartbeatAck() error {
|
||||||
|
log.Debug(fwd.logPrefix(), "handleHeartbeatAck")
|
||||||
|
|
||||||
// The connection is now regarded as established
|
// The connection is now regarded as established
|
||||||
fwd.notifyEstablished()
|
fwd.notifyEstablished()
|
||||||
|
|
||||||
@@ -899,7 +895,7 @@ func (fwd *sleeveForwarder) handleFragTest(frame []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fwd.sendControlMsg([]byte{FragTestAck})
|
return fwd.sendControlMsg(ProtocolFragmentationReceived, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) handleFragTestAck() error {
|
func (fwd *sleeveForwarder) handleFragTestAck() error {
|
||||||
@@ -943,19 +939,18 @@ func (fwd *sleeveForwarder) sendMTUTest() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) handleMTUTest(frame []byte) error {
|
func (fwd *sleeveForwarder) handleMTUTest(frame []byte) error {
|
||||||
buf := make([]byte, 3)
|
buf := make([]byte, 2)
|
||||||
buf[0] = MTUTestAck
|
binary.BigEndian.PutUint16(buf, uint16(len(frame)-EthernetOverhead))
|
||||||
binary.BigEndian.PutUint16(buf[1:], uint16(len(frame)-EthernetOverhead))
|
return fwd.sendControlMsg(ProtocolPMTUVerified, buf)
|
||||||
return fwd.sendControlMsg(buf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fwd *sleeveForwarder) handleMTUTestAck(msg []byte) error {
|
func (fwd *sleeveForwarder) handleMTUTestAck(msg []byte) error {
|
||||||
if len(msg) < 3 {
|
if len(msg) < 2 {
|
||||||
log.Print(fwd.logPrefix(), "Received truncated MTUTestAck")
|
log.Print(fwd.logPrefix(), "Received truncated MTUTestAck")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mtu := int(binary.BigEndian.Uint16(msg[1:]))
|
mtu := int(binary.BigEndian.Uint16(msg))
|
||||||
log.Debug(fwd.logPrefix(),
|
log.Debug(fwd.logPrefix(),
|
||||||
"handleMTUTestAck: for mtu candidate ", mtu)
|
"handleMTUTestAck: for mtu candidate ", mtu)
|
||||||
if mtu != fwd.mtuCandidate {
|
if mtu != fwd.mtuCandidate {
|
||||||
|
|||||||
Reference in new issue
Block a user