protected void DisconnectHandler(object connectiontable, EventArgs args)
{
ConnectionEventArgs ceargs = (ConnectionEventArgs)args;
Connection c = ceargs.Connection;
lock( _sync ) {
_last_connection_time = DateTime.UtcNow;
_need_left = -1;
_need_right = -1;
_current_retry_interval = _DEFAULT_RETRY_INTERVAL;
}
if( !IsActive ) {
return;
}
if( c.MainType != ConnectionType.Structured ) {
//Just activate and see what happens:
Activate();
return;
}
ConnectionList cl = ceargs.CList;
int right_pos = cl.RightInclusiveCount(_node.Address, c.Address);
if( right_pos < DESIRED_NEIGHBORS ) {
//We lost a close friend.
Address target = new DirectionalAddress(DirectionalAddress.Direction.Right);
short ttl = (short)DESIRED_NEIGHBORS;
string contype = STRUC_NEAR;
ISender send = new AHSender(_node, target, ttl, AHHeader.Options.Last);
ConnectTo(send, target, contype, 1);
}
int left_pos = cl.LeftInclusiveCount(_node.Address, c.Address);
if( left_pos < DESIRED_NEIGHBORS ) {
//We lost a close friend.
Address target = new DirectionalAddress(DirectionalAddress.Direction.Left);
short ttl = (short)DESIRED_NEIGHBORS;
string contype = STRUC_NEAR;
ISender send = new AHSender(_node, target, ttl, AHHeader.Options.Last);
ConnectTo(send, target, contype, 1);
}
}