diff --git a/Transfer Virtual Connection.go b/Transfer Virtual Connection.go index 9ba53a4..9d3999e 100644 --- a/Transfer Virtual Connection.go +++ b/Transfer Virtual Connection.go @@ -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{}), } diff --git a/protocol/Message Encoding Transfer.go b/protocol/Message Encoding Transfer.go index 74da6fe..9330583 100644 --- a/protocol/Message Encoding Transfer.go +++ b/protocol/Message Encoding Transfer.go @@ -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) { diff --git a/protocol/Message Encoding.go b/protocol/Message Encoding.go index c7a9c25..20011c1 100644 --- a/protocol/Message Encoding.go +++ b/protocol/Message Encoding.go @@ -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