Example #1
0
  internal static bool? GetFromLocalOutputAccepts(
this OutputListener self, OutputStreamType target)
  {
      if (self == null)
      return null;
        return self.LocalOutputAccepts.Contains(target);
  }
Example #2
0
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
     PeerCast peercast,
     IConnectionHandler connection_handler,
     IPEndPoint ip,
     OutputStreamType local_accepts,
     OutputStreamType global_accepts)
 {
     this.PeerCast                  = peercast;
     this.localOutputAccepts        = local_accepts;
     this.globalOutputAccepts       = global_accepts;
     this.LoopbackAccessControlInfo = new AccessControlInfo(
         OutputStreamType.All,
         false,
         null);
     UpdateLocalAccessControlInfo();
     UpdateGlobalAccessControlInfo();
     this.ConnectionHandler = connection_handler;
     server = new TcpListener(ip);
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         //Windowsの時だけReuseAddressをつける。
         //Windows以外ではReuseAddressがSO_REUSEADDR+SO_REUSEPORT扱いになり
         //monoの4.6ではLinuxでUDP以外にSO_REUSEPORTを付けようとすると失敗する。
         //そのかわりmonoではSO_REUSEADDRが標準で付いてるようなので
         //Windows以外は明示的には付けないようにした。
         server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     }
     if (ip.AddressFamily == AddressFamily.InterNetworkV6)
     {
         server.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, true);
     }
     server.Start(MaxPendingConnections);
     listenTask = StartListen(server, cancellationSource.Token);
 }
Example #3
0
 public static void BuildPath(IAppBuilder builder, string mappath, OutputStreamType accepts, string localpath)
 {
     builder.MapGET(mappath, sub => {
         sub.UseAuth(accepts);
         sub.Run(new HostApp(localpath).Invoke);
     });
 }
Example #4
0
 public OutputListener FindListener(IPAddress remote_addr, OutputStreamType connection_type)
 {
     if (remote_addr == null)
     {
         throw new ArgumentNullException("remote_addr");
     }
     return(FindListener(remote_addr.AddressFamily, remote_addr, connection_type));
 }
Example #5
0
 public AccessControlInfo(
     OutputStreamType accepts,
     bool auth_required,
     AuthenticationKey key)
 {
     this.Accepts = accepts;
     this.AuthorizationRequired = auth_required;
     this.AuthenticationKey     = key;
 }
Example #6
0
 public static void BuildPath(IAppBuilder builder, string mappath, OutputStreamType accepts, string localpath)
 {
     builder.Map(mappath, sub => {
         sub.UseAllowMethods("GET");
         sub.MapMethod("GET", withmethod => {
             withmethod.UseAuth(accepts);
             withmethod.Run(new HostApp(localpath).Invoke);
         });
     });
 }
Example #7
0
  internal static void SetToLocalOutputAccepts(
this OutputListener self, OutputStreamType target, bool? value)
  {
      if (self == null)
      return;
        if (value == true)
      self.LocalOutputAccepts |= target;
        else
      self.LocalOutputAccepts &= ~target;
  }
Example #8
0
        public IPEndPoint GetLocalEndPoint(AddressFamily addr_family, OutputStreamType connection_type)
        {
            var listener = outputListeners.FirstOrDefault(
                x => x.LocalEndPoint.AddressFamily == addr_family &&
                (x.LocalOutputAccepts & connection_type) != 0);

            if (listener != null)
            {
                return(new IPEndPoint(GetLocalAddress(addr_family), listener.LocalEndPoint.Port));
            }
            return(null);
        }
Example #9
0
        public IPEndPoint GetGlobalEndPoint(AddressFamily addr_family, OutputStreamType connection_type)
        {
            var listener = outputListeners.FirstOrDefault(
                x => x.LocalEndPoint.AddressFamily == addr_family &&
                (x.GlobalOutputAccepts & connection_type) != 0);
            var addr = addr_family == AddressFamily.InterNetwork ? GlobalAddress : GlobalAddress6;

            if (listener != null && addr != null)
            {
                return(new IPEndPoint(addr, listener.LocalEndPoint.Port));
            }
            return(null);
        }
