public override void AddPeer(Network network, Node node) { // Don't allow adding the same node (regardless of network) // more than once. foreach (BitTorrentFileTransferPeer p in peers) { if (p.Node.NodeID == node.NodeID) { throw new Exception("This node is already a peer."); } } var peer = new BitTorrentFileTransferPeer(network, node); peers.Add(peer); if ((manager != null) && Direction == FileTransferDirection.Upload && file.Pieces.Length > 0) { peer.Network.SendFileDetails(node, (LocalFile)file); } if (manager == null || manager.State == TorrentState.Stopped) { return; } ConnectToPeer(peer); }
private bool ConnectToPeer(BitTorrentFileTransferPeer peer) { var destination = peer.Node.FirstConnectableDestination; if (destination != null) { var transport = destination.CreateTransport(ConnectionType.TransferConnection); LoggingService.LogDebug("New outgoing connection"); peer.Network.ConnectTo(transport, OutgoingPeerTransportConnected); return(true); } // FIXME: Mark peer as bad! LoggingService.LogError("Transfer can't connect to peer {0} - no destinations available!", peer.Node); return(false); }