server: simplify host creation

This commit is contained in:
Cadey Ratio 2017-01-19 17:17:18 -08:00
parent ab9133c917
commit a6f507710b
2 changed files with 7 additions and 2 deletions

View File

@ -127,6 +127,9 @@ func (s *Server) onionPath(name string) string {
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.Header.Set("X-Forwarded-For", r.RemoteAddr)
r.Header.Set("X-Request-Ingress", time.Now().String())
if r.RequestURI == rpc.DefaultRPCPath {
s.rpcS.ServeHTTP(w, r)
return
@ -184,9 +187,10 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
token := uuid.New()
var pKey *rsa.PrivateKey
if kk, ok := req.PrivKey.(*rsa.PrivateKey); ok {
pKey = kk
} else {
return errors.New("there must be a 1024 bit RSA private key")
}
oi, err := rs.tor.AddOnion(pKey, 80, "127.0.0.1:"+rs.cfg.WebPort)
@ -196,6 +200,7 @@ func (rs *RPCServer) AddHost(req routerpc.AddHostRequest, resp *routerpc.AddHost
resp.OnionHostname = oi.OnionID + ".onion"
resp.Token = token
resp.PrivKey = pKey
if req.Hostname != "" {
rs.Server.ts.AddHost(req.Hostname, token)

View File

@ -76,5 +76,5 @@ func (t *Tor) AddOnion(pKey *rsa.PrivateKey, virtPort uint16, destination string
VirtPort: virtPort,
Target: destination,
},
}, pKey, false)
}, pKey, true)
}