All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bt.protocol.HandshakeFactory Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
package bt.protocol;

import bt.BtException;
import bt.metainfo.TorrentId;
import bt.peer.IPeerRegistry;
import com.google.inject.Inject;

/**
 *

Note that this class implements a service. * Hence, is not a part of the public API and is a subject to change.

*/ public class HandshakeFactory implements IHandshakeFactory { private static final int HANDSHAKE_RESERVED_LENGTH = 8; private IPeerRegistry peerRegistry; @Inject public HandshakeFactory(IPeerRegistry peerRegistry) { this.peerRegistry = peerRegistry; } @Override public Handshake createHandshake(TorrentId torrentId) { try { return new Handshake(new byte[HANDSHAKE_RESERVED_LENGTH], torrentId, peerRegistry.getLocalPeer().getPeerId().orElseThrow(() -> new BtException("Local peer is missing ID"))); } catch (InvalidMessageException e) { throw new BtException("Failed to create handshake", e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy