Moonlight Routine
What would Moonlight Clients do (Needs reviewing)
Viewing Map of Available Nodes:
The user opens the modified Moonlight client on their device. The client sends a request to the DHT to fetch the latest list of available nodes, their status, and geolocation data. The client receives the data, processes it, and presents it to the user as a map or list.
Node Selection:
The user chooses a node on the map or list. The client sends a "pre-connection" request to the selected node to confirm its availability and readiness for a new connection.
Pre-connection Response:
The selected node receives the "pre-connection" request and verifies its status. If it's available and ready, it responds affirmatively; if not, it responds negatively, prompting the Moonlight client to inform the user about the unavailability of the selected node.
Transaction Initiation:
Assuming a positive pre-connection response, the Moonlight client communicates with the Solana blockchain to initiate a transaction. The transaction involves transferring USDC from the borrower's wallet to the lender's wallet.
Transaction Verification:
The Solana blockchain processes the transaction. Depending on the network's congestion and the transaction fee, this process may take some time. Once the transaction is confirmed, the Solana blockchain returns a transaction receipt.
Connection Request:
The Moonlight client sends a connection request to the selected node, including the transaction receipt as proof of payment.
Payment Verification:
The selected node, running the modified Sunshine application, verifies the payment receipt with the Solana blockchain. If the verification succeeds, the node proceeds to the next step; if it fails, it sends an error message back to the client.
Connection Establishment:
Upon successful verification, the Sunshine application starts the gaming server, sets up the necessary streaming protocols, and sends a connection acceptance response to the Moonlight client. The client then establishes a P2P connection with the server.
Gaming Session Start:
The Sunshine application starts the game and begins streaming video to the Moonlight client. Simultaneously, the Moonlight client starts sending user inputs to the Sunshine application.
Gaming Loop:
The gaming session continues until the user decides to terminate it or when the pre-paid gaming session time expires. During this loop, error handling mechanisms are in place to manage situations like network interruptions, high latency, and packet loss.
Session Termination:
When the session ends, both applications terminate their respective sides of the connection. The Sunshine application updates its status in the DHT to "available" and waits for new connection requests.
Initiating Connection Request:
Once a borrower selects a gaming server from the available lenders displayed on the Shaga-Moonlight application (a process facilitated by the DHT as we discussed earlier), a connection request is initiated. This request is typically constructed as a standard internet protocol (IP) packet that contains the borrower's IP address, the lender's IP address, and other necessary metadata.
Communication Protocol:
The connection between the borrower and lender would likely be established using a standard communication protocol such as Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). These protocols handle the sending and receiving of data packets over the internet. TCP is a connection-oriented protocol that guarantees the delivery of packets in the order they were sent. This could be useful for ensuring the integrity of game state updates or control inputs. UDP is a connectionless protocol that doesn't guarantee delivery or ordering, but has less overhead and can provide lower latency. This could be useful for streaming game video or audio data, where occasional lost packets are less problematic.
Secure Session Establishment:
To ensure the security of the connection, a secure session could be established using a protocol like Secure Sockets Layer (SSL) or Transport Layer Security (TLS). This would involve an initial handshake process, where the borrower and lender's applications negotiate encryption settings and authenticate each other.
Game Streaming:
After the secure connection is established, the modified Moonlight application on the borrower's device begins streaming the game from the lender's gaming PC. This involves the lender's PC encoding the game video and audio into a data stream, sending it over the established connection to the borrower's device, where it is decoded and displayed.
Control Input Transmission:
At the same time, control inputs from the borrower (e.g., mouse movements, button presses) are captured by the Moonlight application, encoded into data packets, and sent back to the lender's PC over the established connection. The lender's PC then interprets these inputs and updates the game state accordingly.
Connection Termination:
When the borrower finishes their gaming session, a disconnection message is sent to the lender's PC, and the connection is closed. This would typically involve sending a TCP FIN (finish) or RST (reset) packet to signal the end of the session.