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; }
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); }
void RemoveNeighbor(PeerIdentifier peerIdentifier) { lock (neighbors) { var neighbor = new Neighbor { Identifier = peerIdentifier }; if (neighbors.Contains(neighbor)) neighbors.Remove(neighbor); } }
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 }); } } }
public Receiver(int port, PeerIdentifier peerId, bool loopbacksAllowed) : this(new IPEndPoint(0, port), peerId, loopbacksAllowed) { }
private bool CheckPeer(PeerIdentifier otherPeerId) { return !peerId.Equals(otherPeerId); }
public Sender(IPEndPoint ipEndPoint, PeerIdentifier peerId) { udp = new UdpClient(0) { EnableBroadcast = true }; this.ipEndPoint = ipEndPoint; this.peerId = peerId; }
public Sender(int receiverPort, PeerIdentifier peerId) : this(new IPEndPoint(IPAddress.Broadcast, receiverPort), peerId) { }