Example #1
0
        private ProtocolStack GetManagementBranch()
        {
            ProtocolStackState managementBranchState = new ProtocolStackState();

            managementBranchState.MiddleProtocols.Add(new TransportInfoProtocol());  // Transport Info
            ProtocolStack managementBranch = new ProtocolStack();

            managementBranch.SetState(managementBranchState);
            managementBranchState.Type = DataProtocolType.Management;
            return(managementBranch);
        }
Example #2
0
        private ProtocolStack GetTextBranch()
        {
            // Text Branch
            ProtocolStackState textBranchState = new ProtocolStackState();

            textBranchState.MiddleProtocols.Add(new UTF8Protocol());  // UTF8
            ProtocolStack textBranch = new ProtocolStack();

            textBranch.SetState(textBranchState);
            textBranchState.Type = DataProtocolType.Text;
            return(textBranch);
        }
Example #3
0
        private ProtocolStack GetFileBranch()
        {
            // File Branch
            ProtocolStackState fileBranchState = new ProtocolStackState();

            fileBranchState.MiddleProtocols.Add(new SmallFileProtocol());  // SmallFileProtocol
            ProtocolStack fileBranch = new ProtocolStack();

            fileBranch.SetState(fileBranchState);
            fileBranchState.Type = DataProtocolType.SmallFile;
            return(fileBranch);
        }
Example #4
0
        private static void AddBasicSecurityLayer(ProtocolStackState stackState, AESProtocolState aesState)
        {
            // Heartbeat
            stackState.MiddleProtocols.Add(new HeartbeatProtocol());
            // Timestamp
            stackState.MiddleProtocols.Add(new TimestampProtocol());
            // Seq (this protocol will block broadcasted messages)
            stackState.MiddleProtocols.Add(new SequenceProtocol());
            // AES
            AESProtocol aesP = new AESProtocol();

            aesP.SetState((AESProtocolState)aesState.Clone());
            stackState.MiddleProtocols.Add(aesP);
            // Framing
            stackState.MiddleProtocols.Add(new FramingProtocol());
        }
Example #5
0
        private ProtocolStack GetBroadcastStack()
        {
            ProtocolStackState state = new ProtocolStackState();

            // broadcast protocol
            BroadcastProtocolState broadcaseState = new BroadcastProtocolState();

            broadcaseState.SockController = _options.SockController;
            broadcaseState.SockMgr        = _options.SockMgr;
            state.MiddleProtocols.Add(new BroadcastProtocol(broadcaseState));

            // Disconnect when dataContent invalid and report
            state.MiddleProtocols.Add(new DisconnectProtocol());
            AddBasicSecurityLayer(state, _options.FirstLowAESProtocolState);

            ProtocolStack protocolStack = new ProtocolStack();

            protocolStack.SetState(state);
            return(protocolStack);
        }
Example #6
0
        private ProtocolStack GetDefaultStack()
        {
            ProtocolStackState state = new ProtocolStackState();

            // branching
            List <ProtocolStack> branches = new List <ProtocolStack>();

            branches.Add(GetTextBranch());       // index 0
            branches.Add(GetFileBranch());       // index 1
            branches.Add(GetManagementBranch()); // index 2
            TypeBranchingProtocol branchingProtocol = new TypeBranchingProtocol();

            branchingProtocol.SetBranches(branches);
            state.MiddleProtocols.Add(branchingProtocol);

            // Block invalid DataContent
            state.MiddleProtocols.Add(new BlockProtocol());
            // Type tagging
            TypeTagProtocol typeTagProtocol = new TypeTagProtocol();

            state.MiddleProtocols.Add(typeTagProtocol);

            // Block invalid DataContent
            state.MiddleProtocols.Add(new BlockProtocol());
            // AES
            AESProtocol aesP = new AESProtocol();

            aesP.SetState((AESProtocolState)_options.SecondLowAESProtocolState.Clone());
            state.MiddleProtocols.Add(aesP);

            // Block invalid data and report
            state.MiddleProtocols.Add(new BlockProtocol());
            // Basic Security Layers
            AddBasicSecurityLayer(state, _options.FirstLowAESProtocolState);

            state.Type = DataProtocolType.Text;
            ProtocolStack protocolStack = new ProtocolStack();

            protocolStack.SetState(state);
            return(protocolStack);
        }
Example #7
0
 public void FromLowLayerToHere(DataContent dataContent)
 {
     // block invalid dataContent
     if (dataContent.Data == null)
     {
         return;
     }
     // server start broadcasting
     foreach (SockMgr client in _state.SockController.GetSockList().Clients)
     {
         // don't re-sent to source
         if (client == _state.SockMgr)
         {
             continue;
         }
         // find the same class from other peer sockets and activate them
         ProtocolStackState peerStackState = client.GetProtocolStack().GetState();
         if (typeof(BroadcastProtocol) == peerStackState.MiddleProtocols[0]?.GetType())
         {
             peerStackState.MiddleProtocols[0].FromHighLayerToHere((SocketApp.Protocol.DataContent)dataContent.Clone());
         }
     }
 }
Example #8
0
 // setup Event chains
 public void SetState(ProtocolStackState state)
 {
     UnlinkMiddleProtocols();
     _state = state;
     LinkMiddleProtocols();
 }