コード例 #1
0
 public NamedPipePivotListener(IPacketDispatcher packetDispatcher, Guid id, string pipeName, byte[] stageData)
     : base(packetDispatcher, id)
 {
     this.pipeName  = pipeName;
     this.stageData = stageData;
     WaitForConnection();
 }
コード例 #2
0
        /// <summary>
        /// Creates a Stormancer client instance.
        /// </summary>
        /// <param name="configuration">A configuration instance containing options for the client.</param>
        public Client(ClientConfiguration configuration)
        {
            this._pingInterval = configuration.PingInterval;
            this._scheduler    = configuration.Scheduler;
            DependencyResolver = new StormancerResolver();
            DependencyResolver.Register <ILogger>(() => configuration.Logger);
            DependencyResolver.Register(() => new ApiClient(configuration, DependencyResolver));
            DependencyResolver.Register <ITokenHandler>(() => new TokenHandler());
            DependencyResolver.RegisterComponent <IConnectionHandler>(new IConnectionHandler());
            DependencyResolver.RegisterComponent <IClock>(new IClock(this));

#if UNITY_EDITOR
            IConnectionHandler temp = DependencyResolver.Resolve <IConnectionHandler>();
            temp.PeerConnected += (PeerConnectedContext pcc) =>
            {
                ConnectionWrapper connection = new ConnectionWrapper(pcc.Connection, configuration.Plugins.OfType <EditorPlugin.StormancerEditorPlugin>().First());
                pcc.Connection = connection;
            };
#endif

            this.DependencyResolver.Register <ITransport>(configuration.TransportFactory);
            this._accountId       = configuration.Account;
            this._applicationName = configuration.Application;
            //TODO handle scheduler in the transport
            this._dispatcher  = configuration.Dispatcher;
            _requestProcessor = new Stormancer.Networking.Processors.RequestProcessor(Logger, Enumerable.Empty <IRequestModule>());

            _scenesDispatcher = new Processors.SceneDispatcher();
            this._dispatcher.AddProcessor(_requestProcessor);
            this._dispatcher.AddProcessor(_scenesDispatcher);
            this._metadata = configuration._metadata;

            foreach (var serializer in configuration.Serializers)
            {
                this._serializers.Add(serializer.Name, serializer);
            }

            this._maxPeers = configuration.MaxPeers;

            foreach (var plugin in configuration.Plugins)
            {
                plugin.Build(_pluginCtx);
            }

            var ev = _pluginCtx.ClientCreated;
            if (ev != null)
            {
                ev(this);
            }

            _transport = DependencyResolver.Resolve <ITransport>();
            this._metadata.Add("serializers", string.Join(",", this._serializers.Keys.ToArray()));
            this._metadata.Add("transport", _transport.Name);
            this._metadata.Add("version", "1.1.0");
            this._metadata.Add("platform", "Unity");
            this._metadata.Add("protocol", "2");

            Initialize();
        }
コード例 #3
0
        public PluginManager(IPacketDispatcher packetDispatcher, ChannelManager channelManager)
        {
            this.handlers         = new Dictionary <string, FunctionDefinition>();
            this.extFunctions     = new Dictionary <string, List <string> >();
            this.packetDispatcher = packetDispatcher;
            this.channelManager   = channelManager;
            AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;

            // Internal function registrations
            this.RegisterFunction(string.Empty, "core_enumextcmd", false, this.CoreEnumextcmd);
            this.RegisterFunction(string.Empty, "core_loadlib", false, this.CoreLoadLib);
        }
コード例 #4
0
        /// <summary>
        /// Creates a Stormancer client instance.
        /// </summary>
        /// <param name="configuration">A configuration instance containing options for the client.</param>
        public Client(ClientConfiguration configuration)
        {
            foreach (var plugin in configuration.Plugins)
            {
                plugin.Build(_pluginCtx);
            }

            this._pingInterval = configuration.PingInterval;


            this.DependencyResolver = new DefaultDependencyResolver(b =>
            {
                b.Register(this);

                _pluginCtx.BuildingClientResolver?.Invoke(b);
            });
            this._scheduler       = configuration.Scheduler;
            this._logger          = configuration.Logger;
            this._accountId       = configuration.Account;
            this._applicationName = configuration.Application;
            _apiClient            = new ApiClient(configuration, _tokenHandler);
            this._transport       = configuration.TransportFactory(new Dictionary <string, object> {
                { "ILogger", this._logger }, { "IScheduler", this._scheduler }
            });
            this._dispatcher  = configuration.Dispatcher;
            _requestProcessor = new Stormancer.Networking.Processors.RequestProcessor(_logger, Enumerable.Empty <IRequestModule>(), _systemSerializer);

            _scenesDispatcher = new Processors.SceneDispatcher(new[] { new RouteScenePacketHandler() });
            this._dispatcher.AddProcessor(_requestProcessor);
            this._dispatcher.AddProcessor(_scenesDispatcher);
            this._metadata = configuration._metadata;

            foreach (var serializer in configuration.Serializers)
            {
                this._serializers.Add(serializer.Name, serializer);
            }

            this._metadata.Add("serializers", string.Join(",", this._serializers.Keys));
            this._metadata.Add("transport", _transport.Name);
            this._metadata.Add("version", "1.0.0a");
            this._metadata.Add("platform", "NET45");
            this._metadata.Add("protocol", "2");

            this._maxPeers = configuration.MaxPeers;


            if (_pluginCtx.ClientCreated != null)
            {
                _pluginCtx.ClientCreated(this);
            }
            Initialize();
        }
