示例#1
0
        private void PeerConnected(PeerConnection peer)
        {
            Log.LogInformation($"Connected to peer at {peer.Address}");

            lock (peersLock)
                peers.Add(peer);

            foreach (var module in modules.Modules)
            {
                var context = new PeerContext(
                    peer,
                    peer.GetCustomValues(module),
                    this,
                    messageId => RegisterModuleForMessageId(peer, module, messageId));
                module.OnPeerConnected(context);
            }

            peer.ReceiveData();
        }
示例#2
0
 public void PeerDisconnected(PeerConnection peer)
 {
     mainLoop.AddTask(() => underlying.PeerDisconnected(peer));
 }
示例#3
0
 public void MessageReceived(PeerConnection peer, byte[] data)
 {
     mainLoop.AddTask(() => underlying.MessageReceived(peer, data));
 }
示例#4
0
 private void RegisterModuleForMessageId(PeerConnection peer, IModule module, byte messageId)
 {
     lock (peersLock)
         messageHandlerRegistrations[Tuple.Create(peer, messageId)] = module;
 }
示例#5
0
 private void SetChokedByPeer(PeerConnection peer, bool choked)
 {
     peer.IsChokedByRemotePeer = choked;
 }
示例#6
0
 private void UnchokePeer(PeerConnection peer)
 {
     peer.IsChokingRemotePeer = false;
     peer.SendMessage(new UnchokeMessage());
 }
示例#7
0
 private void SetPeerInterested(PeerConnection peer, bool isInterested)
 {
     peer.IsRemotePeerInterested = isInterested;
 }
示例#8
0
 private void SetPeerBitfield(PeerConnection peer, Bitfield bitfield)
 {
     peer.Available = bitfield;
 }
示例#9
0
 private void SetBlockRequestedByPeer(PeerConnection peer, BlockRequest blockRequest)
 {
     peer.RequestedByRemotePeer.Add(blockRequest);
 }