Example #1
0
 private void SetupPeerCommunicator()
 {
     this.Communicator = new PeerCommunicator(this);
     PeerCommunicatorContainer.Communicator = this.Communicator;
     RemotingConfiguration.RegisterWellKnownServiceType(typeof(PeerCommunicatorContainer),
                                                        "IRC-Client/PeerCommunicator", WellKnownObjectMode.Singleton);
 }
Example #2
0
 public ChatTabPage(IClient user, PeerCommunicator pc, ChatView view)
 {
     this.user = user;
     this.pc   = pc;
     this.view = view;
     Initialize();
 }
Example #3
0
        public ChatUserControl(IClient user, PeerCommunicator pc)
        {
            InitializeComponent();
            Dock = DockStyle.Fill;

            this.user = user;
            this.pc   = pc;
            Enabled   = false;
            AddCenterText("WELCOME IN THE ROOM CHAT WITH " + user.Nickname, neutralColor);
            AddCenterText(System.Environment.NewLine, neutralColor);
        }
Example #4
0
        public void StartChat(IClient client)
        {
            if (View == null)
            {
                View = ChatView.Instance;
            }
            PeerCommunicator pc = Utils.GetClientCommunicator(client);

            View.AddChat(client, pc);
            View.ShowChatView();
        }
Example #5
0
        public ChatUserControl(IClient user, PeerCommunicator pc)
        {
            InitializeComponent();
            Dock = DockStyle.Fill;

            this.user = user;
            this.pc   = pc;
            Enabled   = false;
            AddCenterText("====> Chatting with " + user.RealName + " [", neutralColor);
            AddCenterText(user.Nickname, peerColor);
            AddCenterText("] <====" + System.Environment.NewLine, neutralColor);
        }
Example #6
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!this.IsDisposed)
            {
                this.IsDisposed = true;

                Debug.WriteLine($"disposing peer {this.Endpoint}");

                if (this.communicator != null &&
                    !this.communicator.IsDisposed)
                {
                    this.communicator.Dispose();
                    this.communicator = null;
                }
            }
        }
Example #7
0
        private bool InviteUser(IClient client)
        {
            if (client == null)
            {
                return(false);
            }

            PeerCommunicator communicator = Utils.GetClientCommunicator(client);
            bool             result       = communicator.RequestGroupChat(Owner, this.Hash);

            if (result)
            {
                this.Peers.Add(client.Nickname, communicator);
            }
            return(result);
        }
Example #8
0
        public async void InviteAllUsers()
        {
            // Add owner communicator
            PeerCommunicator communicator = Utils.GetClientCommunicator(this.Owner);

            this.Peers.Add(this.Owner.Nickname, communicator);

            // Invite other users
            bool result;

            foreach (IClient client in Users)
            {
                if (client.Equals(this.Owner))
                {
                    continue;
                }
                result = await Task.Run <bool>(() => InviteUser(client));

                Console.WriteLine("CLIENT: " + client.Nickname + " answered " + result);
            }
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Peer" /> class.
        /// </summary>
        /// <param name="communicator">The communicator.</param>
        /// <param name="pieceManager">The piece manager.</param>
        /// <param name="localPeerId">The local peer identifier.</param>
        /// <param name="peerId">The peer identifier.</param>
        public Peer(PeerCommunicator communicator, PieceManager pieceManager, string localPeerId, string peerId = null)
        {
            communicator.CannotBeNull();
            pieceManager.CannotBeNull();
            localPeerId.CannotBeNullOrEmpty();

            this.PeerId = peerId;

            this.localPeerId = localPeerId;

            this.BitField = new bool[pieceManager.PieceCount];

            this.HandshakeState = peerId == null ? HandshakeState.SentButNotReceived : HandshakeState.SendAndReceived;
            this.SeedingState   = SeedingState.Choked;
            this.LeechingState  = LeechingState.Uninterested;

            this.Downloaded = 0;
            this.Uploaded   = 0;

            this.communicator = communicator;
            this.communicator.MessageReceived    += this.Communicator_MessageReceived;
            this.communicator.CommunicationError += this.Communicator_CommunicationError;

            this.pieceManager = pieceManager;
            this.pieceManager.PieceCompleted += this.PieceManager_PieceCompleted;

            this.Endpoint = this.communicator.Endpoint;

            this.StartSending();
            this.StartDownloading();
            this.StartUploading();
            this.StartKeepingConnectionAlive();

            // send handshake
            this.EnqueueSendMessage(new HandshakeMessage(this.pieceManager.TorrentInfoHash, localPeerId, HandshakeMessage.ProtocolName));
        }
Example #10
0
        public void AddChat(IClient client, PeerCommunicator pc)
        {
            ChatTabPage t = new ChatTabPage(client, pc, this);

            ChatTabsControl.TabPages.Add(t);
        }