public void Equals4() { IPAddressComparer comparer = IPAddressComparer.Default as IPAddressComparer; IPAddress x = null; IPAddress y = IPAddress.Parse("128.0.0.0"); Assert.IsFalse(comparer.Equals(x, y)); Assert.IsFalse(comparer.Equals(y, x)); }
public void Equals2() { IPAddressComparer comparer = IPAddressComparer.Default as IPAddressComparer; string x = "127.0.0.0"; string y = "128.0.0.0"; Assert.IsFalse(comparer.Equals(x, y)); Assert.IsTrue(comparer.Equals(x, x)); }
public void Equals() { IPAddressComparer comparer = IPAddressComparer.Default as IPAddressComparer; IPAddress x = IPAddress.Loopback; IPAddress y = IPAddress.Parse("128.0.0.0"); Assert.IsFalse(comparer.Equals(x, y)); Assert.IsTrue(comparer.Equals(x, x)); }
protected override void AttachCore() { this.logger.LogTrace("()"); if (federationGatewaySettings.FederationNodeIpEndPoints.Any(e => ipAddressComparer.Equals(e.Address, AttachedPeer.PeerEndPoint.Address))) { this.AttachedPeer.MessageReceived.Register(this.OnMessageReceivedAsync, true); } this.logger.LogTrace("(-)"); }
/// <inheritdoc /> public async Task BroadcastAsync(Payload payload) { // TODO: Optimize how federation peers are identified. List <INetworkPeer> peers = this.connectionManager.ConnectedPeers.ToList(); var ipAddressComparer = new IPAddressComparer(); // TODO: Can do the send to each peer in parallel. foreach (INetworkPeer peer in peers) { // Broadcast to peers. if (!peer.IsConnected) { continue; } if (this.federatedPegSettings.FederationNodeIpEndPoints.Any(e => ipAddressComparer.Equals(e.Address, peer.PeerEndPoint.Address))) { try { await peer.SendMessageAsync(payload).ConfigureAwait(false); } catch (OperationCanceledException) { } } } }
public void IPEqualsIPShould() { IPAddress ip1 = IPAddress.Parse("192.168.0.1"); IPAddress ip2 = IPAddress.Parse("192.168.0.1"); IPAddress ip3 = IPAddress.Parse("192.168.0.2"); IPAddressComparer comparer = new IPAddressComparer(); //Test equals method in IPAddressComparer bool isAddressEqual = comparer.Equals(ip1, ip2); bool isAddressEqual2 = comparer.Equals(ip2, ip3); Assert.True(isAddressEqual); Assert.False(isAddressEqual2); //Test compare method in IPAddressComparer int compare = comparer.Compare(ip1, ip3); Assert.Equal(-1, compare); }
public void Equals3() { IPAddressComparer comparer = IPAddressComparer.Default as IPAddressComparer; string x = "abc"; string y = "def"; Assert.IsFalse(comparer.Equals(x, y)); Assert.IsTrue(comparer.Equals(x, x)); x = null; y = null; Assert.IsTrue(comparer.Equals(x, y)); Assert.IsFalse(comparer.Equals(x, "abc")); Assert.IsFalse(comparer.Equals("abc", y)); Assert.IsFalse(comparer.Equals("abc", "127.0.0.0")); Assert.IsFalse(comparer.Equals("127.0.0.0", "abc")); }
/// <inheritdoc /> public async Task BroadcastAsync(RequestPartialTransactionPayload payload) { List <INetworkPeer> peers = this.connectionManager.ConnectedPeers.ToList(); var ipAddressComparer = new IPAddressComparer(); foreach (INetworkPeer peer in peers) { // Broadcast to peers. if (!peer.IsConnected) { continue; } if (this.federatedPegSettings.FederationNodeIpEndPoints.Any(e => ipAddressComparer.Equals(e.Address, peer.PeerEndPoint.Address))) { try { await peer.SendMessageAsync(payload).ConfigureAwait(false); } catch (OperationCanceledException) { } } } }
/// <inheritdoc /> public async Task BroadcastAsync(RequestPartialTransactionPayload payload) { this.logger.LogTrace("({0}:'{1}',{2}:'{3}')", nameof(payload.Command), payload.Command, nameof(payload.DepositId), payload.DepositId); List <INetworkPeer> peers = this.connectionManager.ConnectedPeers.ToList(); var ipAddressComparer = new IPAddressComparer(); foreach (INetworkPeer peer in peers) { // Broadcast to peers. if (!peer.IsConnected) { continue; } if (this.federationGatewaySettings.FederationNodeIpEndPoints.Any(e => ipAddressComparer.Equals(e.Address, peer.PeerEndPoint.Address))) { try { await peer.SendMessageAsync(payload).ConfigureAwait(false); } catch (OperationCanceledException) { } } } this.logger.LogTrace("(-)"); }