public Peer(int accID, NetConnection connection, string mail)
 {
     AccountID = accID;
     Connection = connection;
     Email = mail;
     State = PeerState.inMenu;
 }
Exemplo n.º 2
0
 protected override void HandleRequest(RequestMessage request, PeerState peer)
 {
     if (!peer.IsChoked && request.Length <= Global.Instance.BlockSize)
     {
         BlockManager.GetBlock(new byte[request.Length], request.Index, request.Offset, request.Length, BlockRead, peer);
     }
 }
Exemplo n.º 3
0
        protected override bool AddPeer(PeerState peer)
        {
            if (Peers.Count >= MaxConnectedPeers) return false;

            SendBitfield(peer);
            return base.AddPeer(peer);
        }
Exemplo n.º 4
0
 private static void ClosePeerSocket(PeerState peer)
 {
     if (peer != null && peer.Socket != null && peer.Socket.Connected)
     {
         peer.Socket.Shutdown(SocketShutdown.Both);
         peer.Socket.Close();
     }
 }
Exemplo n.º 5
0
 protected override void HandleBitfield(BitfieldMessage bitfield, PeerState peer)
 {
     //първо викаме имплементацията в TorrentMode
     base.HandleBitfield(bitfield, peer);
     //ако пиъра няма никакви налични блокове, тогава не ни трябва
     if(!peer.NoBlocks)
     {   //ако пиъра има налични блокове, казваме му, че се интересуваме от него
         SendMessage(peer, new InterestedMessage());
     }
 }
Exemplo n.º 6
0
 private static void EndAccept(IAsyncResult ar)
 {
     try
     {
         var socket = (Socket)ar.AsyncState;
         Socket newsocket = socket.EndAccept(ar);
         var peer = new PeerState(newsocket, (IPEndPoint)newsocket.RemoteEndPoint);
         MessageIO.ReceiveHandshake(newsocket, peer, HandshakeReceived);
         BeginListening();
     }
     catch (Exception e)
     {
         RaiseException(e);
     }
 }
Exemplo n.º 7
0
 protected override void HandlePiece(PieceMessage piece, PeerState peer)
 {
     var blockInfo = new BlockInfo(piece.Index, piece.Offset, piece.Data.Length);
     //съобщаваме на BlockStrategistът, че сме получили блок, а той ни казва дали ни е нужен
     if(BlockStrategist.Received(blockInfo))
     {   //ако блока е нужен, записваме го
         WriteBlock(piece);
     }
     //понижаване на брояча за блоковете в изчакване
     peer.PendingBlocks--;
     //изпращане на нова заявка за блок към пиъра
     SendBlockRequests(peer);
 }
Exemplo n.º 8
0
 public CassandraPeerState(PeerState peerState)
 {
     PeerId = peerState.PeerId.ToString();
     NonAckedMessageCount           = peerState.NonAckedMessageCount;
     OldestNonAckedMessageTimestamp = peerState.OldestNonAckedMessageTimestampInTicks;
 }
Exemplo n.º 9
0
 private void InsertPeerState(PeerState peerState)
 {
     DataContext.PeerStates.Insert(new CassandraPeerState(peerState)).Execute();
 }
Exemplo n.º 10
0
 protected override void HandleInterested(InterestedMessage interested, PeerState peer)
 {
     base.HandleInterested(interested, peer);
     peer.IsChoked = false;
     SendMessage(peer, new UnchokeMessage());
 }
Exemplo n.º 11
0
 public StatusChangedNotification(PeerHash peer, PeerState state)
 {
     this.peer  = peer;
     this.state = state;
 }
Exemplo n.º 12
0
 protected virtual void SendHandshake(PeerState peer, HandshakeMessage handshake)
 {
     if (Stopping) return;
     MessageIO.SendMessage(peer.Socket, handshake, peer, HandshakeSent);
 }
Exemplo n.º 13
0
 protected virtual void HandleUnchoke(UnchokeMessage unchoke, PeerState peer)
 {
     peer.AmChoked = false;
 }
Exemplo n.º 14
0
 protected abstract void HandlePiece(PieceMessage piece, PeerState peer);
