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

Peer hashcode fix #194

Open pyckle opened 3 years ago

pyckle commented 3 years ago

Separate Peer into InetPeer (for remote peer), LocalPeer (for the local peer information, and ImmutablePeer for lists of peers that are obtained or sent via peer sharing mechanisms (tracker, PEx, etc.)

InetPeer is not suitable for using as a Map key because it is mutable, including the remote port. The remote port for incoming connections is not known until the extended handshake is completed.

Many extension modules implemented must store state on a per peer basis - it is required by many extension specifications. However the implementations that use Map<Peer, State> are clumsy. These maps must be cleaned whenever a peer disconnects.

This has been solved by adding an additional state map in the ConnectionState object that takes a state class and returns its instance for the peer.

Also, many modules have a common check they need to do - check whether the module is supported by the remote peer. The state of supported modules is now stored in the Peer object, to eliminate the need for all of the modules to consume the ExtendedHandshake message. Also, removing support for protocols is now supported.

PEx now shares additional information about peers. It shares whether they are seeding, whether they are using encryption, as well as whether our connection to them is outgoing or incoming. uTP and hole punching are still not implemented.

codecov-commenter commented 3 years ago

Codecov Report

Merging #194 (21527b1) into master (7dcb93b) will increase coverage by 2.33%. The diff coverage is 70.47%.

:exclamation: Current head 21527b1 differs from pull request most recent head d6c7f0b. Consider uploading reports for the commit d6c7f0b to get more accurate results Impacted file tree graph

@@             Coverage Diff              @@
##             master     #194      +/-   ##
============================================
+ Coverage     65.72%   68.05%   +2.33%     
- Complexity     2378     2512     +134     
============================================
  Files           309      313       +4     
  Lines         10339    10465     +126     
  Branches       1144     1143       -1     
============================================
+ Hits           6795     7122     +327     
+ Misses         2871     2647     -224     
- Partials        673      696      +23     
Impacted Files Coverage Δ
bt-core/src/main/java/bt/event/EventSource.java 0.00% <0.00%> (ø)
...c/main/java/bt/event/PeerBitfieldUpdatedEvent.java 0.00% <ø> (ø)
...ore/src/main/java/bt/event/PeerConnectedEvent.java 50.00% <ø> (ø)
.../src/main/java/bt/event/PeerDisconnectedEvent.java 50.00% <ø> (ø)
bt-core/src/main/java/bt/magnet/UtMetadata.java 69.23% <ø> (ø)
...main/java/bt/net/crypto/MSEHandshakeProcessor.java 67.27% <ø> (+1.10%) :arrow_up:
...n/java/bt/net/pipeline/ChannelPipelineFactory.java 100.00% <ø> (ø)
...n/java/bt/net/pipeline/DefaultChannelPipeline.java 85.71% <ø> (ø)
.../java/bt/net/pipeline/InboundMessageProcessor.java 77.48% <ø> (ø)
...c/main/java/bt/net/pipeline/MessageSerializer.java 100.00% <ø> (ø)
... and 94 more