Ejemplo n.º 1
0
        /// <summary>
        /// Sends a SetTransferRequest message to a specified ServiceSocket
        /// </summary>
        /// <param name="connectedMsg">AsyncMessageTracker holding connected socket</param>
        /// <param name="Service">The state server instance</param>
        /// <param name="Resource">The URI associated with the message</param>
        /// <param name="SessionInfo">The Session information used to populate fields in the message</param>
        /// <param name="Data">The message data</param>
        /// <param name="SuccessAction">The Action to call if the message was accepted</param>
        /// <param name="FailAction">The Action to call if the message transmission failed or was refused</param>
        /// <param name="AlreadyExistsAction">The Action to call if the recipient peer already has the URI</param>
        /// <param name="PeerShuttingDownAction">The Action to call if the recipient peer is shutting down</param>
        /// <param name="TimeoutAction">The Action to call if the transfer timed out. This Action's processing time should be very short because a long list of Timeout actions can be daisy-chained and called one after the other</param>
        /// <param name="Timeout">The timeout time span</param>
        public static void Send(AsyncMessageTracker connectedMsg, StateServer Service, string Resource, ISessionResponseInfo SessionInfo,
            byte[] Data, Action<AsyncMessageTracker> SuccessAction, Action<AsyncMessageTracker> FailAction, Action<AsyncMessageTracker> AlreadyExistsAction, Action<AsyncMessageTracker> PeerShuttingDownAction, System.Threading.WaitCallback TimeoutAction, TimeSpan Timeout)
        {
            StringBuilder headers = new StringBuilder();

            headers.AppendFormat("PUT {0} HTTP/1.1\r\nHost: {1}\r\nX-ID: {2}\r\n", Resource, Service.ServerIP ?? connectedMsg.Socket.LocalIP,  connectedMsg.ID.ToString("N"));

            if (SessionInfo.LockDateInTicks != DateTime.MinValue.Ticks)
            {
                headers.AppendFormat("LockDate: {0}\r\nLockAge: {1}\r\nLockCookie: {2}\r\n", SessionInfo.LockDateInTicks, SessionInfo.LockAgeInSeconds, SessionInfo.LockCookie);
            }

            headers.AppendFormat("X-If-None-Exists: true\r\nExclusive: transfer\r\nTimeout: {0}\r\nExtraFlags: {1}\r\nLast-Modified: {2}\r\n", SessionInfo.Timeout, SessionInfo.ActionFlags, SessionInfo.UpdateDateInTicks);

            ResponseData rdata = new ResponseData(
                MergeResponseData(headers, Data, true, Service.Settings.EncryptPeerData, Service.Authenticator, connectedMsg.Socket.SessionKey),
                typeof(SetTransferRequest)
            );

            //Create new AsyncResultActions object to hold delegates for actions based on the outcome of the call
            AsyncResultActions<AsyncMessageTracker> asyncResults = new AsyncResultActions<AsyncMessageTracker>(connectedMsg);
            asyncResults.Result1Action = SuccessAction;
            asyncResults.Result2Action = FailAction;
            asyncResults.Result3Action = AlreadyExistsAction;
            asyncResults.Result4Action = PeerShuttingDownAction;
            asyncResults.TimeoutAction = TimeoutAction;

            Service.AsyncMessageRequests.Add(DateTime.UtcNow + Timeout, connectedMsg.ID, asyncResults);

            connectedMsg.Socket.Send(rdata);

            Diags.LogSend(connectedMsg.Socket, rdata);
        }
Ejemplo n.º 2
0
        //Timeout action needs to be very short as it can be chained in a long call list of time out actions
        /// <summary>
        /// Sends a BeginAuthRequest message to a specified ServiceSocket
        /// </summary>
        /// <param name="socket">The target ServiceSocket</param>
        /// <param name="Service">The state server instance</param>
        /// <param name="SuccessAction">The Action to call if the message was accepted</param>
        /// <param name="FailAction">The Action to call if the message transmission failed or was refused</param>
        /// <param name="TimeoutAction">The Action to call if the transfer timed out This Action's processing time should be very short because a long list of Timeout actions can be daisy-chained and called one after the other</param>
        /// <param name="Timeout">The timeout time span</param>
        public static void Send(ServiceSocket socket, StateServer Service, Action<ServiceSocket> SuccessAction, Action<ServiceSocket> FailAction, System.Threading.WaitCallback TimeoutAction, TimeSpan Timeout)
        {
            ResponseData rdata = new ResponseData(Encoding.UTF8.GetBytes("GET \\AUTH HTTP/1.1\r\nHost: " + (Service.ServerIP ?? socket.LocalIP) + "\r\n\r\n"), typeof(BeginAuthRequest));

            //Create new AsyncResultActions object to hold delegates for actions based on the outcome of the call
            AsyncResultActions<ServiceSocket> asyncResults = new AsyncResultActions<ServiceSocket>(socket);
            asyncResults.Result1Action = SuccessAction;
            asyncResults.Result2Action = FailAction;
            asyncResults.TimeoutAction = TimeoutAction;

            Service.AsyncSocketRequests.Add(DateTime.UtcNow + Timeout, socket, asyncResults);

            socket.Send(rdata);
            Diags.LogSend(socket, rdata);
        }