Esempio n. 1
0
 private void OnPipeClosed(PipeBase pipe)
 {
     if (this.PipeClosed != null)
     {
         this.PipeClosed(this, new PipeChangedEventArgs(pipe, this.mTunnel));
     }
 }
Esempio n. 2
0
        /// <summary>
        ///     Opens a pipe request with the other side of the tunnel.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="id"></param>
        private PipeBase OpenPipe(PipeType type, UInt32 id = 0)
        {
            //the connecting party doesn't care about the pipe ID.
            if (id == 0)
            {
                id = BitConverter.ToUInt32(SodiumCore.GetRandomBytes(4), 0);
            }
            IHasSerializationTag c    = new CreateAnonymousPipe(type.ToString(), id);
            PipeBase             pipe = null;

            switch (type)
            {
            case PipeType.Control:
                throw new NotSupportedException(
                          "Cannot create a new control pipe where on a tunnel that already has a control pipe");

            case PipeType.Duplex:
                pipe = new DuplexPipe(this.mTunnel, id);
                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }
            this.requestedPipes.Add(id, pipe);
            EncryptedPacket packet = new EncryptedPacket(this.mTunnel.ID, this.ID);

            packet.RPCs.Add(c);
            this.mTunnel.EncryptAndSendPacket(packet);
            return(pipe);
        }
Esempio n. 3
0
 //These are the events raised whenever a paticular request is made on the control pipe
 private void OnPipeCreated(PipeBase pipe)
 {
     if (this.NewPipe != null)
     {
         this.NewPipe(this, new PipeChangedEventArgs(pipe, this.mTunnel));
     }
 }
Esempio n. 4
0
        private void HandleOpenAnonymousPipeRequest(IHasSerializationTag rpc)
        {
            var c = (CreateAnonymousPipe)rpc;
            //handle the pipe type....
            PipeType ctype;

            if (Enum.TryParse(c.PipeType, out ctype))
            {
                //todo: how do we want to handle anonymous pipes? should we make a policy mechanisim?
                if (mTunnel.PipeIDExists(c.ID))
                {
                    RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.ID_ALREADY_EXISTS);
                }
                else if (c.ID == 0)
                {
                    RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.CANNOT_OPEN_ANOTHER_CONTROL);
                }
                else
                {
                    //create the pipe
                    PipeBase createdPipe = null;
                    switch (ctype)
                    {
                    case PipeType.Control:
                        RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.UNSUPPORTED_PIPE_TYPE);
                        break;

                    case PipeType.Duplex:
                        createdPipe = new DuplexPipe(mTunnel, c.ID);
                        mTunnel.OpenPipe(createdPipe);
                        OnPipeCreated(createdPipe);
                        break;

                    default:
                        RefusePipe(c.ID, Packet.RefusePipe.RefusalReason.UNSUPPORTED_PIPE_TYPE);
                        Debug.Fail("Unknown Pipe Type");
                        break;
                    }
                    if (createdPipe != null)
                    {
                        var packet = new EncryptedPacket(mTunnel.ID, ID);
                        packet.RPCs.Add(new AckPipe(createdPipe.ID));
                        mTunnel.EncryptAndSendPacket(packet);
                    }
                }
            }
            else
            {
                RefusePipe(c.ID, Tunneler.Packet.RefusePipe.RefusalReason.UNKNOWN);
            }
        }
Esempio n. 5
0
 public PipeChangedEventArgs(PipeBase pipe, TunnelBase tunnel)
 {
     this.Pipe   = pipe;
     this.Tunnel = tunnel;
 }