Example #1
0
        /// <summary>
        /// 配信を開始します。
        /// </summary>
        /// <param name="yp">チャンネル情報を載せるYellowPage</param>
        /// <param name="channel_id">チャンネルID</param>
        /// <param name="channel_info">チャンネル情報</param>
        /// <param name="source">配信ソース</param>
        /// <param name="content_reader_factory">配信ソースのコンテンツを解析するIContentReaderFactory</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel BroadcastChannel(IYellowPageClient yp, Guid channel_id, ChannelInfo channel_info, Uri source, IContentReaderFactory content_reader_factory)
        {
            Channel channel = null;

            logger.Debug("Broadcasting channel {0} from {1}", channel_id.ToString("N"), source);
            ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => source.Scheme == factory.Scheme);

            if (source_factory == null)
            {
                logger.Error("Protocol `{0}' is not found", source.Scheme);
                throw new ArgumentException(String.Format("Protocol `{0}' is not found", source.Scheme));
            }
            channel = new Channel(this, channel_id, this.BroadcastID, source);
            Utils.ReplaceCollection(ref channels, orig => {
                var new_collection = new List <Channel>(orig);
                new_collection.Add(channel);
                return(new_collection);
            });
            channel.ChannelInfo = channel_info;
            var content_reader = content_reader_factory.Create(channel);
            var source_stream  = source_factory.Create(channel, source, content_reader);

            channel.Start(source_stream);
            if (ChannelAdded != null)
            {
                ChannelAdded(this, new ChannelChangedEventArgs(channel));
            }
            if (yp != null)
            {
                yp.Announce(channel);
            }
            return(channel);
        }
Example #2
0
        /// <summary>
        /// 指定されたプロトコル、名前、URIを使って新しいYPを作成しYPリストに追加します
        /// </summary>
        /// <param name="protocol">YPクライアントのプロトコル名</param>
        /// <param name="name">YPの名前</param>
        /// <param name="uri">YPのURI</param>
        public IYellowPageClient AddYellowPage(string protocol, string name, Uri uri)
        {
            IYellowPageClient yp = null;

            foreach (var factory in YellowPageFactories)
            {
                if (factory.Protocol == protocol)
                {
                    yp = factory.Create(name, uri);
                    break;
                }
            }
            if (yp == null)
            {
                throw new ArgumentException(String.Format("Protocol `{0}' is not found", protocol));
            }
            Utils.ReplaceCollection(ref yellowPages, orig => {
                var new_yps = new List <IYellowPageClient>(orig);
                new_yps.Add(yp);
                return(new_yps);
            });
            logger.Debug("YP Added: {0}", yp.Name);
            if (YellowPagesChanged != null)
            {
                YellowPagesChanged(this, new EventArgs());
            }
            return(yp);
        }
Example #3
0
        /// <summary>
        /// 接続先を指定してチャンネルのリレーを開始します。
        /// URIから接続プロトコルも判別します
        /// </summary>
        /// <param name="channel_id">リレーするチャンネルID</param>
        /// <param name="tracker">接続起点およびプロトコル</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel RelayChannel(Guid channel_id, Uri tracker)
        {
            Channel channel = null;

            logger.Debug("Requesting channel {0} from {1}", channel_id.ToString("N"), tracker);
            ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => tracker.Scheme == factory.Scheme);

            if (source_factory == null)
            {
                logger.Error("Protocol `{0}' is not found", tracker.Scheme);
                throw new ArgumentException(String.Format("Protocol `{0}' is not found", tracker.Scheme));
            }
            channel = new Channel(this, channel_id, tracker);
            Utils.ReplaceCollection(ref channels, orig => {
                var new_collection = new List <Channel>(orig);
                new_collection.Add(channel);
                return(new_collection);
            });
            var source_stream = source_factory.Create(channel, tracker);

            channel.Start(source_stream);
            if (ChannelAdded != null)
            {
                ChannelAdded(this, new ChannelChangedEventArgs(channel));
            }
            return(channel);
        }
Example #4
0
 /// <summary>
 /// 指定されたチャンネルをチャンネル一覧に追加します
 /// </summary>
 /// <param name="channel">追加するチャンネル</param>
 public void AddChannel(Channel channel)
 {
     Utils.ReplaceCollection(ref channels, orig => {
         var new_channels = new List <Channel>(orig);
         new_channels.Add(channel);
         return(new_channels);
     });
 }
Example #5
0
 /// <summary>
 /// 指定した接続待ち受けを終了します。
 /// 既に接続されているクライアント接続には影響ありません
 /// </summary>
 /// <param name="listener">待ち受けを終了するリスナ</param>
 public void StopListen(OutputListener listener)
 {
     listener.Stop();
     Utils.ReplaceCollection(ref outputListeners, orig => {
         var new_collection = new List <OutputListener>(orig);
         new_collection.Remove(listener);
         return(new_collection);
     });
 }