Example #10
0
 public IPEndPoint GetEndPoint(IPAddress remote_addr, OutputStreamType connection_type)
 {
     if (remote_addr == null)
     {
         throw new ArgumentNullException("remote_addr");
     }
     if (Utils.IsSiteLocal(remote_addr))
     {
         return(GetLocalEndPoint(remote_addr.AddressFamily, connection_type));
     }
     else
     {
         return(GetGlobalEndPoint(remote_addr.AddressFamily, connection_type));
     }
 }
Example #11
0
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
     PeerCast peercast,
     IPEndPoint ip,
     OutputStreamType local_accepts,
     OutputStreamType global_accepts)
 {
     this.PeerCast            = peercast;
     this.LocalOutputAccepts  = local_accepts;
     this.GlobalOutputAccepts = global_accepts;
     server = new TcpListener(ip);
     server.Start();
     listenerThread      = new Thread(ListenerThreadFunc);
     listenerThread.Name = String.Format("OutputListenerThread:{0}", ip);
     listenerThread.Start(server);
 }
Example #12
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>
        /// <remarks>WANへのリレーが許可されておりIsFirewalledがtrueだった場合にはnullにリセットします</remarks>
        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, new ConnectionHandler(this), ip, local_accepts, global_accepts);
                ReplaceCollection(ref outputListeners, orig => orig.Add(res));
            }
            catch (System.Net.Sockets.SocketException e) {
                logger.Error("Listen failed: {0}", ip);
                logger.Error(e);
                throw;
            }
            return(res);
        }
Example #13
0
 private void addButton_Click(object sender, EventArgs e)
 {
     Port = (int)portNumber.Value;
     if (addressText.SelectedIndex == 0)
     {
         Address = System.Net.IPAddress.Any;
     }
     else if (addressText.SelectedIndex == 1)
     {
         Address = System.Net.IPAddress.IPv6Any;
     }
     else
     {
         Address = System.Net.IPAddress.Parse(addressText.Text);
     }
     LocalAccepts  = OutputStreamType.Metadata;
     GlobalAccepts = OutputStreamType.Metadata;
     if (portLocalDirect.Checked)
     {
         LocalAccepts |= OutputStreamType.Play;
     }
     if (portLocalRelay.Checked)
     {
         LocalAccepts |= OutputStreamType.Relay;
     }
     if (portLocalInterface.Checked)
     {
         LocalAccepts |= OutputStreamType.Interface;
     }
     if (portGlobalDirect.Checked)
     {
         GlobalAccepts |= OutputStreamType.Play;
     }
     if (portGlobalRelay.Checked)
     {
         GlobalAccepts |= OutputStreamType.Relay;
     }
     if (portGlobalInterface.Checked)
     {
         GlobalAccepts |= OutputStreamType.Interface;
     }
     DialogResult = System.Windows.Forms.DialogResult.OK;
 }
Example #14
0
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
     PeerCast peercast,
     IPEndPoint ip,
     OutputStreamType local_accepts,
     OutputStreamType global_accepts)
 {
     this.PeerCast                    = peercast;
     this.localOutputAccepts          = local_accepts;
     this.globalOutputAccepts         = global_accepts;
     this.LocalAuthorizationRequired  = false;
     this.GlobalAuthorizationRequired = true;
     this.AuthenticationKey           = AuthenticationKey.Generate();
     server = new TcpListener(ip);
     server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     server.Start();
     listenerThread      = new Thread(ListenerThreadFunc);
     listenerThread.Name = String.Format("OutputListenerThread:{0}", ip);
     listenerThread.Start(server);
 }
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
     PeerCast peercast,
     IPEndPoint ip,
     OutputStreamType local_accepts,
     OutputStreamType global_accepts)
 {
     this.PeerCast = peercast;
       this.localOutputAccepts  = local_accepts;
       this.globalOutputAccepts = global_accepts;
       this.LocalAuthorizationRequired  = false;
       this.GlobalAuthorizationRequired = true;
       this.AuthenticationKey = AuthenticationKey.Generate();
       server = new TcpListener(ip);
       server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
       server.Start();
       listenerThread = new Thread(ListenerThreadFunc);
       listenerThread.Name = String.Format("OutputListenerThread:{0}", ip);
       listenerThread.Start(server);
 }
