예제 #1
0
func main() {
	var help = flag.Bool("help", false, "print help")
	var addr = flag.String("addr", "", "address to dial")
	var method = flag.String("method", "", "rpc method")
	var parg = flag.String("arg", "", "method argument")
	flag.Parse()

	if *help || *addr == "" || *method == "" || *parg == "" {
		flag.PrintDefaults()
		return
	}

	client, err := util.JsonRpcDial(*addr)
	if err != nil {
		log.Fatal(err)
	}

	var arg interface{}
	if err := json.Unmarshal([]byte(*parg), &arg); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	var res interface{}
	if err := client.Call(*method, arg, &res); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	log.Printf("%+v\n", res)
}
예제 #2
0
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 {
		flag.PrintDefaults()
		return
	}

	srv := rpc.NewServer()
	srv.Register(&downloader.DownloaderServer{&downloader.Downloader{}})

	server := gjsonrpc.NewServer(srv)
	graceful.SetSighup(server)

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #3
0
파일: main.go 프로젝트: Monnoroch/psearch
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var cacheTime = flag.Int("cachetime", -1, "time to keep resolved records in cache (in seconds)")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 || *cacheTime == -1 {
		flag.PrintDefaults()
		return
	}

	srv := rpc.NewServer()
	srv.Register(&dns.ResolverServer{dns.NewResolver(time.Duration(*cacheTime) * time.Second)})
	log.Println(srv)

	server := gjsonrpc.NewServer(srv)
	graceful.SetSighup(server)

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #4
0
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var dir = flag.String("dir", "", "data directory")
	var maxFileSize = flag.Int("max-size", 10*1024*1024, "maximum file size")
	var maxTime = flag.Int("max-time", 1*60, "maximum time between sync calls (in seconds)")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 {
		flag.PrintDefaults()
		return
	}

	gk, err := gatekeeper.NewGatekeeper(*dir, uint64(*maxFileSize), time.Duration(*maxTime)*time.Second)
	if err != nil {
		log.Fatal(err)
	}

	srv := rpc.NewServer()
	srv.Register(&gatekeeper.GatekeeperServer{gk})

	server := gjsonrpc.NewServer(srv)
	graceful.SetSighup(server)

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #5
0
파일: main.go 프로젝트: Monnoroch/psearch
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var dlerArrd = flag.String("dl", "", "downloader address")
	var dnsAddr = flag.String("dns", "", "dns resolver address")
	var defaultMaxCount = flag.Int("maxcount", 1, "default maximum count urls for specific host to download at once")
	var defaultTimeout = flag.Int("timeout", 0, "default timeout between downloads for specific host (im ms)")
	var pullTimeout = flag.Int("pull-timeout", 100, "pull check timeout (im ms)")
	var workTimeout = flag.Int("work-timeout", 1000, "pull check timeout (im ms)")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 || *dlerArrd == "" {
		flag.PrintDefaults()
		return
	}

	ct, err := caregiver.NewCaregiver(
		*dlerArrd,
		*dnsAddr,
		uint(*defaultMaxCount),
		time.Duration(*defaultTimeout)*time.Millisecond,
		time.Duration(*pullTimeout)*time.Millisecond,
		time.Duration(*workTimeout)*time.Millisecond,
	)
	if err != nil {
		log.Fatal(err)
	}

	srv := rpc.NewServer()
	srv.Register(&caregiver.CaregiverServer{ct})

	server := gjsonrpc.NewServer(srv)
	graceful.SetSighup(server)

	go func() {
		for {
			if err := ct.Start(); err != nil {
				log.Errorln(err)
				time.Sleep(ct.WorkTimeout)
				continue
			}
			break
		}
	}()

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #6
0
파일: main.go 프로젝트: Monnoroch/psearch
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var gkArrd = flag.String("gatekeeper", "", "gatekeeper address")
	var cgAddr = flag.String("caregiver", "", "caregiver address")
	var vint = flag.Int("interval", 1, "sleep interval")
	var pushCnt = flag.Int("push-cnt", 10, "urls to push to the caregiver at a time")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 || *gkArrd == "" || *cgAddr == "" {
		flag.PrintDefaults()
		return
	}

	sp, err := spider.NewSpider(*gkArrd, *cgAddr, time.Duration(*vint)*time.Second, uint(*pushCnt))
	if err != nil {
		log.Fatal(err)
	}

	srv := rpc.NewServer()
	srv.Register(&spider.SpiderServer{sp})

	server := gjsonrpc.NewServer(srv)
	graceful.SetSighup(server)

	go func() {
		for {
			if err := sp.RunPusher(); err != nil {
				log.Errorln(err)
			}
		}
	}()

	go func() {
		for {
			if err := sp.RunPuller(); err != nil {
				log.Errorln(err)
			}
		}
	}()

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #7
0
파일: main.go 프로젝트: Monnoroch/psearch
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var rout = flag.String("rout", "random", "routing policy: random, roundrobin")
	var urls Urls
	flag.Var(&urls, "url", "backend url")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 || urls == nil {
		flag.PrintDefaults()
		return
	}

	router, err := balanser.NewChooser(*rout, urls)
	if err != nil {
		flag.PrintDefaults()
		return
	}

	balanser := bhttp.NewBalanser(router, urls)
	server := ghttp.NewServer(&http.Server{})

	// NOTE: for testing only, so browser wouldn't spam.
	http.HandleFunc("/favicon.ico", ghttp.CreateHandler(server, util.CreateErrorHandler(func(w http.ResponseWriter, r *http.Request) error {
		return nil
	})))

	http.HandleFunc("/", ghttp.CreateHandler(server, util.CreateErrorHandler(func(w http.ResponseWriter, r *http.Request) error {
		errs, err := balanser.Request(w, r)
		for _, e := range errs {
			log.Println(e)
		}
		return err
	})))

	graceful.SetSighup(server)

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}
예제 #8
0
파일: main.go 프로젝트: Monnoroch/psearch
func main() {
	var help = flag.Bool("help", false, "print help")
	var port = flag.Int("port", -1, "port to listen")
	var rout = flag.String("rout", "random", "routing policy: random, roundrobin")
	var urls Urls
	flag.Var(&urls, "url", "backend url")
	var gracefulRestart = graceful.SetFlag()
	flag.Parse()

	if *help || *port == -1 || urls == nil {
		flag.PrintDefaults()
		return
	}

	router, err := balanser.NewChooser(*rout, urls)
	if err != nil {
		flag.PrintDefaults()
		return
	}

	balanser := btcp.NewBalanser(router, urls)
	server := grpc.NewServer(rpc.NewServer(), func(srv *rpc.Server, conn io.ReadWriteCloser) {
		if err := balanser.Request(conn.(*net.TCPConn)); err != nil {
			log.Errorln(err)
		}
	})

	graceful.SetSighup(server)

	if err := server.ListenAndServe(":"+strconv.Itoa(*port), *gracefulRestart); err != nil {
		log.Fatal(errors.NewErr(err))
	}

	if err := graceful.Restart(server); err != nil {
		log.Fatal(err)
	}
}