route/cmd/api/main.go

42 lines
692 B
Go
Raw Normal View History

2017-01-18 09:57:18 +00:00
package main
import (
"crypto/rand"
"crypto/rsa"
2017-01-22 18:20:33 +00:00
"flag"
2017-01-18 09:57:18 +00:00
"log"
"net/rpc"
"git.xeserv.us/xena/route/routerpc"
)
2017-01-22 18:20:33 +00:00
var (
addr = flag.String("addr", "127.0.0.1:9234", "RPC host to connect to")
)
2017-01-18 09:57:18 +00:00
func main() {
2017-01-22 18:20:33 +00:00
flag.Parse()
client, err := rpc.DialHTTP("tcp", *addr)
2017-01-18 09:57:18 +00:00
if err != nil {
log.Fatal(err)
}
pKey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
log.Fatal(err)
}
2017-01-18 09:57:18 +00:00
req := routerpc.AddHostRequest{
2017-01-18 17:01:52 +00:00
APIKey: "hunter2",
PrivKey: pKey,
2017-01-18 09:57:18 +00:00
}
resp := &routerpc.AddHostResponse{}
err = client.Call("Urls.AddHost", req, resp)
if err != nil {
log.Fatal(err)
}
2017-01-18 10:22:52 +00:00
log.Printf("Created host %s (%s) with token %s", resp.Hostname, resp.OnionHostname, resp.Token)
2017-01-18 09:57:18 +00:00
}