コード例 #5
0
        public MDNetworkLib(IPacketDispatcher userPacketDispatcher = null)
        {
            UserManager = new UserTokenManager();

            if (userPacketDispatcher == null)
            {
                PacketDispatcher = new DefaultPacketDispatcher();
            }
            else
            {
                PacketDispatcher = userPacketDispatcher;
            }
        }
コード例 #6
0
ファイル: Session.cs プロジェクト: juney1110/FreeNet
        public Session(bool isClient, Int64 uniqueId, IPacketDispatcher dispatcher, IMessageResolver messageResolver, ServerOption serverOption)
        {
            IsClient   = isClient;
            UniqueId   = uniqueId;
            Dispatcher = dispatcher;
            ServerOpt  = serverOption;

            RefMsgResolver = messageResolver;

            SendingList = new List <ArraySegment <byte> >();

            LatestHeartbeatTime = DateTime.Now.Ticks;
        }
コード例 #7
0
        public Session(Int64 uniqueId, IPacketDispatcher dispatcher)
        {
            UniqueId         = uniqueId;
            Dispatcher       = dispatcher;
            cs_sending_queue = new object();

            MsgResolver         = new MessageResolver();
            Peer                = null;
            SendingList         = new List <ArraySegment <byte> >();
            LatestHeartbeatTime = DateTime.Now.Ticks;

            CurrentState = State.Idle;
        }
コード例 #8
0
        /// <summary>
        /// 로직 스레드를 사용하려면 use_logicthread를 true로 설정한다.
        ///  -> 하나의 로직 스레드를 생성한다.
        ///  -> 메시지는 큐잉되어 싱글 스레드에서 처리된다.
        ///
        /// 로직 스레드를 사용하지 않으려면 use_logicthread를 false로 설정한다.
        ///  -> 별도의 로직 스레드는 생성하지 않는다.
        ///  -> IO스레드에서 직접 메시지 처리를 담당하게 된다.
        /// </summary>
        /// <param name="use_logicthread">true=Create single logic thread. false=Not use any logic thread.</param>
        public NetworkService(ServerOption serverOption, IPacketDispatcher userPacketDispatcher = null)
        {
            ServerOpt  = serverOption;
            SessionMgr = new SessionManager();

            if (userPacketDispatcher == null)
            {
                PacketDispatcher = new DefaultPacketDispatcher();
            }
            else
            {
                PacketDispatcher = userPacketDispatcher;
            }
        }
コード例 #9
0
ファイル: NamedPipePivot.cs プロジェクト: OJ/clr-meterpreter
        public NamedPipePivot(IPacketDispatcher packetDispacher, NamedPipeServerStream server, byte[] stageData)
            : base(packetDispacher)
        {
            this.server = server;
            if (stageData != null && stageData.Length > 0)
            {
                using (var memStream = new MemoryStream(stageData.Length + 4))
                    using (var writer = new BinaryWriter(memStream))
                    {
                        writer.Write(stageData.Length);
                        writer.Write(stageData);
                        Write(memStream.ToArray());
                    }
            }

            EstablishSession();
            ReadHeaderAsync();
        }
コード例 #10
0
        public NamedPipePivot(IPacketDispatcher packetDispacher, NamedPipeServerStream server, byte[] stageData)
            : base(packetDispacher)
        {
            this.readerThread = new Thread(new ThreadStart(this.ReadAsync));
            this.server       = server;
            //this.writer = new BinaryWriter(this.server);
            this.reader = new BinaryReader(this.server);

            if (stageData != null && stageData.Length > 0)
            {
                using (var memStream = new MemoryStream(stageData.Length + 4))
                    using (var writer = new BinaryWriter(memStream))
                    {
                        Write(memStream.ToArray());
                    }
            }

            EstablishSession();
            this.readerThread.Start();
        }
