Turns out internet MTU must be honored, otherwise packets are dropped/not reassembled. Setting to 1500 bytes for transfer messages.

This commit is contained in:
Kleissner
2021-11-05 03:39:46 +01:00
parent 0d62c215ee
commit 14f034cc8d
3 changed files with 5 additions and 2 deletions

View File

@@ -47,7 +47,7 @@ func newVirtualPacketConn(peer *PeerInfo, protocol uint8, hash []byte, offset, l
hash: hash,
offset: offset,
limit: limit,
incomingData: make(chan []byte),
incomingData: make(chan []byte, 100),
outgoingData: make(chan []byte),
terminateChan: make(chan struct{}),
}

View File

@@ -76,7 +76,7 @@ func DecodeTransfer(msg *MessageRaw) (result *MessageTransfer, err error) {
}
// TransferMaxEmbedSize is the maximum size of embedded data inside the Transfer message.
const TransferMaxEmbedSize = udpMaxPacketSize - PacketLengthMin - transferPayloadHeaderSize
const TransferMaxEmbedSize = internetSafeMTU - PacketLengthMin - transferPayloadHeaderSize
// EncodeTransfer encodes a transfer message. The embedded packet size must be smaller than TransferMaxEmbedSize.
func EncodeTransfer(senderPrivateKey *btcec.PrivateKey, data []byte, control, transferProtocol uint8, hash []byte, offset, limit uint64) (packetRaw []byte, err error) {

View File

@@ -26,6 +26,9 @@ type MessageRaw struct {
// However, due to the MTU soft limit and fragmentation, packets should be as small as possible.
const udpMaxPacketSize = 65507
// internetSafeMTU is a value relatively safe to use for transmitting over the internet
const internetSafeMTU = 1500 - 20 - 8
// isPacketSizeExceed checks if the max packet size would be exceeded with the payload
func isPacketSizeExceed(currentSize int, testSize int) bool {
return currentSize+testSize > udpMaxPacketSize-PacketLengthMin