Esempio n. 1
0
        /// <summary>
        /// Adds the given peer to the list (if its address is new), or updates the existing peer.
        /// </summary>
        public static void AddOrUpdate( Peer peer )
        {
            // Ignore our own announcements.
            if ( Server.Connected && peer.EndPoint.Address.Equals( Server.LocalServerEndpoint.Address ) )
                return;

            lock ( _masterList )
            {
                // First see if an existing entry exists and update that one instead.
                foreach ( Peer p in _masterList )
                {
                    if ( p.Equals( peer ) )
                    {
                        p.Name = peer.Name;
                        p.EndPoint = peer.EndPoint;
                        NotifyChangedEvent( );
                        return;
                    }
                }

                // Otherwise, add it as a new entry.
                _masterList.Add( peer );
                NotifyChangedEvent( );
            }
        }
Esempio n. 2
0
        public OutgoingTransfer( FileInfo file, Peer recipient )
        {
            this.File = file;
            this.Recipient = recipient;
            this.FileSize = file.Length;
            this.FileName = file.Name;
            this.Partner = recipient.Name;
            this.Recipient.LastAttemptedCommunication = DateTime.Now;

            // Create a progress notification for this form.
            TransferNotificationForm.CreateForTransfer( this );

            new Thread( new ThreadStart( DoTransfer ) ).Start( );
        }
Esempio n. 3
0
 public OutgoingWhosThere( Peer peerToUpdate )
 {
     this.Peer = peerToUpdate;
     this.Peer.LastAttemptedCommunication = DateTime.Now;
     ThreadPool.QueueUserWorkItem( delegate { SendAsync( ); } );
 }
Esempio n. 4
0
        private static void ProcessHeader( IPAddress sender, Header header )
        {
            var peer = new Peer
            {
                Name = header.Sender.Username,
                EndPoint = new IPEndPoint( sender, header.Sender.ListenPort )
            };

            PeerList.AddOrUpdate( peer );

            // Did they send their peer list, too?
            if ( header.Peers != null && header.Peers.Count > 0 )
            {
                PeerList.AddOrUpdate( header.Peers );
                peer.RegisterEvent(PeerStatistics.EventType.ReceivedPeerList);
                log.InfoFormat( "{0} peers received from {1} via peer exchange.", header.Peers.Count, peer );
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Show the "select file" dialog and if accepted, start the transfer.
 /// </summary>
 /// <param name="p"></param>
 private void promptForFileAndSend( Peer peer )
 {
     selectFileToSendDialog.Title = "Select a file to send to " + peer.Name + "..";
     if ( selectFileToSendDialog.ShowDialog( ) == DialogResult.OK )
         new OutgoingTransfer( new FileInfo( selectFileToSendDialog.FileName ), peer );
 }
Esempio n. 6
0
 public PeerInfoForm( Peer peer )
 {
     this.Peer = peer;
     InitializeComponent( );
     UpdateInformation( );
 }
Esempio n. 7
0
 /// <summary>
 /// Removes the given peer from the list (use with care!)
 /// </summary>
 public static void Remove( Peer peer )
 {
     lock ( _masterList )
         _masterList.Remove( peer );
 }