Exemplo n.º 15
0
 protected virtual void HandleMessage(PeerMessage message, PeerState peer)
 {
     //проверка на типа съобщение и извикване на съответния обработващ метод
     if (message is HandshakeMessage) HandleHandshake((HandshakeMessage)message, peer);
     else if (message is ChokeMessage) HandleChoke((ChokeMessage)message, peer);
     else if (message is UnchokeMessage) HandleUnchoke((UnchokeMessage)message, peer);
     else if (message is InterestedMessage) HandleInterested((InterestedMessage)message, peer);
     else if (message is NotInterestedMessage) HandleNotInterested((NotInterestedMessage)message, peer);
     else if (message is BitfieldMessage) HandleBitfield((BitfieldMessage)message, peer);
     else if (message is HaveMessage) HandleHave((HaveMessage)message, peer);
     else if (message is PieceMessage) HandlePiece((PieceMessage)message, peer);
     else if (message is RequestMessage) HandleRequest((RequestMessage)message, peer);
     //приемане на следващото съобщение от пиъра
     ReceiveMessage(peer);
 }
Exemplo n.º 16
0
 private void SendBlockRequests(PeerState peer)
 {
     //изчисляване на броя на нужните блокове
     int count = RequestsQueueLength - peer.PendingBlocks;
     for(int i=0;i<count;i++)
     {   //поискване на нов блок от BlockStrategistа
         var block = BlockStrategist.Next(peer.Bitfield);
         if (block != BlockInfo.Empty)
         {   //ако адреса на блока е валиден - тоест, има нужда от нов блок, изпраща се съобщение
             SendMessage(peer, new RequestMessage(block.Index, block.Offset, block.Length));
             //увеличаване на броя на изчакващите блокове
             peer.PendingBlocks++;
         }
         else if (BlockStrategist.Complete)
         {   //ако адреса на блока е невалиден, и всички блокове са свалени
             //сигнализираме приключено изтегляне
             OnDownloadComplete();
             return;
         }
     }
 }
Exemplo n.º 17
0
 protected override void HandleUnchoke(UnchokeMessage unchoke, PeerState peer)
 {
     base.HandleUnchoke(unchoke, peer);
     SendBlockRequests(peer);
 }
Exemplo n.º 18
0
 private void MessageCallback(object peer)
 {
     //Pass the message to user defined method first then run defined functions
     //Filter message based on the mode client is in
     NetIncomingMessage msg = this.ReadMessage();
     MMCMessage message = null;
     switch (msg.MessageType)
     {
         case NetIncomingMessageType.DiscoveryResponse:
             RespondDiscoverResponse(msg);
             break;
         case NetIncomingMessageType.DiscoveryRequest:
             RespondDiscover(msg);
             break;
         case NetIncomingMessageType.Data:
             message = JsonConvert.DeserializeObject<MMCMessage>(msg.ReadString());
             if (message.Type.Contains(DataType.STATE))
             {
                 this.pState = message.StateChange;
             }
             break;
     }
     if (UserCallback == null)
         throw new NotImplementedException();
     else
     {
         UserCallback(FilterMessage(message));
     }
 }
Exemplo n.º 19
0
 public void Add(PeerState state)
 {
     _peerStatesByPeerId.Add(state.PeerId, state);
 }
Exemplo n.º 20
0
 protected virtual void HandleNotInterested(NotInterestedMessage notInterested, PeerState peer)
 {
     peer.IsInterested = false;
 }
Exemplo n.º 21
0
 public void Disconnect()
 {
     PeerState = PeerState.Disconnected;
 }
Exemplo n.º 22
0
 protected abstract void HandleRequest(RequestMessage request, PeerState peer);
Exemplo n.º 23
0
 protected override void HandleRequest(RequestMessage request, PeerState peer)
 {
 }
Exemplo n.º 24
0
 protected virtual void ReceiveMessage(PeerState peer)
 {
     if (Stopping) return;
     MessageIO.ReceiveMessage(peer.Socket, peer, MessageReceived);
 }
Exemplo n.º 25
0
 protected virtual bool AddPeer(PeerState peer)
 {
     return Peers.TryAdd(peer.ID, peer);
 }
