You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

6 years ago
6 years ago
6 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. blockchainlib "./blockchainlib"
  7. p2plib "./p2plib"
  8. "github.com/fatih/color"
  9. )
  10. var tp p2plib.ThisPeer
  11. var blockchain blockchainlib.Blockchain
  12. func main() {
  13. if len(os.Args) < 3 {
  14. color.Red("need to call:")
  15. color.Red("./peer client 3001 3002")
  16. os.Exit(3)
  17. }
  18. color.Blue("Starting Peer")
  19. //read configuration file
  20. readConfig("config.json")
  21. //initialize blockchainlib
  22. //InitializeBlockchain(role, ip, port, restport, serverip, serverport)
  23. config.RESTPort = os.Args[3]
  24. tp := blockchain.InitializeBlockchain(os.Args[1], "127.0.0.1",
  25. os.Args[2], os.Args[3], config.ServerIP, config.ServerPort)
  26. if tp.RunningPeer.Role == "client" {
  27. color.Red("http://" + config.IP + ":" + config.ServerRESTPort)
  28. fmt.Println(blockchain.GenesisBlock)
  29. blockchain.ReconstructBlockchainFromBlock("http://"+config.IP+":"+config.ServerRESTPort, blockchain.GenesisBlock)
  30. }
  31. color.Blue("peer and blokcchain initialized")
  32. go runRestServer() //TODO this will not be necessary, due the communications will go full over tcp connections
  33. for tp.Running {
  34. time.Sleep(1000 * time.Millisecond)
  35. }
  36. }