Example #6
0
 /// <summary>
 /// 指定した出力ストリームを出力ストリームリストに追加します
 /// </summary>
 /// <param name="stream">追加する出力ストリーム</param>
 public void AddOutputStream(IOutputStream stream)
 {
     Utils.ReplaceCollection(ref outputStreams, orig => {
         var new_collection = new OutputStreamCollection(outputStreams);
         new_collection.Add(stream);
         return(new_collection);
     });
     if (OutputStreamsChanged != null)
     {
         OutputStreamsChanged(this, new EventArgs());
     }
 }
Example #7
0
 /// <summary>
 /// 指定したYPをYPリストから取り除きます
 /// </summary>
 /// <param name="yp">取り除くYP</param>
 public void RemoveYellowPage(IYellowPageClient yp)
 {
     yp.StopAnnounce();
     Utils.ReplaceCollection(ref yellowPages, orig => {
         var new_yps = new List <IYellowPageClient>(orig);
         new_yps.Remove(yp);
         return(new_yps);
     });
     logger.Debug("YP Removed: {0}", yp.Name);
     if (YellowPagesChanged != null)
     {
         YellowPagesChanged(this, new EventArgs());
     }
 }
Example #8
0
 /// <summary>
 /// 指定したチャンネルをチャンネルリストから取り除きます
 /// </summary>
 /// <param name="channel"></param>
 public void CloseChannel(Channel channel)
 {
     channel.Close();
     Utils.ReplaceCollection(ref channels, orig => {
         var new_channels = new List <Channel>(orig);
         new_channels.Remove(channel);
         return(new_channels);
     });
     logger.Debug("Channel Removed: {0}", channel.ChannelID.ToString("N"));
     if (ChannelRemoved != null)
     {
         ChannelRemoved(this, new ChannelChangedEventArgs(channel));
     }
 }
Example #9
0
        public void RemoveNode(Host host)
        {
            bool removed = false;

            Utils.ReplaceCollection(ref nodes, orig => {
                var new_collection = new List <Host>(orig);
                removed            = new_collection.Remove(host);
                return(new_collection);
            });
            if (removed)
            {
                if (NodesChanged != null)
                {
                    NodesChanged(this, new EventArgs());
                }
            }
        }
Example #10
0
        /// <summary>
        /// 指定した出力ストリームを出力ストリームリストから削除します
        /// </summary>
        /// <param name="stream">削除する出力ストリーム</param>
        public void RemoveOutputStream(IOutputStream stream)
        {
            bool removed = false;

            Utils.ReplaceCollection(ref outputStreams, orig => {
                var new_collection = new OutputStreamCollection(outputStreams);
                removed            = new_collection.Remove(stream);
                return(new_collection);
            });
            if (removed)
            {
                if (OutputStreamsChanged != null)
                {
                    OutputStreamsChanged(this, new EventArgs());
                }
            }
        }
Example #11
0
        /// <summary>
        /// 指定したエンドポイントで接続待ち受けを開始します
        /// </summary>
        /// <param name="ip">待ち受けを開始するエンドポイント</param>
        /// <param name="local_accepts">リンクローカルな接続相手に許可する出力ストリームタイプ</param>
        /// <param name="global_accepts">リンクグローバルな接続相手に許可する出力ストリームタイプ</param>
        /// <returns>接続待ち受け</returns>
        /// <exception cref="System.Net.Sockets.SocketException">待ち受けが開始できませんでした</exception>
        public OutputListener StartListen(IPEndPoint ip, OutputStreamType local_accepts, OutputStreamType global_accepts)
        {
            OutputListener res = null;

            logger.Info("starting listen at {0}", ip);
            try {
                res = new OutputListener(this, ip, local_accepts, global_accepts);
                Utils.ReplaceCollection(ref outputListeners, orig => {
                    var new_collection = new List <OutputListener>(orig);
                    new_collection.Add(res);
                    return(new_collection);
                });
            }
            catch (System.Net.Sockets.SocketException e) {
                logger.Error("Listen failed: {0}", ip);
                logger.Error(e);
                throw;
            }
            return(res);
        }
Example #12
0
 public void AddNode(Host host)
 {
     Utils.ReplaceCollection(ref nodes, orig => {
         var new_collection = new List <Host>(orig);
         var idx            = new_collection.FindIndex(h => h.SessionID == host.SessionID);
         if (idx >= 0)
         {
             new_collection[idx] = host;
         }
         else
         {
             new_collection.Add(host);
         }
         return(new_collection);
     });
     if (NodesChanged != null)
     {
         NodesChanged(this, new EventArgs());
     }
 }