Start a server with startOpts
This commit is contained in:
parent
0e22ae09bd
commit
8c33392ff6
1 changed files with 22 additions and 11 deletions
|
@ -8,25 +8,36 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
port = flag.String("port", ":3000", "port the TCP listener will listen on.")
|
tcp = flag.Int("tcp", 3000, "port TCP listener will listen on.")
|
||||||
seed = flag.String("seed", "", "initial seed servers.")
|
seed = flag.String("seed", "", "initial seed servers.")
|
||||||
net = flag.Int("net", 56753, "the mode the server will operate in.")
|
net = flag.Int("net", 56753, "the mode the server will operate in.")
|
||||||
|
rpc = flag.Int("rpc", 0, "let this server also respond to rpc calls on this port")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Simple dirty and quick bootstrapping for the sake of development.
|
// Simple dirty and quick bootstrapping for the sake of development.
|
||||||
// e.g run 2 nodes:
|
// e.g run 2 nodes:
|
||||||
// neoserver -port :4000
|
// neoserver -tcp :4000
|
||||||
// neoserver -port :3000 -seed 127.0.0.1:4000
|
// neoserver -tcp :3000 -seed 127.0.0.1:4000
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
opts := network.StartOpts{
|
||||||
|
Seeds: parseSeeds(*seed),
|
||||||
|
TCP: *tcp,
|
||||||
|
RPC: *rpc,
|
||||||
|
}
|
||||||
|
|
||||||
s := network.NewServer(network.NetMode(*net))
|
s := network.NewServer(network.NetMode(*net))
|
||||||
seeds := strings.Split(*seed, ",")
|
s.Start(opts)
|
||||||
if len(seeds) == 0 {
|
}
|
||||||
seeds = []string{*seed}
|
|
||||||
}
|
func parseSeeds(s string) []string {
|
||||||
if *seed == "" {
|
if len(s) == 0 {
|
||||||
seeds = []string{}
|
return nil
|
||||||
}
|
}
|
||||||
s.Start(*port, seeds)
|
seeds := strings.Split(s, ",")
|
||||||
|
if len(seeds) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return seeds
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue