Beispiel #1
0
            protected internal override void HandleInternal(ChannelHandlerContext ctx, RpcInfo
                                                            info)
            {
                // This is just like what's done in RpcProgramMountd#handleInternal and
                // RpcProgramNfs3#handleInternal.
                RpcCall rpcCall   = (RpcCall)info.Header();
                int     procedure = rpcCall.GetProcedure();

                if (procedure != 0)
                {
                    bool portMonitorSuccess = DoPortMonitoring(info.RemoteAddress());
                    if (!portMonitorSuccess)
                    {
                        SendRejectedReply(rpcCall, info.RemoteAddress(), ctx);
                        return;
                    }
                }
                resultSize = info.Data().ReadableBytes();
                RpcAcceptedReply reply = RpcAcceptedReply.GetAcceptInstance(1234, new VerifierNone
                                                                                ());
                XDR @out = new XDR();

                reply.Write(@out);
                ChannelBuffer b   = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
                RpcResponse   rsp = new RpcResponse(b, info.RemoteAddress());

                RpcUtil.SendRpcResponse(ctx, rsp);
            }
Beispiel #2
0
            /// <exception cref="System.Exception"/>
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                RpcResponse r = (RpcResponse)e.GetMessage();

                byte[]        fragmentHeader = XDR.RecordMark(r.Data().ReadableBytes(), true);
                ChannelBuffer header         = ChannelBuffers.WrappedBuffer(fragmentHeader);
                ChannelBuffer d = ChannelBuffers.WrappedBuffer(header, r.Data());

                e.GetChannel().Write(d);
            }
Beispiel #3
0
        protected internal static void SendRejectedReply(RpcCall call, EndPoint remoteAddress
                                                         , ChannelHandlerContext ctx)
        {
            XDR            @out  = new XDR();
            RpcDeniedReply reply = new RpcDeniedReply(call.GetXid(), RpcReply.ReplyState.MsgDenied
                                                      , RpcDeniedReply.RejectState.AuthError, new VerifierNone());

            reply.Write(@out);
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, remoteAddress);

            RpcUtil.SendRpcResponse(ctx, rsp);
        }
Beispiel #4
0
			/// <exception cref="System.IO.IOException"/>
			protected internal virtual ChannelFuture SendMapOutput(ChannelHandlerContext ctx, 
				Org.Jboss.Netty.Channel.Channel ch, string user, string mapId, int reduce, ShuffleHandler.Shuffle.MapOutputInfo
				 mapOutputInfo)
			{
				IndexRecord info = mapOutputInfo.indexRecord;
				ShuffleHeader header = new ShuffleHeader(mapId, info.partLength, info.rawLength, 
					reduce);
				DataOutputBuffer dob = new DataOutputBuffer();
				header.Write(dob);
				ch.Write(ChannelBuffers.WrappedBuffer(dob.GetData(), 0, dob.GetLength()));
				FilePath spillfile = new FilePath(mapOutputInfo.mapOutputFileName.ToString());
				RandomAccessFile spill;
				try
				{
					spill = SecureIOUtils.OpenForRandomRead(spillfile, "r", user, null);
				}
				catch (FileNotFoundException)
				{
					ShuffleHandler.Log.Info(spillfile + " not found");
					return null;
				}
				ChannelFuture writeFuture;
				if (ch.GetPipeline().Get<SslHandler>() == null)
				{
					FadvisedFileRegion partition = new FadvisedFileRegion(spill, info.startOffset, info
						.partLength, this._enclosing.manageOsCache, this._enclosing.readaheadLength, this
						._enclosing.readaheadPool, spillfile.GetAbsolutePath(), this._enclosing.shuffleBufferSize
						, this._enclosing.shuffleTransferToAllowed);
					writeFuture = ch.Write(partition);
					writeFuture.AddListener(new _ChannelFutureListener_1135(partition));
				}
				else
				{
					// TODO error handling; distinguish IO/connection failures,
					//      attribute to appropriate spill output
					// HTTPS cannot be done with zero copy.
					FadvisedChunkedFile chunk = new FadvisedChunkedFile(spill, info.startOffset, info
						.partLength, this._enclosing.sslFileBufferSize, this._enclosing.manageOsCache, this
						._enclosing.readaheadLength, this._enclosing.readaheadPool, spillfile.GetAbsolutePath
						());
					writeFuture = ch.Write(chunk);
				}
				this._enclosing.metrics.shuffleConnections.Incr();
				this._enclosing.metrics.shuffleOutputBytes.Incr(info.partLength);
				// optimistic
				return writeFuture;
			}
Beispiel #5
0
        private void SendAcceptedReply(RpcCall call, EndPoint remoteAddress, RpcAcceptedReply.AcceptState
                                       acceptState, ChannelHandlerContext ctx)
        {
            RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(call.GetXid(), acceptState,
                                                                  Verifier.VerifierNone);
            XDR @out = new XDR();

            reply.Write(@out);
            if (acceptState == RpcAcceptedReply.AcceptState.ProgMismatch)
            {
                @out.WriteInt(lowProgVersion);
                @out.WriteInt(highProgVersion);
            }
            ChannelBuffer b   = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(b, remoteAddress);

            RpcUtil.SendRpcResponse(ctx, rsp);
        }
