コード例 #1
0
        public PipeBase GetConnection(UInt32 cid)
        {
            PipeBase connection;

            if (ActivePipes.Find(ref cid, out connection))
            {
                return(connection);
            }
            throw new ArgumentException("ID does not match any existing connection");
        }
コード例 #2
0
        public static int CreatePipe()
        {
            // In order to ensure that pipe indexes start at 1
            if (ActivePipes.Count == 0)
            {
                ActivePipes.Add(null);
            }

            var c = new ClientPipe();

            return(c.Id);
        }
コード例 #3
0
        public override bool ClosePipe(UInt32 id)
        {
            PipeBase c;

            if (ActivePipes.Remove(id, out c))
            {
                var p = new EncryptedPacket(ID, GetNextSeq(), c.ID, 0,
                                            RemoteEndPoint, new byte[0]);
                p.RPCs.Add(new ClosePipeRPC(id));

                EncryptAndSendPacket(p);
                return(true);
            }
            //connection was either already closed or never existed.
            return(false);
        }
コード例 #4
0
        ClientPipe()
        {
            current_results   = new List <SerializedResult>();
            result_semaphores = new Dictionary <uint, Semaphore>();

            pipe = new InternalClientPipe("argon_pipe_server", ".");

            pipe.Start();
            pipe.ServerMessage += OnServerMessage;

            ActivePipes.Add(this);

            Log = new LoggerUid("IPC.ClientPipe", Id);


            Log.WriteLine("Waiting for connection...");
            pipe.WaitForConnection();
            Log.WriteLine("Connected...");
        }
コード例 #5
0
        public override void HandleIncomingPacket(EncryptedPacket p)
        {
            //decrypt the GenericPacket
            //Sodium.PublicKeyBox.Open (p.CipherText, p.Nonce, this.mKeyPair.PrivateKey, this.p)

            switch (State)
            {
            case TunnelState.WaitingForHelloResponse:
                //this should be the hello response
                Debug.Assert(p.HasEPK, "The first GenericPacket back from a hello response has to have a public key attached to it");
                this.recipentEPK = p.EuphemeralPublicKey;
                this.State       = TunnelState.Connected;
                //there could be a payload attached to this GenericPacket
                this.HandleIncomingPacket(p);

                while (this.bufferedEncryptedPackets.Count > 0)
                {
                    this.EncryptAndSendPacket(this.bufferedEncryptedPackets.Dequeue());
                }
                break;

            case TunnelState.Connected:
                Debug.Assert(recipentEPK != null);
                if (p.CipherText.Length > 0)
                {
                    if (p.DecryptPacket(mKeyPair.PrivateKey, recipentEPK))
                    {
                        if (congestionController.CheckResendAck(p))
                        {
                            Console.WriteLine("Resending ack");
                            this.SendAck(p.Ack);
                        }
                        if (congestionController.CheckPacket(p))
                        {
                            PipeBase connection;
                            UInt32   cid = p.CID;
                            if (p.Ack > 0)
                            {
                                this.SendAck(p.Ack);
                            }
                            //only handle packets that have a payload or RPCs
                            if (p.Payload.Length > 0 || p.RPCs.Count > 0)
                            {
                                if (cid == 0)
                                {
                                    ControlPipe.HandlePacket(p);
                                }
                                else
                                {
                                    if (ActivePipes.Find(ref cid, out connection))
                                    {
                                        connection.HandlePacket(p);
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }