Beispiel #1
0
        internal void OnSessionAnnounce(NetworkInterfaceHandler interfaceHandler, Announcement announcement)
        {
            lock (_sessionData)
            {
                AnnouncementIdentifier id          = new AnnouncementIdentifier(interfaceHandler.NetworkInterface, announcement);
                SessionData            sessionData = null;

                bool knownAnnouncement = _announcements.TryGetValue(id, out sessionData);
                if (!knownAnnouncement)
                {
                    announcement.Decompress();

                    Stream             stream      = new MemoryStream(announcement.Payload.Array, announcement.Payload.Offset, announcement.Payload.Count);
                    SessionDescription description = SessionDescription.Load(stream);
                    description.SetReadOnly();

                    SdpSession          session             = new SdpSession(description, interfaceHandler.NetworkInterface);
                    SessionAnnouncement sessionAnnouncement = null;
                    if (_sessionData.TryGetValue(session, out sessionData))
                    {
                        sessionAnnouncement = sessionData.Session;
                    }

                    if (sessionData != null)
                    {
                        if (description.IsUpdateOf(sessionAnnouncement.SessionDescription))
                        {
                            sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                            SessionAnnouncement oldAnnouncement = sessionData.Session;
                            sessionData.Session = sessionAnnouncement;
                            _announcements.Remove(sessionData.Id);
                            sessionData.Id = id;
                            SynchronizationContextPost(o =>
                            {
                                lock (Sessions)
                                {
                                    Sessions.Replace(oldAnnouncement, sessionAnnouncement);
                                }
                            });
                        }
                    }
                    else
                    {
                        sessionAnnouncement = new SessionAnnouncement(description, interfaceHandler.NetworkInterface);
                        sessionData         = new SessionData()
                        {
                            Session = sessionAnnouncement,
                            Timer   = new Timer(OnTimeOut, session, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite),
                            Id      = id
                        };
                        _sessionData.Add(session, sessionData);
                        _announcements.Add(id, sessionData);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Add(sessionAnnouncement);
                            }
                        });
                    }
                }
                sessionData.TimeOutTime = DateTime.Now + DefaultTimeOut;
                sessionData.Timer.Change(DefaultTimeOut, TimeSpan.FromMilliseconds(-1));
            }
        }
Beispiel #2
0
 public AnnouncementIdentifier(NetworkInterface inter, Announcement announcement)
 {
     _interface = inter.Index;
     _address   = announcement.Source;
     _hash      = announcement.Hash;
 }