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.

73 lines
2.3KB

  1. //Author: Martins Eglitis
  2. package main
  3. import (
  4. "flag"
  5. "fmt"
  6. "github.com/sitilge/Peerster/helpers"
  7. "github.com/sitilge/Peerster/periodic"
  8. "github.com/sitilge/Peerster/transport"
  9. "log"
  10. "math/rand"
  11. "net/http"
  12. _ "net/http/pprof"
  13. "sync"
  14. "time"
  15. )
  16. func main() {
  17. clientIP := flag.String("UIIP", "127.0.0.1", "Client IP")
  18. clientPort := flag.String("UIPort", "8080", "Client port")
  19. gossipSocket := flag.String("gossipAddr", "127.0.0.1:5000", "Peerster socket (ip:port)")
  20. gossipName := flag.String("name", "Alpha", "Peerster name")
  21. gossipPeers := flag.String("peers", "", "Peerster peers (ip1:port1,ip2:port2,...)")
  22. gossipSimple := flag.Bool("simple", false, "Peerster simple mode")
  23. gossipPeriodStatus := flag.Int("statusPeriod", 1, "Peerster status period (seconds)")
  24. gossipPeriodEntropy := flag.Int("antiEntropy", 1, "Peerster entropy period (seconds)")
  25. gossipFilterIn := flag.Bool("filterIn", true, "Peerster filter incoming packets")
  26. gossipGroups := flag.String("groups", "", "Peerster groups (group1,group2,...")
  27. profileSocket := flag.String("profileAddr", "", "Peerster profile socket (ip:port)")
  28. profilePeriod := flag.Int("profilePeriod", 0, "Peerster profile period (milliseconds)")
  29. flag.Parse()
  30. if *profileSocket != "" {
  31. go func() {
  32. fmt.Println("Access the profiler at:", fmt.Sprintf("http://%s/debug/pprof", *profileSocket))
  33. err := http.ListenAndServe(*profileSocket, nil)
  34. if err != nil {
  35. log.Fatal(err)
  36. }
  37. }()
  38. }
  39. //parse the initial values
  40. helpers.ParsePeers(*gossipPeers)
  41. helpers.ParseGroups(*gossipGroups)
  42. helpers.ParsePeersterGroups(*gossipGroups)
  43. socketGossip, err := helpers.ParseSocket(*gossipSocket)
  44. if err != nil {
  45. fmt.Println(err)
  46. }
  47. connGossip := transport.ListenUDP(socketGossip.IP, socketGossip.Port)
  48. connClient := transport.ListenUDP(*clientIP, *clientPort)
  49. connWeb := transport.ListenTCP(connGossip, *clientIP, *clientPort, *gossipName, *gossipFilterIn)
  50. //Set a non-constant seed
  51. rand.Seed(time.Now().UnixNano())
  52. var wg sync.WaitGroup
  53. wg.Add(1)
  54. go periodic.Pulse(connGossip, *gossipName, *gossipPeriodStatus, *gossipPeriodEntropy, *profilePeriod)
  55. go transport.ServeUDP(true, connClient, connGossip, socketGossip, *gossipName, *gossipSimple, *gossipFilterIn)
  56. go transport.ServeUDP(false, connClient, connGossip, socketGossip, *gossipName, *gossipSimple, *gossipFilterIn)
  57. go transport.ServeTCP(connWeb)
  58. wg.Wait()
  59. }