this.CurrentEpoch.ServerFinishedVerification = block.Slice(0, Finished.Size);
this.CurrentEpoch.ExpectedClientFinishedVerification = block.Slice(Finished.Size, Finished.Size);
- ResetPeer(ConnectionId.Create(0), 1);
+ ResetPeer(ConnectionId.Create(new IPEndPoint(0,0), 0), 1);
}
public void ResetPeer(ConnectionId connectionId, ulong nextExpectedSequenceNumber)
private readonly ConcurrentDictionary<IPEndPoint, PeerData> existingPeers = new ConcurrentDictionary<IPEndPoint, PeerData>();
- private long connectionId_unsafe = 0;
+ private int connectionSerial_unsafe = 0;
/// <summary>
/// Create a new instance of the DTLS listener
if (record.Epoch == 0 && peer.Epoch != 0)
{
ConnectionId oldConnectionId = peer.ConnectionId;
- peer.ResetPeer(this.AllocateConnectionId(), record.SequenceNumber + 1);
+ peer.ResetPeer(this.AllocateConnectionId(peerAddress), record.SequenceNumber + 1);
// Inform the parent layer that the existing
// connection should be abandoned.
// Allocate state for the new peer and register it
PeerData peer = new PeerData();
- peer.ResetPeer(this.AllocateConnectionId(), record.SequenceNumber + 1);
+ peer.ResetPeer(this.AllocateConnectionId(peerAddress), record.SequenceNumber + 1);
this.existingPeers[peerAddress] = peer;
/// <summary>
/// Allocate a new connection id
/// </summary>
- private ConnectionId AllocateConnectionId()
+ private ConnectionId AllocateConnectionId(IPEndPoint endPoint)
{
- ulong rawConnectionId = (ulong)Interlocked.Increment(ref this.connectionId_unsafe);
- return ConnectionId.Create(rawConnectionId);
+ int rawSerialId = Interlocked.Increment(ref this.connectionSerial_unsafe);
+ return ConnectionId.Create(endPoint, rawSerialId);
}
}
}
public struct ConnectionId : IEquatable<ConnectionId>
{
- public ulong Id;
+ public IPEndPoint EndPoint;
+ public int Serial;
- public static ConnectionId Create(ulong id)
+ public static ConnectionId Create(IPEndPoint endPoint, int serial)
{
- ConnectionId result = new ConnectionId();
- result.Id = id;
- return result;
- }
-
- public static ConnectionId CreateFromEndPoint(IPEndPoint endPoint)
- {
- if (endPoint.AddressFamily != AddressFamily.InterNetwork)
- {
- throw new ArgumentException("ConnectionId only supports IPv4");
- }
-
- ulong port = (ulong)endPoint.Port;
- ulong address = (ulong)endPoint.Address.Address;
- return Create((address << 32) | port);
+ return new ConnectionId{
+ EndPoint = endPoint,
+ Serial = serial,
+ };
}
public bool Equals(ConnectionId other)
{
- return this.Id == other.Id;
+ return this.Serial == other.Serial
+ && this.EndPoint.Equals(other.EndPoint)
+ ;
}
public override bool Equals(object obj)
public override int GetHashCode()
{
- return this.Id.GetHashCode();
+ ///NOTE(mendsley): We're only hashing the endpoint
+ /// here, as the common case will have one
+ /// connection per address+port tuple.
+ return this.EndPoint.GetHashCode();
}
}
return;
}
- ConnectionId connectionId = ConnectionId.CreateFromEndPoint((IPEndPoint)remoteEP);
+ ConnectionId connectionId = ConnectionId.Create((IPEndPoint)remoteEP, 0);
this.ProcessIncomingMessageFromOtherThread(message, (IPEndPoint)remoteEP, connectionId);
}
}