The router may receive heartbeat packets that originated from (the other end of) a different connection with the remote peer than the current one. If we don't detect that, we may erroneously tell the remote peer to mark the connection as 'established'. Which can lead to a crash. To enable detection, we include the connection UID - which is the same at both ends - in the heartbeat frame. That way we can simply ignore heartbeats with a different connection UID than the current connection to the remote peer. Previously heartbeat frames were zero length. In order to include the 64 bit connection UID we could just send 8 octets instead. However, that would potentially trip up the Ethernet decoder at the other end, and in any case we might as well make heartbeats fit the format of other special frames, namely having an all-zero Ethernet header. This in fact results in a simplification of the special frame handling, since heartbeats are no longer *extra* special. Fixes #352.
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package router
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
Protocol = "weave"
|
|
ProtocolVersion = 10
|
|
EthernetOverhead = 14
|
|
UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP
|
|
Port = 6783
|
|
HttpPort = Port + 1
|
|
DefaultPMTU = 65535
|
|
MaxUDPPacketSize = 65536
|
|
ChannelSize = 16
|
|
UDPNonceSendAt = 8192
|
|
FragTestSize = 60001
|
|
PMTUDiscoverySize = 60000
|
|
FastHeartbeat = 500 * time.Millisecond
|
|
SlowHeartbeat = 10 * time.Second
|
|
FetchAllInterval = 30 * time.Second
|
|
FragTestInterval = 5 * time.Minute
|
|
ReadTimeout = 2 * FetchAllInterval
|
|
PMTUVerifyAttempts = 8
|
|
PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt
|
|
MaxDuration = time.Duration(math.MaxInt64)
|
|
)
|
|
|
|
const (
|
|
ProtocolConnectionEstablished = iota
|
|
ProtocolFragmentationReceived
|
|
ProtocolStartFragmentationTest
|
|
ProtocolNonce
|
|
ProtocolFetchAll
|
|
ProtocolUpdate
|
|
ProtocolPMTUVerified
|
|
)
|
|
|
|
var (
|
|
FragTest = make([]byte, FragTestSize)
|
|
PMTUDiscovery = make([]byte, PMTUDiscoverySize)
|
|
ProtocolConnectionEstablishedByte = []byte{ProtocolConnectionEstablished}
|
|
ProtocolFragmentationReceivedByte = []byte{ProtocolFragmentationReceived}
|
|
ProtocolStartFragmentationTestByte = []byte{ProtocolStartFragmentationTest}
|
|
ProtocolNonceByte = []byte{ProtocolNonce}
|
|
ProtocolFetchAllByte = []byte{ProtocolFetchAll}
|
|
ProtocolUpdateByte = []byte{ProtocolUpdate}
|
|
ProtocolPMTUVerifiedByte = []byte{ProtocolPMTUVerified}
|
|
)
|