mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
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:
@@ -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{}),
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user