Esempio n. 1
0
        internal SettingViewModel(PeerCastApplication peca_app)
        {
            this.pecaApp                 = peca_app;
            this.peerCast                = peca_app.PeerCast;
            this.AddPortCommand          = new Command(() => AddPort());
            this.RemovePortCommand       = new Command(() => RemovePort(), () => SelectedPort != null);
            this.AddYellowPageCommand    = new Command(() => AddYellowPage());
            this.RemoveYellowPageCommand = new Command(() => RemoveYellowPage(), () => SelectedYellowPage != null);
            this.CheckBandwidth          = new CheckBandwidthCommand(this);
            channelCleanupMode           = ChannelCleaner.Mode;
            channelCleanupInactiveLimit  = ChannelCleaner.InactiveLimit / 60000;
            maxRelays                 = peerCast.AccessController.MaxRelays;
            maxRelaysPerChannel       = peerCast.AccessController.MaxRelaysPerChannel;
            maxPlays                  = peerCast.AccessController.MaxPlays;
            maxPlaysPerChannel        = peerCast.AccessController.MaxPlaysPerChannel;
            maxUpstreamRate           = peerCast.AccessController.MaxUpstreamRate;
            maxUpstreamRatePerChannel = peerCast.AccessController.MaxUpstreamRatePerChannel;
            isShowWindowOnStartup     = pecaApp.Settings.Get <WPFSettings>().ShowWindowOnStartup;
            ports = new ObservableCollection <OutputListenerViewModel>(
                peerCast.OutputListeners
                .Select(listener => new OutputListenerViewModel(this, listener))
                );
            yellowPages = new ObservableCollection <YellowPageClientViewModel>(
                peerCast.YellowPages
                .Select(yp => new YellowPageClientViewModel(this, yp))
                );
            var port_mapper = pecaApp.Plugins.GetPlugin <PeerCastStation.UI.PortMapper>();

            if (port_mapper != null)
            {
                portMapperEnabled = port_mapper.Enabled;
            }
        }
