/p2p-auction

Primary LanguageJavaScript

Peer to Peer auction challenge by jose

Hello dear team!

I got to complete all the required features with some caveats:

  • The logs deffer a lot, sorry I ran out of time
  • I couldn't figure out the correct way to discover all the peers only by using @hyperswarm/rpc so I used a normal hyperswarm with a harcoded topic. SORRY
  • Some times, some peers don't connect to the swarm I still have to debug.
  • Some times when you ctr + c any peer, the other peers get a disconnection error that I still have to debug.
  • The sell_orders database is currently initialized by server.mjs. IMO there should be a configuration step before starting server.mjs and client.mjs that takes care of initializing the requried databases.
  • I wouldd also loved to have time to refactor the code so that the access to the database is easier for follow, right now to make it easier to read I left everything in server.mjs there is no db access in client.mjs
  • NOTE: I would love to know the best way to share the swarm topic with all the peers, right now I have hardcoded it.

In this document

How to run it

# in the root of the project run
npm install
# create the bootstrap node with:
hyperdht --bootstrap --host 127.0.0.1 --port 30001
# start one peer per terminal session, MAKE SURE TO PASS THE NAME: it is important because that is how I create a db folder for each peer
# npm start <peer-name>
npm start alice
# the app will capture the stdin and interpret commands everytime you hit enter
## Available commands
# A health check for the own server
ping

# A sell product command
sell:<prod>:<initial-price>

# A bid command
# <peer-pub-key> is logged after running 
# > npm start alice
bid:<prod>:<bid-price>:<peer-pub-key>

# A terminate sell command
terminate:<prod>

Part of the challenge TODOs

  • Peer Client: create sell command
  • Peer Client/Server: notify other parties about the new auction
  • Peer Server: create bid command
  • Peer Server: propagate/notify other parties about the new bid
  • Peer Client: create terminate sell command
  • Peer Client: propagate/notify other parties about the termination of the sell_order
  • Peer Server: propagate auction status

Good To Have TODOs

  • Get client example running
  • Get server example running
  • Modify server and client to accept peerName
  • Modify Server and Client to destroy rpc and dht when process finishes
  • Use peer public key to make RPC calls
  • OPTIONAL rpc call to get peer prefered name (peer-name) to improve UX
  • Show a prompt when peer disconets
  • Peer Server: fail bid if sell_order is terminated
  • Peer Server: fail bid if the price is not bigger than current

Demo