route/cmd/api/main.go

42 lines
692 B
Go

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