atomashpolskiy / bt

BitTorrent library and client with DHT, magnet links, encryption and more
https://atomashpolskiy.github.io/bt/
Apache License 2.0
2.42k stars 381 forks source link

[BUG] Many Incoming Encryption fail with InvalidMessage #199

Open pyckle opened 2 years ago

pyckle commented 2 years ago

Describe the bug While testing on a public torrent, many incoming connection negotiations fail with the following error:

[19/Oct/2021:23:23:32,279] TRACE MSEHandshakeProcessor: Negotiated encryption policy: REQUIRE_ENCRYPTED, peer: InetPeer{address=/104.x.x.x, port=63721}
[19/Oct/2021:23:23:32,279] TRACE InboundMessageProcessor: 
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  Debug message: Unknown message type ID: -45
  Peer: InetPeer{address=/104.x.x.x, port=63721}
  Buffer: java.nio.DirectByteBuffer[pos=5 lim=68 cap=1048576]
  Region A: Region{offset=0, limit=0}
  Region B: null
  Decoding params: DecodingBufferView{unconsumedOffset=0, undecodedOffset=68, undecodedLimit=68}
  First undisposed data offset: -1
  Message queue size: 0
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[19/Oct/2021:23:23:32,279] DEBUG PeerConnectionFactory: Failed to establish connection with peer: InetPeer{address=/104.x.x.x, port=63721}. Reason: java.lang.RuntimeException (bt.protocol.InvalidMessageExce
ption: Unknown message type ID: -45)
[19/Oct/2021:23:23:32,280] TRACE PeerConnectionFactory: Failed to establish connection with peer InetPeer{address=/104.x.x.x, port=63721}
java.lang.RuntimeException: bt.protocol.InvalidMessageException: Unknown message type ID: -45
        at bt.net.pipeline.InboundMessageProcessor.processInboundData(InboundMessageProcessor.java:92)
        at bt.net.pipeline.DefaultChannelPipeline.fireDataReceived(DefaultChannelPipeline.java:78)
        at bt.net.pipeline.DefaultChannelPipeline.<init>(DefaultChannelPipeline.java:65)
        at bt.net.pipeline.ChannelPipelineFactory$1.doBuild(ChannelPipelineFactory.java:60)
        at bt.net.pipeline.ChannelPipelineBuilder.build(ChannelPipelineBuilder.java:98)
        at bt.net.PeerConnectionFactory.createPipeline(PeerConnectionFactory.java:216)
        at bt.net.PeerConnectionFactory._createConnection(PeerConnectionFactory.java:171)
        at bt.net.PeerConnectionFactory.createConnection(PeerConnectionFactory.java:128)
        at bt.net.PeerConnectionFactory.createOutgoingConnection(PeerConnectionFactory.java:106)
        at bt.net.ConnectionSource.lambda$createPendingConnFuture$0(ConnectionSource.java:135)
        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: bt.protocol.InvalidMessageException: Unknown message type ID: -45
        at bt.protocol.StandardBittorrentProtocol.readMessageType(StandardBittorrentProtocol.java:226)
        at bt.protocol.StandardBittorrentProtocol.decode(StandardBittorrentProtocol.java:247)
        at bt.net.pipeline.MessageDeserializer.deserialize(MessageDeserializer.java:50)
        at bt.net.pipeline.InboundMessageProcessor.consumeA(InboundMessageProcessor.java:203)
        at bt.net.pipeline.InboundMessageProcessor.processA(InboundMessageProcessor.java:125)
        at bt.net.pipeline.InboundMessageProcessor.processInboundData(InboundMessageProcessor.java:86)
        ... 13 more

Expected behaviour The negotiation to complete correctly.

To Reproduce How can another person reproduce the bug?

Enable tracing and look at the logs in just about any torrent. Here is one for example:

magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent

Screenshots N/A

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

pangoo-reuse commented 2 years ago

Help

How can I limit the upload while downloading? For example, I need an account password to connect to the seed file I am downloading now,please. like Private Tracker