Exemple #1
0
        public void writeMessage(Message msg)
        {
            if (stopped)
            {
                throw InterruptedException();
            }

            EventLock     lk    = new EventLock(writeEvent);
            LevinProtocol proto = new LevinProtocol(connection);

            switch (msg.messageType)
            {
            case P2pContext.Message.NOTIFY:
                proto.sendMessage(new uint(msg.type), msg.data, false);
                break;

            case P2pContext.Message.REQUEST:
                proto.sendMessage(new uint(msg.type), msg.data, true);
                break;

            case P2pContext.Message.REPLY:
                proto.sendReply(new uint(msg.type), msg.data, new uint(msg.returnCode));
                break;
            }
        }
Exemple #2
0
        private void writeHandshake(P2pMessage message)
        {
            CORE_SYNC_DATA coreSync = new CORE_SYNC_DATA();

            LevinProtocol.decode(message.data, coreSync);

            if (m_context.isIncoming())
            {
                // response
                COMMAND_HANDSHAKE.response res = new COMMAND_HANDSHAKE.response();
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: res.node_data = m_node.getNodeData();
                res.node_data.CopyFrom(m_node.getNodeData());
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: res.payload_data = coreSync;
                res.payload_data.CopyFrom(coreSync);
                res.local_peerlist = new LinkedList <PeerlistEntry>(m_node.getLocalPeerList());
                m_context.writeMessage(makeReply(COMMAND_HANDSHAKE.ID, LevinProtocol.encode(res), GlobalMembers.LEVIN_PROTOCOL_RETCODE_SUCCESS));
                m_node.tryPing(m_context);
            }
            else
            {
                // request
                COMMAND_HANDSHAKE.request req = new COMMAND_HANDSHAKE.request();
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: req.node_data = m_node.getNodeData();
                req.node_data.CopyFrom(m_node.getNodeData());
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: req.payload_data = coreSync;
                req.payload_data.CopyFrom(coreSync);
                m_context.writeMessage(makeRequest(COMMAND_HANDSHAKE.ID, LevinProtocol.encode(req)));
            }
        }
Exemple #3
0
        private void handleHandshakeRequest(LevinProtocol.Command cmd)
        {
            COMMAND_HANDSHAKE.request req = new COMMAND_HANDSHAKE.request();
            if (!LevinProtocol.decode <COMMAND_HANDSHAKE.request>(cmd.buf, req))
            {
                throw new System.Exception("Failed to decode COMMAND_HANDSHAKE request");
            }

            m_node.handleNodeData(req.node_data, m_context);
            m_readQueue.Enqueue(new P2pMessage({ cmd.command, LevinProtocol.encode(req.payload_data) })); // enqueue payload info
Exemple #4
0
        public bool readCommand(LevinProtocol.Command cmd)
        {
            if (stopped)
            {
                throw InterruptedException();
            }

            EventLock lk     = new EventLock(readEvent);
            bool      result = new LevinProtocol(connection).readCommand(cmd);

            lastReadTime = Clock.now();
            return(result);
        }
Exemple #5
0
        public bool processIncomingHandshake()
        {
            LevinProtocol.Command cmd = new LevinProtocol.Command();
            if (!m_context.readCommand(cmd))
            {
                throw new System.Exception("Connection unexpectedly closed");
            }

            if (cmd.command == COMMAND_HANDSHAKE.ID)
            {
                handleHandshakeRequest(cmd);
                return(true);
            }

            if (cmd.command == COMMAND_PING.ID)
            {
                COMMAND_PING.response resp = new CryptoNote.COMMAND_PING.response(PING_OK_RESPONSE_STATUS_TEXT, m_node.getPeerId());
                m_context.writeMessage(makeReply(COMMAND_PING.ID, LevinProtocol.encode(resp), GlobalMembers.LEVIN_PROTOCOL_RETCODE_SUCCESS));
                return(false);
            }

            throw new System.Exception("Unexpected command: " + Convert.ToString(cmd.command));
        }