Наследование: FileFind.Meshwork.FileTransfer.FileTransferPeerBase
Пример #1
0
        public override void AddPeer(Network network, Node node)
        {
            // Don't allow adding the same node (regardless of network)
            // more than once.
            if (this.peers.Exists(p => p.Node.NodeID == node.NodeID))
            {
                throw new Exception("This node is already a peer.");
            }

            var peer = new BitTorrentFileTransferPeer(network, node);

            peers.Add(peer);

            if (this.manager != null)
            {
                if (Direction == FileTransferDirection.Upload && File.Pieces.Any())
                {
                    peer.Network.SendFileDetails(node, (LocalFile)File);
                }

                if (this.manager.State != TorrentState.Stopped)
                {
                    ConnectToPeer(peer);
                }
            }
        }
Пример #2
0
        private bool ConnectToPeer(BitTorrentFileTransferPeer peer)
        {
            IDestination destination = peer.Node.FirstConnectableDestination;

            if (destination != null)
            {
                var transport = destination.CreateTransport(ConnectionType.TransferConnection);
                Core.LoggingService.LogDebug("New outgoing connection");
                peer.Network.ConnectTo(transport, OutgoingPeerTransportConnected);
                return(true);
            }

            // FIXME: Mark peer as bad!
            Core.LoggingService.LogError("Transfer can't connect to peer {0} - no destinations available!", peer.Node);
            return(false);
        }
Пример #3
0
 private bool ConnectToPeer(BitTorrentFileTransferPeer peer)
 {
     IDestination destination = peer.Node.FirstConnectableDestination;
     if (destination != null) {
         ITransport transport = destination.CreateTransport(ConnectionType.TransferConnection);
         LoggingService.LogDebug("New outgoing connection");
         peer.Network.ConnectTo(transport, OutgoingPeerTransportConnected);
         return true;
     } else {
         // FIXME: Mark peer as bad!
         LoggingService.LogError("Transfer can't connect to peer {0} - no destinations available!", peer.Node);
         return false;
     }
 }
Пример #4
0
        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.");
                }
            }

            BitTorrentFileTransferPeer 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);
        }