Exemplo n.º 26
0
 protected virtual void SendMessage(PeerState peer, PeerMessage message)
 {
     if (Stopping) return;
     MessageIO.SendMessage(peer.Socket, message, peer, MessageSent);
 }
Exemplo n.º 27
0
 protected virtual void CloseSocket(PeerState peer)
 {
     try
     {
         lock (peer)
             if (peer.Socket != null)
             {
                 Debug.WriteLine("Closing socket with " + peer.Socket.RemoteEndPoint);
                 peer.Socket.Shutdown(SocketShutdown.Both);
                 peer.Socket.Close();
                 RemovePeer(peer.ID);
             }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e, "TransferManager.ClosePeerSocket");
     }
 }
Exemplo n.º 28
0
 protected virtual void HandleBitfield(BitfieldMessage bitfield, PeerState peer)
 {
     bitfield.Bitfield.CopyTo(peer.Bitfield, 0, 0, Metadata.PieceCount);
 }
Exemplo n.º 29
0
 protected virtual void HandleChoke(ChokeMessage choke, PeerState peer)
 {
     peer.AmChoked = true;
 }
Exemplo n.º 30
0
 protected override void HandlePiece(PieceMessage piece, PeerState peer)
 {
 }
Exemplo n.º 31
0
 protected virtual void HandleHandshake(HandshakeMessage handshake, PeerState peer)
 {
     peer.ReceivedHandshake = true;
     peer.ID = handshake.PeerID;
     if (!peer.SentHandshake) SendHandshake(peer, DefaultHandshake);
     else AddPeer(peer);
 }
Exemplo n.º 32
0
 private void SendBitfield(PeerState peer)
 {
     SendMessage(peer, new BitfieldMessage(BlockStrategist.Bitfield));
 }
Exemplo n.º 33
0
 protected virtual void HandleHave(HaveMessage have, PeerState peer)
 {
     if(have.PieceIndex < peer.Bitfield.Count)
         peer.Bitfield[have.PieceIndex] = true;
 }
Exemplo n.º 34
0
 public OmnibusStateEntry(PeerHash peer)
 {
     Peer  = peer;
     State = new PeerState();
 }
Exemplo n.º 35
0
 protected virtual void HandleInterested(InterestedMessage interested, PeerState peer)
 {
     peer.IsInterested = true;
 }
Exemplo n.º 36
0
	/// <summary>
	///	detects cases where the connection process has stalled,
	///	disconnects and tries to connect again
	/// </summary>
	protected virtual void UpdateConnectionState()
	{

		if (!StayConnected)
			return;

		if (PhotonNetwork.connectionStateDetailed != m_LastPeerState)
		{
			string s = PhotonNetwork.connectionStateDetailed.ToString();
			s = ((PhotonNetwork.connectionStateDetailed == PeerState.Joined) ? "--- " + s + " ---" : s);
			vp_MPDebug.Log(s);
		}

		if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
		{
			if (m_ConnectionTimer.Active)
			{
				m_ConnectionTimer.Cancel();
				m_ConnectionAttempts = 0;
			}
		}
		else if ((PhotonNetwork.connectionStateDetailed != m_LastPeerState) && !m_ConnectionTimer.Active)
		{
			vp_Timer.In(LogOnTimeOut, delegate()
			{
				m_ConnectionAttempts++;
				vp_MPDebug.Log("Retrying (" + m_ConnectionAttempts + ") ...");
				//UnityEngine.Debug.Log("Retrying (" + m_ConnectionAttempts + ") ...");
				Disconnect();
				Connect();
				m_LastPeerState = PeerState.Uninitialized;
			}, m_ConnectionTimer);
		}

		m_LastPeerState = PhotonNetwork.connectionStateDetailed;

	}
Exemplo n.º 37
0
 /// <summary>
 /// Method used to require a chunk to the peer represented by the inner channel.
 /// </summary>
 /// <param name="chkrq">ChunkRequest object containing informations about the resource.</param>
 /// <seealso cref="TransportService.Messages.ChunkRequest"/>
 public void GetChunk(ChunkRequest chkrq)
 {
     this.State = PeerState.BUSY;
     this.TimedPeerBlock(3000);
     this.channel.GetChunk(chkrq);
 }