Beispiel #6
0
            protected override object Decode(ChannelHandlerContext ctx, Org.Jboss.Netty.Channel.Channel
                                             channel, ChannelBuffer buf)
            {
                if (buf.ReadableBytes() < 4)
                {
                    return(null);
                }
                buf.MarkReaderIndex();
                byte[] fragmentHeader = new byte[4];
                buf.ReadBytes(fragmentHeader);
                int  length = XDR.FragmentSize(fragmentHeader);
                bool isLast = XDR.IsLastFragment(fragmentHeader);

                if (buf.ReadableBytes() < length)
                {
                    buf.ResetReaderIndex();
                    return(null);
                }
                ChannelBuffer newFragment = buf.ReadSlice(length);

                if (currentFrame == null)
                {
                    currentFrame = newFragment;
                }
                else
                {
                    currentFrame = ChannelBuffers.WrappedBuffer(currentFrame, newFragment);
                }
                if (isLast)
                {
                    ChannelBuffer completeFrame = currentFrame;
                    currentFrame = null;
                    return(completeFrame);
                }
                else
                {
                    return(null);
                }
            }
Beispiel #7
0
            /// <exception cref="System.Exception"/>
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                ChannelBuffer buf  = (ChannelBuffer)e.GetMessage();
                ByteBuffer    b    = buf.ToByteBuffer().AsReadOnlyBuffer();
                XDR           @in  = new XDR(b, XDR.State.Reading);
                RpcInfo       info = null;

                try
                {
                    RpcCall       callHeader = RpcCall.Read(@in);
                    ChannelBuffer dataBuffer = ChannelBuffers.WrappedBuffer(@in.Buffer().Slice());
                    info = new RpcInfo(callHeader, dataBuffer, ctx, e.GetChannel(), e.GetRemoteAddress
                                           ());
                }
                catch (Exception)
                {
                    Log.Info("Malformed RPC request from " + e.GetRemoteAddress());
                }
                if (info != null)
                {
                    Channels.FireMessageReceived(ctx, info);
                }
            }
Beispiel #8
0
        protected override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info)
        {
            RpcCall rpcCall = (RpcCall)info.Header();

            MountInterface.MNTPROC mntproc = MountInterface.MNTPROC.FromValue(rpcCall.GetProcedure
                                                                                  ());
            int xid = rpcCall.GetXid();

            byte[] data = new byte[info.Data().ReadableBytes()];
            info.Data().ReadBytes(data);
            XDR       xdr    = new XDR(data);
            XDR       @out   = new XDR();
            IPAddress client = ((IPEndPoint)info.RemoteAddress()).Address;

            if (mntproc == MountInterface.MNTPROC.Null)
            {
                @out = NullOp(@out, xid, client);
            }
            else
            {
                if (mntproc == MountInterface.MNTPROC.Mnt)
                {
                    // Only do port monitoring for MNT
                    if (!DoPortMonitoring(info.RemoteAddress()))
                    {
                        @out = MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null);
                    }
                    else
                    {
                        @out = Mnt(xdr, @out, xid, client);
                    }
                }
                else
                {
                    if (mntproc == MountInterface.MNTPROC.Dump)
                    {
                        @out = Dump(@out, xid, client);
                    }
                    else
                    {
                        if (mntproc == MountInterface.MNTPROC.Umnt)
                        {
                            @out = Umnt(xdr, @out, xid, client);
                        }
                        else
                        {
                            if (mntproc == MountInterface.MNTPROC.Umntall)
                            {
                                Umntall(@out, xid, client);
                            }
                            else
                            {
                                if (mntproc == MountInterface.MNTPROC.Export)
                                {
                                    // Currently only support one NFS export
                                    IList <NfsExports> hostsMatchers = new AList <NfsExports>();
                                    if (hostsMatcher != null)
                                    {
                                        hostsMatchers.AddItem(hostsMatcher);
                                        @out = MountResponse.WriteExportList(@out, xid, exports, hostsMatchers);
                                    }
                                    else
                                    {
                                        // This means there are no valid exports provided.
                                        RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                         ()).Write(@out);
                                    }
                                }
                                else
                                {
                                    // Invalid procedure
                                    RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone
                                                                     ()).Write(@out);
                                }
                            }
                        }
                    }
                }
            }
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, info.RemoteAddress());

            RpcUtil.SendRpcResponse(ctx, rsp);
        }
Beispiel #9
0
        /// <exception cref="System.Exception"/>
        public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
        {
            RpcInfo info        = (RpcInfo)e.GetMessage();
            RpcCall rpcCall     = (RpcCall)info.Header();
            int     portmapProc = rpcCall.GetProcedure();
            int     xid         = rpcCall.GetXid();
            XDR     @in         = new XDR(info.Data().ToByteBuffer().AsReadOnlyBuffer(), XDR.State.Reading
                                          );
            XDR @out = new XDR();

            if (portmapProc == PmapprocNull)
            {
                @out = NullOp(xid, @in, @out);
            }
            else
            {
                if (portmapProc == PmapprocSet)
                {
                    @out = Set(xid, @in, @out);
                }
                else
                {
                    if (portmapProc == PmapprocUnset)
                    {
                        @out = Unset(xid, @in, @out);
                    }
                    else
                    {
                        if (portmapProc == PmapprocDump)
                        {
                            @out = Dump(xid, @in, @out);
                        }
                        else
                        {
                            if (portmapProc == PmapprocGetport)
                            {
                                @out = Getport(xid, @in, @out);
                            }
                            else
                            {
                                if (portmapProc == PmapprocGetversaddr)
                                {
                                    @out = Getport(xid, @in, @out);
                                }
                                else
                                {
                                    Log.Info("PortmapHandler unknown rpc procedure=" + portmapProc);
                                    RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState
                                                                                          .ProcUnavail, new VerifierNone());
                                    reply.Write(@out);
                                }
                            }
                        }
                    }
                }
            }
            ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer());
            RpcResponse   rsp = new RpcResponse(buf, info.RemoteAddress());

            RpcUtil.SendRpcResponse(ctx, rsp);
        }