Exemplo n.º 1
0
        public void ParseSingleLongPacketDleIsLast()
        {
            List <byte[]>   packets         = new List <byte[]>();
            IPacketsHandler messagesHandler = Substitute.For <IPacketsHandler>();
            ILoggerService  loggerService   = Substitute.For <ILoggerService>();

            messagesHandler.WhenForAnyArgs(m => m.Push(null)).Do(ci => packets.Add(ci.ArgAt <byte[]>(0)));
            ICommunicationChannel handler = new CommunicationChannel(loggerService, null);

            handler.Init(DependencyInjectionFixture.BufferManager, messagesHandler);
            byte[] packet1      = new byte[] { 0x45, 0x65, CommunicationChannel.DLE };
            byte[] packet2      = new byte[] { CommunicationChannel.STX, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0x44 };
            byte[] packet3      = new byte[] { 0x03, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0x44 };
            byte[] parsedPacket = new byte[] { 0xaa, 0xbb, 0xcc, 0xdd, 0x44, 0x03, 0x00, 0xaa, 0xbb };

            handler.PushForParsing(packet1, 0, packet1.Length);
            handler.PushForParsing(packet2, 0, packet2.Length);
            handler.PushForParsing(packet3, 0, packet3.Length);

            Thread.Sleep(100);

            handler.Close();

            Assert.True(packets.Count == 1);

            byte[] messagePacket = packets.First();
            Assert.Equal(messagePacket, parsedPacket);
        }
Exemplo n.º 2
0
 public CommunicationServiceBase(IApplicationContext applicationContext, ILoggerService loggerService, IBufferManagerFactory bufferManagerFactory, IPacketsHandler packetsHandler, INodesResolutionService nodesResolutionService)
 {
     _log = loggerService.GetLogger(GetType().Name);
     _applicationContext     = applicationContext;
     _bufferManagerFactory   = bufferManagerFactory;
     _packetsHandler         = packetsHandler;
     _clientConnectedList    = new List <ICommunicationChannel>();
     _nodesResolutionService = nodesResolutionService;
     _messagesQueue          = new BlockingCollection <KeyValuePair <IKey, byte[]> >();
 }
Exemplo n.º 3
0
        //private read-only IBlocksProcessor _blocksProcessor

        public NodeMain(IServerCommunicationServicesRepository communicationServicesFactory, IServerCommunicationServicesRegistry communicationServicesRegistry, IConfigurationService configurationService, IModulesRepository modulesRepository, IPacketsHandler packetsHandler, IBlocksHandlersRegistry blocksProcessorFactory, ILoggerService loggerService, ISigningServicesRepository signingServicesRepository, IStatesRepository statesRepository)
        {
            _log = loggerService.GetLogger(GetType().Name);
            _communicationServicesFactory  = communicationServicesFactory;
            _communicationServicesRegistry = communicationServicesRegistry;
            _configurationService          = configurationService;
            _modulesRepository             = modulesRepository;
            _packetsHandler            = packetsHandler;
            _signingServicesRepository = signingServicesRepository;
            _nodeContext             = statesRepository.GetInstance <INodeContext>();
            _cancellationTokenSource = new CancellationTokenSource();
        }
Exemplo n.º 4
0
        public void Init(IBufferManager bufferManager, IPacketsHandler packetsHandler)
        {
            _cancellationTokenSource?.Cancel();

            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken       = _cancellationTokenSource.Token;

            _bufferManager  = bufferManager;
            _packetsHandler = packetsHandler;

            _bufferManager.SetBuffer(_socketReceiveAsyncEventArgs, _socketSendAsyncEventArgs);
            _offsetReceive = _socketReceiveAsyncEventArgs.Offset;
            _offsetSend    = _socketSendAsyncEventArgs.Offset;

            ParseReceivedData();
        }
Exemplo n.º 5
0
        public TcpCommunicationService(IApplicationContext applicationContext, ILoggerService loggerService, IBufferManagerFactory bufferManagerFactory, IPacketsHandler packetsHandler, INodesResolutionService nodesResolutionService)
            : base(applicationContext, loggerService, bufferManagerFactory, packetsHandler, nodesResolutionService)
        {
            _acceptEventArgsPool = new GenericPool <SocketAsyncEventArgs>(10);

            for (Int32 i = 0; i < 10; i++)
            {
                _acceptEventArgsPool.Push(CreateNewSocketAsyncEventArgs(_acceptEventArgsPool));
            }
        }
Exemplo n.º 6
0
 public UdpCommunicationService(IApplicationContext applicationContext, ILoggerService loggerService, IBufferManagerFactory bufferManagerFactory, IPacketsHandler packetsHandler, INodesResolutionService nodesResolutionService)
     : base(applicationContext, loggerService, bufferManagerFactory, packetsHandler, nodesResolutionService)
 {
 }