Example #16
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 #17
0
 public OutputListener FindListener(IPAddress remote_addr, OutputStreamType connection_type)
 {
     if (remote_addr == null)
     {
         throw new ArgumentNullException("remote_addr");
     }
     if (Utils.IsSiteLocal(remote_addr))
     {
         var listener = outputListeners.FirstOrDefault(
             x => x.LocalEndPoint.AddressFamily == remote_addr.AddressFamily &&
             (x.LocalOutputAccepts & connection_type) != 0);
         return(listener);
     }
     else
     {
         var listener = outputListeners.FirstOrDefault(
             x => x.LocalEndPoint.AddressFamily == remote_addr.AddressFamily &&
             (x.GlobalOutputAccepts & connection_type) != 0);
         return(listener);
     }
 }
 private void addButton_Click(object sender, EventArgs e)
 {
   Port = (int)portNumber.Value;
   if (addressText.SelectedIndex==0) {
     Address = System.Net.IPAddress.Any;
   }
   else if (addressText.SelectedIndex==1) {
     Address = System.Net.IPAddress.IPv6Any;
   }
   else {
     Address = System.Net.IPAddress.Parse(addressText.Text);
   }
   LocalAccepts  = OutputStreamType.Metadata;
   GlobalAccepts = OutputStreamType.Metadata;
   if (portLocalDirect.Checked)     LocalAccepts |= OutputStreamType.Play;
   if (portLocalRelay.Checked)      LocalAccepts |= OutputStreamType.Relay;
   if (portLocalInterface.Checked)  LocalAccepts |= OutputStreamType.Interface;
   if (portGlobalDirect.Checked)    GlobalAccepts |= OutputStreamType.Play;
   if (portGlobalRelay.Checked)     GlobalAccepts |= OutputStreamType.Relay;
   if (portGlobalInterface.Checked) GlobalAccepts |= OutputStreamType.Interface;
   DialogResult = System.Windows.Forms.DialogResult.OK;
 }
Example #19
0
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
     PeerCast peercast,
     IConnectionHandler connection_handler,
     IPEndPoint ip,
     OutputStreamType local_accepts,
     OutputStreamType global_accepts)
 {
     this.PeerCast                  = peercast;
     this.localOutputAccepts        = local_accepts;
     this.globalOutputAccepts       = global_accepts;
     this.LoopbackAccessControlInfo = new AccessControlInfo(
         OutputStreamType.All,
         false,
         null);
     UpdateLocalAccessControlInfo();
     UpdateGlobalAccessControlInfo();
     this.ConnectionHandler = connection_handler;
     server = new TcpListener(ip);
     if (ip.AddressFamily == AddressFamily.InterNetworkV6)
     {
         server.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, true);
     }
     listenTask = StartListen(server, cancellationSource.Token);
 }
 public AuthMiddleware(Func <IDictionary <string, object>, Task> nextApp, OutputStreamType acceptType)
 {
     this.nextApp    = nextApp;
     this.acceptType = acceptType;
 }
Example #21
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>
 /// <remarks>WANへのリレーが許可されておりIsFirewalledがtrueだった場合にはnullにリセットします</remarks>
 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;
     });
     if ((global_accepts & OutputStreamType.Relay)!=0) {
       OnListenPortOpened();
     }
       }
       catch (System.Net.Sockets.SocketException e) {
     logger.Error("Listen failed: {0}", ip);
     logger.Error(e);
     throw;
       }
       return res;
 }
