Beispiel #1
0
        internal void OnSessionDelete(NetworkInterfaceHandler interfaceHandler, Origin origin)
        {
            lock (_sessionData)
            {
                SdpSession          session             = new SdpSession(origin, interfaceHandler.NetworkInterface);
                SessionData         sessionData         = null;
                SessionAnnouncement sessionAnnouncement = null;
                if (_sessionData.TryGetValue(session, out sessionData))
                {
                    sessionAnnouncement = sessionData.Session;
                }

                if (sessionData != null)
                {
                    if (origin.IsUpdateOrEqual(sessionAnnouncement.SessionDescription.Origin))
                    {
                        sessionData.Timer.Dispose();
                        _sessionData.Remove(session);
                        _announcements.Remove(sessionData.Id);
                        SynchronizationContextPost(o =>
                        {
                            lock (Sessions)
                            {
                                Sessions.Remove(sessionData.Session);
                            }
                        });
                    }
                }
            }
        }
Beispiel #2
0
 private void CheckNetworkInterfaceStatuses(object sender, EventArgs e)
 {
     lock (_interfaceHandlers)
     {
         HashSet <NetworkInterfaceHandler> handlers       = new HashSet <NetworkInterfaceHandler>(_interfaceHandlers.Values);
         NetworkInterfaceInformation[]     interfaceInfos = NetworkInterfaceInformation.GetAllNetworkInterfaces();
         foreach (NetworkInterfaceInformation interfaceInfo in interfaceInfos)
         {
             if (interfaceInfo.NetworkInterfaceType == NetworkInterfaceType.Loopback)
             {
                 continue;
             }
             if (interfaceInfo.NetworkInterfaceType == NetworkInterfaceType.Tunnel)
             {
                 continue;
             }
             int index = interfaceInfo.GetIPProperties().GetIPv4Properties().Index;
             NetworkInterfaceHandler interfaceHandler;
             _interfaceHandlers.TryGetValue(index, out interfaceHandler);
             if (interfaceHandler == null)
             {
                 var networkInterface = new NetworkInterface(interfaceInfo);
                 index            = interfaceInfo.GetIPProperties().GetIPv4Properties().Index;
                 interfaceHandler = new NetworkInterfaceHandler(this, networkInterface);
                 _interfaceHandlers.Add(index, interfaceHandler);
             }
             if (interfaceInfo.OperationalStatus == OperationalStatus.Up)
             {
                 interfaceHandler.Enable();
             }
             else
             {
                 interfaceHandler.Disable();
             }
             handlers.Remove(interfaceHandler);
         }
         foreach (NetworkInterfaceHandler handler in handlers)
         {
             handler.Disable();
         }
     }
 }
Beispiel #3
0
 internal void OnInterfaceDisable(NetworkInterfaceHandler networkInterfaceHandler)
 {
     lock (_sessionData)
     {
         var removedSessions = _sessionData.Where(s => s.Key.NetworkInterface == networkInterfaceHandler.NetworkInterface).ToList();
         foreach (var pair in removedSessions)
         {
             SdpSession  session     = pair.Key;
             SessionData sessionData = pair.Value;
             sessionData.Timer.Dispose();
             _sessionData.Remove(session);
             _announcements.Remove(sessionData.Id);
             SynchronizationContextPost(o =>
             {
                 lock (Sessions)
                 {
                     Sessions.Remove(sessionData.Session);
                 }
             });
         }
     }
 }
Beispiel #4
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));
            }
        }