Git Product home page Git Product logo

rpc-go's Introduction

Distributed Systems and Middleware Final Project

Innopolis University, Spring 2021

1. Description

This is a distributed game that uses peer-to-peer architecture. Each player is a peer.
The game uses Rock-Paper-Scissors-Lizard-Spock rules, originally described there.

2. How does it work

We use libp2p. What is Libp2p?
Good question! Libp2p is a set of protocols, and libraries, that allows to easily build peer-to-peer applications. In other words, it is a middleware for peer-to-peer systems.

libp2p peers are addressed with combination of unique PeerId and listening address, which is regular TCP address/port combination.

libp2p manages communication between peers. It provides a convenient publish-subscribe channel abstraction. We use gossip protocol to make messages reach all peers.

Games hold between peers in the same network. Peers can discover each other with mDNS. When a host starts, it creates a PubSub channel, that will be used for game. It will automatically receives new messages from the game topic.

2. Game process

When a peer wants to launch a new game, it publishes a special message into the PubSub topic. To start a game, all players who wants to participate should send a vote for starting game.

If all nodes voted for starting a game, game starts. Players who had not voted can be kicked.

When the game starts, each node should do following:

  • create a symmetric key
  • choose his move (Rock, Paper, etc.)
  • send message with encrypted move

After node receives moves from all other players, it sends the key to PubSub topic. If some node did not send move or key within a certain timeout, it can be kicked.

Kicking forbids player to take part in games in this GameRoom. Node can start voting for kicking other node by sending a special message to PubSub channel. Then all of the players can vote within a certain timeout. If majority votes. node will be ignored and no players will accept messages from it.

When node knows moves of all players, it performs topological sort to determine who won a game.

rpc-go's People

Contributors

i1i1 avatar mexator avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.