Beispiel #1
0
        private void onCallWebMethodRequest(PeerSocket sender, string msgCode, Guid msgId, string senderId, string receiverId, List<object> data)
        {
            object result = null;
            string methodName = data[0].ToString();

            logEvent(LogType.PeerRequest, "Peer " + senderId + " sent request: " + msgCode);
            logEvent(LogType.BlockWeb, "onCallMethodRequest - Name = " + methodName);

            try
            {
                //others are arguments
                switch (methodName)
                {
                    case "AddBlock": result = AddBlock((BlockHandle)data[1], (string)data[2]); break;
                    case "GetBlockId": result = getBlockId((string)data[1]); break;
                    case "DeleteBlock": DeleteBlock((string)data[1]); break;
                    case "ReloadBlocks": ReloadBlocks(); break;
                    case "Disconnect": Disconnect((string)data[1]); break;
                    case "Dispose": Dispose(); return;
                    case "GetBlockWebMetaInfo": result = GetBlockWebMetaInfo((BlockWebMetaInfoType)data[1], (string)data[2]); break;
                    case "Connect": result = Connect((string)data[1], (int)data[2], (string)data[3]); break;
                    case "BlockHandles": result = BlockIds; break;
                    case "BlockCount": result = BlockCount; break;
                    case "MigrateBlock":
                        {
                            //create given block and send migrate-done
                            string id = (string)data[0];
                            BlockHandle blockId = (BlockHandle)data[1];
                            object customData = data[2];

                            string response = AddBlock(blockId);
                            innerBlocks[response].OnAfterMigration(customData);

                            result = response;
                            break;
                        }
                }
            }
            catch (System.Exception exc)
            {
                logEvent(LogType.Exception, "Error Handling Call on Web Methods (" + methodName + "): " + exc.Message);
                throw;
            }

            sender.SendMessageAsync(msgCode, msgId, result);
        }
Beispiel #2
0
        private void onConnectRequestReceived(PeerSocket sender, string msgCode, Guid msgId, string senderId, string receiverId, List<object> data)
        {
            //step 1 - read the other-side address
            string otherHost = (string)data[0];
            int otherPort = (int)data[1];

            //we use these to store info
            string otherGatewayHost = (string) data[2];
            int otherGatewayPort = (int)data[3];

            logEvent("PM (" + gatewaySocket.ParentId + ") - Receive Connect Request - PeerAddress = " + otherHost+":"+otherPort.ToString() + ", PeerId = " + senderId);

            //step 2 - create a client peer socket and connect to that address
            PeerSocket myClientSocket = new PeerSocket(responseHandlers, gatewaySocket.ParentId, senderId, otherHost, otherPort);

            //step 3 - check if client is connected successfully
            if (!myClientSocket.IsConnected || (myClientSocket.PeerHost != otherHost) ||
                (myClientSocket.PeerPort != otherPort))
            {
                myClientSocket.Dispose();
                myClientSocket = null;

                return;
            }

            //step 4 - add this client socket to peers
            peers.Add(senderId, myClientSocket);
            peersExpireDates[senderId] = DateTime.Now.AddMilliseconds(PeerMsgDef.HeartbeatValidness);

            //step 5 - let sender know that I am connected
            sender.SendMessageAsync(msgCode, msgId, true);

            if (PeerConnected != null)
            {
                PeerConnected(senderId, true, otherGatewayHost, otherGatewayPort );
            }
        }
Beispiel #3
0
        private void onCallBlockMethodRequest(PeerSocket sender, string msgCode, Guid msgId, string senderId, string receiverId, List<object> data)
        {
            object result = null;
            string blockId = (string)data[0];
            string methodName = data[1].ToString();
            string serviceName = "";
            //object[] args = (object[])data[2];

            BlockHandle info = getBlockId(blockId);

            logEvent(LogType.PeerRequest, "Peer " + senderId + " sent request: " + msgCode);
            logEvent(LogType.ProcessRequest, "onCallBlockMethodRequest - Name = " + methodName + " ID=" + info.ToString());

            try
            {
                //others are arguments
                switch (methodName)
                {
                    case "ProcessRequest":
                        {
                            serviceName = data[2].ToString();
                            object[] args = (object[])data[3];

                            logEvent(LogType.ProcessRequest, "onCallBlockMethodRequest - Name = " + methodName + " ID=" + info.ToString() + " service=" + serviceName);

                            result = this[blockId].ProcessRequest(serviceName, args);

                            break;
                        }
                }
            }
            catch (System.Exception exc)
            {
                logEvent(LogType.Exception,"Error Handling Call on Block Service (" + methodName + ","+serviceName+"): " + exc.Message);
                throw;
            }

            sender.SendMessageAsync(msgCode, msgId, result);
        }