コード例 #11
0
        /// <summary>
        /// The main packet processing loop.
        /// </summary>
        /// <remarks>
        /// This method illustrates how the dispatcher can be used. For this illustration
        /// we use an async foreach, to simulate a thread which receives and processes packets
        /// independent of the rest of the process, and which responds to cancellation tokens
        /// by terminating any outstanding dispatches and terminating the waits on any
        /// incoming packets.
        /// </remarks>
        static async Task ProcessPacketsAsync(
            IPacketDispatcher dispatcher,
            IPacketLogger packetLogger,
            CancellationToken cancellationToken)
        {
            await foreach (var packet in GeneratePacketsAsync(cancellationToken))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    await dispatcher.DispatchAsync(packet, cancellationToken);
                }
                catch (Exception ex)
                {
                    Guid correlationId = Guid.NewGuid();
                    Log.Error(ex, "CID:{correlationId}: Exception invoking dispatcher for packet with id {id} and type {type}", correlationId, packet?.Id, packet?.GetType().Name);
                    packetLogger.LogPacket(PacketLogReason.Error, correlationId, packet);
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// 로직 스레드를 사용하려면 use_logicthread를 true로 설정한다.
        ///  -> 하나의 로직 스레드를 생성한다.
        ///  -> 메시지는 큐잉되어 싱글 스레드에서 처리된다.
        ///
        /// 로직 스레드를 사용하지 않으려면 use_logicthread를 false로 설정한다.
        ///  -> 별도의 로직 스레드는 생성하지 않는다.
        ///  -> IO스레드에서 직접 메시지 처리를 담당하게 된다.
        /// </summary>
        /// <param name="use_logicthread">true=Create single logic thread. false=Not use any logic thread.</param>
        public NetworkService(ServerOption serverOption, IPacketDispatcher userPacketDispatcher = null,
                              IMessageResolver userMessageResolver = null)
        {
            ServerOpt   = serverOption;
            UserManager = new SessionManager();

            if (userPacketDispatcher == null)
            {
                PacketDispatcher = new DefaultPacketDispatcher();
            }
            else
            {
                PacketDispatcher = userPacketDispatcher;
            }

            if (userMessageResolver == null)
            {
                MessageResolver = new DefaultMessageResolver(ServerOpt.MaxPacketSize * 3);
            }
            else
            {
                MessageResolver = userMessageResolver;
            }
        }
コード例 #13
0
        public void Process(IPacket packet)
        {
            var code = (WMSG)packet.Code;

            if (code == WMSG.CMSG_AUTH_SESSION)
            {
                HandleAuthSession(packet);
                return;
            }
            IPacketDispatcher dispatcher = Factory.GetDispatcher(code);

            if (dispatcher != null)
            {
                Console.WriteLine(code);
                dispatcher.Dispatch(session, packet);
            }
            else
            {
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(code);
                Console.ForegroundColor = color;
            }
        }
コード例 #14
0
 public PivotListener(IPacketDispatcher packetDispatcher, Guid id)
 {
     PacketDispatcher = packetDispatcher;
     Id = id;
 }
コード例 #15
0
 public ChannelManager(IPacketDispatcher packetDispatcher)
 {
     this.channelCreators  = new Dictionary <string, Func <ChannelManager, Packet, Packet, Channel> >();
     this.activeChannels   = new Dictionary <uint, Channel>();
     this.packetDispatcher = packetDispatcher;
 }
コード例 #16
0
 public ServerSession(Int64 uniqueId, IPacketDispatcher dispatcher) : base(uniqueId, dispatcher)
 {
 }
コード例 #17
0
 public ClientSession(Int64 uniqueId, IPacketDispatcher dispatcher) : base(uniqueId, dispatcher)
 {
 }
コード例 #18
0
 public PivotManager(IPacketDispatcher packetDispatcher)
 {
     this.packetDispatcher = packetDispatcher;
     this.pivotListeners   = new Dictionary <Guid, PivotListener>();
     this.pivots           = new Dictionary <Guid, Pivot.Pivot>();
 }
コード例 #19
0
ファイル: Pivot.cs プロジェクト: mischev/clr-meterpreter
 public Pivot(IPacketDispatcher packetDispacher)
 {
     Id = Guid.NewGuid();
     PacketDispacher = packetDispacher;
 }