Example #22
0
 /// <summary>
 /// 指定したエンドポイントで接続待ち受けをするOutputListenerを初期化します
 /// </summary>
 /// <param name="peercast">所属するPeerCastオブジェクト</param>
 /// <param name="ip">待ち受けをするエンドポイント</param>
 /// <param name="local_accepts">リンクローカルな接続先に許可する出力ストリームタイプ</param>
 /// <param name="global_accepts">リンクグローバルな接続先に許可する出力ストリームタイプ</param>
 internal OutputListener(
   PeerCast peercast,
   IConnectionHandler connection_handler,
   IPEndPoint ip,
   OutputStreamType local_accepts,
   OutputStreamType global_accepts)
 {
   this.PeerCast = peercast;
   this.localOutputAccepts  = local_accepts;
   this.globalOutputAccepts = global_accepts;
   this.LoopbackAccessControlInfo = new AccessControlInfo(
     OutputStreamType.All,
     false,
     null);
   UpdateLocalAccessControlInfo();
   UpdateGlobalAccessControlInfo();
   this.ConnectionHandler = connection_handler;
   server = new TcpListener(ip);
   if (Environment.OSVersion.Platform==PlatformID.Win32NT) {
     //Windowsの時だけReuseAddressをつける。
     //Windows以外ではReuseAddressがSO_REUSEADDR+SO_REUSEPORT扱いになり
     //monoの4.6ではLinuxでUDP以外にSO_REUSEPORTを付けようとすると失敗する。
     //そのかわりmonoではSO_REUSEADDRが標準で付いてるようなので
     //Windows以外は明示的には付けないようにした。
     server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
   }
   server.Start(Int32.MaxValue);
   listenTask = StartListen(server, cancellationSource.Token);
 }
Example #23
0
 public OutputListener FindListener(IPAddress remote_addr, OutputStreamType connection_type)
 {
     if (remote_addr==null) throw new ArgumentNullException("remote_addr");
       if (Utils.IsSiteLocal(remote_addr)) {
     var listener = outputListeners.FirstOrDefault(
       x =>  x.LocalEndPoint.AddressFamily==remote_addr.AddressFamily &&
        (x.LocalOutputAccepts & connection_type)!=0);
     return listener;
       }
       else {
     var listener = outputListeners.FirstOrDefault(
       x => x.LocalEndPoint.AddressFamily==remote_addr.AddressFamily &&
        (x.GlobalOutputAccepts & connection_type)!=0);
     return listener;
       }
 }
Example #24
0
 public RPCMethodAttribute(string name)
 {
     this.Name  = name;
     this.Grant = OutputStreamType.Interface;
 }
Example #25
0
 private static bool Contains(this OutputStreamType self, OutputStreamType other)
 {
     return (self & other) != 0;
 }
 public static IAppBuilder UseAuth(this IAppBuilder appBuilder, OutputStreamType acceptType)
 {
     return(appBuilder.Use <AuthMiddleware>(acceptType));
 }
Example #27
0
 public IPEndPoint GetEndPoint(IPAddress remote_addr, OutputStreamType connection_type)
 {
     if (remote_addr==null) throw new ArgumentNullException("remote_addr");
       if (Utils.IsSiteLocal(remote_addr)) {
     return GetLocalEndPoint(remote_addr.AddressFamily, connection_type);
       }
       else {
     return GetGlobalEndPoint(remote_addr.AddressFamily, connection_type);
       }
 }
Example #28
0
 public RPCMethodAttribute(string name, OutputStreamType grant)
 {
     this.Name  = name;
     this.Grant = grant;
 }
 public AccessControlInfo(
   OutputStreamType accepts,
   bool auth_required,
   AuthenticationKey key)
 {
   this.Accepts                = accepts;
   this.AuthorizationRequired  = auth_required;
   this.AuthenticationKey      = key;
 }
Example #30
0
 public IPEndPoint GetLocalEndPoint(AddressFamily addr_family, OutputStreamType connection_type)
 {
     var listener = outputListeners.FirstOrDefault(
     x =>  x.LocalEndPoint.AddressFamily==addr_family &&
      (x.LocalOutputAccepts & connection_type)!=0);
       var addr = addr_family==AddressFamily.InterNetwork ? LocalAddress : LocalAddress6;
       if (listener!=null) {
     return new IPEndPoint(addr, listener.LocalEndPoint.Port);
       }
       return null;
 }