public static Enum ConvertWaveMessageID(WaveServerComponent appID, short msgID) { switch (appID) { case WaveServerComponent.UserManager: return((UserManagerMessageID)msgID); case WaveServerComponent.CacheAgent: return((CacheAgentMessageID)msgID); case WaveServerComponent.AggregatedMessageAgent: return((AggregateMessageMessageID)msgID); case WaveServerComponent.NavigationAgent: return((NaviAgentMessageID)msgID); case WaveServerComponent.DefinitionsAgent: return((DefAgentMessageID)msgID); case WaveServerComponent.MediaAgent: return((MediaAgentMessageID)msgID); } return(WaveError.Empty); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is AggregateMessageMessageID) { if (data != null) { if ((AggregateMessageMessageID)msgID == AggregateMessageMessageID.AggregateMessage) { foreach (IFieldBase field in data.RootList) { if ((field is BinaryField) && (field.FieldID == (short)AggregateMessageFieldID.PackedMessage)) { // we have embedded message - lets unpack and publish that BinaryField tempBinary = (BinaryField)field; if ((tempBinary.Data != null) && (tempBinary.Data.Length > 0)) { Core.RouteServerMessage(new WaveMessage(tempBinary.Data)); } } } } } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is CacheAgentMessageID) { if (data != null) { switch ((CacheAgentMessageID)msgID) { case CacheAgentMessageID.RequestCacheHash: { WaveMessage msgOut = new WaveMessage(); msgOut.AddBinary(CacheAgentFieldID.CacheHash, Server.CalculateHash()); // return cache's own CIID (if any) if (cacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, cacheID.Value.ToByteArray()); } msgOut.Send(WaveServerComponent.CacheAgent, CacheAgentMessageID.CacheHashCheck); break; } case CacheAgentMessageID.SendWABCacheCIID: { BinaryField bin = (BinaryField)data[MessageOutFieldID.CacheItemID]; if (bin.Data != null) { CacheItemID temp = new CacheItemID(bin.Data); if (!cacheID.HasValue || !cacheID.Value.Equals(temp)) { cacheID = temp; goto case CacheAgentMessageID.ClearCache; } } break; } case CacheAgentMessageID.ClearCache: { Server.Clear(); break; } } } } }
/// <summary> /// Adds message to the transport queue - to be send whenever possible (depends on transport). /// </summary> /// <param name="destination">Server component to send message to.</param> /// <param name="msgID">Message ID (from enumeration of corresponding server component).</param> /// <param name="data">Data to be sent - as either ready WaveMessage or a FieldList.</param> /// <returns>Returns true if the transport is active and message was added to the queue.</returns> public static bool SendMessage(WaveServerComponent destination, Enum msgID, WaveMessage msg) { if (destination != WaveServerComponent.Unknown) { DebugHelper.Trace("Out: {0} -> {1}", destination, msgID); msg.ApplicationID = (int)destination; msg.MessageID = Convert.ToInt16(msgID); return(Network.PostServerMessage(msg)); } return(false); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is DefAgentMessageID) { if (data != null) { switch ((DefAgentMessageID)msgID) { case DefAgentMessageID.BulkDefinitionResponse: { if (data.RootList.Count > 0) { List <FieldList> definitions = new List <FieldList>(data.RootList.Count); foreach (IFieldBase field in data.RootList) { BinaryField bin = field as BinaryField; if ((bin != null) && (bin.Data != null)) { WaveMessage msg = new WaveMessage(bin.Data); if ((DefAgentMessageID)msg.MessageID == DefAgentMessageID.DefinitionResponse) { definitions.Add(msg.RootList); } } } UnpackDefinitions(definitions); } break; } case DefAgentMessageID.DefinitionResponse: { UnpackDefinition(data.RootList); break; } } } } }
/// <summary> /// Routes server message to corresponding Wave Explorer service (if there is one). /// </summary> public static void RouteServerMessage(WaveMessage msg) { if (msg != null) { WaveServerComponent destination = (WaveServerComponent)msg.ApplicationID; Enum msgID = TransportBase.ConvertWaveMessageID(destination, msg.MessageID); DebugHelper.Trace("In: {0} -> {1}", destination, msgID); switch (destination) { case WaveServerComponent.NavigationAgent: Navigation.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.DefinitionsAgent: Definitions.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.CacheAgent: Cache.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.UserManager: Authentication.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.AggregatedMessageAgent: Network.OnMessageReceived(destination, msgID, msg); break; case WaveServerComponent.MediaAgent: Downloads.OnMessageReceived(destination, msgID, msg); break; default: DebugHelper.Out("Message for unsupported or unknown RTDS component {0} was discarded.", destination); break; } } }
public static void Send(this WaveMessage msg, WaveServerComponent destination, Enum msgID) { Core.SendMessage(destination, msgID, msg); }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is MediaAgentMessageID) { if (data != null) { switch ((MediaAgentMessageID)msgID) { case MediaAgentMessageID.DownloadResponse: { // extract useful data byte[] ciidData = data[MessageOutFieldID.CacheItemID].AsByteArray(); byte[] cRefID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); byte cacheHint = (byte)CacheHint.PersistStore_ShouldCache; if (ciidData != null) { cacheHint = data[MessageOutFieldID.CacheHint].AsByte() ?? (byte)CacheHint.PersistStore_ShouldCache; } int downloadSize = data[MessageOutFieldID.DownloadSize].AsInteger() ?? -1; // only sent for multi-frame downloads if (downloadSize != -1) { // first frame of a multi-frame download byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { downloads.Start(ciidData, cRefID, binary, downloadSize, cacheHint); } // ack the frame SendFrameAcknowledgement(ciidData, cRefID, 0); } else { // single frame download byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { // act on download OnDownloadComplete(ciidData, cRefID, binary, cacheHint); // ack the frame SendFrameAcknowledgement(ciidData, cRefID, 0); } } break; } case MediaAgentMessageID.Frame: { short frameNumber = data[MediaReferenceFieldID.FrameNumber].AsShort() ?? -1; if (frameNumber != -1) { byte[] ciidData = data[MessageOutFieldID.CacheItemID].AsByteArray(); byte[] crefID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); if ((crefID != null) || (ciidData != null)) { //IMPLEMENT: support for bulk downloads byte[] binary = data[MediaReferenceFieldID.BinaryFrame].AsByteArray(); if (binary != null) { downloads.Add(ciidData, crefID, binary); // check if complete if (downloads.IsComplete(ciidData, crefID)) { DownloadManager.DownloadRecord dr = downloads.Retrieve(ciidData, crefID); if (dr != null) { OnDownloadComplete(dr.CacheItemID, dr.ContentRefenceID, dr.Buffer, dr.CacheHint); } } // ack the frame SendFrameAcknowledgement(ciidData, crefID, frameNumber); } } } break; } case MediaAgentMessageID.OpenStreamResponse: { byte[] contentID = data[MessageOutFieldID.ContentReferenceID].AsByteArray(); // content reference string streamURL = data[MediaReferenceFieldID.StreamURL].AsString(); byte[] streamSessionID = data[MediaReferenceFieldID.StreamSessionID].AsByteArray(); // for a stream switch between streams where 1 is not an MSG stream the player must be torn down and recreated. // only MSG supports the "fast stream switch" bool nonMsgStream = data.RootList.HasField(MediaReferenceFieldID.NonMSGStream); short mediaType = data[MessageOutFieldID.MediaPrimitiveType].AsShort() ?? -1; Core.NotifyStreamResponseReceived(this, contentID, streamURL, streamSessionID, nonMsgStream, mediaType); break; } } } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is NaviAgentMessageID) { if (data != null) { switch ((NaviAgentMessageID)msgID) { case NaviAgentMessageID.ApplicationResponse: { UnpackApplicationID(data.RootList); // if we've got a cache item ID but no node URI in the message then the server is // telling us that the home node is already in our cache if (data.RootList.GetItemCount(MessageOutFieldID.ItemURI) == 0) { byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); if (ciidData != null) { CacheItemID ciid = new CacheItemID(ciidData); byte[] bin = Core.Cache.Server.FindKey(ciid); if (bin != null) { string uri = StringHelper.GetString(bin); if (!String.IsNullOrEmpty(uri)) { FindAndStoreApplicationMessagePrefix(uri); } GoToNodeByID(ciid, String.Empty, NodeTransition.None, false, Core.UI.RootViewID); break; } } } // we also have the home node goto case NaviAgentMessageID.NodeResponse; } case NaviAgentMessageID.NodeResponse: { UnpackReceivedNode(data.RootList); break; } case NaviAgentMessageID.NodeIsInClientCache: { CacheItemID?ciid = null; short requestID = data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1; byte[] ciidData = data.RootList[MessageOutFieldID.CacheItemID].AsByteArray(); string uri = data.RootList[MessageOutFieldID.ItemURI].AsString(); if (ciidData != null) { ciid = new CacheItemID(ciidData); } RequestData rd = Core.Navigation.Requests.Remove(requestID); if (rd != null) { GoToNodeByID(ciid, uri, rd.Transition, rd.IsPopup, rd.ViewID); } else { GoToNodeByID(ciid, uri, NodeTransition.None, false, Core.UI.RootViewID); } break; } case NaviAgentMessageID.NodeResponseError: { View view = Core.UI[Core.Navigation.Requests.RemoveEx(data.RootList[MessageOutFieldID.RequestID].AsShort() ?? -1)]; if (view != null) { view.SignalNavigationFailure(); } break; } case NaviAgentMessageID.FormResponse: { if (data.RootList.GetItemCount(NaviAgentFieldID.SubmitFormResult) != 1) { break; // illegal message, only one form result should exist } SubmitFormResult sfr = (SubmitFormResult)(data[NaviAgentFieldID.SubmitFormResult].AsShort() ?? (short)SubmitFormResult.Empty); if (sfr == SubmitFormResult.NodeResponse) { UnpackReceivedNode(data.RootList); } //TODO: add waiting for result for form submit/response cycle (when navigation is replaced) break; } default: break; } } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is UserManagerMessageID) { if (data != null) { switch ((UserManagerMessageID)msgID) { case UserManagerMessageID.Challenge: { bool createAccount = false; // check if there is login already (otherwise set defaults) if (!Core.Application.HasLogin) { createAccount = true; Core.Application.UpdateCredentials(GenerateNewUsername(), StringHelper.GetBytes(DefaultPassword)); } // get CSL version WaveCSLVersion serverCSL = (WaveCSLVersion)(data[UserManagerFieldID.CSLVersion].AsShort() ?? (short)WaveCSLVersion.Unknown); switch (serverCSL) { case WaveCSLVersion.Version5: case WaveCSLVersion.Version4: Core.CSLVersion = serverCSL; break; default: Core.CSLVersion = WaveCSLVersion.Version3; break; } // get maximum protocol version WaveProtocolVersion serverProto = (WaveProtocolVersion)(data[UserManagerFieldID.MaxWeMessageVersion].AsByte() ?? (byte)WaveProtocolVersion.Unknown); switch (serverProto) { case WaveProtocolVersion.Version4: Core.ProtocolVersion = WaveProtocolVersion.Version4; break; default: Core.ProtocolVersion = WaveProtocolVersion.Version3; break; } // get challenge BinaryField challenge = (BinaryField)data[UserManagerFieldID.Challenge]; // assemble login message WaveMessage msgOut = new WaveMessage(); msgOut.AddInt16(UserManagerFieldID.CSLVersion, (short)Core.CSLVersion); msgOut.AddBoolean(UserManagerFieldID.EncryptSession, Core.UseEncryption); msgOut.AddInt16(UserManagerFieldID.PriorityMask, NetworkAgent.PrioritiesActiveMask); msgOut.AddBinary(UserManagerFieldID.UserCredentials, ProcessChallenge(challenge.Data, Core.Application, createAccount)); msgOut.AddBoolean(UserManagerFieldID.CreateAccount, createAccount); // cache hash byte[] cacheHash = Core.Cache.CacheHash; msgOut.AddBinary(CacheAgentFieldID.CacheHashCompressed, (cacheHash.Length > 0) ? CompressionHelper.GZipBuffer(cacheHash) : cacheHash); // cache ID (if any) if (Core.Cache.CacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, Core.Cache.CacheID.Value.ToByteArray()); } // compiling device settings FieldList deviceSettingsList = FieldList.CreateField(UserManagerFieldID.DeviceSettings); deviceSettingsList.AddString(UserManagerFieldID.DeviceBuildID, Core.BuildID); deviceSettingsList.AddBoolean(NaviAgentFieldID.DeviceSupportsTouch, true); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionWidth, 480); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionHeight, 800); DeviceGroup[] devs = Core.System.SupportedDeviceGroups; foreach (DeviceGroup dev in devs) { deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceProfileGroup, (short)dev); } deviceSettingsList.AddString(UserManagerFieldID.LanguageID, CultureInfo.CurrentCulture.Name); deviceSettingsList.AddString(UserManagerFieldID.Timezone, Core.Settings.TimeZone); deviceSettingsList.AddBoolean(UserManagerFieldID.AlphaSupport, true); deviceSettingsList.AddBoolean(UserManagerFieldID.CompressionSupport, true); msgOut.AddFieldList(deviceSettingsList); // compiling application request list FieldList appRequestList = FieldList.CreateField(UserManagerFieldID.ApplicationRequest); appRequestList.AddString(NaviAgentFieldID.ApplicationURN, Core.Application.URI); appRequestList.AddInt16(NaviAgentFieldID.ApplicationRequestAction, (short)AppRequestAction.GetAppEntryPage); msgOut.AddFieldList(appRequestList); msgOut.Send(WaveServerComponent.UserManager, UserManagerMessageID.Login); Core.UI.SignalViewNavigationStart(Core.UI.RootViewID); break; } case UserManagerMessageID.EncryptionKeys: { // setting encryption (if allowed by build configuration) if (Core.UseEncryption && (sessionHandshakeFish != null)) { BinaryField sessionKeyField = (BinaryField)data[UserManagerFieldID.SessionKey]; byte[] sessionKey = (byte[])sessionKeyField.Data; sessionHandshakeFish.Decrypt(sessionKey, sessionKey.Length); BinaryField globalServerKeyField = (BinaryField)data[UserManagerFieldID.GlobalServerKey]; byte[] globalServerKey = (byte[])globalServerKeyField.Data; sessionHandshakeFish.Decrypt(globalServerKey, globalServerKey.Length); Core.NotifyEncryptionKeysChanged(this, sessionKey, globalServerKey); } else { Core.NotifyEncryptionKeysChanged(this, null, null); } // setting login data StringField userName = (StringField)data[UserManagerFieldID.CreatedAccountUserName]; if (userName != null) { BinaryField userPass = (BinaryField)data[UserManagerFieldID.CreatedAccountPasswordHash]; if ((userPass != null) && (sessionHandshakeFish != null)) { byte[] passBuffer = (byte[])userPass.Data.Clone(); sessionHandshakeFish.Decrypt(passBuffer, passBuffer.Length); Core.Application.UpdateCredentials(userName.Data, passBuffer); // no longer needed sessionHandshakeFish = null; } } break; } case UserManagerMessageID.LoginResponse: { if (!authenticated) { Int16Field loginStatus = (Int16Field)data[UserManagerFieldID.LoginStatus]; switch ((UserLoginStatus)loginStatus.Data) { case UserLoginStatus.Success: { // signal authentication success Core.NotifyAuthentication(this, data[UserManagerFieldID.SessionInfo].AsByteArray()); // preparing login data message FieldList appContext = (FieldList)data[UserManagerFieldID.ApplicationContext]; if (appContext != null) { int appID = appContext[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; string unqualifiedAppURI = appContext[UserManagerFieldID.ApplicationUnqualifiedURI].AsText(); string fullyQualifiedAppURI = appContext[UserManagerFieldID.ApplicationFullyQualifiedURI].AsText(); Core.NotifySuccessfulLogin(this, appID, unqualifiedAppURI, fullyQualifiedAppURI); } authenticated = true; authenticatedEver = true; break; } case UserLoginStatus.FailedInvalidCredentials: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.InvalidCredentials); break; case UserLoginStatus.FailedNoUser: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.NoSuchUser); break; } } break; } } } } }