Ejemplo n.º 1
0
 private void Ret_Closed(ChannelProxy channel, Exception ex)
 {
     lock (_sync)
     {
         Channels.Remove(channel.ChannelId);
     }
 }
Ejemplo n.º 2
0
 public ChannelProxy CreateNewChannel(Socket socket)
 {
     lock (_sync)
     {
         while (Channels.TryGetValue(_lastChannelId, out var channel))
         {
             _lastChannelId++;
         }
         var ret = Channels[_lastChannelId] = new ChannelProxy(socket);
         ret.ChannelId = _lastChannelId++;
         ret.Closed   += Ret_Closed;
         return(ret);
     }
 }
Ejemplo n.º 3
0
        private void HandleStartNewConnection(ProtocolSocket socket, int id, ushort targetPort, ushort internalPort)
        {
            Console.WriteLine($"HandleStartNewConnection #{id} target={targetPort} internal={internalPort}");
            var localSocket  = TryConnect(BoundInterface.ToString(), targetPort);
            var remoteSocket = TryConnect(RelayAddress, internalPort);
            var success      = localSocket != null && remoteSocket != null;

            if (IsConnected)
            {
                MainSocket.C2S_StartNewConnectionReply(id, internalPort, success);
            }
            var protoSocket = new ProtocolSocket(remoteSocket);

            protoSocket.C2S_StartRelay(id);
            var proxy = new ChannelProxy(localSocket);

            proxy.ChannelId = id;
            proxy.SetProxy(protoSocket);
        }