| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Net; |
| | 4 | |
|
| | 5 | | namespace Ice.Internal; |
| | 6 | |
|
| | 7 | | internal sealed class UdpConnector : Connector |
| | 8 | | { |
| 1 | 9 | | public Transceiver connect() => new UdpTransceiver(_instance, _addr, _sourceAddr, _mcastInterface, _mcastTtl); |
| | 10 | |
|
| 0 | 11 | | public short type() => _instance.type(); |
| | 12 | |
|
| | 13 | | // |
| | 14 | | // Only for use by UdpEndpointI |
| | 15 | | // |
| 1 | 16 | | internal UdpConnector( |
| 1 | 17 | | ProtocolInstance instance, |
| 1 | 18 | | EndPoint addr, |
| 1 | 19 | | EndPoint sourceAddr, |
| 1 | 20 | | string mcastInterface, |
| 1 | 21 | | int mcastTtl, |
| 1 | 22 | | string connectionId) |
| | 23 | | { |
| 1 | 24 | | _instance = instance; |
| 1 | 25 | | _addr = addr; |
| 1 | 26 | | _sourceAddr = sourceAddr; |
| 1 | 27 | | _mcastInterface = mcastInterface; |
| 1 | 28 | | _mcastTtl = mcastTtl; |
| 1 | 29 | | _connectionId = connectionId; |
| 1 | 30 | | } |
| | 31 | |
|
| | 32 | | public override bool Equals(object obj) |
| | 33 | | { |
| 1 | 34 | | if (!(obj is UdpConnector)) |
| | 35 | | { |
| 0 | 36 | | return false; |
| | 37 | | } |
| | 38 | |
|
| 1 | 39 | | if (this == obj) |
| | 40 | | { |
| 1 | 41 | | return true; |
| | 42 | | } |
| | 43 | |
|
| 1 | 44 | | var p = (UdpConnector)obj; |
| 1 | 45 | | if (!_connectionId.Equals(p._connectionId, StringComparison.Ordinal)) |
| | 46 | | { |
| 0 | 47 | | return false; |
| | 48 | | } |
| | 49 | |
|
| 1 | 50 | | if (!_mcastInterface.Equals(p._mcastInterface, StringComparison.Ordinal)) |
| | 51 | | { |
| 0 | 52 | | return false; |
| | 53 | | } |
| | 54 | |
|
| 1 | 55 | | if (_mcastTtl != p._mcastTtl) |
| | 56 | | { |
| 0 | 57 | | return false; |
| | 58 | | } |
| | 59 | |
|
| 1 | 60 | | if (!Network.addressEquals(_sourceAddr, p._sourceAddr)) |
| | 61 | | { |
| 0 | 62 | | return false; |
| | 63 | | } |
| | 64 | |
|
| 1 | 65 | | return _addr.Equals(p._addr); |
| | 66 | | } |
| | 67 | |
|
| 1 | 68 | | public override string ToString() => Network.addrToString(_addr); |
| | 69 | |
|
| | 70 | | public override int GetHashCode() |
| | 71 | | { |
| 1 | 72 | | var hash = new HashCode(); |
| 1 | 73 | | hash.Add(_addr); |
| 1 | 74 | | if (_sourceAddr is not null) |
| | 75 | | { |
| 0 | 76 | | hash.Add(_sourceAddr); |
| | 77 | | } |
| 1 | 78 | | hash.Add(_mcastInterface); |
| 1 | 79 | | hash.Add(_mcastTtl); |
| 1 | 80 | | hash.Add(_connectionId); |
| 1 | 81 | | return hash.ToHashCode(); |
| | 82 | | } |
| | 83 | |
|
| | 84 | | private readonly ProtocolInstance _instance; |
| | 85 | | private readonly EndPoint _addr; |
| | 86 | | private readonly EndPoint _sourceAddr; |
| | 87 | | private readonly string _mcastInterface; |
| | 88 | | private readonly int _mcastTtl; |
| | 89 | | private readonly string _connectionId; |
| | 90 | | } |