protected bool GetSecureSender(Connection con, out SecurityAssociation sa)
{
sa = _so.CreateSecurityAssociation(con.State.Edge);
bool ready = false;
lock(_address_to_sender) {
if(!_registered.ContainsKey(sa)) {
_registered[sa] = true;
sa.StateChangeEvent += SAStateChange;
}
if(sa.State == SecurityAssociation.States.Active ||
sa.State == SecurityAssociation.States.Updating)
{
Address addr = con.Address;
if(_address_to_sender.ContainsKey(addr)) {
SecurityAssociation to_fixup = _address_to_sender[addr] as SecurityAssociation;
if(to_fixup != null && to_fixup != sa) {
to_fixup.StateChangeEvent -= SAStateChange;
_registered.Remove(to_fixup);
}
}
AddConnection(con.Address, sa);
ready = true;
}
}
return ready;
}