private JObject AddYellowPage(string protocol, string name, string uri) { var factory = PeerCast.YellowPageFactories.FirstOrDefault(p => protocol == p.Protocol); if (factory == null) { throw new RPCError(RPCErrorCode.InvalidParams, "protocol Not Found"); } if (name == null) { throw new RPCError(RPCErrorCode.InvalidParams, "name must be String"); } Uri yp_uri; try { yp_uri = new Uri(uri); } catch (ArgumentNullException) { throw new RPCError(RPCErrorCode.InvalidParams, "uri must be String"); } catch (UriFormatException) { throw new RPCError(RPCErrorCode.InvalidParams, "Invalid uri"); } if (!factory.CheckURI(yp_uri)) { throw new RPCError(RPCErrorCode.InvalidParams, String.Format("Not suitable uri for {0}", protocol)); } var yp = PeerCast.AddYellowPage(factory.Protocol, name, yp_uri); var res = new JObject(); res["yellowPageId"] = yp.GetHashCode(); res["name"] = yp.Name; res["uri"] = yp.Uri.ToString(); res["protocol"] = yp.Protocol; return(res); }
public void Apply() { if (!IsModified) { return; } IsModified = false; ChannelCleaner.Mode = channelCleanupMode; ChannelCleaner.InactiveLimit = channelCleanupInactiveLimit * 60000; peerCast.AccessController.MaxRelays = maxRelays; peerCast.AccessController.MaxRelaysPerBroadcastChannel = maxRelaysPerBroadcastChannel; peerCast.AccessController.MaxRelaysPerRelayChannel = maxRelaysPerRelayChannel; peerCast.AccessController.MaxPlays = maxPlays; peerCast.AccessController.MaxPlaysPerBroadcastChannel = maxPlaysPerBroadcastChannel; peerCast.AccessController.MaxPlaysPerRelayChannel = maxPlaysPerRelayChannel; peerCast.AccessController.MaxUpstreamRate = maxUpstreamRate; peerCast.AccessController.MaxUpstreamRateIPv6 = maxUpstreamRateIPv6; peerCast.AccessController.MaxUpstreamRatePerBroadcastChannel = maxUpstreamRatePerBroadcastChannel; peerCast.AccessController.MaxUpstreamRatePerRelayChannel = maxUpstreamRatePerRelayChannel; pecaApp.Settings.Get <WPFSettings>().ShowWindowOnStartup = isShowWindowOnStartup; pecaApp.Settings.Get <WPFSettings>().ShowNotifications = isShowNotifications; pecaApp.Settings.Get <WPFSettings>().RemoteNodeName = remoteNodeName; if (IsListenersModified) { foreach (var listener in peerCast.OutputListeners.ToArray()) { peerCast.StopListen(listener); } foreach (var listener in ports) { var newlistener = peerCast.StartListen(listener.EndPoint, listener.LocalAccepts, listener.GlobalAccepts); newlistener.GlobalAuthorizationRequired = listener.GlobalAuthRequired; newlistener.LocalAuthorizationRequired = listener.LocalAuthRequired; newlistener.AuthenticationKey = listener.AuthenticationKey; } isListenersModified = false; } if (IsYellowPagesModified) { foreach (var yp in peerCast.YellowPages.ToArray()) { peerCast.RemoveYellowPage(yp); } foreach (var yp in yellowPages) { if (String.IsNullOrEmpty(yp.Name)) { continue; } if (String.IsNullOrEmpty(yp.AnnounceUri) && String.IsNullOrEmpty(yp.ChannelsUri)) { continue; } Uri announce_uri = String.IsNullOrEmpty(yp.AnnounceUri) ? null : new Uri(yp.AnnounceUri, UriKind.Absolute); Uri channels_uri = String.IsNullOrEmpty(yp.ChannelsUri) ? null : new Uri(yp.ChannelsUri, UriKind.Absolute); peerCast.AddYellowPage(yp.Protocol.Protocol, yp.Name, announce_uri, channels_uri); } isYellowPagesModified = false; } var port_mapper = pecaApp.Plugins.GetPlugin <PeerCastStation.UI.PortMapperPlugin>(); if (port_mapper != null) { port_mapper.Enabled = portMapperEnabled; 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; peerCast.SetPortStatus(System.Net.Sockets.AddressFamily.InterNetwork, prev.Result.ResultV4 == PortCheckStatus.Opened ? PortStatus.Open : PortStatus.Firewalled); peerCast.SetPortStatus(System.Net.Sockets.AddressFamily.InterNetworkV6, prev.Result.ResultV6 == PortCheckStatus.Opened ? PortStatus.Open : PortStatus.Firewalled); } }); pecaApp.SaveSettings(); }
void LoadSettings() { var s = settings.Get <PeerCastStationSettings>(); try { if (s.Logger != null) { Logger.Level = s.Logger.Level; Logger.LogFileName = s.Logger.LogFileName; Logger.OutputTarget = s.Logger.OutputTarget; } if (s.AccessController != null) { peerCast.AccessController.MaxPlays = s.AccessController.MaxDirects; peerCast.AccessController.MaxRelays = s.AccessController.MaxRelays; peerCast.AccessController.MaxPlaysPerBroadcastChannel = s.AccessController.MaxDirectsPerBroadcastChannel; peerCast.AccessController.MaxPlaysPerRelayChannel = s.AccessController.MaxDirectsPerChannel; peerCast.AccessController.MaxRelaysPerBroadcastChannel = s.AccessController.MaxRelaysPerBroadcastChannel; peerCast.AccessController.MaxRelaysPerRelayChannel = s.AccessController.MaxRelaysPerChannel; peerCast.AccessController.MaxUpstreamRate = s.AccessController.MaxUpstreamRate; peerCast.AccessController.MaxUpstreamRateIPv6 = s.AccessController.MaxUpstreamRateIPv6; peerCast.AccessController.MaxUpstreamRatePerBroadcastChannel = s.AccessController.MaxUpstreamRatePerBroadcastChannel; peerCast.AccessController.MaxUpstreamRatePerRelayChannel = s.AccessController.MaxUpstreamRatePerChannel; } if (s.BroadcastID != Guid.Empty && (AtomCollectionExtensions.IDToByteArray(s.BroadcastID)[0] & 0x01) == 0) { peerCast.BroadcastID = s.BroadcastID; } if (s.Listeners != null) { foreach (var listener in s.Listeners) { try { var ol = peerCast.StartListen(listener.EndPoint, listener.LocalAccepts, listener.GlobalAccepts); ol.GlobalAuthorizationRequired = listener.GlobalAuthRequired; ol.LocalAuthorizationRequired = listener.LocalAuthRequired; ol.AuthenticationKey = new AuthenticationKey(listener.AuthId, listener.AuthPassword); } catch (System.Net.Sockets.SocketException e) { logger.Error(e); } } } if (peerCast.OutputListeners.Count == 0) { var endpoint = new System.Net.IPEndPoint( AppSettingsReader.GetIPAddress("DefaultListenAddress", System.Net.IPAddress.Any), AppSettingsReader.GetInt("DefaultListenPort", 7144) ); try { peerCast.StartListen( endpoint, OutputStreamType.All, OutputStreamType.Metadata | OutputStreamType.Relay); } catch (System.Net.Sockets.SocketException e) { logger.Error(e); try { peerCast.StartListen( new System.Net.IPEndPoint(endpoint.Address, 0), OutputStreamType.All, OutputStreamType.None); } catch (System.Net.Sockets.SocketException e2) { logger.Error(e2); } } } if (s.YellowPages != null) { foreach (var yellowpage in s.YellowPages) { try { peerCast.AddYellowPage(yellowpage.Protocol, yellowpage.Name, yellowpage.Uri, yellowpage.ChannelsUri); } catch (ArgumentException e) { logger.Error(e); } } } } catch (FormatException) { } ChannelCleaner.Mode = settings.Get <ChannelCleanerSettings>().Mode; ChannelCleaner.InactiveLimit = settings.Get <ChannelCleanerSettings>().InactiveLimit; }
void LoadSettings() { var settings = PeerCastStation.Properties.Settings.Default; try { if (settings.AccessController != null) { peerCast.AccessController.MaxPlays = settings.AccessController.MaxDirects; peerCast.AccessController.MaxRelays = settings.AccessController.MaxRelays; peerCast.AccessController.MaxPlaysPerChannel = settings.AccessController.MaxDirectsPerChannel; peerCast.AccessController.MaxRelaysPerChannel = settings.AccessController.MaxRelaysPerChannel; peerCast.AccessController.MaxUpstreamRate = settings.AccessController.MaxUpstreamRate; } if (settings.BroadcastID != Guid.Empty && (AtomCollectionExtensions.IDToByteArray(settings.BroadcastID)[0] & 0x01) == 0) { peerCast.BroadcastID = settings.BroadcastID; } if (settings.Listeners != null) { foreach (var listener in settings.Listeners) { try { peerCast.StartListen(listener.EndPoint, listener.LocalAccepts, listener.GlobalAccepts); } catch (System.Net.Sockets.SocketException e) { logger.Error(e); } } } if (peerCast.OutputListeners.Count == 0) { System.Net.IPAddress listen_addr; if (!System.Net.IPAddress.TryParse(settings.DefaultListenAddress, out listen_addr)) { listen_addr = System.Net.IPAddress.Any; } try { peerCast.StartListen( new System.Net.IPEndPoint(listen_addr, settings.DefaultListenPort), OutputStreamType.All, OutputStreamType.Metadata | OutputStreamType.Relay); } catch (System.Net.Sockets.SocketException e) { logger.Error(e); } } if (settings.YellowPages != null) { foreach (var yellowpage in settings.YellowPages) { try { peerCast.AddYellowPage(yellowpage.Protocol, yellowpage.Name, yellowpage.Uri); } catch (ArgumentException e) { logger.Error(e); } } } } catch (FormatException) { } }