Beispiel #1
0
        public RpcMessage(Socket socket, ByteArrayReference buffer, out UInt32 contentOffset, out UInt32 contentOffsetLimit)
            : base(memberSerializers)
        {
            //
            // TODO: catch socket exception to prevent server from failing
            //

            buffer.EnsureCapacityCopyAllData(12);
            socket.ReadFullSize(buffer.array, 0, 4); // read the size
            Int32 rpcMessageSize = (
                (0x7F000000 & (buffer.array[0] << 24)) |
                (0x00FF0000 & (buffer.array[1] << 16)) |
                (0x0000FF00 & (buffer.array[2] << 8)) |
                (0x000000FF & (buffer.array[3])));

            if ((buffer.array[0] & 0x80) != 0x80)
            {
                throw new NotImplementedException(String.Format("Records with multiple fragments it not currently implemented"));
            }

            buffer.EnsureCapacityCopyAllData((UInt32)rpcMessageSize);
            socket.ReadFullSize(buffer.array, 0, rpcMessageSize);

            //
            // Deserialize
            //
            contentOffsetLimit = (UInt32)rpcMessageSize;

            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StartSerialize();
            }
            contentOffset = Deserialize(buffer.array, 0, (UInt32)rpcMessageSize);
            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StopSerializationAndLog("RpcDeserializationTime");
            }
        }
Beispiel #2
0
        public void SendTcp(Socket socket, ByteArrayReference buffer, ISerializer messageContents)
        {
            UInt32 messageContentLength = (messageContents == null) ? 0 : messageContents.SerializationLength();
            UInt32 totalMessageLength   = SerializationLength() + messageContentLength;

            buffer.EnsureCapacityNoCopy(4 + totalMessageLength); // Extra 4 bytes for the record header

            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StartSerialize();
            }
            UInt32 offset = Serialize(buffer.array, 4);

            if (messageContents != null)
            {
                offset = messageContents.Serialize(buffer.array, offset);
            }
            if (RpcPerformanceLog.rpcMessageSerializationLogger != null)
            {
                RpcPerformanceLog.StopSerializationAndLog("RpcSerializationTime");
            }

            if (offset != totalMessageLength + 4)
            {
                throw new InvalidOperationException(String.Format("[CodeBug] The caclulated serialization length of RpcMessage '{0}' was {1} but actual size was {2}",
                                                                  DataStringBuilder.DataString(this, new StringBuilder()), totalMessageLength, offset));
            }

            //
            // Insert the record header
            //
            buffer.array[0] = (Byte)(0x80 | (totalMessageLength >> 24));
            buffer.array[1] = (Byte)(totalMessageLength >> 16);
            buffer.array[2] = (Byte)(totalMessageLength >> 8);
            buffer.array[3] = (Byte)(totalMessageLength);

            socket.Send(buffer.array, 0, (Int32)(totalMessageLength + 4), SocketFlags.None);
        }
Beispiel #3
0
        public T CallBlockingTcp <T>(UInt32 procedureNumber, ISerializer requestSerializer, IInstanceSerializer <T> responseSerializer, ByteArrayReference buffer)
        {
            UInt32 transmissionID = nextTransactionID++;

            RpcMessage callMessage = new RpcMessage(transmissionID, new RpcCall(programHeader,
                                                                                procedureNumber, credentials, verifier));

            callMessage.SendTcp(socket, buffer, requestSerializer);

            UInt32     contentOffset, contentOffsetLimit;
            RpcMessage replyMessage = new RpcMessage(socket, buffer, out contentOffset, out contentOffsetLimit);

            if (replyMessage.messageType != RpcMessageType.Reply)
            {
                throw new InvalidOperationException(String.Format("Received an Rpc call from '{0}' but expected an rpc reply", socket.RemoteEndPoint));
            }

            if (replyMessage.transmissionID != transmissionID)
            {
                throw new InvalidOperationException(String.Format("Expected reply with transmission id {0} but got {1}", transmissionID, replyMessage.transmissionID));
            }

            RpcReply reply = replyMessage.reply;

            RpcCallFailedException.VerifySuccessfulReply(callMessage.call, reply);

            T      instance;
            UInt32 offset = responseSerializer.Deserialize(buffer.array, contentOffset, contentOffsetLimit, out instance);

            if (offset != contentOffsetLimit)
            {
                StringBuilder dataBuidler = new StringBuilder();
                throw new InvalidOperationException(String.Format("Deserialization of rpc message '{0}' as the following '{1}' resulted in an offset of {2}, but the record had {3} bytes",
                                                                  DataStringBuilder.DataString(reply, dataBuidler), DataStringBuilder.DataString(responseSerializer, instance, dataBuidler), offset, contentOffsetLimit));
            }

            return(instance);
        }
