예제 #1
0
        private void StabilizeHandler(object?sender, System.EventArgs e)
        {
            StabilizeEventArgs eventArgs = (StabilizeEventArgs)e;
            // Log.Debug("Stabilize handler is called by " + eventArgs.DestinationNode);

            var stabilizingNode = eventArgs.DestinationNode;

            if (Node.Predecessor == null)
            {
                Node.Predecessor = stabilizingNode;
            }
            if ((Node.Predecessor.Id <= stabilizingNode.Id && Node.Predecessor.Id.Equals(Node.Id)) ||
                (Node.Predecessor.Id <= stabilizingNode.Id && stabilizingNode.Id < Node.Id) ||
                (Node.Predecessor.Id > Node.Id && Node.Predecessor.Id <= stabilizingNode.Id))
            {
                Node.Predecessor = stabilizingNode;
            }

            // Log.Debug("My predecessor is : " + Node.Predecessor);
            _dhtActions.StabilizeResponse(eventArgs.DestinationNode, Node.Predecessor.Id, Node.Predecessor);
            // Log.Debug("My predecessor is send to : " + eventArgs.DestinationNode);
        }
예제 #2
0
        public void Receive(string responseMessage)
        {
            var dhtProtocolCommandDto = JsonSerializer.Deserialize <DhtProtocolCommandDto>(responseMessage);

            Log.Debug(dhtProtocolCommandDto.ToString());
            switch (dhtProtocolCommandDto.Command)
            {
            case DhtCommand.NOTIFY:
                NotifyEventArgs notifyEventArgs =
                    new NotifyEventArgs {
                    NodeDto = dhtProtocolCommandDto.NodeDto
                };
                OnNotify(notifyEventArgs);
                break;

            case DhtCommand.STABILIZE:
                StabilizeEventArgs stabilizeEventArgs =
                    new StabilizeEventArgs {
                    DestinationNode = dhtProtocolCommandDto.NodeDto
                };
                OnStabilizeHandler(stabilizeEventArgs);
                break;

            case DhtCommand.FIND_SUCCESSOR:
                FindSuccessorEventArgs findSuccessorEventArgs = new FindSuccessorEventArgs
                {
                    Key = dhtProtocolCommandDto.Key, DestinationNode = dhtProtocolCommandDto.NodeDto
                };
                OnFindSuccessor(findSuccessorEventArgs);
                break;

            case DhtCommand.FOUND_SUCCESSOR:
                FoundSuccessorEventArgs foundSuccessorEventArgs = new FoundSuccessorEventArgs
                {
                    SuccessorNode = dhtProtocolCommandDto.NodeDto, Key = dhtProtocolCommandDto.Key
                };
                OnFoundSuccessor(foundSuccessorEventArgs);
                break;

            case DhtCommand.CHECK_PREDECESSOR:
                CheckPredecessorEventArgs checkPredecessorEventArgs = new CheckPredecessorEventArgs
                {
                    DestinationNode = dhtProtocolCommandDto.NodeDto
                };
                OnCheckPredecessorHandler(checkPredecessorEventArgs);
                break;

            case DhtCommand.STABILIZE_RESPONSE:
                StabilizeResponseEventArgs stabilizeResponseEventArgs = new StabilizeResponseEventArgs
                {
                    PredecessorOfSuccessor = dhtProtocolCommandDto.NodeDto
                };
                OnStabilizeResponseHandler(stabilizeResponseEventArgs);
                break;

            case DhtCommand.CHECK_PREDECESSOR_RESPONSE:
                CheckPredecessorResponseEventArgs checkPredecessorResponseEventArgs =
                    new CheckPredecessorResponseEventArgs {
                    Predecessor = dhtProtocolCommandDto.NodeDto
                };
                OnCheckPredecessorResponseHandler(checkPredecessorResponseEventArgs);
                break;

            case DhtCommand.GET:
                GetHandlerEventArgs getHandlerEventArgs = new GetHandlerEventArgs
                {
                    DhtProtocolCommandDto = dhtProtocolCommandDto
                };
                OnGet(getHandlerEventArgs);
                break;

            case DhtCommand.GET_RESPONSE:
                GetResponseHandlerEventArgs getResponseHandlerEventArgs = new GetResponseHandlerEventArgs
                {
                    DestinationNode = dhtProtocolCommandDto.NodeDto,
                    Key             = dhtProtocolCommandDto.Key,
                    Value           = dhtProtocolCommandDto.Value,
                };
                OnGetResponseHandler(getResponseHandlerEventArgs);
                break;

            case DhtCommand.PUT:
                PutHandlerEventArgs putHandlerEventArgs = new PutHandlerEventArgs
                {
                    ProtocolCommandDto = dhtProtocolCommandDto
                };
                OnPut(putHandlerEventArgs);
                break;

            case DhtCommand.PUT_RESPONSE:
                GetResponseHandlerEventArgs putReponseHandlerEventArgs = new GetResponseHandlerEventArgs
                {
                    DestinationNode = dhtProtocolCommandDto.NodeDto,
                    Key             = dhtProtocolCommandDto.Key,
                    Value           = dhtProtocolCommandDto.Value,
                };
                OnPutResponseHandler(putReponseHandlerEventArgs);
                break;

            case DhtCommand.REMOVE_DATA_FROM_EXPIRED_REPLICAS:
                GetHandlerEventArgs removeDataFromExpiredReplicasEventArgs = new GetHandlerEventArgs
                {
                    DhtProtocolCommandDto = dhtProtocolCommandDto
                };
                OnRemoveDataFromExpiredReplicas(removeDataFromExpiredReplicasEventArgs);
                break;

            case DhtCommand.REMOVE_DATA_FROM_EXPIRED_REPLICAS_RESPONSE:
                GetHandlerEventArgs removeDataFromExpiredReplicasResponseEventArgs = new GetHandlerEventArgs
                {
                    DhtProtocolCommandDto = dhtProtocolCommandDto
                };
                OnRemoveDataFromExpiredReplicasResponseHandler(removeDataFromExpiredReplicasResponseEventArgs);
                break;

            default:
                break;
            }
        }