示例#1
0
 public Peer(int port, bool loopbacksAllowed, RsaKeyStore rsaKeyStore)
 {
     neighbors = new List<Neighbor>();
     broadcastPort = port;
     peerId = PeerIdentifier.Create();
     RsaKeyStore = rsaKeyStore;
     receiver = new Receiver(port, peerId, loopbacksAllowed) { RsaKeyStore = rsaKeyStore};
     receiver.MessageReceived += OnMessageReceived;
 }
示例#2
0
 public Receiver(IPEndPoint binding, PeerIdentifier peerId, bool loopbacksAllowed)
 {
     InitLocalIfaces();
     this.loopbacksAllowed = loopbacksAllowed;
     this.peerId = peerId;
     udp = BindClient(binding);
     EndPoints = binding.Address.ToInt32() == 0
                          ? (IEnumerable<IPEndPoint>)localIfaces.Select(i => new IPEndPoint(i, LocalPort)).ToList()
                          : new[] { udp.Client.LocalEndPoint as IPEndPoint };
     udp.BeginReceive(RequestCallback, null);
 }
示例#3
0
 void RemoveNeighbor(PeerIdentifier peerIdentifier)
 {
     lock (neighbors)
     {
         var neighbor = new Neighbor { Identifier = peerIdentifier };
         if (neighbors.Contains(neighbor))
             neighbors.Remove(neighbor);
     }
 }
示例#4
0
 void AddNeighbor(PeerIdentifier peerIdentifier, IPEndPoint endPoint)
 {
     lock (neighbors)
     {
         var neighbor = new Neighbor { Identifier = peerIdentifier };
         if (!neighbors.Contains(neighbor))
         {
             neighbor.IpEndPoints = new[] { endPoint };
             neighbors.Add(neighbor);
         }
         else
         {
             var ne = neighbors.Find(n => n.Equals(neighbor));
             ne.IpEndPoints = ne.IpEndPoints.Concat(new[] { endPoint });
         }
     }
 }
示例#5
0
 public Receiver(int port, PeerIdentifier peerId, bool loopbacksAllowed)
     : this(new IPEndPoint(0, port), peerId, loopbacksAllowed)
 {
 }
示例#6
0
 private bool CheckPeer(PeerIdentifier otherPeerId)
 {
     return !peerId.Equals(otherPeerId);
 }
示例#7
0
 public Sender(IPEndPoint ipEndPoint, PeerIdentifier peerId)
 {
     udp = new UdpClient(0) { EnableBroadcast = true };
     this.ipEndPoint = ipEndPoint;
     this.peerId = peerId;
 }
示例#8
0
 public Sender(int receiverPort, PeerIdentifier peerId)
     : this(new IPEndPoint(IPAddress.Broadcast, receiverPort), peerId)
 {
 }