Esempio n. 2
0
        protected async Task <SourceConnectionClient> DoConnectGiv(Uri source, CancellationToken cancel_token)
        {
            Logger.Debug("DoConnectGiv");
            AddressFamily family = AddressFamily.InterNetwork;

            if (source.HostNameType == UriHostNameType.IPv6)
            {
                family = AddressFamily.InterNetworkV6;
            }

            Socket socket;

            socket = PeerCast.ReceiveGivSocket(Guid.Parse(source.LocalPath.Substring("/channel/".Length)), family);
            if (socket != null)
            {
                var client = new TcpClient();
                client.Client = socket;

                var connection = new SourceConnectionClient(client);
                connection.Stream.ReadTimeout  = 30000;
                connection.Stream.WriteTimeout = 8000;

                remoteHost = socket.RemoteEndPoint;

                this.client = client;

                return(connection);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        private Atom CreatePCPHelo()
        {
            var helo = new AtomCollection();

            helo.SetHeloAgent(PeerCast.AgentName);
            helo.SetHeloSessionID(PeerCast.SessionID);
            switch (PeerCast.GetPortStatus(Channel.NetworkAddressFamily))
            {
            case PortStatus.Open:
            {
                var listener = PeerCast.FindListener(
                    connection.RemoteEndPoint.Address,
                    OutputStreamType.Relay | OutputStreamType.Metadata);
                helo.SetHeloPort(listener.LocalEndPoint.Port);
            }
            break;

            case PortStatus.Firewalled:
                break;

            case PortStatus.Unknown:
            {
                var listener = PeerCast.FindListener(
                    connection.RemoteEndPoint.Address,
                    OutputStreamType.Relay | OutputStreamType.Metadata);
                if (listener != null)
                {
                    helo.SetHeloPing(listener.LocalEndPoint.Port);
                }
            }
            break;
            }
            PCPVersion.SetHeloVersion(helo);
            return(new Atom(Atom.PCP_HELO, helo));
        }
Esempio n. 4
0
        protected void OnPCPOleh(Atom atom)
        {
            var rip = atom.Children.GetHeloRemoteIP();

            if (rip != null)
            {
                var global_addr = PeerCast.GetGlobalAddress(rip.AddressFamily);
                if (global_addr == null ||
                    global_addr.GetAddressLocality() <= rip.GetAddressLocality())
                {
                    PeerCast.SetGlobalAddress(rip);
                }
            }
            var port = atom.Children.GetHeloPort();

            if (port.HasValue)
            {
                PeerCast.SetPortStatus(rip.AddressFamily, port.Value != 0 ? PortStatus.Open : PortStatus.Firewalled);
            }
            var sid = atom.Children.GetHeloSessionID();

            if (sid.HasValue)
            {
                var host = new HostBuilder();
                host.SessionID      = sid.Value;
                host.GlobalEndPoint = connection.RemoteEndPoint;
                uphost = host.ToHost();
            }
        }
Esempio n. 5
0
        private static string BuildIndexTXTEntry(PeerCast peercast, Channel channel)
        {
            var endpoint         = peercast.GetGlobalEndPoint(channel.NetworkAddressFamily, OutputStreamType.Play);
            var enc_channel_name = Uri.EscapeDataString(channel.ChannelInfo.Name);
            var uptime           = (int)channel.Uptime.TotalMinutes;
            var columns          = new string[] {
                channel.ChannelInfo.Name,                           //1 CHANNEL_NAME チャンネル名
                channel.ChannelID.ToString("N").ToUpperInvariant(), //2 ID ID ユニーク値16進数32桁、制限チャンネルは全て0埋め
                endpoint.ToString(),                                //3 TIP TIP ポートも含む。Push配信時はブランク、制限チャンネルは127.0.0.1
                channel.ChannelInfo.URL,                            //4 CONTACT_URL コンタクトURL 基本的にURL、任意の文字列も可 CONTACT_URL
                channel.ChannelInfo.Genre,                          //5 GENRE ジャンル
                channel.ChannelInfo.Desc,                           //6 DETAIL 詳細
                channel.TotalDirects.ToString(),                    //7 LISTENER_NUM Listener数 -1は非表示、-1未満はサーバのメッセージ。ブランクもあるかも
                channel.TotalRelays.ToString(),                     //8 RELAY_NUM Relay数 同上
                channel.ChannelInfo.Bitrate.ToString(),             //9 BITRATE Bitrate 単位は kbps
                channel.ChannelInfo.ContentType,                    //10 TYPE Type たぶん大文字
                channel.ChannelTrack.Creator,                       //11 TRACK_ARTIST トラック アーティスト
                channel.ChannelTrack.Album,                         //12 TRACK_ALBUM トラック アルバム
                channel.ChannelTrack.Name,                          //13 TRACK_TITLE トラック タイトル
                channel.ChannelTrack.URL,                           //14 TRACK_CONTACT_URL トラック コンタクトURL 基本的にURL、任意の文字列も可
                enc_channel_name,                                   //15 ENC_CHANNEL_NAME エンコード済みチャンネル名 URLエンコード(UTF-8)
                $"{uptime/60}:{uptime%60:D2}",                      //16 BROADCAST_TIME 配信時間 000〜99999
                "",                                                 //17 STATUS ステータス 特殊なステータス disconnectしばらく情報の更新が無い、port0Push配信 又はアイコン
                channel.ChannelInfo.Comment,                        //18 COMMENT コメント
                "0",                                                //19 DIRECT ダイレクトの有無 0固定
            }.Select(str => {
                str = System.Text.RegularExpressions.Regex.Replace(str, "&", "&amp;");
                str = System.Text.RegularExpressions.Regex.Replace(str, "<", "&lt;");
                str = System.Text.RegularExpressions.Regex.Replace(str, ">", "&gt;");
                return(str);
            });

            return(String.Join("<>", columns));
        }
Esempio n. 6
0
        public virtual void SendPCPHelo()
        {
            Logger.Debug("Handshake Started");
            var helo = new AtomCollection();

            helo.SetHeloAgent(PeerCast.AgentName);
            helo.SetHeloSessionID(PeerCast.SessionID);
            if (PeerCast.IsFirewalled.HasValue)
            {
                if (PeerCast.IsFirewalled.Value)
                {
                    //Do nothing
                }
                else
                {
                    var listener = PeerCast.FindListener(
                        RemoteEndPoint.Address,
                        OutputStreamType.Relay | OutputStreamType.Metadata);
                    helo.SetHeloPort(listener.LocalEndPoint.Port);
                }
            }
            else
            {
                var listener = PeerCast.FindListener(
                    RemoteEndPoint.Address,
                    OutputStreamType.Relay | OutputStreamType.Metadata);
                if (listener != null)
                {
                    helo.SetHeloPing(listener.LocalEndPoint.Port);
                }
            }
            helo.SetHeloVersion(PCP_VERSION);
            Send(new Atom(Atom.PCP_HELO, helo));
        }
Esempio n. 7
0
 private void RemoveListener(int listenerId)
 {
     foreach (var listener in PeerCast.OutputListeners.Where(ol => ol.GetHashCode() == listenerId))
     {
         PeerCast.StopListen(listener);
     }
 }
Esempio n. 8
0
 public PCPSourceStream(PeerCast peercast, Channel channel, Uri source_uri)
     : base(peercast, channel, source_uri)
 {
     Logger.Debug("Initialized: Channel {0}, Source {1}",
                  channel != null ? channel.ChannelID.ToString("N") : "(null)",
                  source_uri);
 }
Esempio n. 9
0
            private JObject AddListener(string address, int port, int localAccepts, int globalAccepts)
            {
                IPAddress      addr;
                OutputListener listener;
                IPEndPoint     endpoint;

                if (address == null)
                {
                    endpoint = new IPEndPoint(IPAddress.Any, port);
                }
                else if (IPAddress.TryParse(address, out addr))
                {
                    endpoint = new IPEndPoint(addr, port);
                }
                else
                {
                    throw new RPCError(RPCErrorCode.InvalidParams, "Invalid ip address");
                }
                listener = PeerCast.StartListen(endpoint, (OutputStreamType)localAccepts, (OutputStreamType)globalAccepts);
                var res = new JObject();

                res["listenerId"]    = listener.GetHashCode();
                res["address"]       = listener.LocalEndPoint.Address.ToString();
                res["port"]          = listener.LocalEndPoint.Port;
                res["localAccepts"]  = (int)listener.LocalOutputAccepts;
                res["globalAccepts"] = (int)listener.GlobalOutputAccepts;
                return(res);
            }
Esempio n. 10
0
 public PCPOutputStream(
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     AccessControlInfo access_control,
     Channel channel,
     RelayRequest request)
     : base(peercast, input_stream, output_stream, remote_endpoint, access_control, channel, null)
 {
     Logger.Debug("Initialized: Channel {0}, Remote {1}, Request {2} {3} ({4} {5})",
                  channel != null ? channel.ChannelID.ToString("N") : "(null)",
                  remote_endpoint,
                  request.Uri,
                  request.StreamPos,
                  request.PCPVersion,
                  request.UserAgent);
     this.Connection.ReadTimeout = 180000;
     this.Downhost          = null;
     this.UserAgent         = request.UserAgent;
     this.IsChannelFound    = channel != null && channel.Status == SourceStreamStatus.Receiving;
     this.IsRelayFull       = channel != null ? !channel.MakeRelayable(this) : false;
     this.IsProtocolMatched = channel != null ?
                              (channel.Network == NetworkType.IPv6 && request.PCPVersion == PCPVersion.ProtocolVersionIPv6 && remote_endpoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) ||
                              (channel.Network == NetworkType.IPv4 && request.PCPVersion == PCPVersion.ProtocolVersionIPv4 && remote_endpoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) : false;
     this.relayRequest = request;
     this.UserAgent    = request.UserAgent;
 }
Esempio n. 11
0
            private JObject GetStatus()
            {
                var res = new JObject();

                res["uptime"]       = (int)PeerCast.Uptime.TotalSeconds;
                res["isFirewalled"] = PeerCast.IsFirewalled;
                var endpoint =
                    PeerCast.GetGlobalEndPoint(
                        System.Net.Sockets.AddressFamily.InterNetwork,
                        Core.OutputStreamType.Relay);

                res["globalRelayEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null;
                endpoint =
                    PeerCast.GetGlobalEndPoint(
                        System.Net.Sockets.AddressFamily.InterNetwork,
                        Core.OutputStreamType.Play);
                res["globalDirectEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null;
                endpoint =
                    PeerCast.GetLocalEndPoint(
                        System.Net.Sockets.AddressFamily.InterNetwork,
                        Core.OutputStreamType.Relay);
                res["localRelayEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null;
                endpoint =
                    PeerCast.GetLocalEndPoint(
                        System.Net.Sockets.AddressFamily.InterNetwork,
                        Core.OutputStreamType.Play);
                res["localDirectEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null;
                return(res);
            }
 public PCPYellowPageClient(PeerCast peercast, string name, Uri uri)
 {
     this.PeerCast         = peercast;
     this.Name             = name;
     this.Uri              = uri;
     this.Logger           = new Logger(this.GetType());
     this.AnnouncingStatus = AnnouncingStatus.Idle;
 }
 public PCPPongOutputStream(
     PeerCast peercast,
     ConnectionStream connection,
     AccessControlInfo access_control)
     : base(peercast, connection, access_control, null)
 {
     Logger.Debug("Initialized: Remote {0}", RemoteEndPoint);
 }
Esempio n. 14
0
 public RelayTreeViewModel(PeerCast peerCast)
 {
     this.peerCast  = peerCast;
     this.RelayTree = new RelayTreeNodeViewModel[0];
     refresh        = new Command(
         () => Update(this.channel),
         () => channel != null);
 }
Esempio n. 15
0
 public PortMapperMonitor(PeerCast peercast)
 {
     peerCast = peercast;
     NatUtility.DeviceFound += NatUtility_DeviceFound;
     NatUtility.DeviceLost  += NatUtility_DeviceLost;
     NatUtility.StartDiscovery();
     timer.Start();
 }
Esempio n. 16
0
        internal SettingViewModel(PeerCastApplication peca_app)
        {
            this.pecaApp                 = peca_app;
            this.peerCast                = peca_app.PeerCast;
            this.AddPortCommand          = new Command(() => AddPort(PrimaryPort, NetworkType.IPv4));
            this.RemovePortCommand       = new Command(() => RemovePort(), () => SelectedPort != null);
            this.AddYellowPageCommand    = new Command(() => AddYellowPage());
            this.RemoveYellowPageCommand = new Command(() => RemoveYellowPage(), () => SelectedYellowPage != null);
            channelCleanupMode           = ChannelCleaner.Mode;
            channelCleanupInactiveLimit  = ChannelCleaner.InactiveLimit / 60000;
            maxRelays = peerCast.AccessController.MaxRelays;
            maxRelaysPerBroadcastChannel = peerCast.AccessController.MaxRelaysPerBroadcastChannel;
            maxRelaysPerRelayChannel     = peerCast.AccessController.MaxRelaysPerRelayChannel;
            maxPlays = peerCast.AccessController.MaxPlays;
            maxPlaysPerBroadcastChannel        = peerCast.AccessController.MaxPlaysPerBroadcastChannel;
            maxPlaysPerRelayChannel            = peerCast.AccessController.MaxPlaysPerRelayChannel;
            maxUpstreamRate                    = peerCast.AccessController.MaxUpstreamRate;
            maxUpstreamRateIPv6                = peerCast.AccessController.MaxUpstreamRateIPv6;
            maxUpstreamRatePerBroadcastChannel = peerCast.AccessController.MaxUpstreamRatePerBroadcastChannel;
            maxUpstreamRatePerRelayChannel     = peerCast.AccessController.MaxUpstreamRatePerRelayChannel;
            isShowWindowOnStartup              = pecaApp.Settings.Get <WPFSettings>().ShowWindowOnStartup;
            isShowNotifications                = pecaApp.Settings.Get <WPFSettings>().ShowNotifications;
            remoteNodeName = pecaApp.Settings.Get <WPFSettings>().RemoteNodeName;
            ports          = new ObservableCollection <OutputListenerViewModel>(
                peerCast.OutputListeners
                .Select(listener => new OutputListenerViewModel(this, listener))
                );
            ports.CollectionChanged += (sender, args) => {
                OnPropertyChanged(nameof(ExternalAddressesV6));
                OnPropertyChanged(nameof(IPv6Enabled));
            };
            yellowPages = new ObservableCollection <YellowPageClientViewModel>(
                peerCast.YellowPages
                .Select(yp => new YellowPageClientViewModel(this, yp))
                );
            var port_mapper = pecaApp.Plugins.GetPlugin <PeerCastStation.UI.PortMapperPlugin>();

            if (port_mapper != null)
            {
                portMapperEnabled = port_mapper.Enabled;
                port_mapper.DiscoverAsync()
                .ContinueWith(prev => OnPropertyChanged("PortMapperExternalAddresses"));
            }
            PortCheckStatus   = PortCheckStatus.Checking;
            PortCheckV6Status = PortCheckStatus.Checking;
            CheckPortAsync().ContinueWith(prev => {
                if (prev.IsCanceled || prev.IsFaulted)
                {
                    PortCheckStatus   = PortCheckStatus.Failed;
                    PortCheckV6Status = PortCheckStatus.Failed;
                }
                else
                {
                    PortCheckStatus   = prev.Result.ResultV4;
                    PortCheckV6Status = prev.Result.ResultV6;
                }
            });
        }
 public HTTPDummyOutputStream(
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint)
     : base(peercast, input_stream, output_stream, remote_endpoint, null, null)
 {
     Logger.Debug("Initialized: Remote {0}", remote_endpoint);
 }
Esempio n. 18
0
            private void RemoveYellowPage(int yellowPageId)
            {
                var yp = PeerCast.YellowPages.FirstOrDefault(p => p.GetHashCode() == yellowPageId);

                if (yp != null)
                {
                    PeerCast.RemoveYellowPage(yp);
                }
            }
Esempio n. 19
0
 public PCPSourceConnection(
     PeerCast peercast,
     Channel channel,
     Uri source_uri,
     RemoteHostStatus remote_type)
     : base(peercast, channel, source_uri)
 {
     remoteType = remote_type;
 }
 public PCPPongOutputStream(
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     IPEndPoint endpoint,
     byte[] header)
     : base(peercast, input_stream, output_stream, endpoint, null, header)
 {
     Logger.Debug("Initialized: Remote {0}", endpoint);
 }
Esempio n. 21
0
 public PCPSourceConnection(
     PeerCast peercast,
     Channel channel,
     Uri source_uri,
     RemoteHostStatus remote_type)
     : base(peercast, channel, source_uri)
 {
     remoteType  = remote_type;
     contentSink = new AsynchronousContentSink(new ChannelContentSink(channel, true));
 }
Esempio n. 22
0
 public HTTPSourceConnection(
     PeerCast peercast,
     Channel channel,
     Uri source_uri,
     IContentReader content_reader,
     bool use_content_bitrate)
     : base(peercast, channel, source_uri)
 {
     contentReader     = content_reader;
     useContentBitrate = use_content_bitrate;
 }
 public HTTPSourceConnection(
     PeerCast peercast,
     Channel channel,
     Uri source_uri,
     IContentReader content_reader,
     bool use_content_bitrate)
     : base(peercast, channel, source_uri)
 {
     contentReader = content_reader;
     contentSink   = new BufferedContentSink(new AsynchronousContentSink(new ChannelContentSink(channel, use_content_bitrate)));
 }
Esempio n. 24
0
 private bool IsSiteLocal(Host node)
 {
     if (node.GlobalEndPoint != null)
     {
         var global = PeerCast.GetGlobalAddress(node.GlobalEndPoint.AddressFamily);
         return(node.GlobalEndPoint.Equals(global));
     }
     else
     {
         return(true);
     }
 }
Esempio n. 25
0
 public HTTPDummyOutputStream(
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     AccessControlInfo access_control,
     HTTPRequest req)
     : base(peercast, input_stream, output_stream, remote_endpoint, access_control, null, null)
 {
     Logger.Debug("Initialized: Remote {0}", remote_endpoint);
     this.request = req;
 }
Esempio n. 26
0
 public HTMLHostOutputStream(
     HTMLHost owner,
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     HTTPRequest request)
     : base(peercast, input_stream, output_stream, remote_endpoint, null, null)
 {
     this.owner   = owner;
     this.request = request;
     Logger.Debug("Initialized: Remote {0}", remote_endpoint);
 }
Esempio n. 27
0
 public AdminHostOutputStream(
     AdminHost owner,
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     AccessControlInfo access_control,
     HTTPRequest request)
     : base(peercast, input_stream, output_stream, remote_endpoint, access_control, null, null)
 {
     this.owner   = owner;
     this.request = request;
     Logger.Debug("Initialized: Remote {0}", remote_endpoint);
 }
Esempio n. 28
0
 public PeerCastOwinAppBuilder(PeerCastApplication app, PeerCast peerCast, CancellationToken cancellationToken)
 {
     Application = app;
     PeerCast    = peerCast;
     Properties[OwinEnvironment.Owin.Version]   = "1.0.1";
     Properties[OwinEnvironment.Opaque.Version] = "1.0";
     Properties[OwinEnvironment.PeerCastStation.PeerCastApplication] = app;
     Properties[OwinEnvironment.PeerCastStation.PeerCast]            = peerCast;
     Properties[OwinEnvironment.Server.OnInit]       = new Action <Func <Task> >(func => onInitActions.Add(func));
     Properties[OwinEnvironment.Server.OnDispose]    = cancellationToken;
     Properties[OwinEnvironment.Server.Capabilities] = Capabilities;
     Properties[OwinEnvironment.Host.TraceOutput]    = TextWriter.Null;
     Properties[OwinEnvironment.Host.Addresses]      = new List <Dictionary <string, object> >();
 }
Esempio n. 29
0
 public RTMPOutputStream(
     PeerCast peercast,
     ConnectionStream connection,
     AccessControlInfo access_control,
     Guid channel_id)
 {
     connection.ReadTimeout  = Timeout.Infinite;
     connection.WriteTimeout = 10000;
     this.peerCast           = peercast;
     this.inputStream        = connection;
     this.outputStream       = connection;
     this.accessControl      = access_control;
     this.connection         = new RTMPPlayConnection(this, this.inputStream, this.outputStream);
 }
Esempio n. 30
0
 public OWINHostOutputStream(
     PeerCast peercast,
     Stream input_stream,
     Stream output_stream,
     EndPoint remote_endpoint,
     AccessControlInfo access_control,
     HTTPRequest request,
     byte[] header,
     OWINApplication application)
     : base(peercast, input_stream, output_stream, remote_endpoint, access_control, null, header)
 {
     this.request     = request;
     this.application = application;
     Logger.Debug("Initialized: Remote {0}", remote_endpoint);
 }