Beispiel #4
0
 public RpcServerHandler(String serviceName, ByteArrayReference sendBuffer)
 {
     this.serviceName = serviceName;
     this.sendBuffer  = sendBuffer;
 }
        public void Run(TextWriter selectServerEventLog, IPEndPoint debugServerEndPoint, IPEndPoint npcServerEndPoint,
                        IPAddress listenIPAddress, Int32 backlog, SharedFileSystem sharedFileSystem,
                        Int32 portmapPort, Int32 mountPort, Int32 nfsPort, UInt32 readSizeMax, UInt32 suggestedReadSizeMultiple)
        {
            ByteArrayReference sendBuffer = new ByteArrayReference(4096);

            //
            // Create Mappings List
            //
            NamedMapping[] namedMappings = new NamedMapping[] {
                new NamedMapping(PortMap.Name, new Mapping(PortMap.ProgramNumber, PortMap2.ProgramVersion, PortMap.IPProtocolTcp, (UInt32)portmapPort)),
                new NamedMapping(PortMap.Name, new Mapping(PortMap.ProgramNumber, PortMap2.ProgramVersion, PortMap.IPProtocolUdp, (UInt32)portmapPort)),

                new NamedMapping(Mount.Name, new Mapping(Mount.ProgramNumber, Mount1.ProgramVersion, PortMap.IPProtocolTcp, (UInt32)mountPort)),
                new NamedMapping(Mount.Name, new Mapping(Mount.ProgramNumber, Mount1.ProgramVersion, PortMap.IPProtocolUdp, (UInt32)mountPort)),

                new NamedMapping(Mount.Name, new Mapping(Mount.ProgramNumber, Mount3.ProgramVersion, PortMap.IPProtocolTcp, (UInt32)mountPort)),
                new NamedMapping(Mount.Name, new Mapping(Mount.ProgramNumber, Mount3.ProgramVersion, PortMap.IPProtocolUdp, (UInt32)mountPort)),

                new NamedMapping(Nfs.Name, new Mapping(Nfs.ProgramNumber, Nfs3.ProgramVersion, PortMap.IPProtocolTcp, (UInt32)nfsPort)),
                new NamedMapping(Nfs.Name, new Mapping(Nfs.ProgramNumber, Nfs3.ProgramVersion, PortMap.IPProtocolUdp, (UInt32)nfsPort)),
            };

            PortMap2Server   portMapServer = new PortMap2Server(this, namedMappings, sendBuffer);
            Mount1And3Server mountServer   = new Mount1And3Server(this, sharedFileSystem, sendBuffer);
            Nfs3Server       nfsServer     = new Nfs3Server(this, sharedFileSystem, sendBuffer, readSizeMax, suggestedReadSizeMultiple);

            //
            // Create Endpoints
            //
            if (listenIPAddress == null)
            {
                listenIPAddress = IPAddress.Any;
            }
            IPEndPoint portMapEndPoint = new IPEndPoint(listenIPAddress, portmapPort);
            IPEndPoint mountEndPoint   = new IPEndPoint(listenIPAddress, mountPort);
            IPEndPoint nfsEndPoint     = new IPEndPoint(listenIPAddress, nfsPort);

            selectServer = new SelectServerSharedBuffer(false, new byte[4096]);

            AddRpcServer(selectServer, portMapEndPoint, portMapServer, backlog);
            AddRpcServer(selectServer, mountEndPoint, mountServer, backlog);
            AddRpcServer(selectServer, nfsEndPoint, nfsServer, backlog);

            if (debugServerEndPoint != null)
            {
                Socket tcpAcceptSocket = new Socket(debugServerEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                tcpAcceptSocket.Bind(debugServerEndPoint);
                tcpAcceptSocket.Listen(4);
                selectServer.AddListenSocket(tcpAcceptSocket, new ControlServer().AcceptCallback);
            }

            if (npcServerEndPoint != null)
            {
#if !WindowsCE
                /*
                 * NpcSelectServerHandler npcServerHandler;
                 * {
                 *  Nfs3Server.NfsServerManager nfsServerManager = new Nfs3Server.NfsServerManager(nfsServer);
                 *  NpcReflector reflector = new NpcReflector(
                 *      new NpcExecutionObject(nfsServerManager, "Nfs3ServerManager", null, null),
                 *      new NpcExecutionObject(nfsServer, "Nfs3Server", null, null),
                 *      new NpcExecutionObject(portMapServer, "Portmap2Server", null, null),
                 *      new NpcExecutionObject(mountServer, "Mount1And3Server", null, null)
                 *      );
                 *  npcServerHandler = new NpcSelectServerHandler(NpcCallback.Instance, reflector, new DefaultNpcHtmlGenerator("NfsServer", reflector));
                 * }
                 *
                 * Socket tcpAcceptSocket = new Socket(npcServerEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                 * tcpAcceptSocket.Bind(npcServerEndPoint);
                 * tcpAcceptSocket.Listen(4);
                 *
                 * selectServer.control.AddListenSocket(tcpAcceptSocket, npcServerHandler.AcceptCallback);
                 * */
#endif
            }

            this.serverStartTimeStopwatchTicks = Stopwatch.GetTimestamp();

            /*
             * selectServer.Run(selectServerEventLog, new byte[1024], tcpListeners.ToArray(),
             *  new UdpSelectListener[]{
             *      new UdpSelectListener(portMapEndPoint, portMapServer),
             *      new UdpSelectListener(mountEndPoint  , mountServer),
             *      new UdpSelectListener(nfsEndPoint    , nfsServer),
             *  }
             * );
             */
            selectServer.Run();
        }
Beispiel #6
0
 public PortMap2Server(RpcServicesManager servicesManager, NamedMapping[] namedMappings, ByteArrayReference sendBuffer)
     : base("PortMap2", sendBuffer)
 {
     this.servicesManager = servicesManager;
     this.namedMappings   = namedMappings;
 }
Beispiel #7
0
 public Nfs3Server(RpcServicesManager servicesManager, SharedFileSystem sharedFileSystem, ByteArrayReference sendBuffer,
                   UInt32 readSizeMax, UInt32 suggestedReadSizeMultiple)
     : base("Nfs3", sendBuffer)
 {
     this.servicesManager           = servicesManager;
     this.sharedFileSystem          = sharedFileSystem;
     this.fileContents.array        = new Byte[readSizeMax];
     this.suggestedReadSizeMultiple = suggestedReadSizeMultiple;
 }
 public Mount1And3Server(RpcServicesManager servicesManager, SharedFileSystem sharedFileSystem, ByteArrayReference sendBuffer)
     : base("Mount3", sendBuffer)
 {
     this.servicesManager  = servicesManager;
     this.sharedFileSystem = sharedFileSystem;
 }