Пример #1
0
func ping(args []string, c *client.Client) {
	host := ""
	if len(args) > 1 {
		log.Fatalf("Unknown args for ping: %v", args[1:])
	}
	if len(args) == 1 {
		var err error
		host, err = utils.ValidateAddr(args[0])
		if err != nil {
			log.Fatalf("%v", err)
		}
	}
	startTime := time.Now()

	log.Printf("Connection took %v", time.Since(startTime))
	value := make([]byte, 16)
	rand.Read(value)
	echoTime := time.Now()
	result, err := c.Echo(value, host)
	if err != nil {
		log.Fatalf("client.Echo failed: %v", err)
	}
	if !bytes.Equal(value, result) {
		log.Fatalf("Incorrect response from echo")
	}
	log.Printf("Reply took %v: %v", time.Since(echoTime), result)
	// milliseconds
	fmt.Printf("%f\n", float64(time.Since(startTime))/1000000)
}
Пример #2
0
func tunnelCreate(args []string, c *client.Client) {
	host := ""
	udp := false
	filtered := make([]string, 0)
	for _, arg := range args {
		if arg == "--udp" {
			udp = true
		} else {
			filtered = append(filtered, arg)
		}
	}
	args = filtered
	if len(args) > 1 {
		log.Fatalf("Too many args for tunnel-create: %v", args[1:])
	} else if len(args) == 0 {
		log.Fatalf("Argument host is required for tunnel-create")
	}
	host = args[0]
	var err error
	host, err = utils.ValidateAddr(args[0])
	if err != nil {
		log.Fatalf("%v", err)
	}

	src, dst, err := c.CreateTunnel(host, udp)
	if err != nil {
		log.Fatalf("client.CreateTunnel failed: %v", err)
	}
	fmt.Printf("%v %v\n", src, dst)
}
Пример #3
0
func segmentCreate(args []string, c *client.Client) {
	id, init, trig, err := parseSegment(args)
	if err != nil {
		log.Fatalf("Could not parse create: %v", err)
	}

	url, err := c.CreateSegment(id, init, trig)
	if err != nil {
		log.Fatalf("client.CreateSegment failed: %v", err)
	}
	fmt.Printf("%v %v\n", id, url)
}
Пример #4
0
func segmentDelete(args []string, c *client.Client) {
	id := ""
	if len(args) > 1 {
		log.Fatalf("Unknown args for delete: %v", args[1:])
	}
	if len(args) == 1 {
		id = args[0]
	} else {
		log.Fatalf("Argument id is required for delete")
	}

	err := c.DeleteSegment(id)
	if err != nil {
		log.Fatalf("client.DeleteSegment failed: %v", err)
	}
}
Пример #5
0
func tunnelDelete(args []string, c *client.Client) {
	host := ""
	if len(args) > 1 {
		log.Fatalf("Unknown args for tunnel-delete: %v", args[1:])
	}
	if len(args) == 1 {
		var err error
		host, err = utils.ValidateAddr(args[0])
		if err != nil {
			log.Fatalf("%v", err)
		}
	} else {
		log.Fatalf("Argument host is required for tunnel-delete")
	}

	err := c.DeleteTunnel(host)
	if err != nil {
		log.Fatalf("client.DeleteTunnel failed: %v", err)
	}
}