private static Guid FindApplicationEufGuid(P2PApplication p2pApp) { foreach (List <P2PApp> apps in p2pAppCache.Values) { foreach (P2PApp app in apps) { if (app.AppType == p2pApp.GetType()) { return(app.EufGuid); } } } return(Guid.Empty); }
private static uint FindApplicationId(P2PApplication p2pApp) { foreach (List <P2PApp> apps in p2pAppCache.Values) { foreach (P2PApp app in apps) { if (app.AppType == p2pApp.GetType()) { return(app.AppId); } } } return(0); }
private static uint FindApplicationId(P2PApplication p2pApp) { foreach (List<P2PApp> apps in p2pAppCache.Values) { foreach (P2PApp app in apps) if (app.AppType == p2pApp.GetType()) return app.AppId; } return 0; }
private static Guid FindApplicationEufGuid(P2PApplication p2pApp) { foreach (List<P2PApp> apps in p2pAppCache.Values) { foreach (P2PApp app in apps) if (app.AppType == p2pApp.GetType()) return app.EufGuid; } return Guid.Empty; }
private void DisposeApp() { if (p2pApplication != null) { p2pApplication.Dispose(); p2pApplication = null; } }
/// <summary> /// Creates a new session initiated remotely. If the application cannot be handled, decline message will be sent. /// The application will handle all messages automatically and no user interaction is required if AutoAccept is true. /// If AutoAccept is false, <see cref="P2PHandler.InvitationReceived"/> event will be fired. /// </summary> public P2PSession(SLPRequestMessage slp, P2PMessage msg, NSMessageHandler ns, P2PBridge bridge) { nsMessageHandler = ns; invitation = slp; version = slp.P2PVersion; if (version == P2PVersion.P2PV1) { localContact = (slp.ToEmailAccount == ns.Owner.Account) ? ns.Owner : ns.ContactList.GetContactWithCreate(slp.ToEmailAccount, IMAddressInfoType.WindowsLive); remoteContact = ns.ContactList.GetContactWithCreate(slp.FromEmailAccount, IMAddressInfoType.WindowsLive); } else { localContact = (slp.ToEmailAccount == ns.Owner.Account) ? ns.Owner : ns.ContactList.GetContactWithCreate(slp.ToEmailAccount, IMAddressInfoType.WindowsLive); localContactEndPointID = slp.ToEndPoint; remoteContact = ns.ContactList.GetContactWithCreate(slp.FromEmailAccount, IMAddressInfoType.WindowsLive); remoteContactEndPointID = slp.FromEndPoint; } if (!uint.TryParse(slp.BodyValues["SessionID"].Value, out sessionId)) { Trace.WriteLineIf(Settings.TraceSwitch.TraceWarning, "Can't parse SessionID: " + SessionId, GetType().Name); } p2pBridge = bridge; localBaseIdentifier = bridge.SequenceId; localIdentifier = localBaseIdentifier; status = P2PSessionStatus.WaitingForLocal; Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, String.Format("{0} created (Initiated remotely)", SessionId), GetType().Name); remoteContact.DirectBridgeEstablished += RemoteDirectBridgeEstablished; if (msg != null) { // Set remote baseID remoteBaseIdentifier = msg.Header.Identifier; remoteIdentifier = remoteBaseIdentifier; if (version == P2PVersion.P2PV2) remoteIdentifier += msg.V2Header.MessageSize; } // Create application based on invitation uint appId = slp.BodyValues.ContainsKey("AppID") ? uint.Parse(slp.BodyValues["AppID"].Value) : 0; Guid eufGuid = slp.BodyValues.ContainsKey("EUF-GUID") ? new Guid(slp.BodyValues["EUF-GUID"].Value) : Guid.Empty; p2pApplication = P2PApplication.CreateInstance(eufGuid, appId, this); if (p2pApplication != null && p2pApplication.ValidateInvitation(invitation)) { if (p2pApplication.AutoAccept) { Accept(); } else { ns.P2PHandler.OnInvitationReceived(new P2PSessionEventArgs(this)); } } else { Decline(); } }
/// <summary> /// Creates a new session initiated locally and prepares the invitation message. /// The next step must be Invite(). /// </summary> public P2PSession(P2PApplication app) { p2pApplication = app; version = app.P2PVersion; localContact = app.Local; remoteContact = app.Remote; localContactEndPointID = NSMessageHandler.MachineGuid; remoteContactEndPointID = app.Remote.SelectBestEndPointId(); nsMessageHandler = app.Local.NSMessageHandler; sessionId = (uint)random.Next(50000, int.MaxValue); // These 2 fields are set when optimal bridge found. localBaseIdentifier = 0; localIdentifier = 0; invitation = new SLPRequestMessage(RemoteContactEPIDString, MSNSLPRequestMethod.INVITE); invitation.Target = RemoteContactEPIDString; invitation.Source = LocalContactEPIDString; invitation.ContentType = "application/x-msnmsgr-sessionreqbody"; invitation.BodyValues["SessionID"] = SessionId.ToString(System.Globalization.CultureInfo.InvariantCulture); app.SetupInviteMessage(invitation); app.P2PSession = this; // Register events remoteContact.DirectBridgeEstablished += RemoteDirectBridgeEstablished; Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, String.Format("{0} created (Initiated locally)", SessionId), GetType().Name); status = P2PSessionStatus.WaitingForRemote; // Next step must be: Invite() }
public P2PSession AddTransfer(P2PApplication app) { P2PSession session = new P2PSession(app); session.Closed += P2PSessionClosed; if (app.P2PVersion == P2PVersion.P2PV2) p2pV2Sessions.Add(session); else p2pV1Sessions.Add(session); session.Invite(); return session; }